Class B2ContentOutputStreamWriter

  • All Implemented Interfaces:
    B2ContentSink

    public class B2ContentOutputStreamWriter
    extends B2ContentWriter
    B2ContentOutputStreamWriter is a subclass of B2ContentWriter which uses a Helper to create the OutputStream to write to, and optionally, the InputStream to use to reread and verify the SHA1. This is a B2ContentWriter which writes the incoming data into an output stream created by the provided outputStreamCreator. When it is constructed, it is give one or two Suppliers. The outputStreamCreator must return a NEW OutputStream for writing to each time it is called. The inputStreamCreator is optional. If it is provided, it must return a NEW InputStream each time it is called; that InputStream will be used to read back the written contents to verify the SHA1 of the written content (if the SHA1 is available). Note that the arguments are Suppliers, not just stream objects because B2ContentWriters need to be able to handle the SDK performing retries. As mentioned above, be sure to return a new Stream object each time your creators are called.
    • Method Detail

      • 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
      • succeeded

        protected void succeeded()
        Description copied from class: B2ContentWriter
        Called when the download succeeded and, to the extent we're able to verify it, the SHA1 matched. Called at most once for each time that createDestinationOutputStream() is called.
        Overrides:
        succeeded in class B2ContentWriter
      • failed

        protected void failed()
        Description copied from class: B2ContentWriter
        Called after we've created an output stream, but then the download failed for some reason. That reason may include errors with the download, or, to the extent we can verify it, an error with the SHA1 of the written content. Called at most once for each time that createDestinationOutputStream() is called. Called before an attempt to retry the download (if any).
        Overrides:
        failed in class B2ContentWriter