org.restlet.util
Class ByteUtils

java.lang.Object
  extended by org.restlet.util.ByteUtils

public final class ByteUtils
extends Object

Byte manipulation utilities.

Author:
Jerome Louvel (contact@noelios.com)

Method Summary
static ReadableByteChannel getChannel(InputStream inputStream)
          Returns a readable byte channel based on a given inputstream.
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 InputStream getStream(ReadableByteChannel readableChannel)
          Returns an input stream based on a given readable byte channel.
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 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 void write(InputStream inputStream, OutputStream outputStream)
          Writes an input stream to an output stream.
static void write(ReadableByteChannel readableChannel, WritableByteChannel writableChannel)
          Writes a readable channel to a writable channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getChannel

public static ReadableByteChannel getChannel(InputStream inputStream)
                                      throws IOException
Returns a readable byte channel based on a given inputstream. If it is supported by a file a read-only instance of FileChannel is returned.

Parameters:
inputStream - The input stream to convert.
Returns:
A readable byte channel.
Throws:
IOException

getChannel

public static WritableByteChannel getChannel(OutputStream outputStream)
                                      throws IOException
Returns a writable byte channel based on a given output stream.

Parameters:
outputStream - The output stream.
Throws:
IOException

getChannel

public static ReadableByteChannel getChannel(Representation representation)
                                      throws IOException
Returns a readable byte channel based on the given representation's content and its write(WritableByteChannel) method. Internally, it uses a writer thread and a pipe stream.

Returns:
A readable byte channel.
Throws:
IOException

getStream

public static InputStream getStream(ReadableByteChannel readableChannel)
                             throws IOException
Returns an input stream based on a given readable byte channel.

Parameters:
readableChannel - The readable byte channel.
Returns:
An input stream based on a given readable byte channel.
Throws:
IOException

getStream

public static InputStream getStream(Representation representation)
                             throws IOException
Returns an input stream based on the given representation's content and its write(OutputStream) method. Internally, it uses a writer thread and a pipe stream.

Returns:
A stream with the representation's content.
Throws:
IOException

getStream

public static OutputStream getStream(WritableByteChannel writableChannel)
Returns an output stream based on a given writable byte channel.

Parameters:
writableChannel - The writable byte channel.
Returns:
An output stream based on a given writable byte channel.

toString

public 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.

Parameters:
inputStream - The input stream.
Returns:
The converted string.
See Also:
InputStreamReader class, toString(InputStream, CharacterSet)

toString

public static String toString(InputStream inputStream,
                              CharacterSet characterSet)
Converts an input stream to a string using the specified character set for decoding the input stream.

Parameters:
inputStream - The input stream.
characterSet - The character set
Returns:
The converted string.
See Also:
InputStreamReader class

write

public static void write(InputStream inputStream,
                         OutputStream outputStream)
                  throws IOException
Writes an input stream to an output stream. When the reading is done, the input stream is closed.

Parameters:
inputStream - The input stream.
outputStream - The output stream.
Throws:
IOException

write

public static void write(ReadableByteChannel readableChannel,
                         WritableByteChannel writableChannel)
                  throws IOException
Writes a readable channel to a writable channel. It assumes that the readable and writable channels are both in NIO blocking mode.

Parameters:
readableChannel - The readable channel.
writableChannel - The writable channel.
Throws:
IOException


Copyright © 2005-2007 Noelios Technologies.