Package loci.common

Class AbstractNIOHandle

java.lang.Object
loci.common.AbstractNIOHandle
All Implemented Interfaces:
DataInput, DataOutput, IRandomAccess
Direct Known Subclasses:
ByteArrayHandle, NIOFileHandle

public abstract class AbstractNIOHandle extends Object implements IRandomAccess
A wrapper for buffered NIO logic that implements the IRandomAccess interface.
Author:
Chris Allan (callan at blackcat dot ca)
See Also:
  • Field Details

    • EOF_ERROR_MSG

      protected static final String EOF_ERROR_MSG
      Error message to be used when instantiating an EOFException.
      See Also:
  • Constructor Details

    • AbstractNIOHandle

      public AbstractNIOHandle()
  • Method Details

    • exists

      public boolean exists() throws IOException
      Description copied from interface: IRandomAccess
      Returns whether this refers to a valid object
      Specified by:
      exists in interface IRandomAccess
      Returns:
      true if this refers to a valid object
      Throws:
      IOException - if unable to determine whether the object is valid
    • validateMode

      protected void validateMode(String mode)
      Ensures that the file mode is either "r" or "rw".
      Parameters:
      mode - Mode to validate.
      Throws:
      IllegalArgumentException - If an illegal mode is passed.
    • validateLength

      protected boolean validateLength(int writeLength) throws IOException
      Ensures that the handle has the correct length to be written to and extends it as required.
      Parameters:
      writeLength - Number of bytes to write.
      Returns:
      true if the buffer has not required an extension. false otherwise.
      Throws:
      IOException - If there is an error changing the handle's length.
    • setLength

      protected abstract void setLength(long length) throws IOException
      Sets the new length of the handle.
      Parameters:
      length - New length.
      Throws:
      IOException - If there is an error changing the handle's length.