com.sun.jersey.core.util
Class ReaderWriter

java.lang.Object
  extended by com.sun.jersey.core.util.ReaderWriter

public final class ReaderWriter
extends Object

A utlity class for reading and writing using byte and character streams.

If a byte or character array is utilized then the size of the array is by default the value of DEFAULT_BUFFER_SIZE. This value can be set using the system property BUFFER_SIZE_SYSTEM_PROPERTY.

Author:
Paul.Sandoz@Sun.Com

Field Summary
static int BUFFER_SIZE
          The buffer size for arrays of byte and character.
static String BUFFER_SIZE_SYSTEM_PROPERTY
          The system property to set the default buffer size for arrays of byte and character.
static int DEFAULT_BUFFER_SIZE
          The default buffer size for arrays of byte and character.
static Charset UTF8
          The UTF-8 Charset.
 
Constructor Summary
ReaderWriter()
           
 
Method Summary
static Charset getCharset(MediaType m)
          Get the character set from a media type.
static String readFromAsString(InputStream in, MediaType type)
          Read the bytes of an input stream and convert to a string.
static String readFromAsString(Reader reader)
          Read the characters of a reader and convert to a string.
static void writeTo(InputStream in, OutputStream out)
          Read bytes from an input stream and write them to an output stream.
static void writeTo(Reader in, Writer out)
          Read characters from an input stream and write them to an output stream.
static void writeToAsString(String s, OutputStream out, MediaType type)
          Convert a string to bytes and write those bytes to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8

public static final Charset UTF8
The UTF-8 Charset.


BUFFER_SIZE_SYSTEM_PROPERTY

public static final String BUFFER_SIZE_SYSTEM_PROPERTY
The system property to set the default buffer size for arrays of byte and character.

If the property value is not a positive integer then the default buffer size declared by DEFAULT_BUFFER_SIZE will be utilized.

See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default buffer size for arrays of byte and character.

See Also:
Constant Field Values

BUFFER_SIZE

public static final int BUFFER_SIZE
The buffer size for arrays of byte and character.

Constructor Detail

ReaderWriter

public ReaderWriter()
Method Detail

writeTo

public static final void writeTo(InputStream in,
                                 OutputStream out)
                          throws IOException
Read bytes from an input stream and write them to an output stream.

Parameters:
in - the input stream to read from.
out - the output stream to write to.
Throws:
IOException - if there is an error reading or writing bytes.

writeTo

public static final void writeTo(Reader in,
                                 Writer out)
                          throws IOException
Read characters from an input stream and write them to an output stream.

Parameters:
in - the reader to read from.
out - the writer to write to.
Throws:
IOException - if there is an error reading or writing characters.

getCharset

public static final Charset getCharset(MediaType m)
Get the character set from a media type.

The character set is obtained from the media type parameter "charset". If the parameter is not present the UTF8 charset is utilized.

Parameters:
m - the media type.
Returns:
the character set.

readFromAsString

public static final String readFromAsString(InputStream in,
                                            MediaType type)
                                     throws IOException
Read the bytes of an input stream and convert to a string.

Parameters:
in - the input stream to read from.
type - the media type that determines the character set defining how to decode bytes to charaters.
Returns:
the string.
Throws:
IOException - if there is an error reading from the input stream.

readFromAsString

public static final String readFromAsString(Reader reader)
                                     throws IOException
Read the characters of a reader and convert to a string.

Parameters:
reader - the reader
Returns:
the string
Throws:
IOException - if there is an error reading from the reader.

writeToAsString

public static final void writeToAsString(String s,
                                         OutputStream out,
                                         MediaType type)
                                  throws IOException
Convert a string to bytes and write those bytes to an output stream.

Parameters:
s - the string to convert to bytes.
out - the output stream to write to.
type - the media type that determines the character set defining how to decode bytes to characters.
Throws:
IOException


Copyright © 2013 Oracle Corporation. All Rights Reserved.