Package com.mimecast.robin.storage
Class MessageBufferOutputStream
java.lang.Object
java.io.OutputStream
com.mimecast.robin.storage.MessageBufferOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Buffers message receipt in memory and spills to disk after a configured threshold.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate OutputStreamprivate booleanprivate ByteArrayOutputStreamprivate longprivate final Pathprivate final long -
Constructor Summary
ConstructorsConstructorDescriptionMessageBufferOutputStream(long thresholdBytes, Path spillFile) Constructs a new buffered output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private voidvoidflush()booleanChecks if the stream spilled to a file.longsize()Gets the buffered size.private voidspillIfNeeded(int nextWriteBytes) Converts the current buffer into a canonical message source.voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Field Details
-
thresholdBytes
private final long thresholdBytes -
spillFile
-
memoryStream
-
activeStream
-
size
private long size -
closed
private boolean closed
-
-
Constructor Details
-
MessageBufferOutputStream
Constructs a new buffered output stream.- Parameters:
thresholdBytes- Spill threshold.spillFile- Spill target file.
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
size
public long size()Gets the buffered size.- Returns:
- Size in bytes.
-
toMessageSource
Converts the current buffer into a canonical message source.For file-backed messages, returns a
RefCountedFileMessageSourceto support safe concurrent access with automatic cleanup.- Returns:
- MessageSource instance.
-
isSpilledToFile
public boolean isSpilledToFile()Checks if the stream spilled to a file.- Returns:
- Boolean.
-
spillIfNeeded
- Throws:
IOException
-
ensureOpen
- Throws:
IOException
-