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:
IRandomAccess,RandomAccessFile
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringEOF_ERROR_MSGError message to be used when instantiating an EOFException.
-
Constructor Summary
Constructors Constructor Description AbstractNIOHandle()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanexists()Returns whether this refers to a valid objectprotected abstract voidsetLength(long length)Sets the new length of the handle.protected booleanvalidateLength(int writeLength)Ensures that the handle has the correct length to be written to and extends it as required.protected voidvalidateMode(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
-
-
-
-
Field Detail
-
EOF_ERROR_MSG
protected static final String EOF_ERROR_MSG
Error message to be used when instantiating an EOFException.- See Also:
- Constant Field Values
-
-
Method Detail
-
exists
public boolean exists() throws IOExceptionDescription copied from interface:IRandomAccessReturns whether this refers to a valid object- Specified by:
existsin interfaceIRandomAccess- 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 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:
trueif the buffer has not required an extension.falseotherwise.- Throws:
IOException- If there is an error changing the handle's length.
-
setLength
protected abstract void setLength(long length) throws IOExceptionSets the new length of the handle.- Parameters:
length- New length.- Throws:
IOException- If there is an error changing the handle's length.
-
-