Class B2ContentOutputStreamWriter
- java.lang.Object
-
- com.backblaze.b2.client.contentHandlers.B2ContentWriter
-
- com.backblaze.b2.client.contentHandlers.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classB2ContentOutputStreamWriter.Builderstatic interfaceB2ContentOutputStreamWriter.HelperA Helper provides the OutputStream(s) to write to and the InputStream(s) to use to re-read the content after writing it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static B2ContentOutputStreamWriter.Builderbuilder(B2ContentOutputStreamWriter.Helper helper)protected java.io.InputStreamcreateDestinationInputStream()protected java.io.OutputStreamcreateDestinationOutputStream()protected voidfailed()Called after we've created an output stream, but then the download failed for some reason.protected voidsucceeded()Called when the download succeeded and, to the extent we're able to verify it, the SHA1 matched.-
Methods inherited from class com.backblaze.b2.client.contentHandlers.B2ContentWriter
getHeadersOrNull, readContent
-
-
-
-
Method Detail
-
builder
public static B2ContentOutputStreamWriter.Builder builder(B2ContentOutputStreamWriter.Helper helper)
-
createDestinationOutputStream
protected java.io.OutputStream createDestinationOutputStream() throws java.io.IOException- Specified by:
createDestinationOutputStreamin classB2ContentWriter- 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:
createDestinationInputStreamin classB2ContentWriter- 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:B2ContentWriterCalled 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:
succeededin classB2ContentWriter
-
failed
protected void failed()
Description copied from class:B2ContentWriterCalled 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:
failedin classB2ContentWriter
-
-