Interface B2ContentOutputStreamWriter.Helper

  • Enclosing class:
    B2ContentOutputStreamWriter

    public static interface B2ContentOutputStreamWriter.Helper
    A Helper provides the OutputStream(s) to write to and the InputStream(s) to use to re-read the content after writing it. If you want to have the SHA1 verified by re-reading the written content, override shouldVerifySha1ByRereadingFromDestination() to return true and createInputStreamOrNull() to return a new InputStream on the written content each time it is called.
    • Method Detail

      • createOutputStream

        java.io.OutputStream createOutputStream()
                                         throws java.io.IOException
        This might be called multiple times. Be sure to return a NEW OutputStream each time. The Writer will write the entire contents of downloaded stream to the returned OutputStream or fail while trying and possibly ask for another output stream.
        Returns:
        a new OutputStream to write the content to.
        Throws:
        java.io.IOException - if there's trouble making the OutputStream.
      • shouldVerifySha1ByRereadingFromDestination

        default boolean shouldVerifySha1ByRereadingFromDestination()
        This might be called multiple times. Be sure to return the same result every time.
        Returns:
        whether or not we should try to verify the SHA1 be re-reading the content from the destination. The Helper must return the same answer for its entire lifetime.
      • createInputStream

        default java.io.InputStream createInputStream()
                                               throws java.io.IOException
        This might be called multiple times. Be sure to return a NEW InputStream each time. The returned InputStream must start reading at the beginning of the data written by the writer. This will only be called if shouldVerifySha1ByRereadingFromDestination() returns true.
        Returns:
        an InputStream to use to read the written content from its destination.
        Throws:
        java.io.IOException - if there's trouble creating the InputStream.
      • succeeded

        default void succeeded()
        Called after the download succeeds. This can be used to commit to the results of the download. For instance, it could be a good time to move from a temp file name to a final filename. If you hit a serious problem, you will need to throw a RuntimeException to get the exception all the way back to whomever called the download.
      • failed

        default void failed()
        Called after the download fails (if it got as far as calling createOutputStream()). This can be used to cleanup anything that was downloaded. For instance, it could be a good time to delete a temporary file that was used for the download. If you hit a serious problem, you will need to throw a RuntimeException to get the exception all the way back to whomever called the download.