当前位置: 首页>>代码示例>>Java>>正文


Java Helpers.getAvailableBytes方法代码示例

本文整理汇总了Java中com.google.android.vending.expansion.downloader.Helpers.getAvailableBytes方法的典型用法代码示例。如果您正苦于以下问题:Java Helpers.getAvailableBytes方法的具体用法?Java Helpers.getAvailableBytes怎么用?Java Helpers.getAvailableBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.vending.expansion.downloader.Helpers的用法示例。


在下文中一共展示了Helpers.getAvailableBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateSaveFile

import com.google.android.vending.expansion.downloader.Helpers; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:26,代码来源:DownloaderService.java

示例2: writeDataToDestination

import com.google.android.vending.expansion.downloader.Helpers; //导入方法依赖的package包/类
/**
 * 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);
        }
    }
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:35,代码来源:DownloadThread.java

示例3: writeDataToDestination

import com.google.android.vending.expansion.downloader.Helpers; //导入方法依赖的package包/类
/**
 * 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);
        }
    }
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:35,代码来源:DownloadThread.java


注:本文中的com.google.android.vending.expansion.downloader.Helpers.getAvailableBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。