This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: More Java 2 fixes


I'm checking this in.

This fixes a few more divergences from Java 2.
I added a Mauve test case for the ZipInputStream patch.

2000-11-17  Tom Tromey  <tromey@cygnus.com>

	* java/text/CollationKey.java: Implement Comparable.
	(compareTo(Object)): New method.
	* java/text/Collator.java (compare(Object,Object)): New method.
	Implement Comparator.

	* java/util/zip/InflaterInputStream.java (available): New method.
	(close): New method.
	(read, available, skip, fill): Throw exception if stream closed.
	* java/util/zip/ZipInputStream.java (read, skip, readFully, fill,
	getNextEntry): Throw exception if closed.

Tom

Index: java/util/zip/InflaterInputStream.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/zip/InflaterInputStream.java,v
retrieving revision 1.8
diff -u -r1.8 InflaterInputStream.java
--- InflaterInputStream.java	2000/08/24 22:48:12	1.8
+++ InflaterInputStream.java	2000/11/17 20:41:29
@@ -1,6 +1,6 @@
 // InflaterInputStream.java - Input stream filter for decompressing.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -28,6 +28,8 @@
 {
   protected void fill () throws IOException
   {
+    if (inf == null)
+      throw new IOException ("stream closed");
     len = in.read(buf, 0, buf.length);
     if (len != -1)
       inf.setInput(buf, 0, len);
@@ -61,6 +63,8 @@
 
   public int read (byte[] buf, int off, int len) throws IOException
   {
+    if (inf == null)
+      throw new IOException ("stream closed");
     if (inf.finished())
       return -1;
     if (inf.needsInput())
@@ -79,8 +83,26 @@
       }
   }
 
+  public void close () throws IOException
+  {
+    inf = null;
+    super.close ();
+  }
+
+  public int available () throws IOException
+  {
+    // According to the JDK 1.2 docs, this should only ever return 0
+    // or 1 and should not be relied upon by Java programs.
+    if (inf == null)
+      throw new IOException ("stream closed");
+    return inf.finished () ? 0 : 1;
+  }
+
   public long skip (long n) throws IOException
   {
+    if (inf == null)
+      throw new IOException ("stream closed");
+
     if (n == 0)
       return 0;
 
Index: java/util/zip/ZipInputStream.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/zip/ZipInputStream.java,v
retrieving revision 1.10
diff -u -r1.10 ZipInputStream.java
--- ZipInputStream.java	2000/08/20 21:51:19	1.10
+++ ZipInputStream.java	2000/11/17 20:41:29
@@ -35,6 +35,8 @@
 
   public ZipEntry getNextEntry () throws IOException
   {
+    if (closed)
+      throw new IOException ("stream closed");
     if (current != null)
       closeEntry();
     if (in.read() != 'P'
@@ -112,6 +114,8 @@
   // back data.
   protected void fill () throws IOException
   {
+    if (closed)
+      throw new IOException ("stream closed");
     int count = buf.length;
     if (count > compressed_bytes)
       count = compressed_bytes;
@@ -127,9 +131,11 @@
   {
     return new ZipEntry (name);
   }
-  
+
   public int read (byte[] b, int off, int len)  throws IOException
   {
+    if (closed)
+      throw new IOException ("stream closed");
     if (len > avail)
       len = avail;
     int count;
@@ -149,6 +155,8 @@
 
   public long skip (long n)  throws IOException
   {
+    if (closed)
+      throw new IOException ("stream closed");
     if (n > avail)
       n = avail;
     long count;
@@ -160,11 +168,9 @@
     return count;
   }
 
-  public int available() {
-    if (closed)
-      return 0;
-    else
-      return 1;
+  public int available()
+  {
+    return closed ? 0 : 1;
   }
 
   private void readFully (byte[] b)  throws IOException
Index: java/text/CollationKey.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/CollationKey.java,v
retrieving revision 1.3
diff -u -r1.3 CollationKey.java
--- CollationKey.java	2000/03/07 19:55:27	1.3
+++ CollationKey.java	2000/11/17 20:41:29
@@ -1,6 +1,6 @@
 // CollationKey.java - Sort key for locale-sensitive String.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -19,7 +19,7 @@
  * Status: Believed complete and correct.
  */
 
-public final class CollationKey
+public final class CollationKey implements Comparable
 {
   public int compareTo (CollationKey target)
   {
@@ -32,6 +32,11 @@
       }
 
     return key.length - target.key.length;
+  }
+
+  public int compareTo (Object o)
+  {
+    return compareTo ((CollationKey) o);
   }
 
   public boolean equals (Object obj)
Index: java/text/Collator.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/Collator.java,v
retrieving revision 1.6
diff -u -r1.6 Collator.java
--- Collator.java	2000/09/08 19:37:09	1.6
+++ Collator.java	2000/11/17 20:41:30
@@ -13,6 +13,7 @@
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.util.Comparator;
 
 /**
  * @author Tom Tromey <tromey@cygnus.com>
@@ -23,7 +24,7 @@
  * Status: Mostly complete, but parts stubbed out.  Look for FIXME.
  */
 
-public abstract class Collator implements Cloneable
+public abstract class Collator implements Comparator, Cloneable
 {
   public static final int NO_DECOMPOSITION = 0;
   public static final int CANONICAL_DECOMPOSITION = 1;
@@ -41,6 +42,11 @@
   }
 
   public abstract int compare (String source, String target);
+
+  public int compare (Object o1, Object o2)
+  {
+    return compare ((String) o1, (String) o2);
+  }
 
   public boolean equals (Object obj)
   {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]