Modifier and Type | Class and Description |
---|---|
static class |
IOHelper.EncodingFileReader
Encoding-aware file reader.
|
static class |
IOHelper.EncodingFileWriter
Encoding-aware file writer.
|
static class |
IOHelper.EncodingInputStream
Encoding-aware input stream.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE |
static Supplier<Charset> |
defaultCharset |
Modifier and Type | Method and Description |
---|---|
static BufferedInputStream |
buffered(InputStream in)
Wraps the passed
in into a BufferedInputStream
object and returns that. |
static BufferedOutputStream |
buffered(OutputStream out)
Wraps the passed
out into a BufferedOutputStream
object and returns that. |
static BufferedReader |
buffered(Reader reader)
Wraps the passed
reader into a BufferedReader object
and returns that. |
static BufferedWriter |
buffered(Writer writer)
Wraps the passed
writer into a BufferedWriter object
and returns that. |
static void |
close(Closeable... closeables)
Closes the given resources if they are available.
|
static void |
close(Closeable closeable)
Closes the given resource if it is available.
|
static void |
close(Closeable closeable,
String name)
Closes the given resource if it is available.
|
static void |
close(Closeable closeable,
String name,
org.slf4j.Logger log)
Closes the given resource if it is available, logging any closing
exceptions to the given log.
|
static void |
close(FileChannel channel,
String name,
org.slf4j.Logger log,
boolean force)
Closes the given channel if it is available, logging any closing
exceptions to the given log.
|
static void |
close(Writer writer,
FileOutputStream os,
String name,
org.slf4j.Logger log,
boolean force)
Closes the given writer, logging any closing exceptions to the given log.
|
static void |
closeIterator(Object it) |
static void |
closeWithException(Closeable closeable)
Closes the given resource if it is available and don't catch the
exception
|
static int |
copy(InputStream input,
OutputStream output) |
static int |
copy(InputStream input,
OutputStream output,
int bufferSize) |
static int |
copy(InputStream input,
OutputStream output,
int bufferSize,
boolean flushOnEachWrite) |
static int |
copy(Reader input,
Writer output,
int bufferSize) |
static void |
copyAndCloseInput(InputStream input,
OutputStream output) |
static void |
copyAndCloseInput(InputStream input,
OutputStream output,
int bufferSize) |
static void |
force(FileChannel channel,
String name,
org.slf4j.Logger log)
Forces any updates to this channel's file to be written to the storage
device that contains it.
|
static void |
force(FileOutputStream os,
String name,
org.slf4j.Logger log)
Forces any updates to a FileOutputStream be written to the storage device
that contains it.
|
static String |
getCharsetNameFromContentType(String contentType)
Get the charset name from the content type string
|
static String |
loadText(InputStream in)
Loads the entire stream into memory as a String and returns it.
|
static String |
lookupEnvironmentVariable(String key)
Lookup the OS environment variable in a safe manner by
using upper case keys and underscore instead of dash.
|
static String |
newStringFromBytes(byte[] bytes)
Use this function instead of new String(byte[]) to avoid surprises from
non-standard default encodings.
|
static String |
newStringFromBytes(byte[] bytes,
int start,
int length)
Use this function instead of new String(byte[], int, int) to avoid
surprises from non-standard default encodings.
|
static String |
normalizeCharset(String charset)
This method will take off the quotes and double quotes of the charset
|
static InputStream |
toInputStream(File file,
String charset)
Converts the given
File with the given charset to InputStream with the JVM default charset |
static BufferedReader |
toReader(File file,
String charset) |
static String |
toString(BufferedReader reader) |
static String |
toString(Reader reader) |
static BufferedWriter |
toWriter(FileOutputStream os,
String charset) |
static void |
transfer(ReadableByteChannel input,
WritableByteChannel output) |
static void |
validateCharset(String charset) |
public static Supplier<Charset> defaultCharset
public static final int DEFAULT_BUFFER_SIZE
public static String newStringFromBytes(byte[] bytes)
public static String newStringFromBytes(byte[] bytes, int start, int length)
public static BufferedInputStream buffered(InputStream in)
in
into a BufferedInputStream
object and returns that. If the passed in
is already an
instance of BufferedInputStream
returns the same passed
in
reference as is (avoiding double wrapping).in
- the wrapee to be used for the buffering supportin
decorated through a
BufferedInputStream
object as wrapperpublic static BufferedOutputStream buffered(OutputStream out)
out
into a BufferedOutputStream
object and returns that. If the passed out
is already an
instance of BufferedOutputStream
returns the same passed
out
reference as is (avoiding double wrapping).out
- the wrapee to be used for the buffering supportout
decorated through a
BufferedOutputStream
object as wrapperpublic static BufferedReader buffered(Reader reader)
reader
into a BufferedReader
object
and returns that. If the passed reader
is already an
instance of BufferedReader
returns the same passed
reader
reference as is (avoiding double wrapping).reader
- the wrapee to be used for the buffering supportreader
decorated through a
BufferedReader
object as wrapperpublic static BufferedWriter buffered(Writer writer)
writer
into a BufferedWriter
object
and returns that. If the passed writer
is already an
instance of BufferedWriter
returns the same passed
writer
reference as is (avoiding double wrapping).writer
- the wrapee to be used for the buffering supportwriter
decorated through a
BufferedWriter
object as wrapperpublic static String toString(Reader reader) throws IOException
IOException
public static String toString(BufferedReader reader) throws IOException
IOException
public static int copy(InputStream input, OutputStream output) throws IOException
IOException
public static int copy(InputStream input, OutputStream output, int bufferSize) throws IOException
IOException
public static int copy(InputStream input, OutputStream output, int bufferSize, boolean flushOnEachWrite) throws IOException
IOException
public static void copyAndCloseInput(InputStream input, OutputStream output) throws IOException
IOException
public static void copyAndCloseInput(InputStream input, OutputStream output, int bufferSize) throws IOException
IOException
public static int copy(Reader input, Writer output, int bufferSize) throws IOException
IOException
public static void transfer(ReadableByteChannel input, WritableByteChannel output) throws IOException
IOException
public static void force(FileChannel channel, String name, org.slf4j.Logger log)
channel
- the file channelname
- the name of the resourcelog
- the log to use when reporting warnings, will use this class's
own Logger
if log == nullpublic static void force(FileOutputStream os, String name, org.slf4j.Logger log)
os
- the file output streamname
- the name of the resourcelog
- the log to use when reporting warnings, will use this class's
own Logger
if log == nullpublic static void close(Writer writer, FileOutputStream os, String name, org.slf4j.Logger log, boolean force)
writer
- the writer to closeos
- an underlying FileOutputStream that will to be forced to disk
according to the force parametername
- the name of the resourcelog
- the log to use when reporting warnings, will use this class's
own Logger
if log == nullforce
- forces the FileOutputStream to diskpublic static void close(Closeable closeable, String name, org.slf4j.Logger log)
closeable
- the object to closename
- the name of the resourcelog
- the log to use when reporting closure warnings, will use this
class's own Logger
if log == nullpublic static void closeWithException(Closeable closeable) throws IOException
closeable
- the object to closeIOException
public static void close(FileChannel channel, String name, org.slf4j.Logger log, boolean force)
channel
- the file channelname
- the name of the resourcelog
- the log to use when reporting warnings, will use this class's
own Logger
if log == nullforce
- forces the file channel to diskpublic static void close(Closeable closeable, String name)
closeable
- the object to closename
- the name of the resourcepublic static void close(Closeable closeable)
closeable
- the object to closepublic static void close(Closeable... closeables)
closeables
- the objects to closepublic static void closeIterator(Object it) throws IOException
IOException
public static void validateCharset(String charset) throws UnsupportedCharsetException
UnsupportedCharsetException
public static String loadText(InputStream in) throws IOException
IOException
public static String getCharsetNameFromContentType(String contentType)
contentType
- public static String normalizeCharset(String charset)
public static String lookupEnvironmentVariable(String key)
public static InputStream toInputStream(File file, String charset) throws IOException
File
with the given charset to InputStream
with the JVM default charsetfile
- the file to be convertedcharset
- the charset the file is read withIOException
public static BufferedReader toReader(File file, String charset) throws IOException
IOException
public static BufferedWriter toWriter(FileOutputStream os, String charset) throws IOException
IOException
Apache Camel