Class Utils


  • public final class Utils
    extends Object
    Utility methods.
    Author:
    Matthew Tropiano
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • createPathForFile

        public static boolean createPathForFile​(File file)
        Creates the necessary directories for a file path.
        Parameters:
        file - the abstract file path.
        Returns:
        true if the paths were made (or exists), false otherwise.
      • createPathForFile

        public static boolean createPathForFile​(String path)
        Creates the necessary directories for a file path.
        Parameters:
        path - the abstract path.
        Returns:
        true if the paths were made (or exists), false otherwise.
      • createPath

        public static boolean createPath​(String path)
        Creates the necessary directories for a file path.
        Parameters:
        path - the abstract path.
        Returns:
        true if the paths were made (or exists), false otherwise.
      • relay

        public static int relay​(InputStream in,
                                OutputStream out)
                         throws IOException
        Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.
        Parameters:
        in - the input stream to grab data from.
        out - the output stream to write the data to.
        Returns:
        the total amount of bytes relayed.
        Throws:
        IOException - if a read or write error occurs.
      • relay

        public static int relay​(InputStream in,
                                OutputStream out,
                                int bufferSize)
                         throws IOException
        Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.
        Parameters:
        in - the input stream to grab data from.
        out - the output stream to write the data to.
        bufferSize - the buffer size for the I/O. Must be > 0.
        Returns:
        the total amount of bytes relayed.
        Throws:
        IOException - if a read or write error occurs.
      • relay

        public static int relay​(InputStream in,
                                OutputStream out,
                                int bufferSize,
                                int maxLength)
                         throws IOException
        Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.
        Parameters:
        in - the input stream to grab data from.
        out - the output stream to write the data to.
        bufferSize - the buffer size for the I/O. Must be > 0.
        maxLength - the maximum amount of bytes to relay, or a value < 0 for no max.
        Returns:
        the total amount of bytes relayed.
        Throws:
        IOException - if a read or write error occurs.
      • close

        public static void close​(AutoCloseable c)
        Attempts to close an AutoCloseable object. If the object is null, this does nothing.
        Parameters:
        c - the reference to the AutoCloseable object.