Class IoUtils

java.lang.Object
es.kukenan.smartfi.common.utils.IoUtils

public class IoUtils extends Object
Input/Output utils.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default size for buffers used in this class.
    static final String
    Default charset.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Hide constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    read(File file)
    Fully read the given file and return its bytes.
    static byte[]
    Fully read the given stream and return its bytes.
    static String
    Fully read the given stream and return its bytes as a String.
    static boolean
    Safely cleanup the given path.
    static void
    store(InputStream is, File file)
    Store the given input stream as the given file contents.
    static int
    Fully transfer the given stream to the given output stream and return the transferred byte count.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • IoUtils

      private IoUtils()
      Hide constructor.
  • Method Details

    • read

      public static byte[] read(InputStream is) throws IOException
      Fully read the given stream and return its bytes.
      Parameters:
      is - the stream to read from.
      Returns:
      the bytes read.
      Throws:
      IOException - if any IOException is thrown during the process.
    • read

      public static byte[] read(File file) throws IOException
      Fully read the given file and return its bytes.
      Parameters:
      file - the file to read from.
      Returns:
      the bytes read.
      Throws:
      IOException - if any IOException is thrown during the process.
    • transfer

      public static int transfer(InputStream is, OutputStream os) throws IOException
      Fully transfer the given stream to the given output stream and return the transferred byte count.
      Parameters:
      is - the stream to read from.
      os - the stream to write to.
      Returns:
      the transferred byte count.
      Throws:
      IOException - if any IOException is thrown during the process.
    • readString

      public static String readString(InputStream is) throws IOException
      Fully read the given stream and return its bytes as a String.
      Parameters:
      is - the stream to read from.
      Returns:
      the string created from the bytes read.
      Throws:
      IOException - if any IOException is thrown during the process.
    • store

      public static void store(InputStream is, File file) throws IOException
      Store the given input stream as the given file contents.
      Parameters:
      is - data stream to store.
      file - the file where to store de data.
      Throws:
      IOException - if any IOException is thrown during the process.
    • safeCleanUp

      public static boolean safeCleanUp(Path path)
      Safely cleanup the given path. (If an error occurs the method will not fail but return false).
      Parameters:
      path - the directory to delete.
      Returns:
      true if no error caught, false in other case.