Class TestResourceLoaders
- java.lang.Object
-
- com.github.robtimus.junit.support.extension.testresource.TestResourceLoaders
-
public final class TestResourceLoaders extends Object
TestResourceLoaderscontains some utility methods that can be used withLoadWithto load resource into objects.- Author:
- Rob Spoor
- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]toBytes(InputStream inputStream)Loads a resource into a byte array.static CharSequencetoCharSequence(Reader reader)Loads a resource into aCharSequence.static CharSequencetoCharSequence(Reader reader, String lineSeparator)Loads a resource into aCharSequence.static List<String>toLines(Reader reader)Loads a resource into a list, where each element represents a line from the resource.static String[]toLinesArray(Reader reader)Loads a resource into an array, where each element represents a line from the resource.static PropertiestoProperties(Reader reader)Loads a resource into aPropertiesobject.static StringtoString(Reader reader)Loads a resource into a string.static StringtoString(Reader reader, String lineSeparator)Loads a resource into a string.static StringBuildertoStringBuilder(Reader reader)Loads a resource into aStringBuilder.static StringBuildertoStringBuilder(Reader reader, String lineSeparator)Loads a resource into aStringBuilder.
-
-
-
Method Detail
-
toString
public static String toString(Reader reader) throws IOException
Loads a resource into a string.- Parameters:
reader- AReadercontaining the contents of the resource.- Returns:
- The content of the resource as a string.
- Throws:
NullPointerException- If the given reader isnull.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- AReadercontaining 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 isnull.IOException- If an error occurred when loading the resource.
-
toStringBuilder
public static StringBuilder toStringBuilder(Reader reader) throws IOException
Loads a resource into aStringBuilder.- Parameters:
reader- AReadercontaining the contents of the resource.- Returns:
- A
StringBuildercontaining the contents of the resource. - Throws:
NullPointerException- If the given reader isnull.IOException- If an error occurred when loading the resource.
-
toStringBuilder
public static StringBuilder toStringBuilder(Reader reader, String lineSeparator) throws IOException
Loads a resource into aStringBuilder. Any existing line separator will be replaced by the given line separator.- Parameters:
reader- AReadercontaining the contents of the resource.lineSeparator- The line separator to use.- Returns:
- A
StringBuildercontaining the contents of the resource. - Throws:
NullPointerException- If the given reader or line separator isnull.IOException- If an error occurred when loading the resource.
-
toCharSequence
public static CharSequence toCharSequence(Reader reader) throws IOException
Loads a resource into aCharSequence.- Parameters:
reader- AReadercontaining the contents of the resource.- Returns:
- The content of the resource as a
CharSequence. - Throws:
NullPointerException- If the given reader isnull.IOException- If an error occurred when loading the resource.
-
toCharSequence
public static CharSequence toCharSequence(Reader reader, String lineSeparator) throws IOException
Loads a resource into aCharSequence. Any existing line separator will be replaced by the given line separator.- Parameters:
reader- AReadercontaining 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 isnull.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- AnInputStreamcontaining the contents of the resource.- Returns:
- The content of the resource as a byte array.
- Throws:
NullPointerException- If the given input stream isnull.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- AReadercontaining the contents of the resource.- Returns:
- A list containing the lines of the resources/
- Throws:
NullPointerException- If the given reader isnull.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- AReadercontaining the contents of the resource.- Returns:
- An array containing the lines of the resources/
- Throws:
NullPointerException- If the given reader isnull.IOException- If an error occurred when loading the resource.- Since:
- 2.2
-
toProperties
public static Properties toProperties(Reader reader) throws IOException
Loads a resource into aPropertiesobject.- Parameters:
reader- AReadercontaining the contents of the resource.- Returns:
- A
Propertiesobject containing the properties from the resource. - Throws:
NullPointerException- If the given reader isnull.IOException- If an error occurred when loading the resource.- See Also:
Properties.load(Reader)
-
-