org.jppf.server.protocol
Class MemoryLocation

java.lang.Object
  extended by org.jppf.server.protocol.AbstractLocation<byte[]>
      extended by org.jppf.server.protocol.MemoryLocation
All Implemented Interfaces:
Serializable, Location<byte[]>

public class MemoryLocation
extends AbstractLocation<byte[]>

Wrapper fro manipulating a file.

Author:
Laurent Cohen
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jppf.server.protocol.AbstractLocation
eventsEnabled, listeners, path
 
Constructor Summary
MemoryLocation(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(int size)
          Initialize this location and create a buffer of the specified size.
 
Method Summary
 InputStream getInputStream()
          Obtain an input stream to read from this location.
 OutputStream getOutputStream()
          Obtain an output stream to write to this location.
 long size()
          Get the size of the file this location points to.
 byte[] toByteArray()
          Get the content at this location as an array of bytes.
 
Methods inherited from class org.jppf.server.protocol.AbstractLocation
addLocationEventListener, copyTo, fireLocationEvent, getPath, removeLocationEventListener, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MemoryLocation

public MemoryLocation(int size)
Initialize this location and create a buffer of the specified size.

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 Detail

getInputStream

public InputStream getInputStream()
                           throws Exception
Obtain an input stream to read from this location.

Returns:
an InputStream instance.
Throws:
Exception - if an I/O error occurs.
See Also:
Location.getInputStream()

getOutputStream

public OutputStream getOutputStream()
                             throws Exception
Obtain an output stream to write to this location.

Returns:
an OutputStream instance.
Throws:
Exception - if an I/O error occurs.
See Also:
Location.getOutputStream()

size

public long size()
Get the size of the file this location points to.

Returns:
the size as a long value, or -1 if the file does not exist.
See Also:
Location.size()

toByteArray

public byte[] toByteArray()
                   throws Exception
Get the content at this location as an array of bytes. This method is overriden from AbstractLocation.toByteArray() for improved performance.

Specified by:
toByteArray in interface Location<byte[]>
Overrides:
toByteArray in class AbstractLocation<byte[]>
Returns:
a byte array.
Throws:
Exception - if an I/O error occurs.
See Also:
AbstractLocation.toByteArray()


Copyright © 2005-2010 JPPF Team.