@NotThreadSafe public class MemoryBuffer extends Object implements IoBuffer
If the reference to the backing buffer is
null, then any attempt to start input from this I/O buffer results
in a FileNotFoundException.
The reference gets automatically set upon each call to close()
on any OutputStream or SeekableByteChannel which has been
obtained from an output socket for this I/O buffer.
The reference can also get explicitly set by calling the constructor
MemoryBuffer(String, ByteBuffer) or the method
setBuffer(ByteBuffer).
Entry.Access, Entry.Entity, Entry.PosixEntity, Entry.Size, Entry.TypeALL_ACCESS, ALL_POSIX_ACCESS, ALL_POSIX_ENTITIES, ALL_SIZES, ALL_TYPES, DIRECTORY_TYPE, FILE_TYPE, NO_ACCESS, NO_POSIX_ENTITIES, NO_SIZES, NO_TYPES, SPECIAL_TYPE, SYMLINK_TYPE, UNKNOWN| Constructor and Description |
|---|
MemoryBuffer(String name,
ByteBuffer buffer)
Constructs a new memory buffer.
|
MemoryBuffer(String name,
int initialCapacity)
Constructs a new memory buffer.
|
| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
getBuffer()
Returns a duplicate of the nullable
backing buffer with the contents to share with this memory buffer.
|
int |
getCount(Entry.Access type) |
int |
getInitialCapacity()
Returns the initial capacity of the next backing buffer to allocate when
starting output to this memory buffer.
|
String |
getName()
Returns the entry name.
|
long |
getSize(Entry.Size type)
Returns the size of the given
type for this entry in bytes or
Entry.UNKNOWN if not defined or the type is not supported. |
long |
getTime(Entry.Access type)
Returns the time of the given access
type for this entry in
milliseconds since the epoch or -1 if not
defined or the type is not supported. |
InputSocket<MemoryBuffer> |
input()
Returns an input socket for reading this entry.
|
Boolean |
isPermitted(Entry.Access type,
Entry.Entity entity)
Returns
true or false if the given access type
to this entry for the given entity is respectively permitted or
denied. |
OutputSocket<MemoryBuffer> |
output()
Returns an output socket for writing this entry.
|
void |
release()
Releases this resource to its pool.
|
void |
setBuffer(ByteBuffer buffer)
Sets the nullable backing buffer with the contents to share with this
memory buffer.
|
void |
setInitialCapacity(int initialCapacity)
Sets the initial capacity of the next backing buffer to allocate when
starting output to this memory buffer.
|
String |
toString()
Returns a string representation of this object for debugging and logging
purposes.
|
public MemoryBuffer(String name, ByteBuffer buffer)
name - the name of this memory buffer.buffer - the byte buffer with the contents to share with this
memory buffer.public MemoryBuffer(String name, int initialCapacity)
null.name - the name of this memory buffer.initialCapacity - the initial capacity of the next backing buffer
to allocate when starting output to this memory buffer.@Nullable public final ByteBuffer getBuffer()
null is returned.
Otherwise, the returned buffer's position is set to zero and its limit
is set to the size of the contents of this memory buffer.public final int getCount(Entry.Access type)
type - the access type.public final int getInitialCapacity()
public final String getName()
Entry'/' or '\\' or both, according to the rules of the
Container.
This implies that a segment cannot contain separator characters.
".") or
dot-dot ("..") segments which represent the current or
parent segment respectively.
"foo/bar/" and
"./abc/../foo/./def/./../bar/." both refer to the same entry
when being parsed.public final long getSize(Entry.Size type)
Entrytype for this entry in bytes or
Entry.UNKNOWN if not defined or the type is not supported.
This method may not be meaningful for non-Entry.Type.FILE entries.getSize in interface Entrytype - the type of the size.type for this entry in bytes or
Entry.UNKNOWN if not defined or the type is not supported.public final long getTime(Entry.Access type)
Entrytype for this entry in
milliseconds since the epoch or -1 if not
defined or the type is not supported.public final InputSocket<MemoryBuffer> input()
IoEntryIoSocket.target() of the returned socket
must return this entry.public Boolean isPermitted(Entry.Access type, Entry.Entity entity)
Entrytrue or false if the given access type
to this entry for the given entity is respectively permitted or
denied.
Returns null if not defined or the access type or entity is
not supported.isPermitted in interface Entrytype - the type of the access.entity - the entity which desires access.true if and only if the given access type to
this entry is permitted for the given entity.public final OutputSocket<MemoryBuffer> output()
IoEntryIoSocket.target() of the returned socket
must return this entry.public void release()
throws IOException
Releasablerelease in interface Releasable<IOException>IOExceptionpublic final void setBuffer(@Nullable ByteBuffer buffer)
buffer is not null, a
duplicate is made and
rewind in order to protect this
memory buffer from concurrent modifications of the given buffer's
properties.buffer - the nullable byte buffer with the contents to share
with this memory buffer.public final void setInitialCapacity(int initialCapacity)
initialCapacity - the initial capacity of the next backing buffer
to allocate when starting output to this memory buffer.Copyright © 2012–2018 Schlichtherle IT Services. All rights reserved.