Java Code Examples for com.google.android.vending.expansion.downloader.Helpers#isExternalMediaMounted()

The following examples show how to use com.google.android.vending.expansion.downloader.Helpers#isExternalMediaMounted() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example 2
Source File: DownloaderService.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example 3
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example 4
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example 5
Source File: DownloadThread.java    From QtAndroidTools with MIT License 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 *
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example 6
Source File: DownloadThread.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 *
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example 7
Source File: DownloadThread.java    From travelguide with Apache License 2.0 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 * 
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example 8
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 * 
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example 9
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 *
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}