aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util/zip
diff options
context:
space:
mode:
authorTom Tromey <tromey@gcc.gnu.org>1999-04-07 14:42:40 +0000
committerTom Tromey <tromey@gcc.gnu.org>1999-04-07 14:42:40 +0000
commitee9dd3721be68b9fa63dea9aa5a1d86e66958cde (patch)
treed96801a16fdf03a5682ef98730fe333a46eef944 /libjava/java/util/zip
parent140fa895c6b859f827fc4437b91775a82cd105fb (diff)
downloadgcc-ee9dd3721be68b9fa63dea9aa5a1d86e66958cde.zip
gcc-ee9dd3721be68b9fa63dea9aa5a1d86e66958cde.tar.gz
gcc-ee9dd3721be68b9fa63dea9aa5a1d86e66958cde.tar.bz2
Initial revision
From-SVN: r26263
Diffstat (limited to 'libjava/java/util/zip')
-rw-r--r--libjava/java/util/zip/Adler32.java101
-rw-r--r--libjava/java/util/zip/CRC32.java70
-rw-r--r--libjava/java/util/zip/Checksum.java31
-rw-r--r--libjava/java/util/zip/Deflater.java13
-rw-r--r--libjava/java/util/zip/DeflaterOutputStream.java46
-rw-r--r--libjava/java/util/zip/ZipConstants.java13
-rw-r--r--libjava/java/util/zip/ZipEntry.java84
-rw-r--r--libjava/java/util/zip/ZipException.java33
-rw-r--r--libjava/java/util/zip/ZipFile.java81
-rw-r--r--libjava/java/util/zip/ZipOutputStream.java26
10 files changed, 498 insertions, 0 deletions
diff --git a/libjava/java/util/zip/Adler32.java b/libjava/java/util/zip/Adler32.java
new file mode 100644
index 0000000..8e4ab9a
--- /dev/null
+++ b/libjava/java/util/zip/Adler32.java
@@ -0,0 +1,101 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+
+/**
+ * @author Per Bothner
+ * @date April 6, 1999.
+ */
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * The actual Adler32 algorithm is taken from RFC 1950.
+ * Status: Believed complete and correct.
+ */
+
+public class Adler32 implements Checksum
+{
+ private static int BASE = 65521; /* largest prime smaller than 65536 */
+
+ int s1;
+ int s2;
+
+ public Adler32 ()
+ {
+ reset();
+ }
+
+ public void reset () { s1 = 1; s2 = 0; }
+
+ public void update (int bval)
+ {
+ s1 = (s1 + (bval & 0xFF)) % BASE;
+ s2 = (s1 + s2) % BASE;
+ }
+
+ public void update (byte[] buffer)
+ {
+ update(buffer, 0, buffer.length);
+ }
+
+ public void update (byte[] buf, int off, int len)
+ {
+ int s1 = this.s1;
+ int s2 = this.s2;
+ while (len > 0)
+ {
+ // We can defer the modulo operation.
+ int n = 4000;
+ if (n > len)
+ n = len;
+ len -= n;
+ while (--n >= 0)
+ {
+ s1 = s1 + (buf[off++] & 0xFF);
+ s2 = s2 + s1;
+ }
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+ this.s1 = s1;
+ this.s2 = s2;
+ }
+
+ public long getValue()
+ {
+ return ((long) s2 << 16) + s1;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libjava/java/util/zip/CRC32.java b/libjava/java/util/zip/CRC32.java
new file mode 100644
index 0000000..ab19b58
--- /dev/null
+++ b/libjava/java/util/zip/CRC32.java
@@ -0,0 +1,70 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+
+/**
+ * @author Per Bothner
+ * @date April 1, 1999.
+ */
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * The actual CRC32 algorithm is taken from RFC 1952.
+ * Status: Believed complete and correct.
+ */
+
+public class CRC32 implements Checksum
+{
+ int crc = 0;
+
+ static int[] crc_table = make_crc_table();
+
+ /* Make the table for a fast CRC. */
+ static int[] make_crc_table ()
+ {
+ int[] crc_table = new int[256];
+ for (int n = 0; n < 256; n++)
+ {
+ int c = n;
+ for (int k = 8; --k >= 0; )
+ {
+ if ((c & 1) != 0)
+ c = 0xedb88320 ^ (c >>> 1);
+ else
+ c = c >>> 1;
+ }
+ crc_table[n] = c;
+ }
+ return crc_table;
+ }
+
+ public long getValue ()
+ {
+ return (long) crc & 0xffffffffL;
+ }
+
+ public void reset () { crc = 0; }
+
+ public void update (int bval)
+ {
+ int c = ~crc;
+ c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
+ crc = ~c;
+ }
+
+ public void update (byte[] buf, int off, int len)
+ {
+ int c = ~crc;
+ while (--len >= 0)
+ c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
+ crc = ~c;
+ }
+ public void update (byte[] buf) { update(buf, 0, buf.length); }
+}
diff --git a/libjava/java/util/zip/Checksum.java b/libjava/java/util/zip/Checksum.java
new file mode 100644
index 0000000..85cdae2
--- /dev/null
+++ b/libjava/java/util/zip/Checksum.java
@@ -0,0 +1,31 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+
+/**
+ * @author Per Bothner
+ * @date January 9, 1999.
+ */
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * Status: Believed complete and correct.
+ */
+
+public interface Checksum
+{
+ public long getValue ();
+
+ public void reset ();
+
+ public void update (int bval);
+
+ public void update (byte[] buf, int off, int len);
+}
diff --git a/libjava/java/util/zip/Deflater.java b/libjava/java/util/zip/Deflater.java
new file mode 100644
index 0000000..81312e2
--- /dev/null
+++ b/libjava/java/util/zip/Deflater.java
@@ -0,0 +1,13 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+
+public class Deflater
+{
+}
diff --git a/libjava/java/util/zip/DeflaterOutputStream.java b/libjava/java/util/zip/DeflaterOutputStream.java
new file mode 100644
index 0000000..4f0b8b4
--- /dev/null
+++ b/libjava/java/util/zip/DeflaterOutputStream.java
@@ -0,0 +1,46 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+import java.io.*;
+
+/** JUST AN INCOMPLETE STUB! */
+
+public class DeflaterOutputStream extends FilterOutputStream
+{
+ protected byte[] buf;
+
+ protected Deflater def;
+
+ public DeflaterOutputStream(OutputStream out)
+ {
+ this(out, null, 512);
+ }
+
+ public DeflaterOutputStream(OutputStream out, Deflater defl)
+ {
+ this(out, defl, 512);
+ }
+
+ public DeflaterOutputStream(OutputStream out, Deflater defl, int bufsize)
+ {
+ super(out);
+ buf = new byte[bufsize];
+ def = defl;
+ }
+
+ public void finish () throws IOException
+ {
+ }
+
+ public void close () throws IOException
+ {
+ finish();
+ out.close();
+ }
+}
diff --git a/libjava/java/util/zip/ZipConstants.java b/libjava/java/util/zip/ZipConstants.java
new file mode 100644
index 0000000..4aec92e
--- /dev/null
+++ b/libjava/java/util/zip/ZipConstants.java
@@ -0,0 +1,13 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+
+public interface ZipConstants
+{
+}
diff --git a/libjava/java/util/zip/ZipEntry.java b/libjava/java/util/zip/ZipEntry.java
new file mode 100644
index 0000000..d472de5
--- /dev/null
+++ b/libjava/java/util/zip/ZipEntry.java
@@ -0,0 +1,84 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+
+/**
+ * @author Per Bothner
+ * @date January 6, 1999.
+ */
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * Status: Believed complete and correct.
+ */
+
+public class ZipEntry
+{
+ // These values were determined using a simple test program.
+ public static final int STORED = 0;
+ public static final int DEFLATED = 8;
+
+ String comment;
+ long compressedSize = -1;
+ long crc = -1;
+ byte[] extra;
+ int method = -1;
+ String name;
+ long size = -1;
+ long time = -1;
+
+ ZipEntry next;
+
+ public ZipEntry (String name)
+ {
+ this.name = name;
+ }
+
+ public String getComment () { return comment; }
+
+ public long getCompressedSize () { return compressedSize; }
+
+ public long getCrc () { return crc; }
+
+ public byte[] getExtra() { return extra; }
+
+ public int getMethod () { return method; }
+
+ public String getName () { return name; }
+
+ public long getSize () { return size; }
+
+ public long getTime () { return time; }
+
+ public boolean isDirectory ()
+ {
+ if (name != null)
+ {
+ int nlen = name.length();
+ if (nlen > 0 && name.charAt(nlen-1) == '/')
+ return true;
+ }
+ return false;
+ }
+
+ public void setComment (String comment) { this.comment = comment; }
+
+ public void setCrc (long crc) { this.crc = crc; }
+
+ public void setExtra (byte[] extra) { this.extra = extra; }
+
+ public void setMethod(int method) { this.method = method; }
+
+ public void setSize (long size) { this.size = size; }
+
+ public void setTime (long time) { this.time = time; }
+
+ public String toString () { return name; }
+}
diff --git a/libjava/java/util/zip/ZipException.java b/libjava/java/util/zip/ZipException.java
new file mode 100644
index 0000000..5c038a5
--- /dev/null
+++ b/libjava/java/util/zip/ZipException.java
@@ -0,0 +1,33 @@
+// ZipException.java
+
+/* Copyright (C) 1998, 1999 Cygnus Solutions
+
+ This file is part of libjava.
+
+This software is copyrighted work licensed under the terms of the
+Libjava License. Please consult the file "LIBJAVA_LICENSE" for
+details. */
+
+package java.util.zip;
+
+/**
+ * @author Per Bothner
+ * @date January 9, 1999.
+ */
+
+/* Written using on-line Java Platform 1.2 API Specification.
+ * Believed complete and correct.
+ */
+
+public class ZipException extends java.io.IOException
+{
+ public ZipException ()
+ {
+ super();
+ }
+
+ public ZipException (String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/libjava/java/util/zip/ZipFile.java b/libjava/java/util/zip/ZipFile.java
new file mode 100644
index 0000000..75f0a3d
--- /dev/null
+++ b/libjava/java/util/zip/ZipFile.java
@@ -0,0 +1,81 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+import java.io.*;
+
+/** JUST AN INCOMPLETE STUB! */
+
+public class ZipFile implements ZipConstants
+{
+
+ String name;
+ ZipEntry entries;
+
+ public ZipFile (String fname) throws IOException
+ {
+ name = fname;
+ // FIXME
+ }
+
+ public ZipFile (File f) throws IOException
+ {
+ this(f.getPath());
+ }
+
+ public java.util.Enumeration entries()
+ {
+ return new ZipEnumeration(this);
+ }
+
+ public void close() throws IOException
+ {
+ // FIXME
+ }
+
+ public ZipEntry getEntry(String name)
+ {
+ for (ZipEntry entry = entries; entry != null; entry = entry.next)
+ {
+ if (name.equals(entry.getName()))
+ return entry;
+ }
+ return null;
+ }
+
+ public InputStream getInputStream(ZipEntry ze) throws IOException
+ {
+ return null; // FIXME
+ }
+
+ public String getName () { return name; }
+}
+
+class ZipEnumeration implements java.util.Enumeration
+{
+ ZipEntry entry;
+
+ ZipEnumeration (ZipFile zfile)
+ {
+ entry = zfile.entries;
+ }
+
+ public boolean hasMoreElements ()
+ {
+ return entry != null;
+ }
+
+ public Object nextElement ()
+ {
+ ZipEntry cur = entry;
+ if (cur == null)
+ throw new java.util.NoSuchElementException();
+ entry = cur.next;
+ return cur;
+ }
+}
diff --git a/libjava/java/util/zip/ZipOutputStream.java b/libjava/java/util/zip/ZipOutputStream.java
new file mode 100644
index 0000000..42cfb00
--- /dev/null
+++ b/libjava/java/util/zip/ZipOutputStream.java
@@ -0,0 +1,26 @@
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package java.util.zip;
+import java.io.*;
+
+/** JUST AN INCOMPLETE STUB! */
+
+public class ZipOutputStream extends DeflaterOutputStream
+ implements ZipConstants
+{
+ public ZipOutputStream (OutputStream out)
+ {
+ super(out);
+ }
+
+ public void putNextEntry (ZipEntry entry) throws IOException
+ {
+ throw new Error ("java.util.zip.ZipOutputStream.putNextEntry: not implemented");
+ }
+}