Package software.amazon.smithy.utils
Class IoUtils
- java.lang.Object
-
- software.amazon.smithy.utils.IoUtils
-
public final class IoUtils extends java.lang.Object
Utilities for IO operations.
-
-
Method Summary
Modifier and Type Method Description static java.lang.String
readUtf8File(java.lang.String path)
Reads a file into a UTF-8 encoded string.static java.lang.String
readUtf8File(java.nio.file.Path path)
Reads a file into a UTF-8 encoded string.static java.lang.String
readUtf8Resource(java.lang.ClassLoader classLoader, java.lang.String resourcePath)
Reads a class loader resource into a UTF-8 string.static java.lang.String
readUtf8Resource(java.lang.Class clazz, java.lang.String resourcePath)
Reads a class resource into a UTF-8 string.static byte[]
toByteArray(java.io.InputStream is)
Reads and returns the rest of the given input stream as a byte array.static java.lang.String
toUtf8String(java.io.InputStream is)
Reads and returns the rest of the given input stream as a string.
-
-
-
Method Detail
-
toByteArray
public static byte[] toByteArray(java.io.InputStream is)
Reads and returns the rest of the given input stream as a byte array. Caller is responsible for closing the given input stream.- Parameters:
is
- The input stream to convert.- Returns:
- The converted bytes.
-
toUtf8String
public static java.lang.String toUtf8String(java.io.InputStream is)
Reads and returns the rest of the given input stream as a string. Caller is responsible for closing the given input stream.- Parameters:
is
- The input stream to convert.- Returns:
- The converted string.
-
readUtf8File
public static java.lang.String readUtf8File(java.lang.String path)
Reads a file into a UTF-8 encoded string.- Parameters:
path
- Path to the file to read.- Returns:
- Returns the contents of the file.
- Throws:
java.lang.RuntimeException
- if the file can't be read or encoded.
-
readUtf8File
public static java.lang.String readUtf8File(java.nio.file.Path path)
Reads a file into a UTF-8 encoded string.- Parameters:
path
- Path to the file to read.- Returns:
- Returns the contents of the file.
- Throws:
java.lang.RuntimeException
- if the file can't be read or encoded.
-
readUtf8Resource
public static java.lang.String readUtf8Resource(java.lang.ClassLoader classLoader, java.lang.String resourcePath)
Reads a class loader resource into a UTF-8 string.This is equivalent to reading the contents of an
InputStream
fromClassLoader.getResourceAsStream(java.lang.String)
.- Parameters:
classLoader
- Class loader to load from.resourcePath
- Path to the resource to load.- Returns:
- Returns the loaded resource.
- Throws:
java.io.UncheckedIOException
- if the resource cannot be loaded.
-
readUtf8Resource
public static java.lang.String readUtf8Resource(java.lang.Class clazz, java.lang.String resourcePath)
Reads a class resource into a UTF-8 string.This is equivalent to reading the contents of an
InputStream
fromClass.getResourceAsStream(String)
.- Parameters:
clazz
- Class to load from.resourcePath
- Path to the resource to load.- Returns:
- Returns the loaded resource.
- Throws:
java.io.UncheckedIOException
- if the resource cannot be loaded.
-
-