Package org.scijava.io.handle
Class DataHandles
- java.lang.Object
-
- org.scijava.io.handle.DataHandles
-
public final class DataHandles extends Object
Utility methods for working withDataHandles.- Author:
- Curtis Rueden, Gabriel Einsdorf
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longcopy(DataHandle<Location> in, DataHandle<Location> out)Copies all bytes from the input to the output handle.static longcopy(DataHandle<Location> in, DataHandle<Location> out, int length)Copies up tolengthbytes from the input to the output handle.static longcopy(DataHandle<Location> in, DataHandle<Location> out, long length, Task task)Copies up tolengthbytes from the input to the output handle, reporting the progress to the provided task.static longcopy(DataHandle<Location> in, DataHandle<Location> out, long length, Task task, int bufferSize)Copies up tolengthbytes from the input to the output handle, reporting the progress to the provided task.static longcopy(DataHandle<Location> in, DataHandle<Location> out, Task task)Copies all bytes from the input to the output handle, reporting the progress to the provided task.protected static IOExceptionreadOnlyException()protected static IOExceptionwriteOnlyException()static intwriteUTF(String str, DataOutput out)Writes a string to the specified DataOutput using modified UTF-8 encoding in a machine-independent manner.
-
-
-
Method Detail
-
writeUTF
public static int writeUTF(String str, DataOutput out) throws IOException
Writes a string to the specified DataOutput using modified UTF-8 encoding in a machine-independent manner.First, two bytes are written to out as if by the
writeShortmethod giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the modified UTF-8 encoding for the character. If no exception is thrown, the counterwrittenis incremented by the total number of bytes written to the output stream. This will be at least two plus the length ofstr, and at most two plus thrice the length ofstr.- Parameters:
str- a string to be written.out- destination to write to- Returns:
- The number of bytes written out.
- Throws:
IOException- if an I/O error occurs.
-
readOnlyException
protected static IOException readOnlyException()
-
writeOnlyException
protected static IOException writeOnlyException()
-
copy
public static long copy(DataHandle<Location> in, DataHandle<Location> out) throws IOException
Copies all bytes from the input to the output handle. Reading and writing start at the current positions of the handles.- Parameters:
in- the input handleout- the output handle- Returns:
- the number of bytes copied
- Throws:
IOException- if an I/O error occurs.
-
copy
public static long copy(DataHandle<Location> in, DataHandle<Location> out, Task task) throws IOException
Copies all bytes from the input to the output handle, reporting the progress to the provided task. Reading and writing start at the current positions of the handles.- Parameters:
in- the input handleout- the output handletask- task to report progress to- Returns:
- the number of bytes copied
- Throws:
IOException- if an I/O error occurs.
-
copy
public static long copy(DataHandle<Location> in, DataHandle<Location> out, int length) throws IOException
Copies up tolengthbytes from the input to the output handle. Reading and writing start at the current positions of the handles. Stops early if there are no more bytes available from the input handle.- Parameters:
in- the input handleout- the output handlelength- maximum number of bytes to copy; will copy all bytes if set to0- Returns:
- the number of bytes copied
- Throws:
IOException- if an I/O error occurs.
-
copy
public static long copy(DataHandle<Location> in, DataHandle<Location> out, long length, Task task) throws IOException
Copies up tolengthbytes from the input to the output handle, reporting the progress to the provided task. Reading and writing start at the current positions of the handles. Stops early if there are no more bytes available from the input handle.- Parameters:
in- input handleout- the output handlelength- maximum number of bytes to copy; will copy all bytes if set to0task- a task object to use for reporting the status of the copy operation. Can benullif no reporting is needed.- Returns:
- the number of bytes copied
- Throws:
IOException- if an I/O error occurs.
-
copy
public static long copy(DataHandle<Location> in, DataHandle<Location> out, long length, Task task, int bufferSize) throws IOException
Copies up tolengthbytes from the input to the output handle, reporting the progress to the provided task. Reading and writing start at the current positions of the handles. Stops early if there are no more bytes available from the input handle. Uses a buffer of the provided size, instead of using the default size.- Parameters:
in- input handleout- the output handlelength- maximum number of bytes to copy, will copy all bytes if set to0task- a task object to use for reporting the status of the copy operation. Can benullif no reporting is needed.- Returns:
- the number of bytes copied
- Throws:
IOException- if an I/O error occurs.
-
-