org.scijava.io
Class AbstractDataHandle<L extends Location>

java.lang.Object
  extended by org.scijava.AbstractContextual
      extended by org.scijava.plugin.AbstractRichPlugin
          extended by org.scijava.plugin.AbstractTypedPlugin<D>
              extended by org.scijava.plugin.AbstractWrapperPlugin<L>
                  extended by org.scijava.io.AbstractDataHandle<L>
All Implemented Interfaces:
Closeable, DataInput, DataOutput, Comparable<Prioritized>, Contextual, DataHandle<L>, HasPluginInfo, RichPlugin, SciJavaPlugin, TypedPlugin<L>, WrapperPlugin<L>, Prioritized, Typed<L>
Direct Known Subclasses:
FileHandle

public abstract class AbstractDataHandle<L extends Location>
extends AbstractWrapperPlugin<L>
implements DataHandle<L>

Abstract base class for DataHandle plugins.

Author:
Curtis Rueden

Constructor Summary
AbstractDataHandle()
           
 
Method Summary
 String findString(boolean saveString, int blockSize, String... terminators)
          Reads or skips a string ending with one of the given terminating substrings, using the specified block size for buffering.
 String findString(boolean saveString, String... terminators)
          Reads or skips a string ending with one of the given terminating substrings.
 String findString(int blockSize, String... terminators)
          Reads a string ending with one of the given terminating substrings, using the specified block size for buffering.
 String findString(String... terminators)
          Reads a string ending with one of the given terminating substrings.
 String getEncoding()
          Gets the native encoding of the stream.
 ByteOrder getOrder()
          Returns the current order of the stream.
 boolean isLittleEndian()
          Gets the endianness of the stream.
 int read(byte[] b)
          Reads up to b.length bytes of data from the stream into an array of bytes.
 int read(ByteBuffer buf)
          Reads up to buf.remaining() bytes of data from the stream into a ByteBuffer.
 int read(ByteBuffer buf, int len)
          Reads up to len bytes of data from the stream into a ByteBuffer.
 String readCString()
          Reads a string of arbitrary length, terminated by a null char.
 String readString(int n)
          Reads a string of up to length n.
 String readString(String lastChars)
          Reads a string ending with one of the characters in the given string.
 void setEncoding(String encoding)
          Sets the native encoding of the stream.
 void setOrder(boolean little)
          Sets the endianness of the stream.
 void setOrder(ByteOrder order)
          Sets the byte order of the stream.
 long skip(long n)
          Skips over and discards n bytes of data from the stream.
 void write(ByteBuffer buf)
          Writes up to buf.remaining() bytes of data from the given ByteBuffer to the stream.
 void write(ByteBuffer buf, int len)
          Writes up to len bytes of data from the given ByteBuffer to the stream.
 
Methods inherited from class org.scijava.plugin.AbstractWrapperPlugin
get, set
 
Methods inherited from class org.scijava.plugin.AbstractTypedPlugin
supports
 
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
compareTo, getInfo, getPriority, setInfo, setPriority, toString
 
Methods inherited from class org.scijava.AbstractContextual
context, getContext, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.scijava.io.DataHandle
length, offset, read, read, seek
 
Methods inherited from interface org.scijava.plugin.WrapperPlugin
get, set
 
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
 
Methods inherited from interface org.scijava.Prioritized
getPriority, setPriority
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
 
Methods inherited from interface org.scijava.Typed
getType, supports
 
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 java.io.Closeable
close
 

Constructor Detail

AbstractDataHandle

public AbstractDataHandle()
Method Detail

getOrder

public ByteOrder getOrder()
Description copied from interface: DataHandle
Returns the current order of the stream.

Specified by:
getOrder in interface DataHandle<L extends Location>
Returns:
See above.

isLittleEndian

public boolean isLittleEndian()
Description copied from interface: DataHandle
Gets the endianness of the stream.

Specified by:
isLittleEndian in interface DataHandle<L extends Location>

setOrder

public void setOrder(ByteOrder order)
Description copied from interface: DataHandle
Sets the byte order of the stream.

Specified by:
setOrder in interface DataHandle<L extends Location>
Parameters:
order - Order to set.

setOrder

public void setOrder(boolean little)
Description copied from interface: DataHandle
Sets the endianness of the stream.

Specified by:
setOrder in interface DataHandle<L extends Location>

getEncoding

public String getEncoding()
Description copied from interface: DataHandle
Gets the native encoding of the stream.

Specified by:
getEncoding in interface DataHandle<L extends Location>

setEncoding

public void setEncoding(String encoding)
Description copied from interface: DataHandle
Sets the native encoding of the stream.

Specified by:
setEncoding in interface DataHandle<L extends Location>

read

public int read(ByteBuffer buf)
         throws IOException
Description copied from interface: DataHandle
Reads up to buf.remaining() bytes of data from the stream into a ByteBuffer.

Specified by:
read in interface DataHandle<L extends Location>
Throws:
IOException

read

public int read(ByteBuffer buf,
                int len)
         throws IOException
Description copied from interface: DataHandle
Reads up to len bytes of data from the stream into a ByteBuffer.

Specified by:
read in interface DataHandle<L extends Location>
Returns:
the total number of bytes read into the buffer.
Throws:
IOException

write

public void write(ByteBuffer buf)
           throws IOException
Description copied from interface: DataHandle
Writes up to buf.remaining() bytes of data from the given ByteBuffer to the stream.

Specified by:
write in interface DataHandle<L extends Location>
Throws:
IOException

write

public void write(ByteBuffer buf,
                  int len)
           throws IOException
Description copied from interface: DataHandle
Writes up to len bytes of data from the given ByteBuffer to the stream.

Specified by:
write in interface DataHandle<L extends Location>
Throws:
IOException

readCString

public String readCString()
                   throws IOException
Description copied from interface: DataHandle
Reads a string of arbitrary length, terminated by a null char.

Specified by:
readCString in interface DataHandle<L extends Location>
Throws:
IOException

readString

public String readString(int n)
                  throws IOException
Description copied from interface: DataHandle
Reads a string of up to length n.

Specified by:
readString in interface DataHandle<L extends Location>
Throws:
IOException

readString

public String readString(String lastChars)
                  throws IOException
Description copied from interface: DataHandle
Reads a string ending with one of the characters in the given string.

Specified by:
readString in interface DataHandle<L extends Location>
Throws:
IOException
See Also:
DataHandle.findString(String...)

findString

public String findString(String... terminators)
                  throws IOException
Description copied from interface: DataHandle
Reads a string ending with one of the given terminating substrings.

Specified by:
findString in interface DataHandle<L extends Location>
Parameters:
terminators - The strings for which to search.
Returns:
The string from the initial position through the end of the terminating sequence, or through the end of the stream if no terminating sequence is found.
Throws:
IOException

findString

public String findString(boolean saveString,
                         String... terminators)
                  throws IOException
Description copied from interface: DataHandle
Reads or skips a string ending with one of the given terminating substrings.

Specified by:
findString in interface DataHandle<L extends Location>
Parameters:
saveString - Whether to collect the string from the current file pointer to the terminating bytes, and return it. If false, returns null.
terminators - The strings for which to search.
Returns:
The string from the initial position through the end of the terminating sequence, or through the end of the stream if no terminating sequence is found, or null if saveString flag is unset.
Throws:
IOException - If saveString flag is set and the maximum search length (512 MB) is exceeded.

findString

public String findString(int blockSize,
                         String... terminators)
                  throws IOException
Description copied from interface: DataHandle
Reads a string ending with one of the given terminating substrings, using the specified block size for buffering.

Specified by:
findString in interface DataHandle<L extends Location>
Parameters:
blockSize - The block size to use when reading bytes in chunks.
terminators - The strings for which to search.
Returns:
The string from the initial position through the end of the terminating sequence, or through the end of the stream if no terminating sequence is found.
Throws:
IOException

findString

public String findString(boolean saveString,
                         int blockSize,
                         String... terminators)
                  throws IOException
Description copied from interface: DataHandle
Reads or skips a string ending with one of the given terminating substrings, using the specified block size for buffering.

Specified by:
findString in interface DataHandle<L extends Location>
Parameters:
saveString - Whether to collect the string from the current file pointer to the terminating bytes, and return it. If false, returns null.
blockSize - The block size to use when reading bytes in chunks.
terminators - The strings for which to search.
Returns:
The string from the initial position through the end of the terminating sequence, or through the end of the stream if no terminating sequence is found, or null if saveString flag is unset.
Throws:
IOException - If saveString flag is set and the maximum search length (512 MB) is exceeded.

read

public int read(byte[] b)
         throws IOException
Description copied from interface: DataHandle
Reads up to b.length bytes of data from the stream into an array of bytes.

Specified by:
read in interface DataHandle<L extends Location>
Returns:
the total number of bytes read into the buffer.
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Description copied from interface: DataHandle
Skips over and discards n bytes of data from the stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.

Specified by:
skip in interface DataHandle<L extends Location>
Parameters:
n - - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - - if an I/O error occurs.


Copyright © 2009–2015 SciJava. All rights reserved.