文件大于2 GB的InputStream

时间:2018-04-25 09:15:46

标签: java android inputstream

我正在尝试将文件发送到服务器。我得到一个Uri,用inputstream获得getContentResolver().openInputStream(uri),然后继续读取文件的块并通过多个部分将它们发送到服务器。

一切正常,直到我尝试发送的文件大于2GB。当文件超过该值时,该过程正常工作直到~2gb,然后调用.read()的结果为-1,即使该文件远未完全读取。

搜索网络后,我发现inputstream次读取仅限于Integer.MAX_VALUE。但我没有找到解决办法。所以我想我的问题是,是否有一些方法可以让我阅读过2gb?

以下是提到的代码:

InputStream is = getContentResolver().openInputStream(fileUri);

if (is != null) {

    byte[] buffer;
    int maxBufferSize = AppController.UPLOAD_CHUNK_SIZE;
    buffer = new byte[maxBufferSize];

    int fileChunk = 0;
    int read;

    while ((read = is.read(buffer)) != -1) {

        boolean didSend = sendMultipartChunk(upFile, fileChunk, buffer);
        if (didSend) {
            fileChunk++;
        } else {
            uploadedFiles.add(new UploadableFileDTO(true));
            checkIfFinished();
            break;
            }


    }
    is.close();
    sendEndUpload(upFile);

0 个答案:

没有答案
相关问题