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
AnOutputStreamimplementation 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 voidclose()voidflush()voidflush(boolean metaData)booleangetSynchronous()longlength()voidnotifyLengthChange(long newTotalSize)longposition()MappedByteBufferInputStreamposition(long newPosition)longremaining()voidsetLength(long newTotalSize)voidsetSynchronous(boolean s)longskip(long n)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(MappedByteBufferInputStream b, long len)Perform similar towrite(ByteBuffer, int)withMappedByteBufferInputStreaminstead of byte array.voidwrite(ByteBuffer b, int len)Perform similar towrite(byte[], int, int)withByteBufferinstead 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
ByteBufferslices 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.FileResizeOpas 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:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
flush
public final void flush(boolean metaData) throws IOException- Throws:
IOException
-
close
public final void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
write
public final void write(int b) throws IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
write
public final void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public final void write(ByteBuffer b, int len) throws IOException
Perform similar towrite(byte[], int, int)withByteBufferinstead of byte array.- Parameters:
b- theByteBuffersource, 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)withMappedByteBufferInputStreaminstead 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- theByteBuffersource, 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.
-
-