struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephan Schröder" <>
Subject Re: [OT] S2 Stream Result, downloading large file, advice needed
Date Sat, 23 Aug 2008 12:59:01 GMT
> I'm still interested in hear any suggestions. I know that this is not
> strictly an S2 issue but it is related to using a Stream result type.  If
> I was writing a servlet I would just get the OutputStream and write directly
> to it, putting the burden of buffering etc. onto the container.

If you want to write directly on the OutputStream you can implement your own ResultType:

public class ByteContentResult implements Result,StrutsStatics
  public void execute( ActionInvocation invocation )
  throws Exception
    ByteContentProvider bytesProvider = (ByteContentProvider) invocation.getAction();
    //HttpServletResponse response = org.apache.struts2.ServletActionContext.getResponse();
    HttpServletResponse response = (HttpServletResponse)invocation.getInvocationContext().get(

    byte[] content = bytesProvider.getBytes();
    response.setContentLength( content.length );
    ServletOutputStream outstream = response.getOutputStream();
    outstream.write( content );

The action class has only to implement this interface:
public interface ByteContentProvider
  public String getContentType();
  public byte[] getBytes();

Then make your result known in your my-struts-default.xml:
  <result-type name="bytes" class="result.ByteContentResult"/>

GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message