Package org.jppf.location
Class MemoryLocation
java.lang.Object
org.jppf.location.AbstractLocation<byte[]>
org.jppf.location.MemoryLocation
- All Implemented Interfaces:
Serializable,Location<byte[]>
Wrapper for manipulating a block of data in memory.
This implementation of the
Location interface allows writing to and reading from a byte array.- Author:
- Laurent Cohen
- See Also:
-
Field Summary
Fields inherited from class org.jppf.location.AbstractLocation
eventsEnabled, listeners, path -
Constructor Summary
ConstructorsConstructorDescriptionMemoryLocation(byte[] buffer) Initialize this location with the specified buffer.MemoryLocation(byte[] buffer, int offset, int len) Initialize this location with the specified byte array.MemoryLocation(long size) Initialize this location and create a buffer of the specified size. -
Method Summary
Modifier and TypeMethodDescriptionObtain an input stream to read from this location.Obtain an output stream to write to this location.longsize()Get the size of the data this location points to.byte[]Get the content at this location as an array of bytes.Methods inherited from class org.jppf.location.AbstractLocation
addLocationEventListener, copyTo, fireLocationEvent, getPath, removeLocationEventListener, toString
-
Constructor Details
-
MemoryLocation
public MemoryLocation(long size) Initialize this location and create a buffer of the specified size. The size is cast to anintvalue before the internal buffer is initialized.- Parameters:
size- the size of the buffer handled by this memory location.
-
MemoryLocation
public MemoryLocation(byte[] buffer) Initialize this location with the specified buffer.- Parameters:
buffer- an array of bytes.
-
MemoryLocation
public MemoryLocation(byte[] buffer, int offset, int len) Initialize this location with the specified byte array.- Parameters:
buffer- an array of bytes.offset- the start position in the array of bytes.len- the length of the buffer.
-
-
Method Details
-
getInputStream
Description copied from interface:LocationObtain an input stream to read from this location.- Returns:
- an
InputStreaminstance. - Throws:
Exception- if an I/O error occurs.
-
getOutputStream
Description copied from interface:LocationObtain an output stream to write to this location.- Returns:
- an
OutputStreaminstance. - Throws:
Exception- if an I/O error occurs.
-
size
public long size()Get the size of the data this location points to.- Returns:
- the size as a long value, or -1 if the file does not exist.
-
toByteArray
public byte[] toByteArray()Get the content at this location as an array of bytes. This method is overridden fromAbstractLocation.toByteArray()for improved performance.- Specified by:
toByteArrayin interfaceLocation<byte[]>- Overrides:
toByteArrayin classAbstractLocation<byte[]>- Returns:
- a byte array with a length equals to this location's size and starting at the offset specified in the constructor, if any.
-