Class B2ContentMemoryWriter

  • All Implemented Interfaces:
    B2ContentSink

    public class B2ContentMemoryWriter
    extends B2ContentWriter
    This is a B2ContentWriter which records the incoming data into an in-memory byte array. This will completely fail if the contentLen is more than Integer.MAX_VALUE bytes. It may cause other memory-related issues before that.
    • Method Detail

      • readContent

        public void readContent​(B2Headers responseHeaders,
                                java.io.InputStream rawIn)
                         throws B2Exception
        Description copied from interface: B2ContentSink
        Reads the data from the input stream. Does NOT need to close the stream. The caller of readContent() will take care of that. If you don't read to the end of the inputStream, the connection probably won't be re-usable, so read to the end unless you have a good reason not to.
        Specified by:
        readContent in interface B2ContentSink
        Overrides:
        readContent in class B2ContentWriter
        Parameters:
        responseHeaders - the headers from the response
        rawIn - an input stream to read the content of the response
        Throws:
        B2Exception - if there's trouble
      • createDestinationOutputStream

        protected java.io.OutputStream createDestinationOutputStream()
                                                              throws java.io.IOException
        Specified by:
        createDestinationOutputStream in class B2ContentWriter
        Returns:
        an outputStream to write to the destination. calling this is allowed to destroy the existing output (if any) and make it impossible for a stream created by createDestinationInputStream() to be able to read the data, if any.
        Throws:
        java.io.IOException - if there's any trouble
      • createDestinationInputStream

        protected java.io.InputStream createDestinationInputStream()
                                                            throws java.io.IOException
        Specified by:
        createDestinationInputStream in class B2ContentWriter
        Returns:
        a new inputStream to read from the destination. this might not contain what you think it should if readContents hasn't completed successfully.
        Throws:
        java.io.IOException - if there's any trouble
      • getBytes

        public byte[] getBytes()
        Returns:
        null if readContent hasn't made it far enough or a new byteArray with the contents that were read.
        NOTE
        this might be empty or not quite what you expect if readContents() hasn't completed successfully.