Package com.google.api.client.http

Examples of com.google.api.client.http.InputStreamContent


   * @param bytesWritten The number of bytes that have been successfully uploaded on the server
   */
  private void setContentAndHeadersOnCurrentRequest(long bytesWritten) throws IOException {
    int blockSize = (int) Math.min(chunkSize, getMediaContentLength() - bytesWritten);
    // TODO(rmistry): Add tests for LimitInputStream.
    InputStreamContent contentChunk =
        new InputStreamContent(mediaContent.getType(),
          new LimitInputStream(contentInputStream, blockSize));
    contentChunk.setCloseInputStream(false);
    contentChunk.setRetrySupported(true);
    contentChunk.setLength(blockSize);
    // Mark the current position in case we need to retry the request.
    contentInputStream.mark(blockSize);
    currentRequest.setContent(contentChunk);
    currentRequest.getHeaders().setContentRange("bytes " + bytesWritten + "-"
        + (bytesWritten + blockSize - 1) + "/" + getMediaContentLength());
View Full Code Here


    MediaTransport transport = new MediaTransport();
    AbstractGoogleClient client = new MockGoogleClient.Builder(
        transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER, null).setApplicationName(
        "Test Application").build();
    InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    mediaContent.setLength(MediaHttpUploader.DEFAULT_CHUNK_SIZE);
    MockGoogleClientRequest<A> rq =
        new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
    rq.initializeMediaUpload(mediaContent);
    A result = rq.execute();
    assertEquals("somevalue", result.foo);
View Full Code Here

    transport.contentLengthNotSpecified = true;
    AbstractGoogleClient client = new MockGoogleClient.Builder(
        transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER,
        new GZipCheckerInitializer(true)).setApplicationName("Test Application").build();
    InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    MockGoogleClientRequest<A> rq =
        new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
    rq.initializeMediaUpload(mediaContent);
    rq.setDisableGZipContent(true);
    A result = rq.execute();
View Full Code Here

    transport.contentLengthNotSpecified = true;
    AbstractGoogleClient client = new MockGoogleClient.Builder(
        transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER,
        new GZipCheckerInitializer(false)).setApplicationName("Test Application").build();
    InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    MockGoogleClientRequest<A> rq =
        new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
    rq.initializeMediaUpload(mediaContent);
    rq.setDisableGZipContent(false);
    A result = rq.execute();
View Full Code Here

    transport.contentLengthNotSpecified = true;
    AbstractGoogleClient client = new MockGoogleClient.Builder(
        transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER,
        new GZipCheckerInitializer(false)).setApplicationName("Test Application").build();
    InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    MockGoogleClientRequest<A> rq =
        new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
    rq.initializeMediaUpload(mediaContent);
    A result = rq.execute();
    assertEquals("somevalue", result.foo);
View Full Code Here

  public void testUploadMultipleCalls_WithSpecifiedHeader() throws Exception {
    int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 5;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    fakeTransport.assertTestHeaders = true;
    InputStream is = new ByteArrayInputStream(new byte[contentLength]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    mediaContent.setLength(contentLength);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.getInitiationHeaders().set("test-header-name", "test-header-value");
    uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));

    // There should be 6 calls made. 1 initiation request and 5 upload requests.
View Full Code Here

  public void testUploadMultipleCalls_WithNoContentSizeProvided() throws Exception {
    int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 5;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    fakeTransport.contentLengthNotSpecified = true;
    InputStream is = new ByteArrayInputStream(new byte[contentLength]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));

    // There should be 6 calls made. 1 initiation request and 5 upload requests.
    assertEquals(6, fakeTransport.lowLevelExecCalls);
View Full Code Here

        @Override
      public synchronized int read(byte[] b, int off, int len) {
        return super.read(b, off, Math.min(len, MediaHttpUploader.DEFAULT_CHUNK_SIZE / 10));
      }
    };
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));

    // There should be 6 calls made. 1 initiation request and 5 upload requests.
    assertEquals(6, fakeTransport.lowLevelExecCalls);
View Full Code Here

  public void testUploadMultipleCalls_WithNoContentSizeProvided_WithExtraByte() throws Exception {
    int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 5 + 1;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    fakeTransport.contentLengthNotSpecified = true;
    InputStream is = new ByteArrayInputStream(new byte[contentLength]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));

    // There should be 7 calls made. 1 initiation request and 6 upload requests.
    assertEquals(7, fakeTransport.lowLevelExecCalls);
View Full Code Here

  public void testUploadProgressListener() throws Exception {
    int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 2;
    MediaTransport fakeTransport = new MediaTransport(contentLength);
    InputStream is = new ByteArrayInputStream(new byte[contentLength]);
    InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
    mediaContent.setLength(contentLength);
    MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
    uploader.setProgressListener(new ResumableProgressListenerWithTwoUploadCalls());
    uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));
  }
View Full Code Here

TOP

Related Classes of com.google.api.client.http.InputStreamContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.