Class B2ContentMemoryWriter
- java.lang.Object
-
- com.backblaze.b2.client.contentHandlers.B2ContentWriter
-
- com.backblaze.b2.client.contentHandlers.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classB2ContentMemoryWriter.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static B2ContentMemoryWriterbuild()static B2ContentMemoryWriter.Builderbuilder()protected java.io.InputStreamcreateDestinationInputStream()protected java.io.OutputStreamcreateDestinationOutputStream()byte[]getBytes()voidreadContent(B2Headers responseHeaders, java.io.InputStream rawIn)Reads the data from the input stream.-
Methods inherited from class com.backblaze.b2.client.contentHandlers.B2ContentWriter
failed, getHeadersOrNull, succeeded
-
-
-
-
Method Detail
-
readContent
public void readContent(B2Headers responseHeaders, java.io.InputStream rawIn) throws B2Exception
Description copied from interface:B2ContentSinkReads 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:
readContentin interfaceB2ContentSink- Overrides:
readContentin classB2ContentWriter- Parameters:
responseHeaders- the headers from the responserawIn- 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:
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
-
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.
-
builder
public static B2ContentMemoryWriter.Builder builder()
-
build
public static B2ContentMemoryWriter build()
-
-