Class TestResourceLoaders


  • public final class TestResourceLoaders
    extends Object
    TestResourceLoaders contains some utility methods that can be used with LoadWith to load resource into objects.
    Author:
    Rob Spoor
    Since:
    2.0
    • Method Detail

      • toString

        public static String toString​(Reader reader)
                               throws IOException
        Loads a resource into a string.
        Parameters:
        reader - A Reader containing the contents of the resource.
        Returns:
        The content of the resource as a string.
        Throws:
        NullPointerException - If the given reader is null.
        IOException - If an error occurred when loading the resource.
      • toString

        public static String toString​(Reader reader,
                                      String lineSeparator)
                               throws IOException
        Loads a resource into a string. Any existing line separator will be replaced by the given line separator.
        Parameters:
        reader - A Reader containing the contents of the resource.
        lineSeparator - The line separator to use.
        Returns:
        The content of the resource as a string.
        Throws:
        NullPointerException - If the given reader or line separator is null.
        IOException - If an error occurred when loading the resource.
      • toStringBuilder

        public static StringBuilder toStringBuilder​(Reader reader,
                                                    String lineSeparator)
                                             throws IOException
        Loads a resource into a StringBuilder. Any existing line separator will be replaced by the given line separator.
        Parameters:
        reader - A Reader containing the contents of the resource.
        lineSeparator - The line separator to use.
        Returns:
        A StringBuilder containing the contents of the resource.
        Throws:
        NullPointerException - If the given reader or line separator is null.
        IOException - If an error occurred when loading the resource.
      • toCharSequence

        public static CharSequence toCharSequence​(Reader reader,
                                                  String lineSeparator)
                                           throws IOException
        Loads a resource into a CharSequence. Any existing line separator will be replaced by the given line separator.
        Parameters:
        reader - A Reader containing the contents of the resource.
        lineSeparator - The line separator to use.
        Returns:
        The content of the resource as a CharSequence.
        Throws:
        NullPointerException - If the given reader or line separator is null.
        IOException - If an error occurred when loading the resource.
      • toBytes

        public static byte[] toBytes​(InputStream inputStream)
                              throws IOException
        Loads a resource into a byte array.
        Parameters:
        inputStream - An InputStream containing the contents of the resource.
        Returns:
        The content of the resource as a byte array.
        Throws:
        NullPointerException - If the given input stream is null.
        IOException - If an error occurred when loading the resource.
      • toLines

        public static List<String> toLines​(Reader reader)
                                    throws IOException
        Loads a resource into a list, where each element represents a line from the resource.
        Parameters:
        reader - A Reader containing the contents of the resource.
        Returns:
        A list containing the lines of the resources/
        Throws:
        NullPointerException - If the given reader is null.
        IOException - If an error occurred when loading the resource.
        Since:
        2.2
      • toLinesArray

        public static String[] toLinesArray​(Reader reader)
                                     throws IOException
        Loads a resource into an array, where each element represents a line from the resource.
        Parameters:
        reader - A Reader containing the contents of the resource.
        Returns:
        An array containing the lines of the resources/
        Throws:
        NullPointerException - If the given reader is null.
        IOException - If an error occurred when loading the resource.
        Since:
        2.2