Class RandomAccessSource

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class RandomAccessSource
    extends java.lang.Object
    implements java.lang.AutoCloseable
    RandomAccessSource is a wrapper around a native memory-mapped file or byte array. It is used to provide a random access interface to the underlying data.
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomAccessSource​(byte[] data)
      Constructs RandomAccessSource from the given byte array.
      RandomAccessSource​(java.io.InputStream inputStream)
      Constructs RandomAccessSource from the given InputStream effectively reading the whole stream into memory.
      RandomAccessSource​(java.lang.String filePath)
      Constructs RandomAccessSource from the given file effectively creating a memory-mapping.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes native resources held by the object.
      protected void finalize()  
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RandomAccessSource

        public RandomAccessSource​(java.lang.String filePath)
                           throws java.io.IOException
        Constructs RandomAccessSource from the given file effectively creating a memory-mapping. If the desired source is indeed a file on disk, you should prefer this constructor over the InputStream one as memory mapping allows more memory consumption efficient processing.
        Parameters:
        filePath - path to the file
        Throws:
        java.io.IOException - if the file memory mapping fails (e.g. because the file does not exist)
      • RandomAccessSource

        public RandomAccessSource​(byte[] data)
        Constructs RandomAccessSource from the given byte array.
        Parameters:
        data - the byte array to use as the source
      • RandomAccessSource

        public RandomAccessSource​(java.io.InputStream inputStream)
                           throws java.io.IOException
        Constructs RandomAccessSource from the given InputStream effectively reading the whole stream into memory. If your original source is an InputStream you should prefer this constructor over creating a java byte array and using the byte array constructor.
        Parameters:
        inputStream - the input stream to read from
        Throws:
        java.io.IOException - if reading from the stream fails
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • close

        public void close()
        Closes native resources held by the object.
        Specified by:
        close in interface java.lang.AutoCloseable