|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.restlet.engine.io.IoUtils
public class IoUtils
IO manipulation utilities.
| Field Summary | |
|---|---|
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. |
| Method Summary | |
|---|---|
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)
Writes a readable channel to a writable channel. |
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)
Returns a readable byte channel based on a given input stream. |
static WritableByteChannel |
getChannel(OutputStream outputStream)
Returns a writable byte channel based on a given output stream. |
static ReadableByteChannel |
getChannel(Representation representation)
Returns a readable byte channel based on the given representation's content and its write(WritableByteChannel) method. |
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)
Returns an input stream based on a given readable byte channel. |
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)
Returns an output stream based on a given writable byte channel. |
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)
Indicates if the channel is in blocking mode. |
static void |
release(Selector selector,
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,
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
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
| Method Detail |
|---|
public static void copy(InputStream inputStream,
OutputStream outputStream)
throws IOException
inputStream - The input stream.outputStream - The output stream.
IOException
public static void copy(InputStream inputStream,
RandomAccessFile randomAccessFile)
throws IOException
inputStream - The input stream.randomAccessFile - The random access file.
IOException
public static void copy(ReadableByteChannel readableChannel,
WritableByteChannel writableChannel)
throws IOException
readableChannel - The readable channel.writableChannel - The writable channel.
IOException
public 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.
public static ReadableByteChannel getChannel(InputStream inputStream)
throws IOException
inputStream - The input stream to convert.
IOExceptionpublic static WritableByteChannel getChannel(OutputStream outputStream)
outputStream - The output stream.
public static ReadableByteChannel getChannel(Representation representation)
throws IOException
representation - the representation to get the OutputStream from.
IOException
public 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 supported
public static Reader getReader(WriterRepresentation representation)
throws IOException
representation - The representation to read from.
IOException
public static OutputStream getStream(Writer writer,
CharacterSet characterSet)
writer - The writer.characterSet - The character set used to write on the output stream.
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.
public static OutputStream getStream(WritableByteChannel writableChannel)
writableChannel - The writable byte channel.
public static String getText(Representation representation)
throws IOException
representation - The representation to convert.
IOException
public static Writer getWriter(OutputStream outputStream,
CharacterSet characterSet)
outputStream - The target output stream.characterSet - The character set for encoding.
public static boolean isBlocking(Channel channel)
channel - The channel to test.
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 set
InputStreamReaderpublic static String toString(Reader reader)
reader - The characters reader.
InputStreamReader
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||