// Path: AndroidApp/src/ca/psiphon/ploggy/Utils.java
// public static class ApplicationError extends Exception {
//     private static final long serialVersionUID = -3656367025650685613L;
// 
//     public ApplicationError(String tag, String message) {
//         if (tag != null) {
//             Log.addEntry(tag, message);
//         }
//     }
// 
//     public ApplicationError(String tag, Exception e) {
//         // TODO: require message param as well?
//         super(e);
//         String message = e.getLocalizedMessage();
//         if (message == null) {
//             message = "(null)";
//         }
//         Log.addEntry(tag, String.format("%s: %s", e.getClass().toString(), message));
//         // TODO: log stack trace?
//     }
// }


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.content.Context;
import ca.psiphon.ploggy.Utils.ApplicationError;
/*
 * Copyright (c) 2013, Psiphon Inc.
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package ca.psiphon.ploggy;



/**
 * Helpers for managing download files
 */
public class Downloads {

    private static final String LOG_TAG = "Downloads";

    private static final String DOWNLOAD_FILENAME_FORMAT_STRING = "%s-%s.download";
    private static final String DOWNLOADS_DIRECTORY = "ploggyDownloads";

    public static long getDownloadedSize(Data.Download download) {
        return getDownloadFile(download).length();
    }

// Path: AndroidApp/src/ca/psiphon/ploggy/Utils.java
// public static class ApplicationError extends Exception {
//     private static final long serialVersionUID = -3656367025650685613L;
// 
//     public ApplicationError(String tag, String message) {
//         if (tag != null) {
//             Log.addEntry(tag, message);
//         }
//     }
// 
//     public ApplicationError(String tag, Exception e) {
//         // TODO: require message param as well?
//         super(e);
//         String message = e.getLocalizedMessage();
//         if (message == null) {
//             message = "(null)";
//         }
//         Log.addEntry(tag, String.format("%s: %s", e.getClass().toString(), message));
//         // TODO: log stack trace?
//     }
// }


// Path: AndroidApp/src/ca/psiphon/ploggy/Downloads.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.content.Context;
import ca.psiphon.ploggy.Utils.ApplicationError;

/*
 * Copyright (c) 2013, Psiphon Inc.
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package ca.psiphon.ploggy;



/**
 * Helpers for managing download files
 */
public class Downloads {

    private static final String LOG_TAG = "Downloads";

    private static final String DOWNLOAD_FILENAME_FORMAT_STRING = "%s-%s.download";
    private static final String DOWNLOADS_DIRECTORY = "ploggyDownloads";

    public static long getDownloadedSize(Data.Download download) {
        return getDownloadFile(download).length();
    }

    public static OutputStream openDownloadResourceForAppending(Data.Download download) throws ApplicationError {