Initial revision

From-SVN: r26263
This commit is contained in:
Tom Tromey
1999-04-07 14:42:40 +00:00
parent 140fa895c6
commit ee9dd3721b
370 changed files with 173494 additions and 0 deletions
+101
View File
@@ -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;
}
}
+70
View File
@@ -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); }
}
+31
View File
@@ -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);
}
+13
View File
@@ -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
{
}
@@ -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();
}
}
+13
View File
@@ -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
{
}
+84
View File
@@ -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; }
}
+33
View File
@@ -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);
}
}
+81
View File
@@ -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;
}
}
@@ -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");
}
}