Package loci.common

Class AbstractNIOHandle

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

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

    Fields 
    Modifier and Type Field Description
    protected static java.lang.String EOF_ERROR_MSG
    Error message to be used when instantiating an EOFException.
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractNIOHandle()  
  • Method Summary

    Modifier and Type Method Description
    boolean exists()
    Returns whether this refers to a valid object
    protected abstract void setLength​(long length)
    Sets the new length of the handle.
    protected boolean validateLength​(int writeLength)
    Ensures that the handle has the correct length to be written to and extends it as required.
    protected void validateMode​(java.lang.String mode)
    Ensures that the file mode is either "r" or "rw".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    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

    Methods inherited from interface loci.common.IRandomAccess

    close, getFilePointer, getOrder, length, read, read, read, read, seek, setOrder, skipBytes, write, write
  • Field Details

  • Constructor Details

  • Method Details

    • exists

      public boolean exists() throws java.io.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:
      java.io.IOException - if unable to determine whether the object is valid
    • validateMode

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

      protected boolean validateLength​(int writeLength) throws java.io.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:
      java.io.IOException - If there is an error changing the handle's length.
    • setLength

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