Top Description Fields Constructors Methods
com.jogamp.common.nio

public Class MappedByteBufferOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.nio.channels.FileChannel, .FileChannel.MapMode, com.jogamp.common.nio.MappedByteBufferInputStream.CacheMode, .MappedByteBufferInputStream.FileResizeOp

An 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).

Since
2.3.0

Field Summary

Modifier and TypeField and Description
private final MappedByteBufferInputStream

Constructor Summary

AccessConstructor and Description
pack-priv
public
MappedByteBufferOutputStream(final FileChannel
the file channel to be mapped lazily.
fileChannel
,
final FileChannel.MapMode
the map mode, default is FileChannel.MapMode#READ_WRITE.
mmode
,
final MappedByteBufferInputStream.CacheMode cmode, final int
the pow2 slice size, default is MappedByteBufferInputStream#DEFAULT_SLICE_SHIFT.
sliceShift
,
final MappedByteBufferInputStream.FileResizeOp fileResizeOp)

Creates a new instance using the given FileChannel.

Method Summary

Modifier and TypeMethod and Description
public final synchronized void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public final synchronized void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.
public final synchronized void
public final synchronized boolean
public final synchronized long
public final synchronized void
public final synchronized long
public final synchronized MappedByteBufferInputStream
public final synchronized long
public final synchronized void
public final synchronized void
public final synchronized long
public final synchronized void
write(final int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public final synchronized void
write(final byte[]
the data.
b
,
final int
the start offset in the data.
off
,
final int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public final synchronized void
write(final ByteBuffer
the ByteBuffer source, data is read from current ByteBuffer#position()
b
,
final int
the number of bytes to write
len
)

Perform similar to write(byte[], int, int) with ByteBuffer instead of byte array.

public final synchronized void
write(final MappedByteBufferInputStream
the ByteBuffer source, data is read from current MappedByteBufferInputStream#position()
b
,
final long
the number of bytes to write
len
)

Perform similar to write(ByteBuffer, int) with MappedByteBufferInputStream instead of byte array.

Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

parentback to summary
private final MappedByteBufferInputStream parent

Constructor Detail

MappedByteBufferOutputStreamback to summary
pack-priv MappedByteBufferOutputStream(final MappedByteBufferInputStream parent, final MappedByteBufferInputStream.FileResizeOp fileResizeOp) throws IOException
MappedByteBufferOutputStreamback to summary
public MappedByteBufferOutputStream(final FileChannel fileChannel, final FileChannel.MapMode mmode, final MappedByteBufferInputStream.CacheMode cmode, final int sliceShift, final MappedByteBufferInputStream.FileResizeOp fileResizeOp) throws IOException

Creates a new instance using the given FileChannel.

The ByteBuffer slices will be mapped lazily at first usage.

Parameters
fileChannel:FileChannel

the file channel to be mapped lazily.

mmode:FileChannel.MapMode

the map mode, default is FileChannel.MapMode#READ_WRITE.

cmode:MappedByteBufferInputStream.CacheMode

the caching mode, default is MappedByteBufferInputStream.CacheMode#FLUSH_PRE_SOFT.

sliceShift:int

the pow2 slice size, default is MappedByteBufferInputStream#DEFAULT_SLICE_SHIFT.

fileResizeOp:MappedByteBufferInputStream.FileResizeOp

MappedByteBufferInputStream.FileResizeOp as described on MappedByteBufferInputStream#setFileResizeOp(FileResizeOp).

Method Detail

closeback to summary
public final synchronized void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public final synchronized void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public final synchronized void flush(final boolean metaData) throws IOException

See MappedByteBufferInputStream#flush(boolean).

getSynchronousback to summary
public final synchronized boolean getSynchronous()

See MappedByteBufferInputStream#getSynchronous().

lengthback to summary
public final synchronized long length()

See MappedByteBufferInputStream#length().

notifyLengthChangeback to summary
public final synchronized void notifyLengthChange(final long newTotalSize) throws IOException

See MappedByteBufferInputStream#notifyLengthChange(long).

positionback to summary
public final synchronized long position() throws IOException

See MappedByteBufferInputStream#position().

positionback to summary
public final synchronized MappedByteBufferInputStream position(final long newPosition) throws IOException

See MappedByteBufferInputStream#position(long).

remainingback to summary
public final synchronized long remaining() throws IOException

See MappedByteBufferInputStream#remaining().

setLengthback to summary
public final synchronized void setLength(final long newTotalSize) throws IOException

See MappedByteBufferInputStream#setLength(long).

setSynchronousback to summary
public final synchronized void setSynchronous(final boolean s)

See MappedByteBufferInputStream#setSynchronous(boolean).

skipback to summary
public final synchronized long skip(final long n) throws IOException

See MappedByteBufferInputStream#skip(long).

writeback to summary
public final synchronized void write(final int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public final synchronized void write(final byte[] b, final int off, final int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeback to summary
public final synchronized void write(final ByteBuffer b, final int len) throws IOException

Perform similar to write(byte[], int, int) with ByteBuffer instead of byte array.

Parameters
b:ByteBuffer

the ByteBuffer source, data is read from current ByteBuffer#position()

len:int

the number of bytes to write

Exceptions
IOException:
if a buffer slice operation failed or stream has been closed.
writeback to summary
public final synchronized void write(final MappedByteBufferInputStream b, final long len) throws IOException

Perform similar to 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.

Parameters
b:MappedByteBufferInputStream

the ByteBuffer source, data is read from current MappedByteBufferInputStream#position()

len:long

the number of bytes to write

Exceptions
IOException:
if a buffer slice operation failed or stream has been closed.