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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | FixedLengthBlockOutputStream.BufferAtATimeOutputChannel
Helper class to provide channel wrapper for arbitrary output stream that doesn't alter the size of writes. |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final ByteBuffer | |
| private final AtomicBoolean | |
| private final WritableByteChannel |
| Access | Constructor and Description |
|---|---|
| public | FixedLengthBlockOutputStream(final OutputStream
The stream to wrap. os, final int The block size to use. blockSize)Constructs a fixed length block output stream with given destination stream and block size. |
| public | FixedLengthBlockOutputStream(final WritableByteChannel
The writable byte channel to wrap. out, final int The block size to use. blockSize)Constructs a fixed length block output stream with given destination writable byte channel and block size. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. |
| public void | |
| public boolean | |
| private void | |
| private void | |
| public void | write(final byte[]
the data. b, final int the start offset in the data. offset, final int the number of bytes to write. length)Overrides java. len bytes from the specified byte array
starting at offset off to this output stream.
|
| public int | write(final ByteBuffer
The buffer from which bytes are to be retrieved src)Implements java. |
| public void | write(final int
the b)byte.Implements abstract java. |
| private void |
| blockSize | back to summary |
|---|---|
| private final int blockSize | |
| buffer | back to summary |
|---|---|
| private final ByteBuffer buffer | |
| closed | back to summary |
|---|---|
| private final AtomicBoolean closed | |
| out | back to summary |
|---|---|
| private final WritableByteChannel out | |
| FixedLengthBlockOutputStream | back to summary |
|---|---|
| public FixedLengthBlockOutputStream(final OutputStream os, final int blockSize) Constructs a fixed length block output stream with given destination stream and block size.
| |
| FixedLengthBlockOutputStream | back to summary |
|---|---|
| public FixedLengthBlockOutputStream(final WritableByteChannel out, final int blockSize) Constructs a fixed length block output stream with given destination writable byte channel and block size.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this channel. After a channel is closed, any further attempt to invoke I/O
operations upon it will cause a If this channel is already closed then invoking this method has no effect. This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
| |
| flushBlock | back to summary |
|---|---|
| public void flushBlock() throws IOException Potentially pads and then writes the current block to the underlying stream.
| |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Implements java. Doc from java. Tells whether or not this channel is open.
| |
| maybeFlush | back to summary |
|---|---|
| private void maybeFlush() throws IOException | |
| padBlock | back to summary |
|---|---|
| private void padBlock() | |
| write | back to summary |
|---|---|
| public void write(final byte[] b, final int offset, final int length) throws IOException Overrides java. Doc from java. Writes
If
If
| |
| write | back to summary |
|---|---|
| public int write(final ByteBuffer src) throws IOException Implements java. Doc from java. Writes a sequence of bytes to this channel from the given buffer. An attempt is made to write up to r bytes to the channel,
where r is the number of bytes remaining in the buffer, that is,
Suppose that a byte sequence of length n is written, where
Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer. This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.
| |
| write | back to summary |
|---|---|
| public void write(final int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| writeBlock | back to summary |
|---|---|
| private void writeBlock() throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicBoolean | |
| private final OutputStream |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | |
| public int | write(final ByteBuffer
The buffer from which bytes are to be retrieved buffer)Implements java. |
| closed | back to summary |
|---|---|
| private final AtomicBoolean closed | |
| out | back to summary |
|---|---|
| private final OutputStream out | |
| BufferAtATimeOutputChannel | back to summary |
|---|---|
| private BufferAtATimeOutputChannel(final OutputStream out) | |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Doc from java. Closes this channel. After a channel is closed, any further attempt to invoke I/O
operations upon it will cause a If this channel is already closed then invoking this method has no effect. This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
| |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Implements java. Doc from java. Tells whether or not this channel is open.
| |
| write | back to summary |
|---|---|
| public int write(final ByteBuffer buffer) throws IOException Implements java. Doc from java. Writes a sequence of bytes to this channel from the given buffer. An attempt is made to write up to r bytes to the channel,
where r is the number of bytes remaining in the buffer, that is,
Suppose that a byte sequence of length n is written, where
Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer. This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.
| |