cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thelizardreborn <seth.f...@lat-inc.com>
Subject Re: FileInputStream/GZIPOutputStream in flow
Date Tue, 22 Jul 2008 17:51:37 GMT

My solution was to move this section of code into a Java class, and call the
method from flowscript. It seemed that my efforts to create a byte array in
flow would not satisfy the FileInputStream. This code can be ported directly
into Java, changing the vars to type declarations, making sure the
appropriate classes are included, and using "byte[] buf = new byte[1024];"


thelizardreborn wrote:
> 
> I am having a problem writing a gzip file from my flowscript. My basic
> goal is to use flow to gzip existing html documents. The gzip file is
> being created, but is empty (the source file is definitely not empty).
> Here is the relevant part of the code I am using:
> 
>     try {
>       var sep = java.io.File.separator;
>       // Create the GZIP output stream
>       var outFilename = "path"+sep+"to"+sep+"file"+sep+"filename.gzip";
> //absolute file path
>       var out = new java.util.zip.GZIPOutputStream(new
> java.io.FileOutputStream(outFilename));
> 
>       // Open the input file
>       var inFilename = "path"+sep+"to"+sep+"file"+sep+"filename.html";
> //absolute file path
>       java.lang.System.out.println(inFilename);
>       var lineIn = new java.io.FileInputStream(inFilename);
> 
>       // Transfer bytes from the input file to the GZIP output stream
>       /* --Original Code Sample: 
>        * --(ByteArrayOutputStream used instead to get through the
> javascript-ness of flowscript types)
>        * var buf = new byte[1024];
>        */
>       var myByteArray = new java.io.ByteArrayOutputStream(1024);
>       var buf = myByteArray.toByteArray();
>       var len;
>       while ((len = lineIn.read(buf)) > 0) {
>         out.write(buf, 0, len);
>       }
>       lineIn.close();
> 
>       // Complete the GZIP file
>       out.finish();
>       out.close();
>     } catch (e) {
>       java.lang.System.out.println(e);
>     }
> 
> At this point, when I run the code, no errors appear in any of the logs.
> Any ideas what I'm doing wrong? 
> 

-- 
View this message in context: http://www.nabble.com/FileInputStream-GZIPOutputStream-in-flow-tp18577080p18595107.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message