|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.krasnay.scaffold.io.IOUtils
public class IOUtils
Utility methods for dealing with IO. None of these methods throw checked exceptions. Any IOException caught during their operation is wrapped in a RuntimeException and re-thrown.
| Field Summary | |
|---|---|
static int |
BYTE_BUFFER_SIZE
|
static int |
CHAR_BUFFER_SIZE
|
static String |
UTF_8
|
| Constructor Summary | |
|---|---|
IOUtils()
|
|
| Method Summary | |
|---|---|
static void |
close(Closeable c)
Quietly loses the given closeable. |
static void |
copy(Class<?> clazz,
String resourceName,
OutputStream out)
Copies the given resource to an output stream. |
static void |
copy(File in,
File out)
Copies a file. |
static void |
copy(File in,
OutputStream out)
Copies the entire contents of a file to an output stream. |
static void |
copy(InputStream in,
File out)
Copies the entire contents of an input stream to a file. |
static void |
copy(InputStream in,
OutputStream out)
Copies the entire contents of an input stream to an output stream. |
static void |
copy(InputStream in,
OutputStream out,
int bufferSize)
Copies the entire contents of an input stream to an output stream. |
static void |
copy(Reader reader,
Writer writer)
Copies the entire contents of a reader to a writer. |
static void |
copy(Reader reader,
Writer writer,
int bufferSize)
Copies the entire contents of a reader to a writer. |
static void |
copy(Source source,
Sink sink)
Copies the contents of a source to a sink using the default buffer size. |
static void |
copy(Source source,
Sink sink,
int bufferSize)
Copies the contents of a source to a sink using a given buffer size. |
static void |
copy(String s,
OutputStream outputStream)
Copies the given string to an output stream using UTF-8 encoding. |
static byte[] |
toByteArray(Class<?> clazz,
String resource)
Loads the contents of the given resource into a byte array. |
static byte[] |
toByteArray(InputStream inputStream)
Copy the given input stream into a byte array. |
static byte[] |
toByteArray(Source source)
Loads the contents of the source into a byte array. |
static byte[] |
toByteArray(URL url)
Copy the contents of the given URL into a byte array. |
static String |
toString(Class<?> clazz,
String resource,
String encoding)
Loads the given resource as a string using the given encoding. |
static String |
toString(File file,
String encoding)
Reads the contents of a file into a string. |
static String |
toString(InputStream in,
String encoding)
Reads the contents of an InputStream into a string. |
static String |
toString(Reader reader)
Reads the contents of a Reader into a string. |
static String |
toString(Source source,
String encoding)
Reads the contents of a Source into a string. |
static String |
toString(URL url,
String encoding)
Copies the content of the given URL to a String. |
static String |
toStringUtf8(Class<?> clazz,
String resource)
Loads the given resource as a string using UTF-8 encoding. |
static String |
toStringUtf8(File file)
Reads the contents of a file into a string using UTF-8 character encoding. |
static String |
toStringUtf8(InputStream in)
Reads the contents of an input stream into a string using UTF-8 character encoding. |
static String |
toStringUtf8(URL url)
Downloads the given URL into a string, using UTF-8 encoding. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String UTF_8
public static final int BYTE_BUFFER_SIZE
public static final int CHAR_BUFFER_SIZE
| Constructor Detail |
|---|
public IOUtils()
| Method Detail |
|---|
public static void close(Closeable c)
c - Closeable (e.g. InputStream, Reader) to be closed. May be null.
public static void copy(Class<?> clazz,
String resourceName,
OutputStream out)
clazz - Class associated with the resource.resourceName - Name of the resource relative to the given class.out - OutputStream to receive the copy.
public static void copy(File in,
OutputStream out)
in - File to be copied.out - OutputStream to receive the copy.
public static void copy(InputStream in,
File out)
in - InputStream to be copied.out - File to receive the copy.
public static void copy(File in,
File out)
in - File to be copied.out - File to receive the copy.
public static void copy(InputStream in,
OutputStream out)
in - InputStream to be copied.out - OutputStream to receive the copy.
public static void copy(InputStream in,
OutputStream out,
int bufferSize)
in - InputStream to be copied.out - OutputStream to receive the copy.bufferSize - Size of buffer used for transfers.
public static void copy(Source source,
Sink sink)
public static void copy(Source source,
Sink sink,
int bufferSize)
public static void copy(Reader reader,
Writer writer)
reader - Reader to be copied.writer - Writer to receive the copy.
public static void copy(Reader reader,
Writer writer,
int bufferSize)
reader - Reader to be copied.writer - Writer to receive the copy.bufferSize - Size of buffer used for transfers.
public static void copy(String s,
OutputStream outputStream)
public static byte[] toByteArray(InputStream inputStream)
inputStream - Stream to copy.
public static byte[] toByteArray(Class<?> clazz,
String resource)
public static byte[] toByteArray(Source source)
public static byte[] toByteArray(URL url)
url - URL to download.
public static String toString(Class<?> clazz,
String resource,
String encoding)
clazz - Class that is the base for the resource.resource - Resource name to load.encoding - Encoding to use.
public static String toString(File file,
String encoding)
file - File to be loaded.encoding - Text encoding of the file, e.g. "UTF-8".
public static String toString(InputStream in,
String encoding)
in - InputStream to read.encoding - Text encoding of the stream, e.g. "UTF-8".
public static String toString(Source source,
String encoding)
source - Source to read.encoding - Text encoding of the stream, e.g. "UTF-8".public static String toString(Reader reader)
reader - Reader to be read.
public static String toString(URL url,
String encoding)
url - URL to download.encoding - Encoding to use when converting bytes to characters.
public static String toStringUtf8(Class<?> clazz,
String resource)
clazz - Class that is the base for the resource.resource - Resource name to load.public static String toStringUtf8(File file)
file - File to be read.public static String toStringUtf8(InputStream in)
in - Input stream to be read.public static String toStringUtf8(URL url)
url - URL to download.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||