Class FixedLengthBlockOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,Channel
,WritableByteChannel
It can be be used to support output to devices such as tape drives that require output in this format. If the final block does not have enough content to fill an entire block, the output will be padded to a full block size.
This class can be used to support TAR,PAX, and CPIO blocked output to character special devices. It is not recommended that this class be used unless writing to such devices, as the padding serves no useful purpose in such cases.
This class should normally wrap a FileOutputStream or associated WritableByteChannel directly. If there is an intervening filter that modified the output, such as a CompressorOutputStream, or performs its own buffering, such as BufferedOutputStream, output to the device may no longer be of the specified size.
Any content written to this stream should be self-delimiting and should tolerate any padding added to fill the last block.
- Since:
- 1.15
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Helper class to provide channel wrapper for arbitrary output stream that doesn't alter the size of writes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
private final ByteBuffer
private final AtomicBoolean
private final WritableByteChannel
-
Constructor Summary
ConstructorsConstructorDescriptionFixedLengthBlockOutputStream
(OutputStream os, int blockSize) Create a fixed length block output stream with given destination stream and block sizeFixedLengthBlockOutputStream
(WritableByteChannel out, int blockSize) Create a fixed length block output stream with given destination writable byte channel and block size -
Method Summary
Methods inherited from class java.io.OutputStream
flush, write
-
Field Details
-
out
-
blockSize
private final int blockSize -
buffer
-
closed
-
-
Constructor Details
-
FixedLengthBlockOutputStream
Create a fixed length block output stream with given destination stream and block size- Parameters:
os
- The stream to wrap.blockSize
- The block size to use.
-
FixedLengthBlockOutputStream
Create a fixed length block output stream with given destination writable byte channel and block size- Parameters:
out
- The writable byte channel to wrap.blockSize
- The block size to use.
-
-
Method Details
-
maybeFlush
- Throws:
IOException
-
writeBlock
- Throws:
IOException
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
IOException
-
isOpen
public boolean isOpen() -
flushBlock
Potentially pads and then writes the current block to the underlying stream.- Throws:
IOException
- if writing fails
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
padBlock
private void padBlock()
-