Package loci.common

Interface IRandomAccess

All Superinterfaces:
java.io.DataInput, java.io.DataOutput
All Known Implementing Classes:
AbstractNIOHandle, ByteArrayHandle, BZip2Handle, FileHandle, GZipHandle, NIOFileHandle, S3Handle, StreamHandle, URLHandle, ZipHandle

public interface IRandomAccess
extends java.io.DataInput, java.io.DataOutput
Interface for random access into structures (e.g., files or arrays).
Author:
Curtis Rueden ctrueden at wisc.edu
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes this random access stream and releases any system resources associated with the stream.
    boolean exists()
    Returns whether this refers to a valid object
    long getFilePointer()
    Returns the current offset in this stream.
    java.nio.ByteOrder getOrder()
    Returns the current order (endianness) of the stream.
    long length()
    Returns the length of this stream.
    int read​(byte[] b)
    Reads up to b.length bytes of data from this stream into an array of bytes.
    int read​(byte[] b, int off, int len)
    Reads up to len bytes of data from this stream into an array of bytes.
    int read​(java.nio.ByteBuffer buffer)
    Reads up to buffer.capacity() bytes of data from this stream into a ByteBuffer.
    int read​(java.nio.ByteBuffer buffer, int offset, int len)
    Reads up to len bytes of data from this stream into a ByteBuffer.
    void seek​(long pos)
    Sets the stream pointer offset, measured from the beginning of this stream, at which the next read or write occurs.
    void setOrder​(java.nio.ByteOrder order)
    Sets the byte order (endianness) of the stream.
    long skipBytes​(long n)
    A long variant of DataInput.skipBytes(int).
    void write​(java.nio.ByteBuffer buf)
    Writes up to buffer.capacity() bytes of data from the given ByteBuffer to this stream.
    void write​(java.nio.ByteBuffer buf, int off, int len)
    Writes up to len bytes of data from the given ByteBuffer to this stream.

    Methods inherited from interface java.io.DataInput

    readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes

    Methods inherited from interface java.io.DataOutput

    write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
  • Method Details

    • close

      void close() throws java.io.IOException
      Closes this random access stream and releases any system resources associated with the stream.
      Throws:
      java.io.IOException - if the underlying stream(s) could not be closed
    • getFilePointer

      long getFilePointer() throws java.io.IOException
      Returns the current offset in this stream.
      Returns:
      the current byte offset within the file; expected to be non-negative and less than the value of #length()
      Throws:
      java.io.IOException - if the offset cannot be retrieved
    • exists

      boolean exists() throws java.io.IOException
      Returns whether this refers to a valid object
      Returns:
      true if this refers to a valid object
      Throws:
      java.io.IOException - if unable to determine whether the object is valid
    • length

      long length() throws java.io.IOException
      Returns the length of this stream.
      Returns:
      the length in bytes of the stream
      Throws:
      java.io.IOException - if the length cannot be retrieved
    • getOrder

      java.nio.ByteOrder getOrder()
      Returns the current order (endianness) of the stream.
      Returns:
      See above.
    • setOrder

      void setOrder​(java.nio.ByteOrder order)
      Sets the byte order (endianness) of the stream.
      Parameters:
      order - Order to set.
    • read

      int read​(byte[] b) throws java.io.IOException
      Reads up to b.length bytes of data from this stream into an array of bytes.
      Parameters:
      b - the array to fill from this stream
      Returns:
      the total number of bytes read into the buffer.
      Throws:
      java.io.IOException - if reading is not possible
    • read

      int read​(byte[] b, int off, int len) throws java.io.IOException
      Reads up to len bytes of data from this stream into an array of bytes.
      Parameters:
      b - the array to fill from this stream
      off - the offset in b from which to start filling; expected to be non-negative and no greater than b.length - len
      len - the number of bytes to read; expected to be positive and no greater than b.length - offset
      Returns:
      the total number of bytes read into the buffer.
      Throws:
      java.io.IOException - if reading is not possible
    • read

      int read​(java.nio.ByteBuffer buffer) throws java.io.IOException
      Reads up to buffer.capacity() bytes of data from this stream into a ByteBuffer.
      Parameters:
      buffer - the ByteBuffer to fill from this stream
      Returns:
      the total number of bytes read into the buffer.
      Throws:
      java.io.IOException - if reading is not possible
    • read

      int read​(java.nio.ByteBuffer buffer, int offset, int len) throws java.io.IOException
      Reads up to len bytes of data from this stream into a ByteBuffer.
      Parameters:
      buffer - the ByteBuffer to fill from this stream
      offset - the offset in b from which to start filling; expected to be non-negative and no greater than buffer.capacity() - len
      len - the number of bytes to read; expected to be positive and no greater than buffer.capacity() - offset
      Returns:
      the total number of bytes read into the buffer.
      Throws:
      java.io.IOException - if reading is not possible
    • seek

      void seek​(long pos) throws java.io.IOException
      Sets the stream pointer offset, measured from the beginning of this stream, at which the next read or write occurs.
      Parameters:
      pos - new byte offset (pointer) in the current stream. Unless otherwise noted, may be larger or smaller than the current pointer, but must be non-negative and less than the value of #length()
      Throws:
      java.io.IOException - if pos is invalid or the seek fails
      See Also:
      getFilePointer()
    • skipBytes

      long skipBytes​(long n) throws java.io.IOException
      A long variant of DataInput.skipBytes(int).
      Parameters:
      n - the number of bytes to skip
      Returns:
      the number of bytes skipped
      Throws:
      java.io.IOException - if the operation failed
    • write

      void write​(java.nio.ByteBuffer buf) throws java.io.IOException
      Writes up to buffer.capacity() bytes of data from the given ByteBuffer to this stream.
      Parameters:
      buf - the ByteBuffer containing bytes to write to this stream
      Throws:
      java.io.IOException - if writing is not possible
    • write

      void write​(java.nio.ByteBuffer buf, int off, int len) throws java.io.IOException
      Writes up to len bytes of data from the given ByteBuffer to this stream.
      Parameters:
      buf - the ByteBuffer containing bytes to write to this stream
      off - the offset in b from which to start writing; expected to be non-negative and no greater than buf.capacity() - len
      len - the number of bytes to write; expected to be positive and no greater than buf.capacity() - offset
      Throws:
      java.io.IOException - if writing is not possible