public final class ReaderWriter
extends java.lang.Object
If a byte or character array is utilized then the size of the array is by default the value of 8192. This value can be set using the system property "jersey.config.io.bufferSize".
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE
The buffer size for arrays of byte and character.
|
private static java.util.logging.Logger |
LOGGER |
static java.nio.charset.Charset |
UTF8
The UTF-8 Charset.
|
Modifier | Constructor and Description |
---|---|
private |
ReaderWriter()
Prevents instantiation.
|
Modifier and Type | Method and Description |
---|---|
private static int |
getBufferSize() |
static java.nio.charset.Charset |
getCharset(javax.ws.rs.core.MediaType m)
Get the character set from a media type.
|
static java.lang.String |
readFromAsString(java.io.InputStream in,
javax.ws.rs.core.MediaType type)
Read the bytes of an input stream and convert to a string.
|
static java.lang.String |
readFromAsString(java.io.Reader reader)
Read the characters of a reader and convert to a string.
|
static void |
safelyClose(java.io.Closeable closeable)
Safely close a closeable, without throwing an exception.
|
static void |
writeTo(java.io.InputStream in,
java.io.OutputStream out)
Read bytes from an input stream and write them to an output stream.
|
static void |
writeTo(java.io.Reader in,
java.io.Writer out)
Read characters from an input stream and write them to an output stream.
|
static void |
writeToAsString(java.lang.String s,
java.io.OutputStream out,
javax.ws.rs.core.MediaType type)
Convert a string to bytes and write those bytes to an output stream.
|
private static final java.util.logging.Logger LOGGER
public static final java.nio.charset.Charset UTF8
public static final int BUFFER_SIZE
private static int getBufferSize()
public static void writeTo(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the input stream to read from.out
- the output stream to write to.java.io.IOException
- if there is an error reading or writing bytes.public static void writeTo(java.io.Reader in, java.io.Writer out) throws java.io.IOException
in
- the reader to read from.out
- the writer to write to.java.io.IOException
- if there is an error reading or writing characters.public static java.nio.charset.Charset getCharset(javax.ws.rs.core.MediaType m)
The character set is obtained from the media type parameter "charset".
If the parameter is not present the UTF8
charset is utilized.
m
- the media type.public static java.lang.String readFromAsString(java.io.InputStream in, javax.ws.rs.core.MediaType type) throws java.io.IOException
in
- the input stream to read from.type
- the media type that determines the character set defining
how to decode bytes to characters.java.io.IOException
- if there is an error reading from the input stream.public static java.lang.String readFromAsString(java.io.Reader reader) throws java.io.IOException
reader
- the readerjava.io.IOException
- if there is an error reading from the reader.public static void writeToAsString(java.lang.String s, java.io.OutputStream out, javax.ws.rs.core.MediaType type) throws java.io.IOException
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.java.io.IOException
- in case of a write failure.public static void safelyClose(java.io.Closeable closeable)
closeable
- object to be closed.