[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] Re: Patches to java.util.zip by Christian Schlichtherle
From: |
Mark Wielaard |
Subject: |
[cp-patches] Re: Patches to java.util.zip by Christian Schlichtherle |
Date: |
Tue, 30 Aug 2005 23:45:20 +0200 |
Hi (moved to classpath-patches)
On Tue, 2005-08-30 at 18:02 +0200, Mark Wielaard wrote:
> I need to go through the rest of these patches.
> It would help if they could be rediffed against current CVS head and
> extra functionality would be moved to a new package.
I reviewed the rest but dropped everything that would need new
constructors. It would be best to rewrite that part so that it is an
extension for another (gnu) package.
While reviewing the classes I fixed some other small issues that I saw
in the code. I choose to treat all strings explicitly as UTF-8 encoded
although CP437 would probably be also a defensible choice. I did not use
any of your int -> long changes in the method signatures since I was not
sure how and where that was actually needed. If there is a change in the
zip format could you give a reference to that and explain how the patch
changes the values that gets written/read?
I committed the following:
2005-08-30 Mark Wielaard <address@hidden>
Christian Schlichtherle <address@hidden>
* java/util/zip/ZipEntry.java (setTime): Use
Calendar.setTimeInMillis().
(getTime): First parse extra bytes. Use Calendar.getTimeInMillis().
(parseExtra): Don't return early to make sure that KNOWN_EXTRA is
always set.
* java/util/zip/ZipFile.java (readEntries): Parse name and comment
as UTF-8 string.
(close): Check that raf is not null.
* java/util/zip/ZipInputStream.java (getNextEntry): Set name as
UTF-8 bytes.
* java/util/zip/ZipOutputStream.java (setComment): Set comment as
UTF-8 bytes.
(putNextEntry): Likewise for name.
(finish): Likewise for both.
Could you check whether I missed something essential from your original
patch?
Thanks,
Mark
Index: java/util/zip/ZipEntry.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipEntry.java,v
retrieving revision 1.18
diff -u -r1.18 ZipEntry.java
--- java/util/zip/ZipEntry.java 2 Jul 2005 20:32:44 -0000 1.18
+++ java/util/zip/ZipEntry.java 30 Aug 2005 21:36:13 -0000
@@ -39,7 +39,6 @@
package java.util.zip;
import java.util.Calendar;
-import java.util.Date;
/**
* This class represents a member of a zip archive. ZipFile and
@@ -173,7 +172,7 @@
Calendar cal = getCalendar();
synchronized (cal)
{
- cal.setTime(new Date(time));
+ cal.setTimeInMillis(time);
dostime = (cal.get(Calendar.YEAR) - 1980 & 0x7f) << 25
| (cal.get(Calendar.MONTH) + 1) << 21
| (cal.get(Calendar.DAY_OF_MONTH)) << 16
@@ -190,12 +189,12 @@
*/
public long getTime()
{
+ // The extra bytes might contain the time (posix/unix extension)
+ parseExtra();
+
if ((known & KNOWN_TIME) == 0)
return -1;
- // The extra bytes might contain the time (posix/unix extension)
- parseExtra ();
-
int sec = 2 * (dostime & 0x1f);
int min = (dostime >> 5) & 0x3f;
int hrs = (dostime >> 11) & 0x1f;
@@ -209,7 +208,7 @@
synchronized (cal)
{
cal.set(year, mon, day, hrs, min, sec);
- return cal.getTime().getTime();
+ return cal.getTimeInMillis();
}
}
catch (RuntimeException ex)
@@ -367,10 +366,10 @@
catch (ArrayIndexOutOfBoundsException ex)
{
/* be lenient */
- return;
}
known |= KNOWN_EXTRA;
+ return;
}
/**
Index: java/util/zip/ZipFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipFile.java,v
retrieving revision 1.23
diff -u -r1.23 ZipFile.java
--- java/util/zip/ZipFile.java 2 Jul 2005 20:32:44 -0000 1.23
+++ java/util/zip/ZipFile.java 30 Aug 2005 21:36:13 -0000
@@ -48,6 +48,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
@@ -284,7 +285,15 @@
buffer = new byte[needBuffer];
raf.readFully(buffer, 0, nameLen);
- String name = new String(buffer, 0, 0, nameLen);
+ String name;
+ try
+ {
+ name = new String(buffer, 0, nameLen, "UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
ZipEntry entry = new ZipEntry(name);
entry.setMethod(method);
@@ -301,7 +310,14 @@
if (commentLen > 0)
{
raf.readFully(buffer, 0, commentLen);
- entry.setComment(new String(buffer, 0, commentLen));
+ try
+ {
+ entry.setComment(new String(buffer, 0, commentLen, "UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
}
entry.offset = offset;
entries.put(name, entry);
@@ -317,6 +333,10 @@
*/
public void close() throws IOException
{
+ RandomAccessFile raf = this.raf;
+ if (raf == null)
+ return;
+
synchronized (raf)
{
closed = true;
Index: java/util/zip/ZipInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipInputStream.java,v
retrieving revision 1.15
diff -u -r1.15 ZipInputStream.java
--- java/util/zip/ZipInputStream.java 2 Jul 2005 20:32:44 -0000 1.15
+++ java/util/zip/ZipInputStream.java 30 Aug 2005 21:36:13 -0000
@@ -1,5 +1,5 @@
/* ZipInputStream.java --
- Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,7 @@
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
/**
* This is a FilterInputStream that reads the files in an zip archive
@@ -171,7 +172,15 @@
byte[] buffer = new byte[nameLen];
readFully(buffer);
- String name = new String(buffer);
+ String name;
+ try
+ {
+ name = new String(buffer, "UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
entry = createZipEntry(name);
entryAtEOF = false;
Index: java/util/zip/ZipOutputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipOutputStream.java,v
retrieving revision 1.10
diff -u -r1.10 ZipOutputStream.java
--- java/util/zip/ZipOutputStream.java 2 Jul 2005 20:32:45 -0000 1.10
+++ java/util/zip/ZipOutputStream.java 30 Aug 2005 21:36:13 -0000
@@ -1,5 +1,5 @@
/* ZipOutputStream.java --
- Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,6 +40,7 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Vector;
@@ -102,7 +103,14 @@
public void setComment(String comment)
{
byte[] commentBytes;
- commentBytes = comment.getBytes();
+ try
+ {
+ commentBytes = comment.getBytes("UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
if (commentBytes.length > 0xffff)
throw new IllegalArgumentException("Comment too long.");
zipComment = commentBytes;
@@ -226,7 +234,15 @@
writeLeInt(0);
writeLeInt(0);
}
- byte[] name = entry.getName().getBytes();
+ byte[] name;
+ try
+ {
+ name = entry.getName().getBytes("UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
if (name.length > 0xffff)
throw new ZipException("Name too long.");
byte[] extra = entry.getExtra();
@@ -357,15 +373,30 @@
writeLeInt((int)entry.getCompressedSize());
writeLeInt((int)entry.getSize());
- byte[] name = entry.getName().getBytes();
+ byte[] name;
+ try
+ {
+ name = entry.getName().getBytes("UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
if (name.length > 0xffff)
throw new ZipException("Name too long.");
byte[] extra = entry.getExtra();
if (extra == null)
extra = new byte[0];
- String strComment = entry.getComment();
- byte[] comment = strComment != null
- ? strComment.getBytes() : new byte[0];
+ String str = entry.getComment();
+ byte[] comment;
+ try
+ {
+ comment = str != null ? str.getBytes("UTF-8") : new byte[0];
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
if (comment.length > 0xffff)
throw new ZipException("Comment too long.");
signature.asc
Description: This is a digitally signed message part
- [cp-patches] Re: Patches to java.util.zip by Christian Schlichtherle,
Mark Wielaard <=