public class IoUtils extends 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(InputStream inputStream,
OutputStream outputStream)
Copies an input stream to an output stream.
|
static void |
copy(InputStream inputStream,
RandomAccessFile randomAccessFile)
Copies an input stream to a random access file.
|
static void |
copy(ReadableByteChannel readableChannel,
WritableByteChannel writableChannel)
Deprecated.
NIO will be removed in next major release.
|
static void |
copy(Reader reader,
Writer writer)
Copies characters from a reader to a writer.
|
static boolean |
delete(File file)
Deletes an individual file or an empty directory.
|
static boolean |
delete(File file,
boolean recursive)
Deletes an individual file or a directory.
|
static boolean |
delete(File file,
boolean recursive,
boolean garbageCollect)
Deletes an individual file or a directory.
|
static long |
exhaust(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 ReadableByteChannel |
getChannel(InputStream inputStream)
Deprecated.
NIO will be removed in next major release.
|
static WritableByteChannel |
getChannel(OutputStream outputStream)
Deprecated.
NIO will be removed in next major release.
|
static ReadableByteChannel |
getChannel(Representation representation)
Deprecated.
NIO will be removed in next major release.
|
static Reader |
getReader(InputStream stream,
CharacterSet characterSet)
Returns a reader from an input stream and a character set.
|
static Reader |
getReader(WriterRepresentation representation)
Returns a reader from a writer representation.Internally, it uses a writer
thread and a pipe stream.
|
static InputStream |
getStream(ReadableByteChannel readableChannel)
Deprecated.
NIO will be removed in next major release.
|
static InputStream |
getStream(Reader reader,
CharacterSet characterSet)
Returns an input stream based on a given character reader.
|
static InputStream |
getStream(Representation representation)
Returns an input stream based on the given representation's content and its
write(OutputStream) method.
|
static OutputStream |
getStream(WritableByteChannel writableChannel)
Deprecated.
NIO will be removed in next major release.
|
static OutputStream |
getStream(Writer writer,
CharacterSet characterSet)
Returns an output stream based on a given writer.
|
static String |
getText(Representation representation)
Converts the representation to a string value.
|
static Writer |
getWriter(OutputStream outputStream,
CharacterSet characterSet)
Returns a writer to the given output stream, using the given character set
for encoding to bytes.
|
static boolean |
isBlocking(Channel channel)
Deprecated.
|
static void |
release(Selector selector,
SelectionKey selectionKey)
Deprecated.
NIO will be removed in next major release.
|
static byte[] |
toByteArray(char[] chars)
Converts a char array into a byte array using the default character set.
|
static byte[] |
toByteArray(char[] chars,
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,
String charsetName)
Converts a byte array into a character array using the default character set.
|
static String |
toHexString(byte[] byteArray)
Converts a byte array into an hexadecimal string.
|
static String |
toString(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 String |
toString(InputStream inputStream,
CharacterSet characterSet)
Converts an input stream to a string using the specified character set for
decoding the input stream.
|
static String |
toString(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(InputStream inputStream, OutputStream outputStream) throws IOException
inputStream - The input stream.outputStream - The output stream.IOExceptionpublic static void copy(InputStream inputStream, RandomAccessFile randomAccessFile) throws IOException
inputStream - The input stream.randomAccessFile - The random access file.IOException@Deprecated public static void copy(ReadableByteChannel readableChannel, WritableByteChannel writableChannel) throws IOException
readableChannel - The readable channel.writableChannel - The writable channel.IOExceptionpublic static void copy(Reader reader, Writer writer) throws IOException
reader - The reader.writer - The writer.IOExceptionpublic static boolean delete(File file)
file - The individual file or directory to delete.public static boolean delete(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(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(InputStream input) throws IOException
input - The input stream to exhaust.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.@Deprecated public static ReadableByteChannel getChannel(InputStream inputStream) throws IOException
inputStream - The input stream to convert.IOException@Deprecated public static WritableByteChannel getChannel(OutputStream outputStream)
outputStream - The output stream.@Deprecated public static ReadableByteChannel getChannel(Representation representation) throws IOException
representation - the representation to get the OutputStream
from.IOExceptionpublic static Reader getReader(InputStream stream, CharacterSet characterSet) throws UnsupportedEncodingException
stream - The input stream.characterSet - The character set. May be null.UnsupportedEncodingException - if a character set is given, but not
supportedpublic static Reader getReader(WriterRepresentation representation) throws IOException
representation - The representation to read from.IOExceptionpublic static OutputStream getStream(Writer writer, CharacterSet characterSet)
writer - The writer.characterSet - The character set used to write on the output stream.@Deprecated public static InputStream getStream(ReadableByteChannel readableChannel)
readableChannel - The readable byte channel.public static InputStream getStream(Reader reader, CharacterSet characterSet)
reader - The character reader.characterSet - The stream character set.public static InputStream getStream(Representation representation)
representation - the representation to get the
OutputStream from.@Deprecated public static OutputStream getStream(WritableByteChannel writableChannel)
writableChannel - The writable byte channel.public static String getText(Representation representation) throws IOException
representation - The representation to convert.IOExceptionpublic static Writer getWriter(OutputStream outputStream, CharacterSet characterSet)
outputStream - The target output stream.characterSet - The character set for encoding.@Deprecated public static boolean isBlocking(Channel channel)
channel - The channel to test.@Deprecated public static void release(Selector selector, SelectionKey selectionKey) throws IOException
selector - The associated selector.selectionKey - The used selection key.IOExceptionpublic static byte[] toByteArray(char[] chars)
chars - The source characters.public static byte[] toByteArray(char[] chars,
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,
String charsetName)
bytes - The source bytes.charsetName - The character set to use.public static String toHexString(byte[] byteArray)
byteArray - The byte array to convert.public static String toString(InputStream inputStream)
inputStream - The input stream.InputStreamReader,
toString(InputStream, CharacterSet)public static String toString(InputStream inputStream, CharacterSet characterSet)
inputStream - The input stream.characterSet - The character setInputStreamReaderpublic static String toString(Reader reader)
reader - The characters reader.InputStreamReaderCopyright © 2005–2025. All rights reserved.