Any word as to whether this will work with 2.3?  In other words, should I
add this to the solutions for calling ServletOutputStream under
VelocityOnlyLayout?

Thanks,

Chris

> -----Original Message-----
> From: Rodrigo Reyes [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 19, 2003 2:28 PM
> To: Turbine Developers List
> Subject: Re: Direct Response and IllegalStateException
>
>
> Peter
>     This is a screen which returns an image. Hope this helps...
>
> Rodrigo
>
> /*
> * Created on Mar 17, 2003
> *
> */
> package com.sipecom.modules.screens;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import javax.servlet.ServletOutputStream;
> import org.apache.turbine.modules.screens.RawScreen;
> import org.apache.turbine.util.RunData;
> /**
> * @author <a href="mailto:[EMAIL PROTECTED]">Rodrigo Reyes C.</a>
> */
> public class ImageGetter extends RawScreen {
>
>     protected String getContentType(RunData data) {
>         return "image/jpeg";
>     }
>
>     protected void doOutput(RunData data) throws Exception {
>         try {
>         String path = data.getServletContext().getRealPath("/");
>         String fileName = data.getParameters().getString("src");
>         fileName = path + fileName;
>         data.getResponse().setHeader("Content-Disposition", "inline;
> filename=" + fileName);
>         ServletOutputStream out = data.getResponse().getOutputStream();
>         InputStream is = null;
>         File file = null;
>         is = new FileInputStream(fileName);
>         file = new File(fileName);
>         // Get the size of the file
>         long length = file.length();
>         // You cannot create an array using a long type.
>         // It needs to be an int type.
>         // Before converting to an int type, check
>         // to ensure that file is not larger than Integer.MAX_VALUE.
>         if (length > Integer.MAX_VALUE) {
>             // File is too large
>         }
>         // Create the byte array to hold the data
>         byte[] bytes = new byte[(int) length];
>         // Read in the bytes
>         int offset = 0;
>         int numRead = 0;
>         while (offset < bytes.length && (numRead = is.read(bytes, offset,
> bytes.length - offset))>= 0) {
>             offset += numRead;
>         }
>         // Ensure all the bytes have been read in
>         if (offset < bytes.length) {
>             throw new IOException("Could not completely read file " +
> file.getName());
>         }
>         // Close the input stream and return bytes
>         is.close();
>         out.write(bytes);
>         out.flush();
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
> ----- Original Message -----
> From: "Peter Courcoux" <[EMAIL PROTECTED]>
> To: "Turbine Developers List" <[EMAIL PROTECTED]>
> Sent: Wednesday, March 19, 2003 4:00 PM
> Subject: Re: Direct Response and IllegalStateException
>
>
> > Rodrigo,
> >
> > I am not familiar with that pattern of use. How do you use the
> > RawScreen? Are you doing this with 2.2? I'm sure I tried extending
> > RawScreen and hit a problem but I cannot remember what.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to