emul/mini/src/main/java/java/util/zip/ZipInputStream.java
branchemul
changeset 611 9839e9a75bcf
parent 609 48ef38e9677e
child 694 0d277415ed02
     1.1 --- a/emul/mini/src/main/java/java/util/zip/ZipInputStream.java	Wed Jan 30 14:00:17 2013 +0100
     1.2 +++ b/emul/mini/src/main/java/java/util/zip/ZipInputStream.java	Wed Jan 30 14:03:49 2013 +0100
     1.3 @@ -29,9 +29,8 @@
     1.4  import java.io.IOException;
     1.5  import java.io.EOFException;
     1.6  import java.io.PushbackInputStream;
     1.7 -import java.nio.charset.Charset;
     1.8 -import java.nio.charset.StandardCharsets;
     1.9  import static java.util.zip.ZipConstants64.*;
    1.10 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
    1.11  
    1.12  /**
    1.13   * This class implements an input stream filter for reading files in the
    1.14 @@ -56,8 +55,6 @@
    1.15      // one entry
    1.16      private boolean entryEOF = false;
    1.17  
    1.18 -    private ZipCoder zc;
    1.19 -
    1.20      /**
    1.21       * Check to make sure that this stream has not been closed
    1.22       */
    1.23 @@ -76,7 +73,12 @@
    1.24       * @param in the actual input stream
    1.25       */
    1.26      public ZipInputStream(InputStream in) {
    1.27 -        this(in, StandardCharsets.UTF_8);
    1.28 +//        this(in, "UTF-8");
    1.29 +        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
    1.30 +        usesDefaultInflater = true;
    1.31 +        if(in == null) {
    1.32 +            throw new NullPointerException("in is null");
    1.33 +        }
    1.34      }
    1.35  
    1.36      /**
    1.37 @@ -92,7 +94,7 @@
    1.38       *        flag is set).
    1.39       *
    1.40       * @since 1.7
    1.41 -     */
    1.42 +     *
    1.43      public ZipInputStream(InputStream in, Charset charset) {
    1.44          super(new PushbackInputStream(in, 512), new Inflater(true), 512);
    1.45          usesDefaultInflater = true;
    1.46 @@ -103,6 +105,7 @@
    1.47              throw new NullPointerException("charset is null");
    1.48          this.zc = ZipCoder.get(charset);
    1.49      }
    1.50 +    */
    1.51  
    1.52      /**
    1.53       * Reads the next ZIP file entry and positions the stream at the
    1.54 @@ -295,8 +298,8 @@
    1.55          readFully(b, 0, len);
    1.56          // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
    1.57          ZipEntry e = createZipEntry(((flag & EFS) != 0)
    1.58 -                                    ? zc.toStringUTF8(b, len)
    1.59 -                                    : zc.toString(b, len));
    1.60 +                                    ? toStringUTF8(b, len)
    1.61 +                                    : toString(b, len));
    1.62          // now get the remaining fields for the entry
    1.63          if ((flag & 1) == 1) {
    1.64              throw new ZipException("encrypted ZIP entry not supported");
    1.65 @@ -453,4 +456,12 @@
    1.66      private static final long get64(byte b[], int off) {
    1.67          return get32(b, off) | (get32(b, off+4) << 32);
    1.68      }
    1.69 +
    1.70 +    private static String toStringUTF8(byte[] arr, int len) {
    1.71 +        return new String(arr, 0, len);
    1.72 +    }
    1.73 +    
    1.74 +    private static String toString(byte[] b, int len) {
    1.75 +        return new String(b, 0, len);
    1.76 +    }
    1.77  }