com.sun.jersey.core.provider
Class AbstractMessageReaderWriterProvider<T>

java.lang.Object
  extended by com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider<T>
All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<T>, javax.ws.rs.ext.MessageBodyWriter<T>
Direct Known Subclasses:
AbstractJAXBProvider, AtomEntryProvider, AtomFeedProvider, BaseFormProvider, ByteArrayProvider, DataSourceProvider, DocumentProvider, FileProvider, InputStreamProvider, JSONLowLevelProvider, JSONWithPaddingProvider, MimeMultipartProvider, ReaderProvider, RenderedImageProvider, StringProvider

public abstract class AbstractMessageReaderWriterProvider<T>
extends java.lang.Object
implements javax.ws.rs.ext.MessageBodyReader<T>, javax.ws.rs.ext.MessageBodyWriter<T>

Author:
Paul.Sandoz@Sun.Com

Field Summary
static java.nio.charset.Charset UTF8
          The UTF-8 Charset.
 
Constructor Summary
AbstractMessageReaderWriterProvider()
           
 
Method Summary
static java.nio.charset.Charset getCharset(javax.ws.rs.core.MediaType m)
          Get the character set from a media type.
 long getSize(T t, java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
           
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 void writeTo(java.io.InputStream in, java.io.OutputStream out)
          Reader bytes from an input stream and write then to an output stream.
static void writeTo(java.io.Reader in, java.io.Writer out)
          Reader characters from an input stream and write then 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ws.rs.ext.MessageBodyReader
isReadable, readFrom
 
Methods inherited from interface javax.ws.rs.ext.MessageBodyWriter
isWriteable, writeTo
 

Field Detail

UTF8

public static final java.nio.charset.Charset UTF8
The UTF-8 Charset.

Constructor Detail

AbstractMessageReaderWriterProvider

public AbstractMessageReaderWriterProvider()
Method Detail

writeTo

public static final void writeTo(java.io.InputStream in,
                                 java.io.OutputStream out)
                          throws java.io.IOException
Reader bytes from an input stream and write then 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 final void writeTo(java.io.Reader in,
                                 java.io.Writer out)
                          throws java.io.IOException
Reader characters from an input stream and write then 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 final 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 UTF8 charset is utilized.

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

readFromAsString

public static final java.lang.String readFromAsString(java.io.InputStream in,
                                                      javax.ws.rs.core.MediaType type)
                                               throws java.io.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:
java.io.IOException - if there is an error reading from the input stream.

writeToAsString

public static final void writeToAsString(java.lang.String s,
                                         java.io.OutputStream out,
                                         javax.ws.rs.core.MediaType type)
                                  throws java.io.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:
java.io.IOException

getSize

public long getSize(T t,
                    java.lang.Class<?> type,
                    java.lang.reflect.Type genericType,
                    java.lang.annotation.Annotation[] annotations,
                    javax.ws.rs.core.MediaType mediaType)
Specified by:
getSize in interface javax.ws.rs.ext.MessageBodyWriter<T>


Copyright © 2011 Sun Microsystems, Inc. All Rights Reserved.