Class TestResourceLoaders
- java.lang.Object
-
- com.github.robtimus.junit.support.extension.testresource.TestResourceLoaders
-
public final class TestResourceLoaders extends Object
TestResourceLoaders
contains some utility methods that can be used withLoadWith
to 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 CharSequence
toCharSequence(Reader reader)
Loads a resource into aCharSequence
.static CharSequence
toCharSequence(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 Properties
toProperties(Reader reader)
Loads a resource into aProperties
object.static String
toString(Reader reader)
Loads a resource into a string.static String
toString(Reader reader, String lineSeparator)
Loads a resource into a string.static StringBuilder
toStringBuilder(Reader reader)
Loads a resource into aStringBuilder
.static StringBuilder
toStringBuilder(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
- AReader
containing 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
- AReader
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 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
- AReader
containing the contents of the resource.- Returns:
- A
StringBuilder
containing 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
- AReader
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 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
- AReader
containing 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
- AReader
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 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
- AnInputStream
containing 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
- AReader
containing 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
- AReader
containing 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 aProperties
object.- Parameters:
reader
- AReader
containing the contents of the resource.- Returns:
- A
Properties
object 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)
-
-