public class FixedLengthBlockOutputStream
extends java.io.OutputStream
implements java.nio.channels.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.
Constructor and Description |
---|
FixedLengthBlockOutputStream(java.io.OutputStream os,
int blockSize)
Create a fixed length block output stream with given destination stream and block size
|
FixedLengthBlockOutputStream(java.nio.channels.WritableByteChannel out,
int blockSize)
Create a fixed length block output stream with given destination writable byte channel and block size
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flushBlock()
Potentially pads and then writes the current block to the underlying stream.
|
boolean |
isOpen() |
void |
write(byte[] b,
int offset,
int length) |
int |
write(java.nio.ByteBuffer src) |
void |
write(int b) |
public FixedLengthBlockOutputStream(java.io.OutputStream os, int blockSize)
os
- The stream to wrap.blockSize
- The block size to use.public FixedLengthBlockOutputStream(java.nio.channels.WritableByteChannel out, int blockSize)
out
- The writable byte channel to wrap.blockSize
- The block size to use.public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b, int offset, int length) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public int write(java.nio.ByteBuffer src) throws java.io.IOException
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void flushBlock() throws java.io.IOException
java.io.IOException
- if writing failspublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
close
in class java.io.OutputStream
java.io.IOException
Copyright © 2010 - 2020 Adobe. All Rights Reserved