Class ByteArrayContent

java.lang.Object
com.google.api.client.http.AbstractInputStreamContent
com.google.api.client.http.ByteArrayContent
All Implemented Interfaces:
HttpContent, StreamingContent

public final class ByteArrayContent extends AbstractInputStreamContent
Concrete implementation of AbstractInputStreamContent that generates repeatable input streams based on the contents of byte array.

Sample use:

 
 static void setJsonContent(HttpRequest request, byte[] json) {
 request.setContent(new ByteArrayContent("application/json", json));
 }
 
 

Implementation is not thread-safe.

Since:
1.4
  • Field Details

    • byteArray

      private final byte[] byteArray
      Byte array content.
    • offset

      private final int offset
      Starting offset into the byte array.
    • length

      private final int length
      Length of bytes to read from byte array.
  • Constructor Details

    • ByteArrayContent

      public ByteArrayContent(String type, byte[] array)
      Constructor from byte array content that has already been encoded.
      Parameters:
      type - content type or null for none
      array - byte array content
      Since:
      1.5
    • ByteArrayContent

      public ByteArrayContent(String type, byte[] array, int offset, int length)
      Constructor from byte array content that has already been encoded, specifying a range of bytes to read from the input byte array.
      Parameters:
      type - content type or null for none
      array - byte array content
      offset - starting offset into the byte array
      length - of bytes to read from byte array
      Since:
      1.7
  • Method Details