com.google.api.client.http.ByteArrayContent

Here are the examples of the java api class com.google.api.client.http.ByteArrayContent taken from open source projects.

1. MediaHttpUploaderTest#testDirectUploadServerErrorWithBackOffEnabled()

View license
public void testDirectUploadServerErrorWithBackOffEnabled() throws Exception {
    int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 2;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    fakeTransport.testServerError = true;
    fakeTransport.directUploadEnabled = true;
    ByteArrayContent mediaContent = new ByteArrayContent(TEST_CONTENT_TYPE, new byte[contentLength]);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, new ZeroBackOffRequestInitializer());
    uploader.setDirectUploadEnabled(true);
    uploader.upload(new GenericUrl(TEST_DIRECT_REQUEST_URL));
    // should be 2 calls made: 1 upload request with server error, 1 successful upload request
    assertEquals(2, fakeTransport.lowLevelExecCalls);
}

2. MediaHttpUploaderTest#testDirectUploadServerErrorWithBackOffDisabled()

View license
public void testDirectUploadServerErrorWithBackOffDisabled() throws Exception {
    int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 2;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    fakeTransport.testServerError = true;
    fakeTransport.directUploadEnabled = true;
    ByteArrayContent mediaContent = new ByteArrayContent(TEST_CONTENT_TYPE, new byte[contentLength]);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.setDirectUploadEnabled(true);
    uploader.upload(new GenericUrl(TEST_DIRECT_REQUEST_URL));
    // should be 1 call made: 1 upload request with server error
    assertEquals(1, fakeTransport.lowLevelExecCalls);
}

3. MediaHttpUploaderTest#testDirectMediaUploadWithZeroContent()

View license
public void testDirectMediaUploadWithZeroContent() throws Exception {
    int contentLength = 0;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    fakeTransport.directUploadEnabled = true;
    ByteArrayContent mediaContent = new ByteArrayContent(TEST_CONTENT_TYPE, new byte[contentLength]);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.setDirectUploadEnabled(true);
    uploader.upload(new GenericUrl(TEST_DIRECT_REQUEST_URL));
    // There should be only 1 call made for direct media upload.
    assertEquals(1, fakeTransport.lowLevelExecCalls);
}

4. DriveTask#insertPreferencesFile()

View license
/**
   * Inserts preferences file into the appdata folder.
   * @param content The application context.
   * @return Inserted file.
   * @throws IOException
   */
public File insertPreferencesFile(String content) throws IOException {
    File metadata = new File();
    metadata.setTitle(FILE_NAME);
    metadata.setParents(Arrays.asList(new ParentReference().setId("appdata")));
    ByteArrayContent c = ByteArrayContent.fromString(FILE_MIME_TYPE, content);
    return mDriveService.files().insert(metadata, c).execute();
}

5. DriveTask#updatePreferencesFile()

View license
/**
   * Updates the preferences file with content.
   * @param file File metadata.
   * @param content File content in JSON.
   * @return Updated file.
   * @throws IOException
   */
public File updatePreferencesFile(File file, String content) throws IOException {
    ByteArrayContent c = ByteArrayContent.fromString(FILE_MIME_TYPE, content);
    return mDriveService.files().update(file.getId(), file, c).execute();
}

6. MediaHttpUploaderTest#testResumableMediaUploadWithZeroContent()

View license
public void testResumableMediaUploadWithZeroContent() throws Exception {
    int contentLength = 0;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    ByteArrayContent mediaContent = new ByteArrayContent(TEST_CONTENT_TYPE, new byte[contentLength]);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));
    // There should be 2 calls made. 1 initiation request and 1 upload request.
    assertEquals(2, fakeTransport.lowLevelExecCalls);
}