public class MappedByteBufferOutputStream extends OutputStream
OutputStream implementation based on an underlying FileChannel's memory mapped ByteBuffer.
Implementation is based on MappedByteBufferInputStream, using it as its parent instance.
An instance maybe created via its parent MappedByteBufferInputStream.getOutputStream(FileResizeOp)
or directly #MappedByteBufferOutputStream(FileChannel, MapMode, CacheMode, int, FileResizeOp).
| Constructor and Description |
|---|
MappedByteBufferOutputStream(FileChannel fileChannel,
FileChannel.MapMode mmode,
MappedByteBufferInputStream.CacheMode cmode,
int sliceShift,
MappedByteBufferInputStream.FileResizeOp fileResizeOp)
Creates a new instance using the given
FileChannel. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
void |
flush(boolean metaData)
|
boolean |
getSynchronous()
|
long |
length()
|
void |
notifyLengthChange(long newTotalSize)
|
long |
position()
|
MappedByteBufferInputStream |
position(long newPosition)
|
long |
remaining()
|
void |
setLength(long newTotalSize)
|
void |
setSynchronous(boolean s)
|
long |
skip(long n)
|
void |
write(byte[] b,
int off,
int len) |
void |
write(ByteBuffer b,
int len)
Perform similar to
write(byte[], int, int)
with ByteBuffer instead of byte array. |
void |
write(int b) |
void |
write(MappedByteBufferInputStream b,
long len)
Perform similar to
write(ByteBuffer, int)
with MappedByteBufferInputStream instead of byte array. |
writepublic MappedByteBufferOutputStream(FileChannel fileChannel, FileChannel.MapMode mmode, MappedByteBufferInputStream.CacheMode cmode, int sliceShift, MappedByteBufferInputStream.FileResizeOp fileResizeOp) throws IOException
FileChannel.
The ByteBuffer slices will be mapped lazily at first usage.
fileChannel - the file channel to be mapped lazily.mmode - the map mode, default is FileChannel.MapMode#READ_WRITE.cmode - the caching mode, default is MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT.sliceShift - the pow2 slice size, default is MappedByteBufferInputStream.DEFAULT_SLICE_SHIFT.fileResizeOp - MappedByteBufferInputStream.FileResizeOp as described on MappedByteBufferInputStream.setFileResizeOp(FileResizeOp).IOExceptionpublic final void setSynchronous(boolean s)
public final boolean getSynchronous()
public final void setLength(long newTotalSize)
throws IOException
IOExceptionpublic final void notifyLengthChange(long newTotalSize)
throws IOException
IOExceptionpublic final long length()
public final long remaining()
throws IOException
IOExceptionpublic final long position()
throws IOException
IOExceptionpublic final MappedByteBufferInputStream position(long newPosition) throws IOException
IOExceptionpublic final long skip(long n)
throws IOException
IOExceptionpublic final void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic final void flush(boolean metaData)
throws IOException
IOExceptionpublic final void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionpublic final void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(ByteBuffer b, int len) throws IOException
write(byte[], int, int)
with ByteBuffer instead of byte array.b - the ByteBuffer source, data is read from current Buffer.position()len - the number of bytes to writeIOException - if a buffer slice operation failed or stream has been closed.public final void write(MappedByteBufferInputStream b, long len) throws IOException
write(ByteBuffer, int)
with MappedByteBufferInputStream instead of byte array.
Method directly copies memory mapped ByteBuffer'ed data
from the given input stream to this stream without extra data copy.
b - the ByteBuffer source, data is read from current MappedByteBufferInputStream.position()len - the number of bytes to writeIOException - if a buffer slice operation failed or stream has been closed.