Class MemoryLocation

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

public class MemoryLocation extends AbstractLocation<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:
  • Constructor Details

    • MemoryLocation

      public MemoryLocation(long size)
      Initialize this location and create a buffer of the specified size. The size is cast to an int value 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

      public InputStream getInputStream() throws Exception
      Description copied from interface: Location
      Obtain an input stream to read from this location.
      Returns:
      an InputStream instance.
      Throws:
      Exception - if an I/O error occurs.
    • getOutputStream

      public OutputStream getOutputStream() throws Exception
      Description copied from interface: Location
      Obtain an output stream to write to this location.
      Returns:
      an OutputStream instance.
      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 from AbstractLocation.toByteArray() for improved performance.
      Specified by:
      toByteArray in interface Location<byte[]>
      Overrides:
      toByteArray in class AbstractLocation<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.