Package com.jogamp.common.nio
Class MappedByteBufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.jogamp.common.nio.MappedByteBufferOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class MappedByteBufferOutputStream extends OutputStream
AnOutputStream
implementation based on an underlyingFileChannel
's memory mappedByteBuffer
.Implementation is based on
MappedByteBufferInputStream
, using it as its parent instance.An instance maybe created via its parent
MappedByteBufferInputStream.getOutputStream(FileResizeOp)
or directlyMappedByteBufferOutputStream(FileChannel, MapMode, CacheMode, int, FileResizeOp)
.- Since:
- 2.3.0
-
-
Constructor Summary
Constructors Constructor Description MappedByteBufferOutputStream(FileChannel fileChannel, FileChannel.MapMode mmode, MappedByteBufferInputStream.CacheMode cmode, int sliceShift, MappedByteBufferInputStream.FileResizeOp fileResizeOp)
Creates a new instance using the givenFileChannel
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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(int b)
void
write(MappedByteBufferInputStream b, long len)
Perform similar towrite(ByteBuffer, int)
withMappedByteBufferInputStream
instead of byte array.void
write(ByteBuffer b, int len)
Perform similar towrite(byte[], int, int)
withByteBuffer
instead of byte array.-
Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
-
-
-
Constructor Detail
-
MappedByteBufferOutputStream
public MappedByteBufferOutputStream(FileChannel fileChannel, FileChannel.MapMode mmode, MappedByteBufferInputStream.CacheMode cmode, int sliceShift, MappedByteBufferInputStream.FileResizeOp fileResizeOp) throws IOException
Creates a new instance using the givenFileChannel
.The
ByteBuffer
slices will be mapped lazily at first usage.- Parameters:
fileChannel
- the file channel to be mapped lazily.mmode
- the map mode, default isFileChannel.MapMode.READ_WRITE
.cmode
- the caching mode, default isMappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT
.sliceShift
- the pow2 slice size, default isMappedByteBufferInputStream.DEFAULT_SLICE_SHIFT
.fileResizeOp
-MappedByteBufferInputStream.FileResizeOp
as described onMappedByteBufferInputStream.setFileResizeOp(FileResizeOp)
.- Throws:
IOException
-
-
Method Detail
-
setSynchronous
public final void setSynchronous(boolean s)
-
getSynchronous
public final boolean getSynchronous()
-
setLength
public final void setLength(long newTotalSize) throws IOException
- Throws:
IOException
-
notifyLengthChange
public final void notifyLengthChange(long newTotalSize) throws IOException
- Throws:
IOException
-
length
public final long length()
-
remaining
public final long remaining() throws IOException
- Throws:
IOException
-
position
public final long position() throws IOException
- Throws:
IOException
-
position
public final MappedByteBufferInputStream position(long newPosition) throws IOException
- Throws:
IOException
-
skip
public final long skip(long n) throws IOException
- Throws:
IOException
-
flush
public final void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
flush
public final void flush(boolean metaData) throws IOException
- Throws:
IOException
-
close
public final void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
write
public final void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public final void write(byte[] b, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public final void write(ByteBuffer b, int len) throws IOException
Perform similar towrite(byte[], int, int)
withByteBuffer
instead of byte array.- Parameters:
b
- theByteBuffer
source, data is read from currentBuffer.position()
len
- the number of bytes to write- Throws:
IOException
- if a buffer slice operation failed or stream has beenclosed
.
-
write
public final void write(MappedByteBufferInputStream b, long len) throws IOException
Perform similar towrite(ByteBuffer, int)
withMappedByteBufferInputStream
instead of byte array.Method directly copies memory mapped
ByteBuffer
'ed data from the given input stream to this stream without extra data copy.- Parameters:
b
- theByteBuffer
source, data is read from currentMappedByteBufferInputStream.position()
len
- the number of bytes to write- Throws:
IOException
- if a buffer slice operation failed or stream has beenclosed
.
-
-