On Mar 10, 2008, at 10:11 AM, Bill Burke wrote:
>
> Marc Hadley wrote:
>> On Mar 7, 2008, at 3:51 PM, Bill Burke wrote:
>>>
>>> Also, can consider a simple Representation interface? I know it
>>> would be easy to implement one with the @Provider model, but I
>>> think its a good idea.
>>>
>> I think the combination of Response and ResponseBuilder already
>> fulfill the role of representation.
>
> @GET
> public Representation get()
> {
>
> Connection conn = ...;
> Blob blob = rs.getBlob(...);
>
> return new Representation() {
> public write(OutputStream stream) {
> // stream the output
> blob.close();
> rs.close();
> conn.close();
> }
> };
>
> }
>
> Instead of requiring the awkward creation and registration of
> MessageBodyWriters, you allow the component to return a
> Representation object, which is really a MessageBodyWriter-like
> object instantiated by the resource.
>
@GET
public InputStream get() {
Connection conn = ...;
Blob blob = rs.getBlob(...);
return new InputStream() {
InputStream is = blob.getBinaryStream();
public int read() throws IOException {
return is.read();
}
public void close() throws IOException {
is.close();
blob.close();
rs.close();
}
};
}
Wrap the InputStream in a Response to supply the metadata...
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.