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 objectprotected 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
-
Field Details
-
EOF_ERROR_MSG
protected static final java.lang.String EOF_ERROR_MSGError message to be used when instantiating an EOFException.- See Also:
- Constant Field Values
-
-
Constructor Details
-
AbstractNIOHandle
public AbstractNIOHandle()
-
-
Method Details
-
exists
public boolean exists() throws java.io.IOExceptionDescription copied from interface:IRandomAccess
Returns whether this refers to a valid object- Specified by:
exists
in interfaceIRandomAccess
- 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.IOExceptionEnsures 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.IOExceptionSets the new length of the handle.- Parameters:
length
- New length.- Throws:
java.io.IOException
- If there is an error changing the handle's length.
-