public class IoUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE
The size to use when instantiating buffered items such as instances of
the
BufferedReader class. |
static int |
TIMEOUT_MS
The number of milliseconds after which IO operation will time out.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Copies an input stream to an output stream.
|
static void |
copy(java.io.InputStream inputStream,
java.io.RandomAccessFile randomAccessFile)
Copies an input stream to a random access file.
|
static void |
copy(java.nio.channels.ReadableByteChannel readableChannel,
java.nio.channels.WritableByteChannel writableChannel)
Writes a readable channel to a writable channel.
|
static void |
copy(java.io.Reader reader,
java.io.Writer writer)
Copies characters from a reader to a writer.
|
static boolean |
delete(java.io.File file)
Deletes an individual file or an empty directory.
|
static boolean |
delete(java.io.File file,
boolean recursive)
Deletes an individual file or a directory.
|
static boolean |
delete(java.io.File file,
boolean recursive,
boolean garbageCollect)
Deletes an individual file or a directory.
|
static long |
exhaust(java.io.InputStream input)
Exhaust the content of the representation by reading it and silently
discarding anything read.
|
static long |
getAvailableSize(Representation representation)
Returns the size effectively available.
|
static java.nio.channels.ReadableByteChannel |
getChannel(java.io.InputStream inputStream)
Returns a readable byte channel based on a given input stream.
|
static java.nio.channels.WritableByteChannel |
getChannel(java.io.OutputStream outputStream)
Returns a writable byte channel based on a given output stream.
|
static java.nio.channels.ReadableByteChannel |
getChannel(Representation representation)
Returns a readable byte channel based on the given representation's
content and its write(WritableByteChannel) method.
|
static java.io.Reader |
getReader(java.io.InputStream stream,
CharacterSet characterSet)
Returns a reader from an input stream and a character set.
|
static java.io.Reader |
getReader(WriterRepresentation representation)
Returns a reader from a writer representation.Internally, it uses a
writer thread and a pipe stream.
|
static java.io.InputStream |
getStream(java.nio.channels.ReadableByteChannel readableChannel)
Returns an input stream based on a given readable byte channel.
|
static java.io.InputStream |
getStream(java.io.Reader reader,
CharacterSet characterSet)
Returns an input stream based on a given character reader.
|
static java.io.InputStream |
getStream(Representation representation)
Returns an input stream based on the given representation's content and
its write(OutputStream) method.
|
static java.io.OutputStream |
getStream(java.nio.channels.WritableByteChannel writableChannel)
Returns an output stream based on a given writable byte channel.
|
static java.io.OutputStream |
getStream(java.io.Writer writer,
CharacterSet characterSet)
Returns an output stream based on a given writer.
|
static java.lang.String |
getText(Representation representation)
Converts the representation to a string value.
|
static java.io.Writer |
getWriter(java.io.OutputStream outputStream,
CharacterSet characterSet)
Returns a writer to the given output stream, using the given character
set for encoding to bytes.
|
static boolean |
isBlocking(java.nio.channels.Channel channel)
Indicates if the channel is in blocking mode.
|
static void |
release(java.nio.channels.Selector selector,
java.nio.channels.SelectionKey selectionKey)
Release the selection key, working around for bug #6403933.
|
static byte[] |
toByteArray(char[] chars)
Converts a char array into a byte array using the default character set.
|
static byte[] |
toByteArray(char[] chars,
java.lang.String charsetName)
Converts a char array into a byte array using the provided character set.
|
static char[] |
toCharArray(byte[] bytes)
Converts a byte array into a character array using the default character
set.
|
static char[] |
toCharArray(byte[] bytes,
java.lang.String charsetName)
Converts a byte array into a character array using the default character
set.
|
static java.lang.String |
toHexString(byte[] byteArray)
Converts a byte array into an hexadecimal string.
|
static java.lang.String |
toString(java.io.InputStream inputStream)
Converts an input stream to a string.
As this method uses the InputstreamReader class, the default character set is used for decoding the input stream. |
static java.lang.String |
toString(java.io.InputStream inputStream,
CharacterSet characterSet)
Converts an input stream to a string using the specified character set
for decoding the input stream.
|
static java.lang.String |
toString(java.io.Reader reader)
Converts a reader to a string.
|
public static final int BUFFER_SIZE
BufferedReader class. It looks for the System property
"org.restlet.engine.io.bufferSize" and if not defined, uses the "8192"
default value.public static final int TIMEOUT_MS
public static void copy(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException
inputStream - The input stream.outputStream - The output stream.java.io.IOExceptionpublic static void copy(java.io.InputStream inputStream,
java.io.RandomAccessFile randomAccessFile)
throws java.io.IOException
inputStream - The input stream.randomAccessFile - The random access file.java.io.IOExceptionpublic static void copy(java.nio.channels.ReadableByteChannel readableChannel,
java.nio.channels.WritableByteChannel writableChannel)
throws java.io.IOException
readableChannel - The readable channel.writableChannel - The writable channel.java.io.IOExceptionpublic static void copy(java.io.Reader reader,
java.io.Writer writer)
throws java.io.IOException
reader - The reader.writer - The writer.java.io.IOExceptionpublic static boolean delete(java.io.File file)
file - The individual file or directory to delete.public static boolean delete(java.io.File file,
boolean recursive)
file - The individual file or directory to delete.recursive - Indicates if directory with content should be deleted
recursively as well.public static boolean delete(java.io.File file,
boolean recursive,
boolean garbageCollect)
file - The individual file or directory to delete.recursive - Indicates if directory with content should be deleted
recursively as well.garbageCollect - Indicates if the garbage collector should be run.public static long exhaust(java.io.InputStream input)
throws java.io.IOException
input - The input stream to exhaust.java.io.IOExceptionpublic static long getAvailableSize(Representation representation)
Representation.getSize() if no
range is defined, otherwise it
returns the size of the range using Range.getSize().representation - The representation to evaluate.public static java.nio.channels.ReadableByteChannel getChannel(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The input stream to convert.java.io.IOExceptionpublic static java.nio.channels.WritableByteChannel getChannel(java.io.OutputStream outputStream)
outputStream - The output stream.public static java.nio.channels.ReadableByteChannel getChannel(Representation representation) throws java.io.IOException
representation - the representation to get the OutputStream from.java.io.IOExceptionpublic static java.io.Reader getReader(java.io.InputStream stream,
CharacterSet characterSet)
throws java.io.UnsupportedEncodingException
stream - The input stream.characterSet - The character set. May be null.java.io.UnsupportedEncodingException - if a character set is given, but not supportedpublic static java.io.Reader getReader(WriterRepresentation representation) throws java.io.IOException
representation - The representation to read from.java.io.IOExceptionpublic static java.io.OutputStream getStream(java.io.Writer writer,
CharacterSet characterSet)
writer - The writer.characterSet - The character set used to write on the output stream.public static java.io.InputStream getStream(java.nio.channels.ReadableByteChannel readableChannel)
readableChannel - The readable byte channel.public static java.io.InputStream getStream(java.io.Reader reader,
CharacterSet characterSet)
reader - The character reader.characterSet - The stream character set.public static java.io.InputStream getStream(Representation representation)
representation - the representation to get the OutputStream from.public static java.io.OutputStream getStream(java.nio.channels.WritableByteChannel writableChannel)
writableChannel - The writable byte channel.public static java.lang.String getText(Representation representation) throws java.io.IOException
representation - The representation to convert.java.io.IOExceptionpublic static java.io.Writer getWriter(java.io.OutputStream outputStream,
CharacterSet characterSet)
outputStream - The target output stream.characterSet - The character set for encoding.public static boolean isBlocking(java.nio.channels.Channel channel)
channel - The channel to test.public static void release(java.nio.channels.Selector selector,
java.nio.channels.SelectionKey selectionKey)
throws java.io.IOException
selector - The associated selector.selectionKey - The used selection key.java.io.IOExceptionpublic static byte[] toByteArray(char[] chars)
chars - The source characters.public static byte[] toByteArray(char[] chars,
java.lang.String charsetName)
chars - The source characters.charsetName - The character set to use.public static char[] toCharArray(byte[] bytes)
bytes - The source bytes.public static char[] toCharArray(byte[] bytes,
java.lang.String charsetName)
bytes - The source bytes.charsetName - The character set to use.public static java.lang.String toHexString(byte[] byteArray)
byteArray - The byte array to convert.public static java.lang.String toString(java.io.InputStream inputStream)
inputStream - The input stream.InputStreamReader,
toString(InputStream, CharacterSet)public static java.lang.String toString(java.io.InputStream inputStream,
CharacterSet characterSet)
inputStream - The input stream.characterSet - The character setInputStreamReaderpublic static java.lang.String toString(java.io.Reader reader)
reader - The characters reader.InputStreamReaderCopyright © 2005-2018 Restlet.