Package org.scijava.io.handle
Class FileHandle
-
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable,Comparable<Prioritized>,Contextual,Identifiable,DataHandle<FileLocation>,Locatable,Logged,HasPluginInfo,RichPlugin,SciJavaPlugin,TypedPlugin<FileLocation>,WrapperPlugin<FileLocation>,Prioritized,Typed<FileLocation>,Versioned
public class FileHandle extends AbstractDataHandle<FileLocation>
DataHandlefor aFileLocation.- Author:
- Curtis Rueden
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.scijava.io.handle.DataHandle
DataHandle.ByteOrder
-
-
Field Summary
-
Fields inherited from interface org.scijava.io.handle.DataHandle
DEFAULT_BLOCK_SIZE, MAX_SEARCH_SIZE
-
-
Constructor Summary
Constructors Constructor Description FileHandle()FileHandle(FileLocation location)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanexists()Tests whether this handle's location actually exists at the source.StringgetMode()RandomAccessFilegetRandomAccessFile()Gets the random access file object backing this FileHandle.Class<FileLocation>getType()Gets the type associated with the object.booleanisReadable()Gets whether reading from this handle is supported.booleanisWritable()Gets whether writing to this handle is supported.DatelastModified()Gets the last modified timestamp of the location.longlength()Returns the length of the data in bytes.longoffset()Returns the current offset in the stream.intread()Reads the next byte of data from the stream.intread(byte[] b)Reads up to b.length bytes of data from the stream into an array of bytes.intread(byte[] b, int off, int len)Reads up tolenbytes of data from the stream into an array of bytes.booleanreadBoolean()bytereadByte()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)StringreadLine()intreadUnsignedByte()StringreadUTF()voidseek(long pos)Sets the stream offset, measured from the beginning of the stream, at which the next read or write occurs.voidset(FileLocation loc)Associates the given data object with this plugin.voidsetLength(long length)Sets the new length of the handle.voidsetMode(String mode)intskipBytes(int n)voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(String s)voidwriteChars(String s)voidwriteUTF(String str)-
Methods inherited from class org.scijava.io.handle.AbstractDataHandle
conversionBuffer, getEncoding, getOrder, setEncoding, setOrder
-
Methods inherited from class org.scijava.plugin.AbstractWrapperPlugin
get
-
Methods inherited from class org.scijava.plugin.AbstractTypedPlugin
supports
-
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
getInfo, getPriority, setInfo, setPriority, toString
-
Methods inherited from class org.scijava.AbstractContextual
context, getContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.io.handle.DataHandle
available, checksum, ensureReadable, ensureWritable, findString, findString, findString, findString, isBigEndian, isLittleEndian, readChar, readCString, readDouble, readFloat, readInt, readLong, readShort, readString, readString, readUnsignedShort, setLittleEndian, skip, writeChar, writeDouble, writeFloat, writeInt, writeLine, writeLong, writeShort
-
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
-
Methods inherited from interface org.scijava.Locatable
getLocation
-
Methods inherited from interface org.scijava.Prioritized
compareTo, getPriority, setPriority
-
Methods inherited from interface org.scijava.plugin.RichPlugin
getIdentifier, log
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
Methods inherited from interface org.scijava.plugin.WrapperPlugin
get
-
-
-
-
Constructor Detail
-
FileHandle
public FileHandle()
-
FileHandle
public FileHandle(FileLocation location)
-
-
Method Detail
-
getRandomAccessFile
public RandomAccessFile getRandomAccessFile() throws IOException
Gets the random access file object backing this FileHandle. If the underlying file does not exist yet, it will be created.- Throws:
IOException
-
getMode
public String getMode()
-
setMode
public void setMode(String mode)
-
isReadable
public boolean isReadable()
Description copied from interface:DataHandleGets whether reading from this handle is supported.
-
isWritable
public boolean isWritable()
Description copied from interface:DataHandleGets whether writing to this handle is supported.
-
exists
public boolean exists()
Description copied from interface:DataHandleTests whether this handle's location actually exists at the source.- Returns:
- True if the location exists; false if not.
-
lastModified
public Date lastModified()
Description copied from interface:DataHandleGets the last modified timestamp of the location.- Returns:
- The last modified timestamp, or null if the handle does not support this feature or if the location does not exist.
-
offset
public long offset() throws IOExceptionDescription copied from interface:DataHandleReturns the current offset in the stream.- Throws:
IOException
-
length
public long length() throws IOExceptionDescription copied from interface:DataHandleReturns the length of the data in bytes.- Returns:
- The length, or -1 if the length is unknown.
- Throws:
IOException
-
setLength
public void setLength(long length) throws IOExceptionDescription copied from interface:DataHandleSets the new length of the handle.- Parameters:
length- New length.- Throws:
IOException- If there is an error changing the handle's length.
-
read
public int read() throws IOExceptionDescription copied from interface:DataHandleReads the next byte of data from the stream.- Returns:
- the next byte of data, or -1 if the end of the stream is reached.
- Throws:
IOException- - if an I/O error occurs.
-
read
public int read(byte[] b) throws IOExceptionDescription copied from interface:DataHandleReads up to b.length bytes of data from the stream into an array of bytes.- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOExceptionDescription copied from interface:DataHandleReads up tolenbytes of data from the stream into an array of bytes.- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException
-
seek
public void seek(long pos) throws IOExceptionDescription copied from interface:DataHandleSets the stream offset, measured from the beginning of the stream, at which the next read or write occurs.- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException- Throws:
IOException
-
readByte
public byte readByte() throws IOException- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Throws:
IOException
-
write
public void write(int b) throws IOException- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean v) throws IOException- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Throws:
IOException
-
writeUTF
public void writeUTF(String str) throws IOException
- Throws:
IOException
-
close
public void close() throws IOException- Throws:
IOException
-
set
public void set(FileLocation loc)
Description copied from interface:WrapperPluginAssociates the given data object with this plugin. It must be a compatible object (i.e.,Typed.supports(T)must return true).- Specified by:
setin interfaceWrapperPlugin<FileLocation>- Overrides:
setin classAbstractWrapperPlugin<FileLocation>- Parameters:
loc- The data object to associate with the plugin.
-
getType
public Class<FileLocation> getType()
Description copied from interface:TypedGets the type associated with the object.
-
-