Top Fields Constructors Methods
jdk.nio.zipfs

public Class ByteArrayChannel

extends Object
implements SeekableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.SeekableByteChannel, java.nio.channels.ByteChannel, java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ReadableByteChannel
Known Direct Subclasses
jdk.nio.zipfs.ZipFileSystem.EntryOutputChannel
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, .NonWritableChannelException, .SeekableByteChannel, java.util.Arrays, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock

Field Summary

Modifier and TypeField and Description
private byte[]
private boolean
private int
private static final int
MAX_ARRAY_SIZE

The maximum size of array to allocate.

private int
private boolean
private final ReadWriteLock

Constructor Summary

AccessConstructor and Description
pack-priv
ByteArrayChannel(int sz, boolean readonly)

pack-priv
ByteArrayChannel(byte[] buf, boolean readonly)

Method Summary

Modifier and TypeMethod and Description
private final void
pack-priv final void
public void
close()

Implements java.nio.channels.Channel.close.

Closes this channel.
private final void
pack-priv final void
private void
ensureCapacity(int minCapacity)

private void
private void
grow(int
the desired minimum capacity
minCapacity
)

Increases the capacity to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

private static int
hugeCapacity(int minCapacity)

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.
public long
position()

Implements java.nio.channels.SeekableByteChannel.position.

Returns this channel's position.
public SeekableByteChannel
position(long
The new position, a non-negative integer counting the number of bytes from the beginning of the entity
pos
)

Implements java.nio.channels.SeekableByteChannel.position.

Sets this channel's position.
public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements java.nio.channels.SeekableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.
public long
size()

Implements java.nio.channels.SeekableByteChannel.size.

Returns the current size of entity to which this channel is connected.
public byte[]

Returns:

the current contents of this channel, as a byte array.
toByteArray
()

Creates a newly allocated byte array.

public SeekableByteChannel
truncate(long
The new size, a non-negative byte count
size
)

Implements java.nio.channels.SeekableByteChannel.truncate.

Truncates the entity, to which this channel is connected, to the given size.
public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.SeekableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private byte[] buf
closedback to summary
private boolean closed
lastback to summary
private int last
MAX_ARRAY_SIZEback to summary
private static final int MAX_ARRAY_SIZE

The maximum size of array to allocate. Some VMs reserve some header words in an array. Attempts to allocate larger arrays may result in OutOfMemoryError: Requested array size exceeds VM limit

posback to summary
private int pos
readonlyback to summary
private boolean readonly
rwlockback to summary
private final ReadWriteLock rwlock

Constructor Detail

ByteArrayChannelback to summary
pack-priv ByteArrayChannel(int sz, boolean readonly)
ByteArrayChannelback to summary
pack-priv ByteArrayChannel(byte[] buf, boolean readonly)

Method Detail

beginReadback to summary
private final void beginRead()
beginWriteback to summary
pack-priv final void beginWrite()
closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
endReadback to summary
private final void endRead()
endWriteback to summary
pack-priv final void endWrite()
ensureCapacityback to summary
private void ensureCapacity(int minCapacity)
ensureOpenback to summary
private void ensureOpen() throws IOException
growback to summary
private void grow(int minCapacity)

Increases the capacity to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters
minCapacity:int

the desired minimum capacity

hugeCapacityback to summary
private static int hugeCapacity(int minCapacity)
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
positionback to summary
public long position() throws IOException

Implements java.nio.channels.SeekableByteChannel.position.

Doc from java.nio.channels.SeekableByteChannel.position.

Returns this channel's position.

Returns:long

This channel's position, a non-negative integer counting the number of bytes from the beginning of the entity to the current position

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
positionback to summary
public SeekableByteChannel position(long pos) throws IOException

Implements java.nio.channels.SeekableByteChannel.position.

Doc from java.nio.channels.SeekableByteChannel.position.

Sets this channel's position.

Setting the position to a value that is greater than the current size is legal but does not change the size of the entity. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the entity to grow to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

Setting the channel's position is not recommended when connected to an entity, typically a file, that is opened with the APPEND option. When opened for append, the position is first advanced to the end before writing.

Parameters
pos:long

The new position, a non-negative integer counting the number of bytes from the beginning of the entity

Returns:SeekableByteChannel

This channel

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.SeekableByteChannel.read.

Doc from java.nio.channels.SeekableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

Bytes are read starting at this channel's current position, and then the position is updated with the number of bytes actually read. Otherwise this method behaves exactly as specified in the ReadableByteChannel interface.

Parameters
dst:ByteBuffer

Doc from java.nio.channels.ReadableByteChannel.read.

The buffer into which bytes are to be transferred

Returns:int

Doc from java.nio.channels.ReadableByteChannel.read.

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.ReadableByteChannel.read.

If some other I/O error occurs

sizeback to summary
public long size() throws IOException

Implements java.nio.channels.SeekableByteChannel.size.

Doc from java.nio.channels.SeekableByteChannel.size.

Returns the current size of entity to which this channel is connected.

Returns:long

The current size, measured in bytes

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
toByteArrayback to summary
public byte[] toByteArray()

Creates a newly allocated byte array. Its size is the current size of this channel and the valid contents of the buffer have been copied into it.

Returns:byte[]

the current contents of this channel, as a byte array.

truncateback to summary
public SeekableByteChannel truncate(long size) throws IOException

Implements java.nio.channels.SeekableByteChannel.truncate.

Doc from java.nio.channels.SeekableByteChannel.truncate.

Truncates the entity, to which this channel is connected, to the given size.

If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. If the given size is greater than or equal to the current size then the entity is not modified. In either case, if the current position is greater than the given size then it is set to that size.

An implementation of this interface may prohibit truncation when connected to an entity, typically a file, opened with the APPEND option.

Parameters
size:long

The new size, a non-negative byte count

Returns:SeekableByteChannel

This channel

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.SeekableByteChannel.write.

Doc from java.nio.channels.SeekableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

Bytes are written starting at this channel's current position, unless the channel is connected to an entity such as a file that is opened with the APPEND option, in which case the position is first advanced to the end. The entity to which the channel is connected is grown, if necessary, to accommodate the written bytes, and then the position is updated with the number of bytes actually written. Otherwise this method behaves exactly as specified by the WritableByteChannel interface.

Parameters
src:ByteBuffer

Doc from java.nio.channels.WritableByteChannel.write.

The buffer from which bytes are to be retrieved

Returns:int

Doc from java.nio.channels.WritableByteChannel.write.

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.WritableByteChannel.write.

If some other I/O error occurs