Class MockHttpContent

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

@Beta public class MockHttpContent extends Object implements HttpContent
Beta
Mock for HttpContent.

Implementation is not thread-safe.

Since:
1.3
  • Field Details

    • length

      private long length
      HTTP content length or -1 by default.
    • type

      private String type
      HTTP content type or null by default.
    • content

      private byte[] content
      HTTP content or an empty byte array by default.
  • Constructor Details

    • MockHttpContent

      public MockHttpContent()
  • Method Details

    • getLength

      public long getLength() throws IOException
      Description copied from interface: HttpContent
      Returns the content length or less than zero if not known.
      Specified by:
      getLength in interface HttpContent
      Throws:
      IOException
    • getType

      public String getType()
      Description copied from interface: HttpContent
      Returns the content type or null for none.
      Specified by:
      getType in interface HttpContent
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Description copied from interface: StreamingContent
      Writes the byte content to the given output stream.

      Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the output stream has not been closed, and will fail to work if it has been closed.

      Specified by:
      writeTo in interface HttpContent
      Specified by:
      writeTo in interface StreamingContent
      Parameters:
      out - output stream
      Throws:
      IOException
    • retrySupported

      public boolean retrySupported()
      Description copied from interface: HttpContent
      Returns whether or not retry is supported on this content type.
      Specified by:
      retrySupported in interface HttpContent
    • getContent

      public final byte[] getContent()
      Returns the HTTP content.
      Since:
      1.5
    • setContent

      public MockHttpContent setContent(byte[] content)
      Sets the HTTP content.

      Default value is an empty byte array.

      Since:
      1.5
    • setLength

      public MockHttpContent setLength(long length)
      Returns the HTTP content length or -1 for unknown.

      Default value is -1.

      Since:
      1.5
    • setType

      public MockHttpContent setType(String type)
      Sets the HTTP content type or null for none.
      Since:
      1.5