Class IoUtils

java.lang.Object
nva.commons.core.ioutils.IoUtils

public final class IoUtils extends Object
  • Field Details

  • Method Details

    • inputStreamFromResources

      @Deprecated public static InputStream inputStreamFromResources(Path path)
      Deprecated.
      Read resource file as an InputStream. The root folder for the resources is considered to be the folders src/main/resources and src/test/resources/, or any other standard reosources folder.
      Parameters:
      path - the Path to the resource.
      Returns:
      an InputStream with the data.
    • inputStreamFromResources

      public static InputStream inputStreamFromResources(String path)
      Read resource file as an InputStream. The root folder for the resources is considered to be the folders src/main/resources and src/test/resources/, or any other standard reosources folder.

      The resource is first looked up via the thread context class loader, falling back to the class loader that loaded this class. The fallback is required on threads whose context class loader cannot see application classes, such as ForkJoinPool common-pool workers on AWS Lambda.

      Parameters:
      path - the path to the resource.
      Returns:
      an InputStream with the data.
    • pathToString

      public static String pathToString(Path path)
    • streamToString

      public static String streamToString(InputStream stream)
      Return a String the stream data encoded in UTF-8.
      Parameters:
      stream - the InputStream
      Returns:
      the output String.
    • stringFromFile

      public static String stringFromFile(Path path)
      Read file as a String. Encoding is UTF-8. New lines are being preserved.
      Parameters:
      path - Path to the file
      Returns:
      the content of the file in a String.
    • linesfromResource

      public static List<String> linesfromResource(Path path)
      Read resource file as a List of Strings. The root folder for the resources is considered to be the folders src/main/resources and src/test/resources/, or any other standard resources folder. Each element of the list contains a line of the file.
      Parameters:
      path - the Path to the resource.
      Returns:
      a List with the lines of the file.
    • stringFromResources

      public static String stringFromResources(Path path)
      Read resource file as a String The root folder for the resources is considered to be the folders src/main/resources and src/test/resources/, or any other standard resources folder. New lines in the resource file are preserved
      Parameters:
      path - the Path to the resource.
      Returns:
      a String with the contents of the file.
    • stringToStream

      public static InputStream stringToStream(String input)
      Tranform a string to an inputStream. Encoding is UTF-8.
      Parameters:
      input - a String
      Returns:
      a InputStream
    • inputStreamToBytes

      public static byte[] inputStreamToBytes(InputStream inputStream) throws IOException
      Throws:
      IOException