Class ChunkedBlobOutputStream<T>
java.lang.Object
java.io.OutputStream
org.elasticsearch.repositories.blobstore.ChunkedBlobOutputStream<T>
- Type Parameters:
T
- type of chunk identifier
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Base class for doing chunked writes to a blob store. Some blob stores require either up-front knowledge of the size of the blob that
will be written or writing it in chunks that are then joined into the final blob at the end of the write. This class provides a basis
on which to implement an output stream that encapsulates such a chunked write.
-
Field Summary
Modifier and TypeFieldDescriptionprotected ReleasableBytesStreamOutput
Current write buffer.protected long
Number of bytes flushed to blob storage so far.List of identifiers of already written chunks.protected boolean
Set to true once no more calls towrite(int)
are expected and the blob has been received bywrite(int)
in full so thatclose()
knows whether to clean up existing chunks or finish a chunked write. -
Constructor Summary
ModifierConstructorDescriptionprotected
ChunkedBlobOutputStream(BigArrays bigArrays, long maxBytesToBuffer)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
finishPart(T partId)
Finish writing the current buffer contents to storage and track them by the givenpartId
.protected abstract void
Write the contents ofbuffer
to storage.void
Mark all blob bytes as properly received bywrite(int)
, indicating thatclose()
may finalize the blob.protected abstract void
Invoked once all write chunks/parts are ready to be combined into the final blob.protected abstract void
Invoked in case writing all chunks of data to storage failed.void
write(byte[] b, int off, int len)
void
write(int b)
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
parts
List of identifiers of already written chunks. -
buffer
Current write buffer. -
successful
protected boolean successfulSet to true once no more calls towrite(int)
are expected and the blob has been received bywrite(int)
in full so thatclose()
knows whether to clean up existing chunks or finish a chunked write. -
flushedBytes
protected long flushedBytesNumber of bytes flushed to blob storage so far.
-
-
Constructor Details
-
ChunkedBlobOutputStream
-
-
Method Details
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
markSuccess
public final void markSuccess()Mark all blob bytes as properly received bywrite(int)
, indicating thatclose()
may finalize the blob. -
finishPart
Finish writing the current buffer contents to storage and track them by the givenpartId
. Depending on whether all contents have already been written either prepare the write buffer for additional writes or release the buffer.- Parameters:
partId
- part identifier to track for use when closing
-
flushBuffer
Write the contents ofbuffer
to storage. Implementations should callfinishPart(T)
at the end to track the the chunk of data just written and readybuffer
for the next write.- Throws:
IOException
-
onCompletion
Invoked once all write chunks/parts are ready to be combined into the final blob. Implementations must invoke the necessary logic for combining the uploaded chunks into the final blob in this method.- Throws:
IOException
-
onFailure
protected abstract void onFailure()Invoked in case writing all chunks of data to storage failed. Implementations should run any cleanup required for the already written data in this method.
-