public class Utils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static int |
copyStreams(java.io.InputStream is,
java.io.OutputStream os)
Copies an
InputStream into on OutputStream byte-to-byte. |
static int |
copyStreams(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
Copies an
InputStream into on OutputStream byte-to-byte. |
static TypeAwareByteSource |
getFile(java.io.File file)
Locates and reads a file either by a direct path or by a relative path in classpath.
|
static ByteSource |
getFileAsByteSource(java.io.File file)
Locates and reads a file either by a direct path or by a relative path in classpath.
|
static java.net.URL |
getResource(java.lang.String path)
Finds a resource with a given name.
|
static java.io.InputStream |
getResourceAsStream(java.lang.String path)
Returns an input stream for reading the specified resource.
|
static byte[] |
readFileToBytes(java.io.File file)
Reads a
File into an array of bytes. |
static byte[] |
readInputStreamToBytes(java.io.InputStream is)
Reads an
InputStream into an array of bytes. |
static byte[] |
readInputStreamToBytes(java.io.InputStream is,
int bufferSize)
Reads an
InputStream into an array of bytes. |
static java.lang.String |
readInputStreamToString(java.io.InputStream is)
Reads an
InputStream into a String. |
@Nonnull
public static java.lang.String readInputStreamToString(@Nonnull
java.io.InputStream is)
throws java.io.IOException
InputStream into a String. Uses UTF-8 encoding and 10 kilobytes buffer by
default.is - a stream to read fromjava.io.IOException - in case of a read errorpublic static byte[] readInputStreamToBytes(@Nonnull
java.io.InputStream is)
throws java.io.IOException
InputStream into an array of bytes. Uses 10 kilobytes buffer by default.is - a stream to read fromjava.io.IOException - in case of a read errorpublic static int copyStreams(@Nonnull
java.io.InputStream is,
@Nonnull
java.io.OutputStream os,
int bufferSize)
throws java.io.IOException
InputStream into on OutputStream byte-to-byte.is - a stream to read fromos - a stream to write tobufferSize - size of read buffer in bytesjava.io.IOException - in case of a read errorpublic static int copyStreams(@Nonnull
java.io.InputStream is,
@Nonnull
java.io.OutputStream os)
throws java.io.IOException
InputStream into on OutputStream byte-to-byte.is - a stream to read fromos - a stream to write tojava.io.IOException - in case of a read errorpublic static byte[] readInputStreamToBytes(@Nonnull
java.io.InputStream is,
int bufferSize)
throws java.io.IOException
InputStream into an array of bytes.is - a stream to read frombufferSize - size of read buffer in bytesjava.io.IOException - in case of a read errorpublic static byte[] readFileToBytes(@Nonnull
java.io.File file)
throws java.io.IOException
File into an array of bytes.file - a file to readjava.io.IOException - in case of a read error, or a file not found@Nonnull
public static java.io.InputStream getResourceAsStream(@Nonnull
java.lang.String path)
throws java.io.FileNotFoundException
path - resource name or path to the resourcejava.io.FileNotFoundException - if no resource found@Nonnull
public static java.net.URL getResource(@Nonnull
java.lang.String path)
throws java.io.FileNotFoundException
path - resource name or path to the resourcejava.io.FileNotFoundException - if no resource foundpublic static ByteSource getFileAsByteSource(@Nonnull java.io.File file) throws java.io.IOException
file - a file to locate and readjava.io.IOException - in case of a read error, or a file not foundpublic static TypeAwareByteSource getFile(@Nonnull java.io.File file) throws java.io.IOException
file - a file to locate and readjava.io.IOException - in case of a read error, or a file not found