Class ReaderWriter
- java.lang.Object
-
- org.glassfish.jersey.message.internal.ReaderWriter
-
public final class ReaderWriter extends java.lang.ObjectA utility 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 8192. This value can be set using the system property "jersey.config.io.bufferSize".
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_SIZEThe buffer size for arrays of byte and character.private static java.util.logging.LoggerLOGGERstatic java.nio.charset.CharsetUTF8The UTF-8 Charset.
-
Constructor Summary
Constructors Modifier Constructor Description privateReaderWriter()Prevents instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intgetBufferSize()static java.nio.charset.CharsetgetCharset(javax.ws.rs.core.MediaType m)Get the character set from a media type.static java.lang.StringreadFromAsString(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.StringreadFromAsString(java.io.Reader reader)Read the characters of a reader and convert to a string.static voidsafelyClose(java.io.Closeable closeable)Safely close a closeable, without throwing an exception.static voidwriteTo(java.io.InputStream in, java.io.OutputStream out)Read bytes from an input stream and write them to an output stream.static voidwriteTo(java.io.Reader in, java.io.Writer out)Read characters from an input stream and write them to an output stream.static voidwriteToAsString(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.
-
-
-
Method Detail
-
getBufferSize
private static int getBufferSize()
-
writeTo
public static void writeTo(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionRead 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:
java.io.IOException- if there is an error reading or writing bytes.
-
writeTo
public static void writeTo(java.io.Reader in, java.io.Writer out) throws java.io.IOExceptionRead 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:
java.io.IOException- if there is an error reading or writing characters.
-
getCharset
public static java.nio.charset.Charset getCharset(javax.ws.rs.core.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
UTF8charset is utilized.- Parameters:
m- the media type.- Returns:
- the character set.
-
readFromAsString
public static java.lang.String readFromAsString(java.io.InputStream in, javax.ws.rs.core.MediaType type) throws java.io.IOExceptionRead 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 characters.- Returns:
- the string.
- Throws:
java.io.IOException- if there is an error reading from the input stream.
-
readFromAsString
public static java.lang.String readFromAsString(java.io.Reader reader) throws java.io.IOExceptionRead the characters of a reader and convert to a string.- Parameters:
reader- the reader- Returns:
- the string
- Throws:
java.io.IOException- if there is an error reading from the reader.
-
writeToAsString
public static void writeToAsString(java.lang.String s, java.io.OutputStream out, javax.ws.rs.core.MediaType type) throws java.io.IOExceptionConvert 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:
java.io.IOException- in case of a write failure.
-
safelyClose
public static void safelyClose(java.io.Closeable closeable)
Safely close a closeable, without throwing an exception.- Parameters:
closeable- object to be closed.
-
-