On Nov 7, 2007, at 6:39 AM, Paul Sandoz wrote:
>
>> Split them into two interfaces. We may as well take stefans comment
>> into consideration and rename the EntityProvider to something less
>> confusing.
>
> Agreed, what about MessageBodyReader and MessageBodyWriter ? I like
> the idea of keeping the names close to reading/writing since that is
> what these do with InputStream and OutputStream respectively.
>
> While we are this the topic... It is sometimes useful for a
> container to ask a writer if it knows the size of something it will
> write, so the container can use chunked encoding or Content-Length,
> for example if File or byte[], or ByteArrayInputStream types are
> used then a writer knows the length. So we could have a method:
>
> // Returns a non-negative integer if size is known
> long MessageBodyWriter.getSize(T t)
>
Something like:
public interface MessageBodyReader<T> {
boolean isReadable(Class<?> type);
T readFrom(Class<T> type, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException;
}
and
public interface MessageBodyWriter<T> {
boolean isWriteable(Class<?> type);
void writeTo(T t, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException;
long getSize(T t)
}
with the corresponding:
public abstract class ProviderFactory {
...
public abstract <T> MessageBodyReader<T>
createMessageBodyReader(Class<T> type, MediaType media);
public abstract <T> MessageBodyWriter<T>
createMessageBodyWriter(Class<T> type, MediaType media);
}
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.