Hi Upayavira,
attached is a patch which should offer the STORED functionality. It's not
very nice, but I don't see an easier way than buffering the whole stream.
Cheers
Matthias
Index: ZipArchiveSerializer.java
===================================================================
RCS file:
/home/cvspublic/cocoon-2.1/src/java/org/apache/cocoon/serialization/ZipArchiveSerializer.java,v
retrieving revision 1.4
diff -u -r1.4 ZipArchiveSerializer.java
--- ZipArchiveSerializer.java 23 May 2003 09:53:46 -0000 1.4
+++ ZipArchiveSerializer.java 16 Jun 2003 12:55:56 -0000
@@ -57,6 +57,7 @@
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import java.util.zip.CRC32;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.ComponentException;
@@ -288,21 +289,56 @@
new SAXException("Cannot specify both 'src' and 'serializer' on a Zip
entry '" + name + "'");
}
+ String method = atts.getValue("method");
+ if (method!=null) {
+ if (!method.equalsIgnoreCase("STORED") &&
!method.equalsIgnoreCase("DEFLATED")) {
+ throw this.exception =
+ new SAXException("Method attribute must be either STORED or
DEFLATED");
+ }
+ }
+
Source source = null;
try {
- // Create a new Zip entry
- ZipEntry entry = new ZipEntry(name);
- this.zipOutput.putNextEntry(entry);
-
if (src != null) {
// Get the source and its data
source = resolver.resolveURI(src);
InputStream sourceInput = source.getInputStream();
+ // Create a new Zip entry
+ ZipEntry entry = new ZipEntry(name);
+
+ // read the inputstream an pipe it through the crc32
+ byte[] resultbuffer = null;
+ if ("STORED".equalsIgnoreCase(method)) {
+ entry.setMethod(ZipEntry.STORED);
+ CRC32 crc=new CRC32();
+ int lenmax = 0;
+ int len = 0;
+ byte[] tempresultbuffer = null;
+
+ while ((len = sourceInput.read(buffer)) > 0)
+ {
+ crc.update(buffer,0,len);
+ tempresultbuffer = new byte[len + lenmax];
+ if (lenmax != 0)
+ System.arraycopy(resultbuffer, 0, tempresultbuffer, 0,
lenmax);
+ System.arraycopy(buffer, 0, tempresultbuffer, lenmax, len);
+ lenmax += len;
+ resultbuffer = tempresultbuffer;
+ }
+ entry.setSize(lenmax);
+ entry.setCrc(crc.getValue());
+ }
+ this.zipOutput.putNextEntry(entry);
+
// Copy the source to the zip
- int len;
- while ((len = sourceInput.read(this.buffer)) > 0) {
- this.zipOutput.write(this.buffer, 0, len);
+ if ("STORED".equalsIgnoreCase(method))
+ this.zipOutput.write(resultbuffer);
+ else {
+ int len;
+ while ((len = sourceInput.read(this.buffer)) > 0) {
+ this.zipOutput.write(this.buffer, 0, len);
+ }
}
// and close the entry
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]