Module org.elasticsearch.server
Class TruncatedOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.elasticsearch.common.io.stream.TruncatedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Truncates writes once the max size is exceeded.
However, when writing byte arrays, the stream does not check whether there is capacity for the full
array prior to writing, so there is overspill of up to b.length - 1.
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionTruncatedOutputStream(OutputStream out, IntSupplier currentSizeSupplier, int maxSize) -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidwrite(byte[] b) If there is at least one byte of space left in the stream then writes the byte stream.voidwrite(byte[] b, int off, int len) If there is at least one byte of space left in the stream then writes the byte stream.voidwrite(int b) If there is at least one byte of space left in the stream then write the byteMethods inherited from class java.io.FilterOutputStream
close, flushMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
TruncatedOutputStream
-
-
Method Details
-
hasCapacity
public boolean hasCapacity()- Returns:
- True if there is at least one byte of space left to write
-
write
If there is at least one byte of space left in the stream then write the byte- Overrides:
writein classFilterOutputStream- Parameters:
b- The byte to write to the underlying stream- Throws:
IOException- – if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
write
If there is at least one byte of space left in the stream then writes the byte stream. Therefore, up to b.length - 1 bytes will overflow.- Overrides:
writein classFilterOutputStream- Parameters:
b- The bytes to write to the underlying stream- Throws:
IOException- – if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
write
If there is at least one byte of space left in the stream then writes the byte stream. Therefore, up to len - 1 bytes will overflow.- Overrides:
writein classFilterOutputStream- Parameters:
b- The byte array to write fromoff- The index of the first byte to write.len- The number of bytes to write- Throws:
IOException- – if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-