Example usage for com.google.api.client.googleapis.media MediaHttpUploader DEFAULT_CHUNK_SIZE

List of usage examples for com.google.api.client.googleapis.media MediaHttpUploader DEFAULT_CHUNK_SIZE

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.media MediaHttpUploader DEFAULT_CHUNK_SIZE.

Prototype

int DEFAULT_CHUNK_SIZE

To view the source code for com.google.api.client.googleapis.media MediaHttpUploader DEFAULT_CHUNK_SIZE.

Click Source Link

Document

Default maximum number of bytes that will be uploaded to the server in any single HTTP request (set to 10 MB).

Usage

From source file:org.mrpdaemon.android.encdroid.GoogleDriveOutputStream.java

License:Open Source License

public GoogleDriveOutputStream(final GoogleDriveFileProvider fileProvider, final String dstPath,
        final long length) throws IOException {
    this.failed = false;

    Log.d(TAG, "Creating output stream for path " + dstPath);

    // Create pipes
    pipeDrive = new PipedInputStream();
    pipeToWrite = new PipedOutputStream(pipeDrive);

    // Delete file touched by encfs-java
    if (fileProvider.exists(dstPath)) {
        fileProvider.delete(dstPath);//from  w w w  . ja v a  2  s . c  o m
    }

    final File newFile = fileProvider.prepareFileForCreation(dstPath);

    thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                InputStreamContent streamContent = new InputStreamContent("application/octet-stream",
                        pipeDrive);
                streamContent.setLength(length);

                Drive.Files.Insert insert = fileProvider.getDriveService().files().insert(newFile,
                        streamContent);

                // Use resumable upload to not time out for larger files
                MediaHttpUploader uploader = insert.getMediaHttpUploader();
                uploader.setDirectUploadEnabled(false);
                uploader.setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE);

                insert.execute();

            } catch (IOException e) {
                if (e.getMessage() != null) {
                    GoogleDriveOutputStream.this.fail(e.getMessage());
                } else {
                    GoogleDriveOutputStream.this.fail(e.toString());
                }
            }
        }
    });

    thread.start();
}