Class DataHandles


  • public final class DataHandles
    extends Object
    Utility methods for working with DataHandles.
    Author:
    Curtis Rueden, Gabriel Einsdorf
    • 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 writeShort method 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 counter written is incremented by the total number of bytes written to the output stream. This will be at least two plus the length of str, and at most two plus thrice the length of str.

        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 handle
        out - 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 handle
        out - the output handle
        task - 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 to length bytes 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 handle
        out - the output handle
        length - maximum number of bytes to copy; will copy all bytes if set to 0
        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 to length 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. Stops early if there are no more bytes available from the input handle.
        Parameters:
        in - input handle
        out - the output handle
        length - maximum number of bytes to copy; will copy all bytes if set to 0
        task - a task object to use for reporting the status of the copy operation. Can be null if 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 to length 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. 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 handle
        out - the output handle
        length - maximum number of bytes to copy, will copy all bytes if set to 0
        task - a task object to use for reporting the status of the copy operation. Can be null if no reporting is needed.
        Returns:
        the number of bytes copied
        Throws:
        IOException - if an I/O error occurs.