public final class ReaderWriter extends 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.
|
static Charset |
UTF8
Deprecated.
use
StandardCharsets.UTF_8 instead |
Modifier and Type | Method and Description |
---|---|
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 |
safelyClose(Closeable closeable)
Safely close a closeable, without throwing an exception.
|
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.
|
@Deprecated public static final Charset UTF8
StandardCharsets.UTF_8
insteadpublic static final int BUFFER_SIZE
public static void writeTo(InputStream in, OutputStream out) throws IOException
in
- the input stream to read from.out
- the output stream to write to.IOException
- if there is an error reading or writing bytes.public static void writeTo(Reader in, Writer out) throws IOException
in
- the reader to read from.out
- the writer to write to.IOException
- if there is an error reading or writing characters.public static Charset getCharset(MediaType m)
The character set is obtained from the media type parameter "charset".
If the parameter is not present the StandardCharsets.UTF_8
charset is utilized.
m
- the media type.public static String readFromAsString(InputStream in, MediaType type) throws IOException
in
- the input stream to read from.type
- the media type that determines the character set defining
how to decode bytes to characters.IOException
- if there is an error reading from the input stream.public static String readFromAsString(Reader reader) throws IOException
reader
- the readerIOException
- if there is an error reading from the reader.public static void writeToAsString(String s, OutputStream out, MediaType type) throws 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.IOException
- in case of a write failure.public static void safelyClose(Closeable closeable)
closeable
- object to be closed.Copyright © 2007-2023, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.