Package net.morimekta.testing
Class ResourceUtils
- java.lang.Object
-
- net.morimekta.testing.ResourceUtils
-
public class ResourceUtils extends java.lang.Object
Utility for help with managing resources during tests.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.File
copyResourceTo(java.lang.String resource, java.io.File target)
Copy a resource to the target directory.static java.nio.ByteBuffer
getResourceAsByteBuffer(java.lang.String resource)
Get the resource content as a byte buffer.static byte[]
getResourceAsBytes(java.lang.String resource)
Get the resource content as a byte array.static java.io.BufferedInputStream
getResourceAsStream(java.lang.String resource)
Get the resource as a buffered input stream.static java.lang.String
getResourceAsString(java.lang.String resource)
Get the resource content as a string.static java.io.File
writeContentTo(java.lang.String content, java.io.File target)
Write the file content to the target file.
-
-
-
Method Detail
-
copyResourceTo
public static java.io.File copyResourceTo(java.lang.String resource, java.io.File target)
Copy a resource to the target directory. The resource file retains it's name. If the target is a file, the file is overwritten with the content of the resource file.- Parameters:
resource
- The resource path.target
- Target file or directory.- Returns:
- File created and written to.
-
writeContentTo
public static java.io.File writeContentTo(java.lang.String content, java.io.File target)
Write the file content to the target file.- Parameters:
content
- The file content.target
- The file to write to.- Returns:
- File written to.
-
getResourceAsStream
public static java.io.BufferedInputStream getResourceAsStream(java.lang.String resource)
Get the resource as a buffered input stream. Fail if no such resource exists.- Parameters:
resource
- The resource to get.- Returns:
- The buffered input stream.
-
getResourceAsBytes
public static byte[] getResourceAsBytes(java.lang.String resource)
Get the resource content as a byte array. Fail if the resource does not exist, or if we failed to read the resource file.- Parameters:
resource
- The resource to read.- Returns:
- The resource content as byte array.
-
getResourceAsByteBuffer
public static java.nio.ByteBuffer getResourceAsByteBuffer(java.lang.String resource)
Get the resource content as a byte buffer. Fail if the resource does not exist, or if we failed to read the resource file.- Parameters:
resource
- The resource to read.- Returns:
- The resource content as byte buffer.
-
getResourceAsString
public static java.lang.String getResourceAsString(java.lang.String resource)
Get the resource content as a string. Fail if the resource does not exist, or if we failed to read the resource file.- Parameters:
resource
- The resource to read.- Returns:
- The resource content as string.
-
-