Separating the unzipping functionality into own module. Step one.
1.1 --- a/pom.xml Wed May 07 11:55:06 2014 +0200
1.2 +++ b/pom.xml Wed May 07 16:47:24 2014 +0200
1.3 @@ -87,6 +87,7 @@
1.4 <exclude>.*/**</exclude>
1.5 <exclude>rt/emul/mini/src/main/**</exclude>
1.6 <exclude>rt/emul/compact/src/main/**</exclude>
1.7 + <exclude>rt/emul/zip/src/main/**</exclude>
1.8 <exclude>rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java</exclude>
1.9 <exclude>rt/archetype/src/main/resources/archetype-resources/**</exclude>
1.10 <exclude>rt/emul/*/src/test/resources/**</exclude>
2.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipArchive.java Wed May 07 11:55:06 2014 +0200
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,154 +0,0 @@
2.4 -/**
2.5 - * Back 2 Browser Bytecode Translator
2.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 - *
2.8 - * This program is free software: you can redistribute it and/or modify
2.9 - * it under the terms of the GNU General Public License as published by
2.10 - * the Free Software Foundation, version 2 of the License.
2.11 - *
2.12 - * This program is distributed in the hope that it will be useful,
2.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 - * GNU General Public License for more details.
2.16 - *
2.17 - * You should have received a copy of the GNU General Public License
2.18 - * along with this program. Look for COPYING file in the top folder.
2.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 - */
2.21 -package org.apidesign.bck2brwsr.compact.tck;
2.22 -
2.23 -import java.io.ByteArrayOutputStream;
2.24 -import java.io.IOException;
2.25 -import java.io.InputStream;
2.26 -import java.util.Arrays;
2.27 -import java.util.LinkedHashMap;
2.28 -import java.util.Map;
2.29 -import java.util.Objects;
2.30 -import java.util.zip.ZipEntry;
2.31 -import org.apidesign.bck2brwsr.emul.zip.ZipInputStream;
2.32 -
2.33 -/**
2.34 - *
2.35 - * @author Jaroslav Tulach <jtulach@netbeans.org>
2.36 - */
2.37 -final class ZipArchive {
2.38 - private final Map<String, byte[]> entries = new LinkedHashMap<>();
2.39 -
2.40 - public static ZipArchive createZip(InputStream is) throws IOException {
2.41 - ZipArchive a = new ZipArchive();
2.42 - readZip(is, a);
2.43 - return a;
2.44 - }
2.45 -
2.46 - public static ZipArchive createReal(InputStream is) throws IOException {
2.47 - ZipArchive a = new ZipArchive();
2.48 - realZip(is, a);
2.49 - return a;
2.50 - }
2.51 -
2.52 - /**
2.53 - * Registers entry name and data
2.54 - */
2.55 - final void register(String entry, InputStream is) throws IOException {
2.56 - ByteArrayOutputStream os = new ByteArrayOutputStream();
2.57 - for (;;) {
2.58 - int ch = is.read();
2.59 - if (ch == -1) {
2.60 - break;
2.61 - }
2.62 - os.write(ch);
2.63 - }
2.64 - os.close();
2.65 - entries.put(entry, os.toByteArray());
2.66 - }
2.67 -
2.68 - @Override
2.69 - public int hashCode() {
2.70 - return entries.hashCode();
2.71 - }
2.72 -
2.73 - @Override
2.74 - public boolean equals(Object obj) {
2.75 - if (obj == null) {
2.76 - return false;
2.77 - }
2.78 - if (getClass() != obj.getClass()) {
2.79 - return false;
2.80 - }
2.81 - final ZipArchive other = (ZipArchive) obj;
2.82 - if (!Objects.deepEquals(this.entries, other.entries)) {
2.83 - return false;
2.84 - }
2.85 - return true;
2.86 - }
2.87 -
2.88 - @Override
2.89 - public String toString() {
2.90 - StringBuilder sb = new StringBuilder();
2.91 - for (Map.Entry<String, byte[]> en : entries.entrySet()) {
2.92 - String string = en.getKey();
2.93 - byte[] bs = en.getValue();
2.94 - sb.append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
2.95 - }
2.96 - return sb.toString();
2.97 - }
2.98 -
2.99 - public void assertEquals(ZipArchive zip, String msg) {
2.100 - boolean ok = true;
2.101 - StringBuilder sb = new StringBuilder();
2.102 - sb.append(msg);
2.103 - for (Map.Entry<String, byte[]> en : entries.entrySet()) {
2.104 - String string = en.getKey();
2.105 - byte[] bs = en.getValue();
2.106 - byte[] other = zip.entries.get(string);
2.107 - sb.append("\n");
2.108 - if (other == null) {
2.109 - sb.append("EXTRA ").append(string).append(" = ").append(Arrays.toString(bs));
2.110 - ok = false;
2.111 - continue;
2.112 - }
2.113 - if (Arrays.equals(bs, other)) {
2.114 - sb.append("OK ").append(string);
2.115 - continue;
2.116 - } else {
2.117 - sb.append("DIFF ").append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
2.118 - sb.append(" TO").append(string).append(" = ").append(Arrays.toString(other)).append("\n");
2.119 - ok = false;
2.120 - continue;
2.121 - }
2.122 - }
2.123 - for (Map.Entry<String, byte[]> entry : zip.entries.entrySet()) {
2.124 - String string = entry.getKey();
2.125 - if (entries.get(string) == null) {
2.126 - sb.append("MISS ").append(string).append(" = ").append(Arrays.toString(entry.getValue()));
2.127 - ok = false;
2.128 - }
2.129 - }
2.130 - if (!ok) {
2.131 - assert false : sb.toString();
2.132 - }
2.133 - }
2.134 -
2.135 - public static void readZip(InputStream is, ZipArchive data) throws IOException {
2.136 - ZipInputStream zip = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(is);
2.137 - for (;;) {
2.138 - ZipEntry en = zip.getNextEntry();
2.139 - if (en == null) {
2.140 - return;
2.141 - }
2.142 - data.register(en.getName(), zip);
2.143 - }
2.144 - }
2.145 -
2.146 - public static void realZip(InputStream is, ZipArchive data) throws IOException {
2.147 - java.util.zip.ZipInputStream zip = new java.util.zip.ZipInputStream(is);
2.148 - for (;;) {
2.149 - ZipEntry en = zip.getNextEntry();
2.150 - if (en == null) {
2.151 - return;
2.152 - }
2.153 - data.register(en.getName(), zip);
2.154 - }
2.155 - }
2.156 -
2.157 -}
3.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java Wed May 07 11:55:06 2014 +0200
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,43 +0,0 @@
3.4 -/**
3.5 - * Back 2 Browser Bytecode Translator
3.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 - *
3.8 - * This program is free software: you can redistribute it and/or modify
3.9 - * it under the terms of the GNU General Public License as published by
3.10 - * the Free Software Foundation, version 2 of the License.
3.11 - *
3.12 - * This program is distributed in the hope that it will be useful,
3.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 - * GNU General Public License for more details.
3.16 - *
3.17 - * You should have received a copy of the GNU General Public License
3.18 - * along with this program. Look for COPYING file in the top folder.
3.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 - */
3.21 -package org.apidesign.bck2brwsr.compact.tck;
3.22 -
3.23 -import java.io.IOException;
3.24 -import java.io.InputStream;
3.25 -import org.apidesign.bck2brwsr.vmtest.Compare;
3.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
3.27 -import org.testng.annotations.Factory;
3.28 -
3.29 -/**
3.30 - *
3.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
3.32 - */
3.33 -public class ZipCompatibilityTest {
3.34 - @Compare
3.35 - public String testDemoStaticCalculator() throws IOException {
3.36 - InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
3.37 - ZipArchive zip = ZipArchive.createZip(is);
3.38 - final String ts = zip.toString();
3.39 - return ts.substring(0, 4096) + ts.hashCode();
3.40 - }
3.41 -
3.42 - @Factory
3.43 - public static Object[] create() {
3.44 - return VMTest.create(ZipCompatibilityTest.class);
3.45 - }
3.46 -}
4.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipVsJzLibTest.java Wed May 07 11:55:06 2014 +0200
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,39 +0,0 @@
4.4 -/**
4.5 - * Back 2 Browser Bytecode Translator
4.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 - *
4.8 - * This program is free software: you can redistribute it and/or modify
4.9 - * it under the terms of the GNU General Public License as published by
4.10 - * the Free Software Foundation, version 2 of the License.
4.11 - *
4.12 - * This program is distributed in the hope that it will be useful,
4.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 - * GNU General Public License for more details.
4.16 - *
4.17 - * You should have received a copy of the GNU General Public License
4.18 - * along with this program. Look for COPYING file in the top folder.
4.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 - */
4.21 -package org.apidesign.bck2brwsr.compact.tck;
4.22 -
4.23 -import java.io.IOException;
4.24 -import java.io.InputStream;
4.25 -import org.testng.annotations.Test;
4.26 -
4.27 -/**
4.28 - *
4.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
4.30 - */
4.31 -public class ZipVsJzLibTest {
4.32 - @Test public void r() throws IOException {
4.33 - InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
4.34 - ZipArchive zip = ZipArchive.createZip(is);
4.35 -
4.36 - is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
4.37 - ZipArchive real = ZipArchive.createReal(is);
4.38 -
4.39 - real.assertEquals(zip, "Are they the same?");
4.40 - }
4.41 -
4.42 -}
5.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/CRC32Test.java Wed May 07 11:55:06 2014 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,41 +0,0 @@
5.4 -/**
5.5 - * Back 2 Browser Bytecode Translator
5.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.7 - *
5.8 - * This program is free software: you can redistribute it and/or modify
5.9 - * it under the terms of the GNU General Public License as published by
5.10 - * the Free Software Foundation, version 2 of the License.
5.11 - *
5.12 - * This program is distributed in the hope that it will be useful,
5.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 - * GNU General Public License for more details.
5.16 - *
5.17 - * You should have received a copy of the GNU General Public License
5.18 - * along with this program. Look for COPYING file in the top folder.
5.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
5.20 - */
5.21 -package org.apidesign.bck2brwsr.vmtest.impl;
5.22 -
5.23 -import java.io.UnsupportedEncodingException;
5.24 -import java.util.zip.CRC32;
5.25 -import org.apidesign.bck2brwsr.vmtest.Compare;
5.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
5.27 -import org.testng.annotations.Factory;
5.28 -
5.29 -/**
5.30 - *
5.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
5.32 - */
5.33 -public class CRC32Test {
5.34 -
5.35 - @Compare public long crc1() throws UnsupportedEncodingException {
5.36 - CRC32 crc = new CRC32();
5.37 - crc.update("Hello World!".getBytes("UTF-8"));
5.38 - return crc.getValue();
5.39 - }
5.40 -
5.41 - @Factory public static Object[] create() {
5.42 - return VMTest.create(CRC32Test.class);
5.43 - }
5.44 -}
6.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipEntryTest.java Wed May 07 11:55:06 2014 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,67 +0,0 @@
6.4 -/**
6.5 - * Back 2 Browser Bytecode Translator
6.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.7 - *
6.8 - * This program is free software: you can redistribute it and/or modify
6.9 - * it under the terms of the GNU General Public License as published by
6.10 - * the Free Software Foundation, version 2 of the License.
6.11 - *
6.12 - * This program is distributed in the hope that it will be useful,
6.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.15 - * GNU General Public License for more details.
6.16 - *
6.17 - * You should have received a copy of the GNU General Public License
6.18 - * along with this program. Look for COPYING file in the top folder.
6.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
6.20 - */
6.21 -package org.apidesign.bck2brwsr.vmtest.impl;
6.22 -
6.23 -import java.io.ByteArrayInputStream;
6.24 -import java.io.IOException;
6.25 -import java.io.InputStream;
6.26 -import org.apidesign.bck2brwsr.emul.zip.FastJar;
6.27 -import org.testng.annotations.Test;
6.28 -import static org.testng.Assert.*;
6.29 -
6.30 -/**
6.31 - *
6.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
6.33 - */
6.34 -@GenerateZip(name = "five.zip", contents = {
6.35 - "1.txt", "one",
6.36 - "2.txt", "duo",
6.37 - "3.txt", "three",
6.38 - "4.txt", "four",
6.39 - "5.txt", "five"
6.40 -})
6.41 -public class ZipEntryTest {
6.42 - @Test
6.43 - public void readEntriesEffectively() throws IOException {
6.44 - InputStream is = ZipEntryTest.class.getResourceAsStream("five.zip");
6.45 - byte[] arr = new byte[is.available()];
6.46 - int len = is.read(arr);
6.47 - assertEquals(len, arr.length, "Read fully");
6.48 -
6.49 - FastJar fj = new FastJar(arr);
6.50 - FastJar.Entry[] entrs = fj.list();
6.51 -
6.52 - assertEquals(5, entrs.length, "Five entries");
6.53 -
6.54 - for (int i = 1; i <= 5; i++) {
6.55 - FastJar.Entry en = entrs[i - 1];
6.56 - assertEquals(en.name, i + ".txt");
6.57 -// assertEquals(cis.cnt, 0, "Content of the file should be skipped, not read");
6.58 - }
6.59 -
6.60 - assertContent("three", fj.getInputStream(entrs[3 - 1]), "read OK");
6.61 - assertContent("five", fj.getInputStream(entrs[5 - 1]), "read OK");
6.62 - }
6.63 -
6.64 - private static void assertContent(String exp, InputStream is, String msg) throws IOException {
6.65 - byte[] arr = new byte[512];
6.66 - int len = is.read(arr);
6.67 - String s = new String(arr, 0, len);
6.68 - assertEquals(exp, s, msg);
6.69 - }
6.70 -}
7.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Wed May 07 11:55:06 2014 +0200
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,108 +0,0 @@
7.4 -/**
7.5 - * Back 2 Browser Bytecode Translator
7.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.7 - *
7.8 - * This program is free software: you can redistribute it and/or modify
7.9 - * it under the terms of the GNU General Public License as published by
7.10 - * the Free Software Foundation, version 2 of the License.
7.11 - *
7.12 - * This program is distributed in the hope that it will be useful,
7.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 - * GNU General Public License for more details.
7.16 - *
7.17 - * You should have received a copy of the GNU General Public License
7.18 - * along with this program. Look for COPYING file in the top folder.
7.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
7.20 - */
7.21 -package org.apidesign.bck2brwsr.vmtest.impl;
7.22 -
7.23 -import java.io.IOException;
7.24 -import java.io.InputStream;
7.25 -import java.util.Objects;
7.26 -import java.util.zip.ZipEntry;
7.27 -import java.util.zip.ZipInputStream;
7.28 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
7.29 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
7.30 -import org.apidesign.bck2brwsr.vmtest.Compare;
7.31 -import org.apidesign.bck2brwsr.vmtest.Http;
7.32 -import org.apidesign.bck2brwsr.vmtest.VMTest;
7.33 -import org.testng.annotations.Factory;
7.34 -
7.35 -/**
7.36 - *
7.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
7.38 - */
7.39 -@GenerateZip(name = "readAnEntry.zip", contents = {
7.40 - "my/main/file.txt", "Hello World!"
7.41 -})
7.42 -public class ZipFileTest {
7.43 -
7.44 - @Compare public String readAnEntry() throws IOException {
7.45 - InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip");
7.46 - ZipInputStream zip = new ZipInputStream(is);
7.47 - ZipEntry entry = zip.getNextEntry();
7.48 - assertEquals(entry.getName(), "my/main/file.txt", "Correct entry");
7.49 -
7.50 - byte[] arr = new byte[4096];
7.51 - int len = zip.read(arr);
7.52 -
7.53 - assertEquals(zip.getNextEntry(), null, "No next entry");
7.54 -
7.55 - final String ret = new String(arr, 0, len, "UTF-8");
7.56 - return ret;
7.57 - }
7.58 -
7.59 - @JavaScriptBody(args = { "res", "path" }, body =
7.60 - "var myvm = bck2brwsr.apply(null, path);\n"
7.61 - + "var cls = myvm.loadClass('java.lang.String');\n"
7.62 - + "return cls.getClass__Ljava_lang_Class_2().getResourceAsStream__Ljava_io_InputStream_2Ljava_lang_String_2(res);\n"
7.63 - )
7.64 - private static native Object loadVMResource(String res, String...path);
7.65 -
7.66 - @Http({
7.67 - @Http.Resource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip")
7.68 - })
7.69 - @BrwsrTest public void canVmLoadResourceFromZip() throws IOException {
7.70 - Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar");
7.71 - assert res instanceof InputStream : "Got array of bytes: " + res;
7.72 - InputStream is = (InputStream)res;
7.73 -
7.74 - byte[] arr = new byte[4096];
7.75 - int len = is.read(arr);
7.76 -
7.77 - final String ret = new String(arr, 0, len, "UTF-8");
7.78 -
7.79 - assertEquals(ret, "Hello World!", "Can read the bytes");
7.80 - }
7.81 -
7.82 - @GenerateZip(name = "cpattr.zip", contents = {
7.83 - "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n"
7.84 - + "Created-By: hand\n"
7.85 - + "Class-Path: realJar.jar\n\n\n"
7.86 - })
7.87 - @Http({
7.88 - @Http.Resource(path = "/readComplexEntry.jar", mimeType = "x-application/zip", content = "", resource="cpattr.zip"),
7.89 - @Http.Resource(path = "/realJar.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip"),
7.90 - })
7.91 - @BrwsrTest public void understandsClassPathAttr() throws IOException {
7.92 - Object res = loadVMResource("/my/main/file.txt", "/readComplexEntry.jar");
7.93 - assert res instanceof InputStream : "Got array of bytes: " + res;
7.94 - InputStream is = (InputStream)res;
7.95 -
7.96 - byte[] arr = new byte[4096];
7.97 - int len = is.read(arr);
7.98 -
7.99 - final String ret = new String(arr, 0, len, "UTF-8");
7.100 -
7.101 - assertEquals(ret, "Hello World!", "Can read the bytes from secondary JAR");
7.102 - }
7.103 -
7.104 - private static void assertEquals(Object real, Object exp, String msg) {
7.105 - assert Objects.equals(exp, real) : msg + " exp: " + exp + " real: " + real;
7.106 - }
7.107 -
7.108 - @Factory public static Object[] create() {
7.109 - return VMTest.create(ZipFileTest.class);
7.110 - }
7.111 -}
8.1 --- a/rt/emul/mini/src/main/java/java/util/zip/Adler32.java Wed May 07 11:55:06 2014 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,205 +0,0 @@
8.4 -/* Adler32.java - Computes Adler32 data checksum of a data stream
8.5 - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
8.6 -
8.7 -This file is part of GNU Classpath.
8.8 -
8.9 -GNU Classpath is free software; you can redistribute it and/or modify
8.10 -it under the terms of the GNU General Public License as published by
8.11 -the Free Software Foundation; either version 2, or (at your option)
8.12 -any later version.
8.13 -
8.14 -GNU Classpath is distributed in the hope that it will be useful, but
8.15 -WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8.17 -General Public License for more details.
8.18 -
8.19 -You should have received a copy of the GNU General Public License
8.20 -along with GNU Classpath; see the file COPYING. If not, write to the
8.21 -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
8.22 -02111-1307 USA.
8.23 -
8.24 -Linking this library statically or dynamically with other modules is
8.25 -making a combined work based on this library. Thus, the terms and
8.26 -conditions of the GNU General Public License cover the whole
8.27 -combination.
8.28 -
8.29 -As a special exception, the copyright holders of this library give you
8.30 -permission to link this library with independent modules to produce an
8.31 -executable, regardless of the license terms of these independent
8.32 -modules, and to copy and distribute the resulting executable under
8.33 -terms of your choice, provided that you also meet, for each linked
8.34 -independent module, the terms and conditions of the license of that
8.35 -module. An independent module is a module which is not derived from
8.36 -or based on this library. If you modify this library, you may extend
8.37 -this exception to your version of the library, but you are not
8.38 -obligated to do so. If you do not wish to do so, delete this
8.39 -exception statement from your version. */
8.40 -
8.41 -package java.util.zip;
8.42 -
8.43 -/*
8.44 - * Written using on-line Java Platform 1.2 API Specification, as well
8.45 - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
8.46 - * The actual Adler32 algorithm is taken from RFC 1950.
8.47 - * Status: Believed complete and correct.
8.48 - */
8.49 -
8.50 -/**
8.51 - * Computes Adler32 checksum for a stream of data. An Adler32
8.52 - * checksum is not as reliable as a CRC32 checksum, but a lot faster to
8.53 - * compute.
8.54 - *<p>
8.55 - * The specification for Adler32 may be found in RFC 1950.
8.56 - * (ZLIB Compressed Data Format Specification version 3.3)
8.57 - *<p>
8.58 - *<p>
8.59 - * From that document:
8.60 - *<p>
8.61 - * "ADLER32 (Adler-32 checksum)
8.62 - * This contains a checksum value of the uncompressed data
8.63 - * (excluding any dictionary data) computed according to Adler-32
8.64 - * algorithm. This algorithm is a 32-bit extension and improvement
8.65 - * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
8.66 - * standard.
8.67 - *<p>
8.68 - * Adler-32 is composed of two sums accumulated per byte: s1 is
8.69 - * the sum of all bytes, s2 is the sum of all s1 values. Both sums
8.70 - * are done modulo 65521. s1 is initialized to 1, s2 to zero. The
8.71 - * Adler-32 checksum is stored as s2*65536 + s1 in most-
8.72 - * significant-byte first (network) order."
8.73 - *<p>
8.74 - * "8.2. The Adler-32 algorithm
8.75 - *<p>
8.76 - * The Adler-32 algorithm is much faster than the CRC32 algorithm yet
8.77 - * still provides an extremely low probability of undetected errors.
8.78 - *<p>
8.79 - * The modulo on unsigned long accumulators can be delayed for 5552
8.80 - * bytes, so the modulo operation time is negligible. If the bytes
8.81 - * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
8.82 - * and order sensitive, unlike the first sum, which is just a
8.83 - * checksum. That 65521 is prime is important to avoid a possible
8.84 - * large class of two-byte errors that leave the check unchanged.
8.85 - * (The Fletcher checksum uses 255, which is not prime and which also
8.86 - * makes the Fletcher check insensitive to single byte changes 0 <->
8.87 - * 255.)
8.88 - *<p>
8.89 - * The sum s1 is initialized to 1 instead of zero to make the length
8.90 - * of the sequence part of s2, so that the length does not have to be
8.91 - * checked separately. (Any sequence of zeroes has a Fletcher
8.92 - * checksum of zero.)"
8.93 - *
8.94 - * @author John Leuner, Per Bothner
8.95 - * @since JDK 1.1
8.96 - *
8.97 - * @see InflaterInputStream
8.98 - * @see DeflaterOutputStream
8.99 - */
8.100 -public class Adler32 implements Checksum
8.101 -{
8.102 -
8.103 - /** largest prime smaller than 65536 */
8.104 - private static final int BASE = 65521;
8.105 -
8.106 - private int checksum; //we do all in int.
8.107 -
8.108 - //Note that java doesn't have unsigned integers,
8.109 - //so we have to be careful with what arithmetic
8.110 - //we do. We return the checksum as a long to
8.111 - //avoid sign confusion.
8.112 -
8.113 - /**
8.114 - * Creates a new instance of the <code>Adler32</code> class.
8.115 - * The checksum starts off with a value of 1.
8.116 - */
8.117 - public Adler32 ()
8.118 - {
8.119 - reset();
8.120 - }
8.121 -
8.122 - /**
8.123 - * Resets the Adler32 checksum to the initial value.
8.124 - */
8.125 - public void reset ()
8.126 - {
8.127 - checksum = 1; //Initialize to 1
8.128 - }
8.129 -
8.130 - /**
8.131 - * Updates the checksum with the byte b.
8.132 - *
8.133 - * @param bval the data value to add. The high byte of the int is ignored.
8.134 - */
8.135 - public void update (int bval)
8.136 - {
8.137 - //We could make a length 1 byte array and call update again, but I
8.138 - //would rather not have that overhead
8.139 - int s1 = checksum & 0xffff;
8.140 - int s2 = checksum >>> 16;
8.141 -
8.142 - s1 = (s1 + (bval & 0xFF)) % BASE;
8.143 - s2 = (s1 + s2) % BASE;
8.144 -
8.145 - checksum = (s2 << 16) + s1;
8.146 - }
8.147 -
8.148 - /**
8.149 - * Updates the checksum with the bytes taken from the array.
8.150 - *
8.151 - * @param buffer an array of bytes
8.152 - */
8.153 - public void update (byte[] buffer)
8.154 - {
8.155 - update(buffer, 0, buffer.length);
8.156 - }
8.157 -
8.158 - /**
8.159 - * Updates the checksum with the bytes taken from the array.
8.160 - *
8.161 - * @param buf an array of bytes
8.162 - * @param off the start of the data used for this update
8.163 - * @param len the number of bytes to use for this update
8.164 - */
8.165 - public void update (byte[] buf, int off, int len)
8.166 - {
8.167 - //(By Per Bothner)
8.168 - int s1 = checksum & 0xffff;
8.169 - int s2 = checksum >>> 16;
8.170 -
8.171 - while (len > 0)
8.172 - {
8.173 - // We can defer the modulo operation:
8.174 - // s1 maximally grows from 65521 to 65521 + 255 * 3800
8.175 - // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
8.176 - int n = 3800;
8.177 - if (n > len)
8.178 - n = len;
8.179 - len -= n;
8.180 - while (--n >= 0)
8.181 - {
8.182 - s1 = s1 + (buf[off++] & 0xFF);
8.183 - s2 = s2 + s1;
8.184 - }
8.185 - s1 %= BASE;
8.186 - s2 %= BASE;
8.187 - }
8.188 -
8.189 - /*Old implementation, borrowed from somewhere:
8.190 - int n;
8.191 -
8.192 - while (len-- > 0) {
8.193 -
8.194 - s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
8.195 - s2 = (s2 + s1) % BASE;
8.196 - }*/
8.197 -
8.198 - checksum = (s2 << 16) | s1;
8.199 - }
8.200 -
8.201 - /**
8.202 - * Returns the Adler32 data checksum computed so far.
8.203 - */
8.204 - public long getValue()
8.205 - {
8.206 - return (long) checksum & 0xffffffffL;
8.207 - }
8.208 -}
9.1 --- a/rt/emul/mini/src/main/java/java/util/zip/CRC32.java Wed May 07 11:55:06 2014 +0200
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,132 +0,0 @@
9.4 -/* CRC32.java - Computes CRC32 data checksum of a data stream
9.5 - Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
9.6 -
9.7 -This file is part of GNU Classpath.
9.8 -
9.9 -GNU Classpath is free software; you can redistribute it and/or modify
9.10 -it under the terms of the GNU General Public License as published by
9.11 -the Free Software Foundation; either version 2, or (at your option)
9.12 -any later version.
9.13 -
9.14 -GNU Classpath is distributed in the hope that it will be useful, but
9.15 -WITHOUT ANY WARRANTY; without even the implied warranty of
9.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9.17 -General Public License for more details.
9.18 -
9.19 -You should have received a copy of the GNU General Public License
9.20 -along with GNU Classpath; see the file COPYING. If not, write to the
9.21 -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
9.22 -02111-1307 USA.
9.23 -
9.24 -Linking this library statically or dynamically with other modules is
9.25 -making a combined work based on this library. Thus, the terms and
9.26 -conditions of the GNU General Public License cover the whole
9.27 -combination.
9.28 -
9.29 -As a special exception, the copyright holders of this library give you
9.30 -permission to link this library with independent modules to produce an
9.31 -executable, regardless of the license terms of these independent
9.32 -modules, and to copy and distribute the resulting executable under
9.33 -terms of your choice, provided that you also meet, for each linked
9.34 -independent module, the terms and conditions of the license of that
9.35 -module. An independent module is a module which is not derived from
9.36 -or based on this library. If you modify this library, you may extend
9.37 -this exception to your version of the library, but you are not
9.38 -obligated to do so. If you do not wish to do so, delete this
9.39 -exception statement from your version. */
9.40 -
9.41 -package java.util.zip;
9.42 -
9.43 -/*
9.44 - * Written using on-line Java Platform 1.2 API Specification, as well
9.45 - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
9.46 - * The actual CRC32 algorithm is taken from RFC 1952.
9.47 - * Status: Believed complete and correct.
9.48 - */
9.49 -
9.50 -/**
9.51 - * Computes CRC32 data checksum of a data stream.
9.52 - * The actual CRC32 algorithm is described in RFC 1952
9.53 - * (GZIP file format specification version 4.3).
9.54 - * Can be used to get the CRC32 over a stream if used with checked input/output
9.55 - * streams.
9.56 - *
9.57 - * @see InflaterInputStream
9.58 - * @see DeflaterOutputStream
9.59 - *
9.60 - * @author Per Bothner
9.61 - * @date April 1, 1999.
9.62 - */
9.63 -public class CRC32 implements Checksum
9.64 -{
9.65 - /** The crc data checksum so far. */
9.66 - private int crc = 0;
9.67 -
9.68 - /** The fast CRC table. Computed once when the CRC32 class is loaded. */
9.69 - private static int[] crc_table = make_crc_table();
9.70 -
9.71 - /** Make the table for a fast CRC. */
9.72 - private static int[] make_crc_table ()
9.73 - {
9.74 - int[] crc_table = new int[256];
9.75 - for (int n = 0; n < 256; n++)
9.76 - {
9.77 - int c = n;
9.78 - for (int k = 8; --k >= 0; )
9.79 - {
9.80 - if ((c & 1) != 0)
9.81 - c = 0xedb88320 ^ (c >>> 1);
9.82 - else
9.83 - c = c >>> 1;
9.84 - }
9.85 - crc_table[n] = c;
9.86 - }
9.87 - return crc_table;
9.88 - }
9.89 -
9.90 - /**
9.91 - * Returns the CRC32 data checksum computed so far.
9.92 - */
9.93 - public long getValue ()
9.94 - {
9.95 - return (long) crc & 0xffffffffL;
9.96 - }
9.97 -
9.98 - /**
9.99 - * Resets the CRC32 data checksum as if no update was ever called.
9.100 - */
9.101 - public void reset () { crc = 0; }
9.102 -
9.103 - /**
9.104 - * Updates the checksum with the int bval.
9.105 - *
9.106 - * @param bval (the byte is taken as the lower 8 bits of bval)
9.107 - */
9.108 -
9.109 - public void update (int bval)
9.110 - {
9.111 - int c = ~crc;
9.112 - c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
9.113 - crc = ~c;
9.114 - }
9.115 -
9.116 - /**
9.117 - * Adds the byte array to the data checksum.
9.118 - *
9.119 - * @param buf the buffer which contains the data
9.120 - * @param off the offset in the buffer where the data starts
9.121 - * @param len the length of the data
9.122 - */
9.123 - public void update (byte[] buf, int off, int len)
9.124 - {
9.125 - int c = ~crc;
9.126 - while (--len >= 0)
9.127 - c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
9.128 - crc = ~c;
9.129 - }
9.130 -
9.131 - /**
9.132 - * Adds the complete byte array to the data checksum.
9.133 - */
9.134 - public void update (byte[] buf) { update(buf, 0, buf.length); }
9.135 -}
10.1 --- a/rt/emul/mini/src/main/java/java/util/zip/Checksum.java Wed May 07 11:55:06 2014 +0200
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,60 +0,0 @@
10.4 -/*
10.5 - * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
10.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 - *
10.8 - * This code is free software; you can redistribute it and/or modify it
10.9 - * under the terms of the GNU General Public License version 2 only, as
10.10 - * published by the Free Software Foundation. Oracle designates this
10.11 - * particular file as subject to the "Classpath" exception as provided
10.12 - * by Oracle in the LICENSE file that accompanied this code.
10.13 - *
10.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 - * version 2 for more details (a copy is included in the LICENSE file that
10.18 - * accompanied this code).
10.19 - *
10.20 - * You should have received a copy of the GNU General Public License version
10.21 - * 2 along with this work; if not, write to the Free Software Foundation,
10.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 - *
10.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10.25 - * or visit www.oracle.com if you need additional information or have any
10.26 - * questions.
10.27 - */
10.28 -
10.29 -package java.util.zip;
10.30 -
10.31 -/**
10.32 - * An interface representing a data checksum.
10.33 - *
10.34 - * @author David Connelly
10.35 - */
10.36 -public
10.37 -interface Checksum {
10.38 - /**
10.39 - * Updates the current checksum with the specified byte.
10.40 - *
10.41 - * @param b the byte to update the checksum with
10.42 - */
10.43 - public void update(int b);
10.44 -
10.45 - /**
10.46 - * Updates the current checksum with the specified array of bytes.
10.47 - * @param b the byte array to update the checksum with
10.48 - * @param off the start offset of the data
10.49 - * @param len the number of bytes to use for the update
10.50 - */
10.51 - public void update(byte[] b, int off, int len);
10.52 -
10.53 - /**
10.54 - * Returns the current checksum value.
10.55 - * @return the current checksum value
10.56 - */
10.57 - public long getValue();
10.58 -
10.59 - /**
10.60 - * Resets the checksum to its initial value.
10.61 - */
10.62 - public void reset();
10.63 -}
11.1 --- a/rt/emul/mini/src/main/java/java/util/zip/DataFormatException.java Wed May 07 11:55:06 2014 +0200
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,52 +0,0 @@
11.4 -/*
11.5 - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
11.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 - *
11.8 - * This code is free software; you can redistribute it and/or modify it
11.9 - * under the terms of the GNU General Public License version 2 only, as
11.10 - * published by the Free Software Foundation. Oracle designates this
11.11 - * particular file as subject to the "Classpath" exception as provided
11.12 - * by Oracle in the LICENSE file that accompanied this code.
11.13 - *
11.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 - * version 2 for more details (a copy is included in the LICENSE file that
11.18 - * accompanied this code).
11.19 - *
11.20 - * You should have received a copy of the GNU General Public License version
11.21 - * 2 along with this work; if not, write to the Free Software Foundation,
11.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 - *
11.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
11.25 - * or visit www.oracle.com if you need additional information or have any
11.26 - * questions.
11.27 - */
11.28 -
11.29 -package java.util.zip;
11.30 -
11.31 -/**
11.32 - * Signals that a data format error has occurred.
11.33 - *
11.34 - * @author David Connelly
11.35 - */
11.36 -public
11.37 -class DataFormatException extends Exception {
11.38 - private static final long serialVersionUID = 2219632870893641452L;
11.39 -
11.40 - /**
11.41 - * Constructs a DataFormatException with no detail message.
11.42 - */
11.43 - public DataFormatException() {
11.44 - super();
11.45 - }
11.46 -
11.47 - /**
11.48 - * Constructs a DataFormatException with the specified detail message.
11.49 - * A detail message is a String that describes this particular exception.
11.50 - * @param s the String containing a detail message
11.51 - */
11.52 - public DataFormatException(String s) {
11.53 - super(s);
11.54 - }
11.55 -}
12.1 --- a/rt/emul/mini/src/main/java/java/util/zip/Inflater.java Wed May 07 11:55:06 2014 +0200
12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
12.3 @@ -1,310 +0,0 @@
12.4 -/*
12.5 - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
12.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12.7 - *
12.8 - * This code is free software; you can redistribute it and/or modify it
12.9 - * under the terms of the GNU General Public License version 2 only, as
12.10 - * published by the Free Software Foundation. Oracle designates this
12.11 - * particular file as subject to the "Classpath" exception as provided
12.12 - * by Oracle in the LICENSE file that accompanied this code.
12.13 - *
12.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
12.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12.17 - * version 2 for more details (a copy is included in the LICENSE file that
12.18 - * accompanied this code).
12.19 - *
12.20 - * You should have received a copy of the GNU General Public License version
12.21 - * 2 along with this work; if not, write to the Free Software Foundation,
12.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12.23 - *
12.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12.25 - * or visit www.oracle.com if you need additional information or have any
12.26 - * questions.
12.27 - */
12.28 -
12.29 -package java.util.zip;
12.30 -
12.31 -/**
12.32 - * This class provides support for general purpose decompression using the
12.33 - * popular ZLIB compression library. The ZLIB compression library was
12.34 - * initially developed as part of the PNG graphics standard and is not
12.35 - * protected by patents. It is fully described in the specifications at
12.36 - * the <a href="package-summary.html#package_description">java.util.zip
12.37 - * package description</a>.
12.38 - *
12.39 - * <p>The following code fragment demonstrates a trivial compression
12.40 - * and decompression of a string using <tt>Deflater</tt> and
12.41 - * <tt>Inflater</tt>.
12.42 - *
12.43 - * <blockquote><pre>
12.44 - * try {
12.45 - * // Encode a String into bytes
12.46 - * String inputString = "blahblahblah\u20AC\u20AC";
12.47 - * byte[] input = inputString.getBytes("UTF-8");
12.48 - *
12.49 - * // Compress the bytes
12.50 - * byte[] output = new byte[100];
12.51 - * Deflater compresser = new Deflater();
12.52 - * compresser.setInput(input);
12.53 - * compresser.finish();
12.54 - * int compressedDataLength = compresser.deflate(output);
12.55 - *
12.56 - * // Decompress the bytes
12.57 - * Inflater decompresser = new Inflater();
12.58 - * decompresser.setInput(output, 0, compressedDataLength);
12.59 - * byte[] result = new byte[100];
12.60 - * int resultLength = decompresser.inflate(result);
12.61 - * decompresser.end();
12.62 - *
12.63 - * // Decode the bytes into a String
12.64 - * String outputString = new String(result, 0, resultLength, "UTF-8");
12.65 - * } catch(java.io.UnsupportedEncodingException ex) {
12.66 - * // handle
12.67 - * } catch (java.util.zip.DataFormatException ex) {
12.68 - * // handle
12.69 - * }
12.70 - * </pre></blockquote>
12.71 - *
12.72 - * @see Deflater
12.73 - * @author David Connelly
12.74 - *
12.75 - */
12.76 -public
12.77 -class Inflater {
12.78 - private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
12.79 -
12.80 - /**
12.81 - * Creates a new decompressor. If the parameter 'nowrap' is true then
12.82 - * the ZLIB header and checksum fields will not be used. This provides
12.83 - * compatibility with the compression format used by both GZIP and PKZIP.
12.84 - * <p>
12.85 - * Note: When using the 'nowrap' option it is also necessary to provide
12.86 - * an extra "dummy" byte as input. This is required by the ZLIB native
12.87 - * library in order to support certain optimizations.
12.88 - *
12.89 - * @param nowrap if true then support GZIP compatible compression
12.90 - */
12.91 - public Inflater(boolean nowrap) {
12.92 - if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
12.93 - impl = null;
12.94 - } else {
12.95 - impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
12.96 - }
12.97 - }
12.98 -
12.99 - /**
12.100 - * Creates a new decompressor.
12.101 - */
12.102 - public Inflater() {
12.103 - this(false);
12.104 - }
12.105 -
12.106 - /**
12.107 - * Sets input data for decompression. Should be called whenever
12.108 - * needsInput() returns true indicating that more input data is
12.109 - * required.
12.110 - * @param b the input data bytes
12.111 - * @param off the start offset of the input data
12.112 - * @param len the length of the input data
12.113 - * @see Inflater#needsInput
12.114 - */
12.115 - public void setInput(byte[] b, int off, int len) {
12.116 - impl.setInput(b, off, len);
12.117 - }
12.118 -
12.119 - /**
12.120 - * Sets input data for decompression. Should be called whenever
12.121 - * needsInput() returns true indicating that more input data is
12.122 - * required.
12.123 - * @param b the input data bytes
12.124 - * @see Inflater#needsInput
12.125 - */
12.126 - public void setInput(byte[] b) {
12.127 - impl.setInput(b);
12.128 - }
12.129 -
12.130 - /**
12.131 - * Sets the preset dictionary to the given array of bytes. Should be
12.132 - * called when inflate() returns 0 and needsDictionary() returns true
12.133 - * indicating that a preset dictionary is required. The method getAdler()
12.134 - * can be used to get the Adler-32 value of the dictionary needed.
12.135 - * @param b the dictionary data bytes
12.136 - * @param off the start offset of the data
12.137 - * @param len the length of the data
12.138 - * @see Inflater#needsDictionary
12.139 - * @see Inflater#getAdler
12.140 - */
12.141 - public void setDictionary(byte[] b, int off, int len) {
12.142 - impl.setDictionary(b, off, len);
12.143 - }
12.144 -
12.145 - /**
12.146 - * Sets the preset dictionary to the given array of bytes. Should be
12.147 - * called when inflate() returns 0 and needsDictionary() returns true
12.148 - * indicating that a preset dictionary is required. The method getAdler()
12.149 - * can be used to get the Adler-32 value of the dictionary needed.
12.150 - * @param b the dictionary data bytes
12.151 - * @see Inflater#needsDictionary
12.152 - * @see Inflater#getAdler
12.153 - */
12.154 - public void setDictionary(byte[] b) {
12.155 - impl.setDictionary(b);
12.156 - }
12.157 -
12.158 - /**
12.159 - * Returns the total number of bytes remaining in the input buffer.
12.160 - * This can be used to find out what bytes still remain in the input
12.161 - * buffer after decompression has finished.
12.162 - * @return the total number of bytes remaining in the input buffer
12.163 - */
12.164 - public int getRemaining() {
12.165 - return impl.getRemaining();
12.166 - }
12.167 -
12.168 - /**
12.169 - * Returns true if no data remains in the input buffer. This can
12.170 - * be used to determine if #setInput should be called in order
12.171 - * to provide more input.
12.172 - * @return true if no data remains in the input buffer
12.173 - */
12.174 - public boolean needsInput() {
12.175 - return impl.needsInput();
12.176 - }
12.177 -
12.178 - /**
12.179 - * Returns true if a preset dictionary is needed for decompression.
12.180 - * @return true if a preset dictionary is needed for decompression
12.181 - * @see Inflater#setDictionary
12.182 - */
12.183 - public boolean needsDictionary() {
12.184 - return impl.needsDictionary();
12.185 - }
12.186 -
12.187 - /**
12.188 - * Returns true if the end of the compressed data stream has been
12.189 - * reached.
12.190 - * @return true if the end of the compressed data stream has been
12.191 - * reached
12.192 - */
12.193 - public boolean finished() {
12.194 - return impl.finished();
12.195 - }
12.196 -
12.197 - /**
12.198 - * Uncompresses bytes into specified buffer. Returns actual number
12.199 - * of bytes uncompressed. A return value of 0 indicates that
12.200 - * needsInput() or needsDictionary() should be called in order to
12.201 - * determine if more input data or a preset dictionary is required.
12.202 - * In the latter case, getAdler() can be used to get the Adler-32
12.203 - * value of the dictionary required.
12.204 - * @param b the buffer for the uncompressed data
12.205 - * @param off the start offset of the data
12.206 - * @param len the maximum number of uncompressed bytes
12.207 - * @return the actual number of uncompressed bytes
12.208 - * @exception DataFormatException if the compressed data format is invalid
12.209 - * @see Inflater#needsInput
12.210 - * @see Inflater#needsDictionary
12.211 - */
12.212 - public int inflate(byte[] b, int off, int len)
12.213 - throws DataFormatException
12.214 - {
12.215 - return impl.inflate(b, off, len);
12.216 - }
12.217 -
12.218 - /**
12.219 - * Uncompresses bytes into specified buffer. Returns actual number
12.220 - * of bytes uncompressed. A return value of 0 indicates that
12.221 - * needsInput() or needsDictionary() should be called in order to
12.222 - * determine if more input data or a preset dictionary is required.
12.223 - * In the latter case, getAdler() can be used to get the Adler-32
12.224 - * value of the dictionary required.
12.225 - * @param b the buffer for the uncompressed data
12.226 - * @return the actual number of uncompressed bytes
12.227 - * @exception DataFormatException if the compressed data format is invalid
12.228 - * @see Inflater#needsInput
12.229 - * @see Inflater#needsDictionary
12.230 - */
12.231 - public int inflate(byte[] b) throws DataFormatException {
12.232 - return impl.inflate(b);
12.233 - }
12.234 -
12.235 - /**
12.236 - * Returns the ADLER-32 value of the uncompressed data.
12.237 - * @return the ADLER-32 value of the uncompressed data
12.238 - */
12.239 - public int getAdler() {
12.240 - return impl.getAdler();
12.241 - }
12.242 -
12.243 - /**
12.244 - * Returns the total number of compressed bytes input so far.
12.245 - *
12.246 - * <p>Since the number of bytes may be greater than
12.247 - * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
12.248 - * the preferred means of obtaining this information.</p>
12.249 - *
12.250 - * @return the total number of compressed bytes input so far
12.251 - */
12.252 - public int getTotalIn() {
12.253 - return impl.getTotalIn();
12.254 - }
12.255 -
12.256 - /**
12.257 - * Returns the total number of compressed bytes input so far.</p>
12.258 - *
12.259 - * @return the total (non-negative) number of compressed bytes input so far
12.260 - * @since 1.5
12.261 - */
12.262 - public long getBytesRead() {
12.263 - return impl.getBytesRead();
12.264 - }
12.265 -
12.266 - /**
12.267 - * Returns the total number of uncompressed bytes output so far.
12.268 - *
12.269 - * <p>Since the number of bytes may be greater than
12.270 - * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
12.271 - * the preferred means of obtaining this information.</p>
12.272 - *
12.273 - * @return the total number of uncompressed bytes output so far
12.274 - */
12.275 - public int getTotalOut() {
12.276 - return impl.getTotalOut();
12.277 - }
12.278 -
12.279 - /**
12.280 - * Returns the total number of uncompressed bytes output so far.</p>
12.281 - *
12.282 - * @return the total (non-negative) number of uncompressed bytes output so far
12.283 - * @since 1.5
12.284 - */
12.285 - public long getBytesWritten() {
12.286 - return impl.getBytesWritten();
12.287 - }
12.288 -
12.289 - /**
12.290 - * Resets inflater so that a new set of input data can be processed.
12.291 - */
12.292 - public void reset() {
12.293 - impl.reset();
12.294 - }
12.295 -
12.296 - /**
12.297 - * Closes the decompressor and discards any unprocessed input.
12.298 - * This method should be called when the decompressor is no longer
12.299 - * being used, but will also be called automatically by the finalize()
12.300 - * method. Once this method is called, the behavior of the Inflater
12.301 - * object is undefined.
12.302 - */
12.303 - public void end() {
12.304 - impl.end();
12.305 - }
12.306 -
12.307 - /**
12.308 - * Closes the decompressor when garbage is collected.
12.309 - */
12.310 - protected void finalize() {
12.311 - end();
12.312 - }
12.313 -}
13.1 --- a/rt/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java Wed May 07 11:55:06 2014 +0200
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,288 +0,0 @@
13.4 -/*
13.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
13.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13.7 - *
13.8 - * This code is free software; you can redistribute it and/or modify it
13.9 - * under the terms of the GNU General Public License version 2 only, as
13.10 - * published by the Free Software Foundation. Oracle designates this
13.11 - * particular file as subject to the "Classpath" exception as provided
13.12 - * by Oracle in the LICENSE file that accompanied this code.
13.13 - *
13.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
13.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.17 - * version 2 for more details (a copy is included in the LICENSE file that
13.18 - * accompanied this code).
13.19 - *
13.20 - * You should have received a copy of the GNU General Public License version
13.21 - * 2 along with this work; if not, write to the Free Software Foundation,
13.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13.23 - *
13.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13.25 - * or visit www.oracle.com if you need additional information or have any
13.26 - * questions.
13.27 - */
13.28 -
13.29 -package java.util.zip;
13.30 -
13.31 -import java.io.FilterInputStream;
13.32 -import java.io.InputStream;
13.33 -import java.io.IOException;
13.34 -import java.io.EOFException;
13.35 -
13.36 -/**
13.37 - * This class implements a stream filter for uncompressing data in the
13.38 - * "deflate" compression format. It is also used as the basis for other
13.39 - * decompression filters, such as GZIPInputStream.
13.40 - *
13.41 - * @see Inflater
13.42 - * @author David Connelly
13.43 - */
13.44 -public
13.45 -class InflaterInputStream extends FilterInputStream {
13.46 - /**
13.47 - * Decompressor for this stream.
13.48 - */
13.49 - protected Inflater inf;
13.50 -
13.51 - /**
13.52 - * Input buffer for decompression.
13.53 - */
13.54 - protected byte[] buf;
13.55 -
13.56 - /**
13.57 - * Length of input buffer.
13.58 - */
13.59 - protected int len;
13.60 -
13.61 - private boolean closed = false;
13.62 - // this flag is set to true after EOF has reached
13.63 - private boolean reachEOF = false;
13.64 -
13.65 - /**
13.66 - * Check to make sure that this stream has not been closed
13.67 - */
13.68 - private void ensureOpen() throws IOException {
13.69 - if (closed) {
13.70 - throw new IOException("Stream closed");
13.71 - }
13.72 - }
13.73 -
13.74 -
13.75 - /**
13.76 - * Creates a new input stream with the specified decompressor and
13.77 - * buffer size.
13.78 - * @param in the input stream
13.79 - * @param inf the decompressor ("inflater")
13.80 - * @param size the input buffer size
13.81 - * @exception IllegalArgumentException if size is <= 0
13.82 - */
13.83 - public InflaterInputStream(InputStream in, Inflater inf, int size) {
13.84 - super(in);
13.85 - if (in == null || inf == null) {
13.86 - throw new NullPointerException();
13.87 - } else if (size <= 0) {
13.88 - throw new IllegalArgumentException("buffer size <= 0");
13.89 - }
13.90 - this.inf = inf;
13.91 - buf = new byte[size];
13.92 - }
13.93 -
13.94 - /**
13.95 - * Creates a new input stream with the specified decompressor and a
13.96 - * default buffer size.
13.97 - * @param in the input stream
13.98 - * @param inf the decompressor ("inflater")
13.99 - */
13.100 - public InflaterInputStream(InputStream in, Inflater inf) {
13.101 - this(in, inf, 512);
13.102 - }
13.103 -
13.104 - boolean usesDefaultInflater = false;
13.105 -
13.106 - /**
13.107 - * Creates a new input stream with a default decompressor and buffer size.
13.108 - * @param in the input stream
13.109 - */
13.110 - public InflaterInputStream(InputStream in) {
13.111 - this(in, new Inflater());
13.112 - usesDefaultInflater = true;
13.113 - }
13.114 -
13.115 - private byte[] singleByteBuf = new byte[1];
13.116 -
13.117 - /**
13.118 - * Reads a byte of uncompressed data. This method will block until
13.119 - * enough input is available for decompression.
13.120 - * @return the byte read, or -1 if end of compressed input is reached
13.121 - * @exception IOException if an I/O error has occurred
13.122 - */
13.123 - public int read() throws IOException {
13.124 - ensureOpen();
13.125 - return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
13.126 - }
13.127 -
13.128 - /**
13.129 - * Reads uncompressed data into an array of bytes. If <code>len</code> is not
13.130 - * zero, the method will block until some input can be decompressed; otherwise,
13.131 - * no bytes are read and <code>0</code> is returned.
13.132 - * @param b the buffer into which the data is read
13.133 - * @param off the start offset in the destination array <code>b</code>
13.134 - * @param len the maximum number of bytes read
13.135 - * @return the actual number of bytes read, or -1 if the end of the
13.136 - * compressed input is reached or a preset dictionary is needed
13.137 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
13.138 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
13.139 - * <code>len</code> is negative, or <code>len</code> is greater than
13.140 - * <code>b.length - off</code>
13.141 - * @exception ZipException if a ZIP format error has occurred
13.142 - * @exception IOException if an I/O error has occurred
13.143 - */
13.144 - public int read(byte[] b, int off, int len) throws IOException {
13.145 - ensureOpen();
13.146 - if (b == null) {
13.147 - throw new NullPointerException();
13.148 - } else if (off < 0 || len < 0 || len > b.length - off) {
13.149 - throw new IndexOutOfBoundsException();
13.150 - } else if (len == 0) {
13.151 - return 0;
13.152 - }
13.153 - try {
13.154 - int n;
13.155 - while ((n = inf.inflate(b, off, len)) == 0) {
13.156 - if (inf.finished() || inf.needsDictionary()) {
13.157 - reachEOF = true;
13.158 - return -1;
13.159 - }
13.160 - if (inf.needsInput()) {
13.161 - fill();
13.162 - }
13.163 - }
13.164 - return n;
13.165 - } catch (DataFormatException e) {
13.166 - String s = e.getMessage();
13.167 - throw new ZipException(s != null ? s : "Invalid ZLIB data format");
13.168 - }
13.169 - }
13.170 -
13.171 - /**
13.172 - * Returns 0 after EOF has been reached, otherwise always return 1.
13.173 - * <p>
13.174 - * Programs should not count on this method to return the actual number
13.175 - * of bytes that could be read without blocking.
13.176 - *
13.177 - * @return 1 before EOF and 0 after EOF.
13.178 - * @exception IOException if an I/O error occurs.
13.179 - *
13.180 - */
13.181 - public int available() throws IOException {
13.182 - ensureOpen();
13.183 - if (reachEOF) {
13.184 - return 0;
13.185 - } else {
13.186 - return 1;
13.187 - }
13.188 - }
13.189 -
13.190 - private byte[] b = new byte[512];
13.191 -
13.192 - /**
13.193 - * Skips specified number of bytes of uncompressed data.
13.194 - * @param n the number of bytes to skip
13.195 - * @return the actual number of bytes skipped.
13.196 - * @exception IOException if an I/O error has occurred
13.197 - * @exception IllegalArgumentException if n < 0
13.198 - */
13.199 - public long skip(long n) throws IOException {
13.200 - if (n < 0) {
13.201 - throw new IllegalArgumentException("negative skip length");
13.202 - }
13.203 - ensureOpen();
13.204 - int max = (int)Math.min(n, Integer.MAX_VALUE);
13.205 - int total = 0;
13.206 - while (total < max) {
13.207 - int len = max - total;
13.208 - if (len > b.length) {
13.209 - len = b.length;
13.210 - }
13.211 - len = read(b, 0, len);
13.212 - if (len == -1) {
13.213 - reachEOF = true;
13.214 - break;
13.215 - }
13.216 - total += len;
13.217 - }
13.218 - return total;
13.219 - }
13.220 -
13.221 - /**
13.222 - * Closes this input stream and releases any system resources associated
13.223 - * with the stream.
13.224 - * @exception IOException if an I/O error has occurred
13.225 - */
13.226 - public void close() throws IOException {
13.227 - if (!closed) {
13.228 - if (usesDefaultInflater)
13.229 - inf.end();
13.230 - in.close();
13.231 - closed = true;
13.232 - }
13.233 - }
13.234 -
13.235 - /**
13.236 - * Fills input buffer with more data to decompress.
13.237 - * @exception IOException if an I/O error has occurred
13.238 - */
13.239 - protected void fill() throws IOException {
13.240 - ensureOpen();
13.241 - len = in.read(buf, 0, buf.length);
13.242 - if (len == -1) {
13.243 - throw new EOFException("Unexpected end of ZLIB input stream");
13.244 - }
13.245 - inf.setInput(buf, 0, len);
13.246 - }
13.247 -
13.248 - /**
13.249 - * Tests if this input stream supports the <code>mark</code> and
13.250 - * <code>reset</code> methods. The <code>markSupported</code>
13.251 - * method of <code>InflaterInputStream</code> returns
13.252 - * <code>false</code>.
13.253 - *
13.254 - * @return a <code>boolean</code> indicating if this stream type supports
13.255 - * the <code>mark</code> and <code>reset</code> methods.
13.256 - * @see java.io.InputStream#mark(int)
13.257 - * @see java.io.InputStream#reset()
13.258 - */
13.259 - public boolean markSupported() {
13.260 - return false;
13.261 - }
13.262 -
13.263 - /**
13.264 - * Marks the current position in this input stream.
13.265 - *
13.266 - * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
13.267 - * does nothing.
13.268 - *
13.269 - * @param readlimit the maximum limit of bytes that can be read before
13.270 - * the mark position becomes invalid.
13.271 - * @see java.io.InputStream#reset()
13.272 - */
13.273 - public synchronized void mark(int readlimit) {
13.274 - }
13.275 -
13.276 - /**
13.277 - * Repositions this stream to the position at the time the
13.278 - * <code>mark</code> method was last called on this input stream.
13.279 - *
13.280 - * <p> The method <code>reset</code> for class
13.281 - * <code>InflaterInputStream</code> does nothing except throw an
13.282 - * <code>IOException</code>.
13.283 - *
13.284 - * @exception IOException if this method is invoked.
13.285 - * @see java.io.InputStream#mark(int)
13.286 - * @see java.io.IOException
13.287 - */
13.288 - public synchronized void reset() throws IOException {
13.289 - throw new IOException("mark/reset not supported");
13.290 - }
13.291 -}
14.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZStreamRef.java Wed May 07 11:55:06 2014 +0200
14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
14.3 @@ -1,46 +0,0 @@
14.4 -/*
14.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
14.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14.7 - *
14.8 - * This code is free software; you can redistribute it and/or modify it
14.9 - * under the terms of the GNU General Public License version 2 only, as
14.10 - * published by the Free Software Foundation. Oracle designates this
14.11 - * particular file as subject to the "Classpath" exception as provided
14.12 - * by Oracle in the LICENSE file that accompanied this code.
14.13 - *
14.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
14.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14.17 - * version 2 for more details (a copy is included in the LICENSE file that
14.18 - * accompanied this code).
14.19 - *
14.20 - * You should have received a copy of the GNU General Public License version
14.21 - * 2 along with this work; if not, write to the Free Software Foundation,
14.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14.23 - *
14.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14.25 - * or visit www.oracle.com if you need additional information or have any
14.26 - * questions.
14.27 - */
14.28 -
14.29 -package java.util.zip;
14.30 -
14.31 -/**
14.32 - * A reference to the native zlib's z_stream structure.
14.33 - */
14.34 -
14.35 -class ZStreamRef {
14.36 -
14.37 - private long address;
14.38 - ZStreamRef (long address) {
14.39 - this.address = address;
14.40 - }
14.41 -
14.42 - long address() {
14.43 - return address;
14.44 - }
14.45 -
14.46 - void clear() {
14.47 - address = 0;
14.48 - }
14.49 -}
15.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipConstants.java Wed May 07 11:55:06 2014 +0200
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,98 +0,0 @@
15.4 -/*
15.5 - * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
15.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15.7 - *
15.8 - * This code is free software; you can redistribute it and/or modify it
15.9 - * under the terms of the GNU General Public License version 2 only, as
15.10 - * published by the Free Software Foundation. Oracle designates this
15.11 - * particular file as subject to the "Classpath" exception as provided
15.12 - * by Oracle in the LICENSE file that accompanied this code.
15.13 - *
15.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
15.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15.17 - * version 2 for more details (a copy is included in the LICENSE file that
15.18 - * accompanied this code).
15.19 - *
15.20 - * You should have received a copy of the GNU General Public License version
15.21 - * 2 along with this work; if not, write to the Free Software Foundation,
15.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15.23 - *
15.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15.25 - * or visit www.oracle.com if you need additional information or have any
15.26 - * questions.
15.27 - */
15.28 -
15.29 -package java.util.zip;
15.30 -
15.31 -/*
15.32 - * This interface defines the constants that are used by the classes
15.33 - * which manipulate ZIP files.
15.34 - *
15.35 - * @author David Connelly
15.36 - */
15.37 -interface ZipConstants {
15.38 - /*
15.39 - * Header signatures
15.40 - */
15.41 - static long LOCSIG = 0x04034b50L; // "PK\003\004"
15.42 - static long EXTSIG = 0x08074b50L; // "PK\007\008"
15.43 - static long CENSIG = 0x02014b50L; // "PK\001\002"
15.44 - static long ENDSIG = 0x06054b50L; // "PK\005\006"
15.45 -
15.46 - /*
15.47 - * Header sizes in bytes (including signatures)
15.48 - */
15.49 - static final int LOCHDR = 30; // LOC header size
15.50 - static final int EXTHDR = 16; // EXT header size
15.51 - static final int CENHDR = 46; // CEN header size
15.52 - static final int ENDHDR = 22; // END header size
15.53 -
15.54 - /*
15.55 - * Local file (LOC) header field offsets
15.56 - */
15.57 - static final int LOCVER = 4; // version needed to extract
15.58 - static final int LOCFLG = 6; // general purpose bit flag
15.59 - static final int LOCHOW = 8; // compression method
15.60 - static final int LOCTIM = 10; // modification time
15.61 - static final int LOCCRC = 14; // uncompressed file crc-32 value
15.62 - static final int LOCSIZ = 18; // compressed size
15.63 - static final int LOCLEN = 22; // uncompressed size
15.64 - static final int LOCNAM = 26; // filename length
15.65 - static final int LOCEXT = 28; // extra field length
15.66 -
15.67 - /*
15.68 - * Extra local (EXT) header field offsets
15.69 - */
15.70 - static final int EXTCRC = 4; // uncompressed file crc-32 value
15.71 - static final int EXTSIZ = 8; // compressed size
15.72 - static final int EXTLEN = 12; // uncompressed size
15.73 -
15.74 - /*
15.75 - * Central directory (CEN) header field offsets
15.76 - */
15.77 - static final int CENVEM = 4; // version made by
15.78 - static final int CENVER = 6; // version needed to extract
15.79 - static final int CENFLG = 8; // encrypt, decrypt flags
15.80 - static final int CENHOW = 10; // compression method
15.81 - static final int CENTIM = 12; // modification time
15.82 - static final int CENCRC = 16; // uncompressed file crc-32 value
15.83 - static final int CENSIZ = 20; // compressed size
15.84 - static final int CENLEN = 24; // uncompressed size
15.85 - static final int CENNAM = 28; // filename length
15.86 - static final int CENEXT = 30; // extra field length
15.87 - static final int CENCOM = 32; // comment length
15.88 - static final int CENDSK = 34; // disk number start
15.89 - static final int CENATT = 36; // internal file attributes
15.90 - static final int CENATX = 38; // external file attributes
15.91 - static final int CENOFF = 42; // LOC header offset
15.92 -
15.93 - /*
15.94 - * End of central directory (END) header field offsets
15.95 - */
15.96 - static final int ENDSUB = 8; // number of entries on this disk
15.97 - static final int ENDTOT = 10; // total number of entries
15.98 - static final int ENDSIZ = 12; // central directory size in bytes
15.99 - static final int ENDOFF = 16; // offset of first CEN header
15.100 - static final int ENDCOM = 20; // zip file comment length
15.101 -}
16.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipEntry.java Wed May 07 11:55:06 2014 +0200
16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
16.3 @@ -1,331 +0,0 @@
16.4 -/*
16.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
16.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16.7 - *
16.8 - * This code is free software; you can redistribute it and/or modify it
16.9 - * under the terms of the GNU General Public License version 2 only, as
16.10 - * published by the Free Software Foundation. Oracle designates this
16.11 - * particular file as subject to the "Classpath" exception as provided
16.12 - * by Oracle in the LICENSE file that accompanied this code.
16.13 - *
16.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
16.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16.17 - * version 2 for more details (a copy is included in the LICENSE file that
16.18 - * accompanied this code).
16.19 - *
16.20 - * You should have received a copy of the GNU General Public License version
16.21 - * 2 along with this work; if not, write to the Free Software Foundation,
16.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16.23 - *
16.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16.25 - * or visit www.oracle.com if you need additional information or have any
16.26 - * questions.
16.27 - */
16.28 -
16.29 -package java.util.zip;
16.30 -
16.31 -/**
16.32 - * This class is used to represent a ZIP file entry.
16.33 - *
16.34 - * @author David Connelly
16.35 - */
16.36 -public
16.37 -class ZipEntry implements ZipConstants, Cloneable {
16.38 - String name; // entry name
16.39 - long time = -1; // modification time (in DOS time)
16.40 - long crc = -1; // crc-32 of entry data
16.41 - long size = -1; // uncompressed size of entry data
16.42 - long csize = -1; // compressed size of entry data
16.43 - int method = -1; // compression method
16.44 - int flag = 0; // general purpose flag
16.45 - byte[] extra; // optional extra field data for entry
16.46 - String comment; // optional comment string for entry
16.47 -
16.48 - /**
16.49 - * Compression method for uncompressed entries.
16.50 - */
16.51 - public static final int STORED = 0;
16.52 -
16.53 - /**
16.54 - * Compression method for compressed (deflated) entries.
16.55 - */
16.56 - public static final int DEFLATED = 8;
16.57 -
16.58 - /**
16.59 - * Creates a new zip entry with the specified name.
16.60 - *
16.61 - * @param name the entry name
16.62 - * @exception NullPointerException if the entry name is null
16.63 - * @exception IllegalArgumentException if the entry name is longer than
16.64 - * 0xFFFF bytes
16.65 - */
16.66 - public ZipEntry(String name) {
16.67 - if (name == null) {
16.68 - throw new NullPointerException();
16.69 - }
16.70 - if (name.length() > 0xFFFF) {
16.71 - throw new IllegalArgumentException("entry name too long");
16.72 - }
16.73 - this.name = name;
16.74 - }
16.75 -
16.76 - /**
16.77 - * Creates a new zip entry with fields taken from the specified
16.78 - * zip entry.
16.79 - * @param e a zip Entry object
16.80 - */
16.81 - public ZipEntry(ZipEntry e) {
16.82 - name = e.name;
16.83 - time = e.time;
16.84 - crc = e.crc;
16.85 - size = e.size;
16.86 - csize = e.csize;
16.87 - method = e.method;
16.88 - flag = e.flag;
16.89 - extra = e.extra;
16.90 - comment = e.comment;
16.91 - }
16.92 -
16.93 - /*
16.94 - * Creates a new un-initialized zip entry
16.95 - */
16.96 - ZipEntry() {}
16.97 -
16.98 - /**
16.99 - * Returns the name of the entry.
16.100 - * @return the name of the entry
16.101 - */
16.102 - public String getName() {
16.103 - return name;
16.104 - }
16.105 -
16.106 - /**
16.107 - * Sets the modification time of the entry.
16.108 - * @param time the entry modification time in number of milliseconds
16.109 - * since the epoch
16.110 - * @see #getTime()
16.111 - */
16.112 - public void setTime(long time) {
16.113 - this.time = javaToDosTime(time);
16.114 - }
16.115 -
16.116 - /**
16.117 - * Returns the modification time of the entry, or -1 if not specified.
16.118 - * @return the modification time of the entry, or -1 if not specified
16.119 - * @see #setTime(long)
16.120 - */
16.121 - public long getTime() {
16.122 - return time != -1 ? dosToJavaTime(time) : -1;
16.123 - }
16.124 -
16.125 - /**
16.126 - * Sets the uncompressed size of the entry data.
16.127 - * @param size the uncompressed size in bytes
16.128 - * @exception IllegalArgumentException if the specified size is less
16.129 - * than 0, is greater than 0xFFFFFFFF when
16.130 - * <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
16.131 - * or is less than 0 when ZIP64 is supported
16.132 - * @see #getSize()
16.133 - */
16.134 - public void setSize(long size) {
16.135 - if (size < 0) {
16.136 - throw new IllegalArgumentException("invalid entry size");
16.137 - }
16.138 - this.size = size;
16.139 - }
16.140 -
16.141 - /**
16.142 - * Returns the uncompressed size of the entry data, or -1 if not known.
16.143 - * @return the uncompressed size of the entry data, or -1 if not known
16.144 - * @see #setSize(long)
16.145 - */
16.146 - public long getSize() {
16.147 - return size;
16.148 - }
16.149 -
16.150 - /**
16.151 - * Returns the size of the compressed entry data, or -1 if not known.
16.152 - * In the case of a stored entry, the compressed size will be the same
16.153 - * as the uncompressed size of the entry.
16.154 - * @return the size of the compressed entry data, or -1 if not known
16.155 - * @see #setCompressedSize(long)
16.156 - */
16.157 - public long getCompressedSize() {
16.158 - return csize;
16.159 - }
16.160 -
16.161 - /**
16.162 - * Sets the size of the compressed entry data.
16.163 - * @param csize the compressed size to set to
16.164 - * @see #getCompressedSize()
16.165 - */
16.166 - public void setCompressedSize(long csize) {
16.167 - this.csize = csize;
16.168 - }
16.169 -
16.170 - /**
16.171 - * Sets the CRC-32 checksum of the uncompressed entry data.
16.172 - * @param crc the CRC-32 value
16.173 - * @exception IllegalArgumentException if the specified CRC-32 value is
16.174 - * less than 0 or greater than 0xFFFFFFFF
16.175 - * @see #getCrc()
16.176 - */
16.177 - public void setCrc(long crc) {
16.178 - if (crc < 0 || crc > 0xFFFFFFFFL) {
16.179 - throw new IllegalArgumentException("invalid entry crc-32");
16.180 - }
16.181 - this.crc = crc;
16.182 - }
16.183 -
16.184 - /**
16.185 - * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
16.186 - * not known.
16.187 - * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
16.188 - * not known
16.189 - * @see #setCrc(long)
16.190 - */
16.191 - public long getCrc() {
16.192 - return crc;
16.193 - }
16.194 -
16.195 - /**
16.196 - * Sets the compression method for the entry.
16.197 - * @param method the compression method, either STORED or DEFLATED
16.198 - * @exception IllegalArgumentException if the specified compression
16.199 - * method is invalid
16.200 - * @see #getMethod()
16.201 - */
16.202 - public void setMethod(int method) {
16.203 - if (method != STORED && method != DEFLATED) {
16.204 - throw new IllegalArgumentException("invalid compression method");
16.205 - }
16.206 - this.method = method;
16.207 - }
16.208 -
16.209 - /**
16.210 - * Returns the compression method of the entry, or -1 if not specified.
16.211 - * @return the compression method of the entry, or -1 if not specified
16.212 - * @see #setMethod(int)
16.213 - */
16.214 - public int getMethod() {
16.215 - return method;
16.216 - }
16.217 -
16.218 - /**
16.219 - * Sets the optional extra field data for the entry.
16.220 - * @param extra the extra field data bytes
16.221 - * @exception IllegalArgumentException if the length of the specified
16.222 - * extra field data is greater than 0xFFFF bytes
16.223 - * @see #getExtra()
16.224 - */
16.225 - public void setExtra(byte[] extra) {
16.226 - if (extra != null && extra.length > 0xFFFF) {
16.227 - throw new IllegalArgumentException("invalid extra field length");
16.228 - }
16.229 - this.extra = extra;
16.230 - }
16.231 -
16.232 - /**
16.233 - * Returns the extra field data for the entry, or null if none.
16.234 - * @return the extra field data for the entry, or null if none
16.235 - * @see #setExtra(byte[])
16.236 - */
16.237 - public byte[] getExtra() {
16.238 - return extra;
16.239 - }
16.240 -
16.241 - /**
16.242 - * Sets the optional comment string for the entry.
16.243 - *
16.244 - * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
16.245 - * specified comment string is greater than 0xFFFF bytes after encoding, only
16.246 - * the first 0xFFFF bytes are output to the ZIP file entry.
16.247 - *
16.248 - * @param comment the comment string
16.249 - *
16.250 - * @see #getComment()
16.251 - */
16.252 - public void setComment(String comment) {
16.253 - this.comment = comment;
16.254 - }
16.255 -
16.256 - /**
16.257 - * Returns the comment string for the entry, or null if none.
16.258 - * @return the comment string for the entry, or null if none
16.259 - * @see #setComment(String)
16.260 - */
16.261 - public String getComment() {
16.262 - return comment;
16.263 - }
16.264 -
16.265 - /**
16.266 - * Returns true if this is a directory entry. A directory entry is
16.267 - * defined to be one whose name ends with a '/'.
16.268 - * @return true if this is a directory entry
16.269 - */
16.270 - public boolean isDirectory() {
16.271 - return name.endsWith("/");
16.272 - }
16.273 -
16.274 - /**
16.275 - * Returns a string representation of the ZIP entry.
16.276 - */
16.277 - public String toString() {
16.278 - return getName();
16.279 - }
16.280 -
16.281 - /*
16.282 - * Converts DOS time to Java time (number of milliseconds since epoch).
16.283 - */
16.284 - private static long dosToJavaTime(long dtime) {
16.285 - return dtime;
16.286 - /* XXX:
16.287 - Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
16.288 - (int)(((dtime >> 21) & 0x0f) - 1),
16.289 - (int)((dtime >> 16) & 0x1f),
16.290 - (int)((dtime >> 11) & 0x1f),
16.291 - (int)((dtime >> 5) & 0x3f),
16.292 - (int)((dtime << 1) & 0x3e));
16.293 - return d.getTime();
16.294 - */
16.295 - }
16.296 -
16.297 - /*
16.298 - * Converts Java time to DOS time.
16.299 - */
16.300 - private static long javaToDosTime(long time) {
16.301 - return time;
16.302 - /* XXX:
16.303 - Date d = new Date(time);
16.304 - int year = d.getYear() + 1900;
16.305 - if (year < 1980) {
16.306 - return (1 << 21) | (1 << 16);
16.307 - }
16.308 - return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
16.309 - d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
16.310 - d.getSeconds() >> 1;
16.311 - */
16.312 - }
16.313 -
16.314 - /**
16.315 - * Returns the hash code value for this entry.
16.316 - */
16.317 - public int hashCode() {
16.318 - return name.hashCode();
16.319 - }
16.320 -
16.321 - /**
16.322 - * Returns a copy of this entry.
16.323 - */
16.324 - public Object clone() {
16.325 - try {
16.326 - ZipEntry e = (ZipEntry)super.clone();
16.327 - e.extra = (extra == null) ? null : extra.clone();
16.328 - return e;
16.329 - } catch (CloneNotSupportedException e) {
16.330 - // This should never happen, since we are Cloneable
16.331 - throw new IllegalStateException();
16.332 - }
16.333 - }
16.334 -}
17.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipException.java Wed May 07 11:55:06 2014 +0200
17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
17.3 @@ -1,60 +0,0 @@
17.4 -/*
17.5 - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
17.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17.7 - *
17.8 - * This code is free software; you can redistribute it and/or modify it
17.9 - * under the terms of the GNU General Public License version 2 only, as
17.10 - * published by the Free Software Foundation. Oracle designates this
17.11 - * particular file as subject to the "Classpath" exception as provided
17.12 - * by Oracle in the LICENSE file that accompanied this code.
17.13 - *
17.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
17.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17.17 - * version 2 for more details (a copy is included in the LICENSE file that
17.18 - * accompanied this code).
17.19 - *
17.20 - * You should have received a copy of the GNU General Public License version
17.21 - * 2 along with this work; if not, write to the Free Software Foundation,
17.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17.23 - *
17.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17.25 - * or visit www.oracle.com if you need additional information or have any
17.26 - * questions.
17.27 - */
17.28 -
17.29 -package java.util.zip;
17.30 -
17.31 -import java.io.IOException;
17.32 -
17.33 -/**
17.34 - * Signals that a Zip exception of some sort has occurred.
17.35 - *
17.36 - * @author unascribed
17.37 - * @see java.io.IOException
17.38 - * @since JDK1.0
17.39 - */
17.40 -
17.41 -public
17.42 -class ZipException extends IOException {
17.43 - private static final long serialVersionUID = 8000196834066748623L;
17.44 -
17.45 - /**
17.46 - * Constructs a <code>ZipException</code> with <code>null</code>
17.47 - * as its error detail message.
17.48 - */
17.49 - public ZipException() {
17.50 - super();
17.51 - }
17.52 -
17.53 - /**
17.54 - * Constructs a <code>ZipException</code> with the specified detail
17.55 - * message.
17.56 - *
17.57 - * @param s the detail message.
17.58 - */
17.59 -
17.60 - public ZipException(String s) {
17.61 - super(s);
17.62 - }
17.63 -}
18.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipInputStream.java Wed May 07 11:55:06 2014 +0200
18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
18.3 @@ -1,194 +0,0 @@
18.4 -/*
18.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
18.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
18.7 - *
18.8 - * This code is free software; you can redistribute it and/or modify it
18.9 - * under the terms of the GNU General Public License version 2 only, as
18.10 - * published by the Free Software Foundation. Oracle designates this
18.11 - * particular file as subject to the "Classpath" exception as provided
18.12 - * by Oracle in the LICENSE file that accompanied this code.
18.13 - *
18.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
18.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18.17 - * version 2 for more details (a copy is included in the LICENSE file that
18.18 - * accompanied this code).
18.19 - *
18.20 - * You should have received a copy of the GNU General Public License version
18.21 - * 2 along with this work; if not, write to the Free Software Foundation,
18.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18.23 - *
18.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
18.25 - * or visit www.oracle.com if you need additional information or have any
18.26 - * questions.
18.27 - */
18.28 -
18.29 -package java.util.zip;
18.30 -
18.31 -import java.io.InputStream;
18.32 -import java.io.IOException;
18.33 -
18.34 -/**
18.35 - * This class implements an input stream filter for reading files in the
18.36 - * ZIP file format. Includes support for both compressed and uncompressed
18.37 - * entries.
18.38 - *
18.39 - * @author David Connelly
18.40 - */
18.41 -public
18.42 -class ZipInputStream extends InflaterInputStream implements ZipConstants {
18.43 - private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
18.44 -
18.45 - /**
18.46 - * Creates a new ZIP input stream.
18.47 - *
18.48 - * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
18.49 - * decode the entry names.
18.50 - *
18.51 - * @param in the actual input stream
18.52 - */
18.53 - public ZipInputStream(InputStream in) {
18.54 - super(in);
18.55 - impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
18.56 - }
18.57 -
18.58 - /**
18.59 - * Creates a new ZIP input stream.
18.60 - *
18.61 - * @param in the actual input stream
18.62 - *
18.63 - * @param charset
18.64 - * The {@linkplain java.nio.charset.Charset charset} to be
18.65 - * used to decode the ZIP entry name (ignored if the
18.66 - * <a href="package-summary.html#lang_encoding"> language
18.67 - * encoding bit</a> of the ZIP entry's general purpose bit
18.68 - * flag is set).
18.69 - *
18.70 - * @since 1.7
18.71 - *
18.72 - public ZipInputStream(InputStream in, Charset charset) {
18.73 - super(new PushbackInputStream(in, 512), new Inflater(true), 512);
18.74 - usesDefaultInflater = true;
18.75 - if(in == null) {
18.76 - throw new NullPointerException("in is null");
18.77 - }
18.78 - if (charset == null)
18.79 - throw new NullPointerException("charset is null");
18.80 - this.zc = ZipCoder.get(charset);
18.81 - }
18.82 - */
18.83 -
18.84 - /**
18.85 - * Reads the next ZIP file entry and positions the stream at the
18.86 - * beginning of the entry data.
18.87 - * @return the next ZIP file entry, or null if there are no more entries
18.88 - * @exception ZipException if a ZIP file error has occurred
18.89 - * @exception IOException if an I/O error has occurred
18.90 - */
18.91 - public ZipEntry getNextEntry() throws IOException {
18.92 - return impl.getNextEntry();
18.93 - }
18.94 -
18.95 - /**
18.96 - * Closes the current ZIP entry and positions the stream for reading the
18.97 - * next entry.
18.98 - * @exception ZipException if a ZIP file error has occurred
18.99 - * @exception IOException if an I/O error has occurred
18.100 - */
18.101 - public void closeEntry() throws IOException {
18.102 - impl.closeEntry();
18.103 - }
18.104 -
18.105 - /**
18.106 - * Returns 0 after EOF has reached for the current entry data,
18.107 - * otherwise always return 1.
18.108 - * <p>
18.109 - * Programs should not count on this method to return the actual number
18.110 - * of bytes that could be read without blocking.
18.111 - *
18.112 - * @return 1 before EOF and 0 after EOF has reached for current entry.
18.113 - * @exception IOException if an I/O error occurs.
18.114 - *
18.115 - */
18.116 - public int available() throws IOException {
18.117 - return impl.available();
18.118 - }
18.119 -
18.120 - /**
18.121 - * Reads from the current ZIP entry into an array of bytes.
18.122 - * If <code>len</code> is not zero, the method
18.123 - * blocks until some input is available; otherwise, no
18.124 - * bytes are read and <code>0</code> is returned.
18.125 - * @param b the buffer into which the data is read
18.126 - * @param off the start offset in the destination array <code>b</code>
18.127 - * @param len the maximum number of bytes read
18.128 - * @return the actual number of bytes read, or -1 if the end of the
18.129 - * entry is reached
18.130 - * @exception NullPointerException if <code>b</code> is <code>null</code>.
18.131 - * @exception IndexOutOfBoundsException if <code>off</code> is negative,
18.132 - * <code>len</code> is negative, or <code>len</code> is greater than
18.133 - * <code>b.length - off</code>
18.134 - * @exception ZipException if a ZIP file error has occurred
18.135 - * @exception IOException if an I/O error has occurred
18.136 - */
18.137 - public int read(byte[] b, int off, int len) throws IOException {
18.138 - return impl.read(b, off, len);
18.139 - }
18.140 -
18.141 - /**
18.142 - * Skips specified number of bytes in the current ZIP entry.
18.143 - * @param n the number of bytes to skip
18.144 - * @return the actual number of bytes skipped
18.145 - * @exception ZipException if a ZIP file error has occurred
18.146 - * @exception IOException if an I/O error has occurred
18.147 - * @exception IllegalArgumentException if n < 0
18.148 - */
18.149 - public long skip(long n) throws IOException {
18.150 - return impl.skip(n);
18.151 - }
18.152 -
18.153 - /**
18.154 - * Closes this input stream and releases any system resources associated
18.155 - * with the stream.
18.156 - * @exception IOException if an I/O error has occurred
18.157 - */
18.158 - public void close() throws IOException {
18.159 - impl.close();
18.160 - }
18.161 -
18.162 - /**
18.163 - * Creates a new <code>ZipEntry</code> object for the specified
18.164 - * entry name.
18.165 - *
18.166 - * @param name the ZIP file entry name
18.167 - * @return the ZipEntry just created
18.168 - */
18.169 - protected ZipEntry createZipEntry(String name) {
18.170 - return new ZipEntry(name);
18.171 - }
18.172 -
18.173 - @Override
18.174 - public int read() throws IOException {
18.175 - return impl.read();
18.176 - }
18.177 -
18.178 - @Override
18.179 - public boolean markSupported() {
18.180 - return impl.markSupported();
18.181 - }
18.182 -
18.183 - @Override
18.184 - public void mark(int readlimit) {
18.185 - impl.mark(readlimit);
18.186 - }
18.187 -
18.188 - @Override
18.189 - public void reset() throws IOException {
18.190 - impl.reset();
18.191 - }
18.192 -
18.193 - @Override
18.194 - public int read(byte[] b) throws IOException {
18.195 - return impl.read(b);
18.196 - }
18.197 -}
19.1 --- a/rt/emul/mini/src/main/java/java/util/zip/package-info.java Wed May 07 11:55:06 2014 +0200
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,21 +0,0 @@
19.4 -/**
19.5 - * Back 2 Browser Bytecode Translator
19.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
19.7 - *
19.8 - * This program is free software: you can redistribute it and/or modify
19.9 - * it under the terms of the GNU General Public License as published by
19.10 - * the Free Software Foundation, version 2 of the License.
19.11 - *
19.12 - * This program is distributed in the hope that it will be useful,
19.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
19.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19.15 - * GNU General Public License for more details.
19.16 - *
19.17 - * You should have received a copy of the GNU General Public License
19.18 - * along with this program. Look for COPYING file in the top folder.
19.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
19.20 - */
19.21 -@Exported
19.22 -package java.util.zip;
19.23 -
19.24 -import org.apidesign.bck2brwsr.core.Exported;
20.1 --- a/rt/emul/mini/src/main/java/java/util/zip/package.html Wed May 07 11:55:06 2014 +0200
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,98 +0,0 @@
20.4 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
20.5 -<html>
20.6 -<head>
20.7 -<!--
20.8 -Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
20.9 -DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.10 -
20.11 -This code is free software; you can redistribute it and/or modify it
20.12 -under the terms of the GNU General Public License version 2 only, as
20.13 -published by the Free Software Foundation. Oracle designates this
20.14 -particular file as subject to the "Classpath" exception as provided
20.15 -by Oracle in the LICENSE file that accompanied this code.
20.16 -
20.17 -This code is distributed in the hope that it will be useful, but WITHOUT
20.18 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.19 -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.20 -version 2 for more details (a copy is included in the LICENSE file that
20.21 -accompanied this code).
20.22 -
20.23 -You should have received a copy of the GNU General Public License version
20.24 -2 along with this work; if not, write to the Free Software Foundation,
20.25 -Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.26 -
20.27 -Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20.28 -or visit www.oracle.com if you need additional information or have any
20.29 -questions.
20.30 --->
20.31 -
20.32 -</head>
20.33 -<body bgcolor="white">
20.34 -
20.35 -Provides classes for reading and writing the standard ZIP and GZIP
20.36 -file formats. Also includes classes for compressing and decompressing
20.37 -data using the DEFLATE compression algorithm, which is used by the
20.38 -ZIP and GZIP file formats. Additionally, there are utility classes
20.39 -for computing the CRC-32 and Adler-32 checksums of arbitrary
20.40 -input streams.
20.41 -
20.42 -
20.43 -<h2>Package Specification</h2>
20.44 -
20.45 -</a>
20.46 -<ul>
20.47 - <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
20.48 - Info-ZIP Application Note 970311
20.49 - </a> - a detailed description of the Info-ZIP format upon which
20.50 - the <code>java.util.zip</code> classes are based.
20.51 -<p>
20.52 - <a name="zip64">
20.53 - <li>An implementation may optionally support the ZIP64(tm) format extensions
20.54 - defined by the
20.55 - <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
20.56 - PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
20.57 - are used to overcome the size limitations of the original ZIP format.
20.58 -<p>
20.59 - <a name="lang_encoding">
20.60 - <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
20.61 - PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
20.62 - encode ZIP entry filename and comment fields using UTF-8.
20.63 -<p>
20.64 - <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
20.65 - ZLIB Compressed Data Format Specification version 3.3</a>
20.66 -
20.67 - <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
20.68 - (RFC 1950)
20.69 -<p>
20.70 - <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
20.71 - DEFLATE Compressed Data Format Specification version 1.3</a>
20.72 -
20.73 - <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
20.74 - (RFC 1951)
20.75 -<p>
20.76 - <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
20.77 - GZIP file format specification version 4.3</a>
20.78 -
20.79 - <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
20.80 - (RFC 1952)
20.81 -<p>
20.82 - <li>CRC-32 checksum is described in RFC 1952 (above)
20.83 -<p>
20.84 - <li>Adler-32 checksum is described in RFC 1950 (above)
20.85 -</ul>
20.86 -
20.87 -
20.88 -<!--
20.89 -<h2>Related Documentation</h2>
20.90 -
20.91 -For overviews, tutorials, examples, guides, and tool documentation, please see:
20.92 -<ul>
20.93 - <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
20.94 -</ul>
20.95 --->
20.96 -
20.97 -@since JDK1.1
20.98 -</body>
20.99 -</html>
20.100 -
20.101 -
21.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java Wed May 07 11:55:06 2014 +0200
21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
21.3 @@ -1,139 +0,0 @@
21.4 -/* -*-mode:java; c-basic-offset:2; -*- */
21.5 -/*
21.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
21.7 -
21.8 -Redistribution and use in source and binary forms, with or without
21.9 -modification, are permitted provided that the following conditions are met:
21.10 -
21.11 - 1. Redistributions of source code must retain the above copyright notice,
21.12 - this list of conditions and the following disclaimer.
21.13 -
21.14 - 2. Redistributions in binary form must reproduce the above copyright
21.15 - notice, this list of conditions and the following disclaimer in
21.16 - the documentation and/or other materials provided with the distribution.
21.17 -
21.18 - 3. The names of the authors may not be used to endorse or promote products
21.19 - derived from this software without specific prior written permission.
21.20 -
21.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
21.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21.31 - */
21.32 -/*
21.33 - * This program is based on zlib-1.1.3, so all credit should go authors
21.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
21.35 - * and contributors of zlib.
21.36 - */
21.37 -
21.38 -package org.apidesign.bck2brwsr.emul.zip;
21.39 -
21.40 -final class Adler32 implements Checksum {
21.41 -
21.42 - // largest prime smaller than 65536
21.43 - static final private int BASE=65521;
21.44 - // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
21.45 - static final private int NMAX=5552;
21.46 -
21.47 - private long s1=1L;
21.48 - private long s2=0L;
21.49 -
21.50 - public void reset(long init){
21.51 - s1=init&0xffff;
21.52 - s2=(init>>16)&0xffff;
21.53 - }
21.54 -
21.55 - public void reset(){
21.56 - s1=1L;
21.57 - s2=0L;
21.58 - }
21.59 -
21.60 - public long getValue(){
21.61 - return ((s2<<16)|s1);
21.62 - }
21.63 -
21.64 - public void update(byte[] buf, int index, int len){
21.65 -
21.66 - if(len==1){
21.67 - s1+=buf[index++]&0xff; s2+=s1;
21.68 - s1%=BASE;
21.69 - s2%=BASE;
21.70 - return;
21.71 - }
21.72 -
21.73 - int len1 = len/NMAX;
21.74 - int len2 = len%NMAX;
21.75 - while(len1-->0) {
21.76 - int k=NMAX;
21.77 - len-=k;
21.78 - while(k-->0){
21.79 - s1+=buf[index++]&0xff; s2+=s1;
21.80 - }
21.81 - s1%=BASE;
21.82 - s2%=BASE;
21.83 - }
21.84 -
21.85 - int k=len2;
21.86 - len-=k;
21.87 - while(k-->0){
21.88 - s1+=buf[index++]&0xff; s2+=s1;
21.89 - }
21.90 - s1%=BASE;
21.91 - s2%=BASE;
21.92 - }
21.93 -
21.94 - public Adler32 copy(){
21.95 - Adler32 foo = new Adler32();
21.96 - foo.s1 = this.s1;
21.97 - foo.s2 = this.s2;
21.98 - return foo;
21.99 - }
21.100 -
21.101 - // The following logic has come from zlib.1.2.
21.102 - static long combine(long adler1, long adler2, long len2){
21.103 - long BASEL = (long)BASE;
21.104 - long sum1;
21.105 - long sum2;
21.106 - long rem; // unsigned int
21.107 -
21.108 - rem = len2 % BASEL;
21.109 - sum1 = adler1 & 0xffffL;
21.110 - sum2 = rem * sum1;
21.111 - sum2 %= BASEL; // MOD(sum2);
21.112 - sum1 += (adler2 & 0xffffL) + BASEL - 1;
21.113 - sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
21.114 - if (sum1 >= BASEL) sum1 -= BASEL;
21.115 - if (sum1 >= BASEL) sum1 -= BASEL;
21.116 - if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
21.117 - if (sum2 >= BASEL) sum2 -= BASEL;
21.118 - return sum1 | (sum2 << 16);
21.119 - }
21.120 -
21.121 -/*
21.122 - private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
21.123 - public void update(byte[] buf, int index, int len){
21.124 - if(buf==null) {adler.reset();}
21.125 - else{adler.update(buf, index, len);}
21.126 - }
21.127 - public void reset(){
21.128 - adler.reset();
21.129 - }
21.130 - public void reset(long init){
21.131 - if(init==1L){
21.132 - adler.reset();
21.133 - }
21.134 - else{
21.135 - System.err.println("unsupported operation");
21.136 - }
21.137 - }
21.138 - public long getValue(){
21.139 - return adler.getValue();
21.140 - }
21.141 -*/
21.142 -}
22.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Wed May 07 11:55:06 2014 +0200
22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
22.3 @@ -1,181 +0,0 @@
22.4 -/* -*-mode:java; c-basic-offset:2; -*- */
22.5 -/*
22.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
22.7 -
22.8 -Redistribution and use in source and binary forms, with or without
22.9 -modification, are permitted provided that the following conditions are met:
22.10 -
22.11 - 1. Redistributions of source code must retain the above copyright notice,
22.12 - this list of conditions and the following disclaimer.
22.13 -
22.14 - 2. Redistributions in binary form must reproduce the above copyright
22.15 - notice, this list of conditions and the following disclaimer in
22.16 - the documentation and/or other materials provided with the distribution.
22.17 -
22.18 - 3. The names of the authors may not be used to endorse or promote products
22.19 - derived from this software without specific prior written permission.
22.20 -
22.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
22.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
22.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22.31 - */
22.32 -/*
22.33 - * This program is based on zlib-1.1.3, so all credit should go authors
22.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
22.35 - * and contributors of zlib.
22.36 - */
22.37 -
22.38 -package org.apidesign.bck2brwsr.emul.zip;
22.39 -
22.40 -import org.apidesign.bck2brwsr.emul.lang.System;
22.41 -
22.42 -final class CRC32 implements Checksum {
22.43 -
22.44 - /*
22.45 - * The following logic has come from RFC1952.
22.46 - */
22.47 - private int v = 0;
22.48 - private static int[] crc_table = null;
22.49 - static {
22.50 - crc_table = new int[256];
22.51 - for (int n = 0; n < 256; n++) {
22.52 - int c = n;
22.53 - for (int k = 8; --k >= 0; ) {
22.54 - if ((c & 1) != 0)
22.55 - c = 0xedb88320 ^ (c >>> 1);
22.56 - else
22.57 - c = c >>> 1;
22.58 - }
22.59 - crc_table[n] = c;
22.60 - }
22.61 - }
22.62 -
22.63 - public void update (byte[] buf, int index, int len) {
22.64 - int c = ~v;
22.65 - while (--len >= 0)
22.66 - c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
22.67 - v = ~c;
22.68 - }
22.69 -
22.70 - public void reset(){
22.71 - v = 0;
22.72 - }
22.73 -
22.74 - public void reset(long vv){
22.75 - v = (int)(vv&0xffffffffL);
22.76 - }
22.77 -
22.78 - public long getValue(){
22.79 - return (long)(v&0xffffffffL);
22.80 - }
22.81 -
22.82 - // The following logic has come from zlib.1.2.
22.83 - private static final int GF2_DIM = 32;
22.84 - static long combine(long crc1, long crc2, long len2){
22.85 - long row;
22.86 - long[] even = new long[GF2_DIM];
22.87 - long[] odd = new long[GF2_DIM];
22.88 -
22.89 - // degenerate case (also disallow negative lengths)
22.90 - if (len2 <= 0)
22.91 - return crc1;
22.92 -
22.93 - // put operator for one zero bit in odd
22.94 - odd[0] = 0xedb88320L; // CRC-32 polynomial
22.95 - row = 1;
22.96 - for (int n = 1; n < GF2_DIM; n++) {
22.97 - odd[n] = row;
22.98 - row <<= 1;
22.99 - }
22.100 -
22.101 - // put operator for two zero bits in even
22.102 - gf2_matrix_square(even, odd);
22.103 -
22.104 - // put operator for four zero bits in odd
22.105 - gf2_matrix_square(odd, even);
22.106 -
22.107 - // apply len2 zeros to crc1 (first square will put the operator for one
22.108 - // zero byte, eight zero bits, in even)
22.109 - do {
22.110 - // apply zeros operator for this bit of len2
22.111 - gf2_matrix_square(even, odd);
22.112 - if ((len2 & 1)!=0)
22.113 - crc1 = gf2_matrix_times(even, crc1);
22.114 - len2 >>= 1;
22.115 -
22.116 - // if no more bits set, then done
22.117 - if (len2 == 0)
22.118 - break;
22.119 -
22.120 - // another iteration of the loop with odd and even swapped
22.121 - gf2_matrix_square(odd, even);
22.122 - if ((len2 & 1)!=0)
22.123 - crc1 = gf2_matrix_times(odd, crc1);
22.124 - len2 >>= 1;
22.125 -
22.126 - // if no more bits set, then done
22.127 - } while (len2 != 0);
22.128 -
22.129 - /* return combined crc */
22.130 - crc1 ^= crc2;
22.131 - return crc1;
22.132 - }
22.133 -
22.134 - private static long gf2_matrix_times(long[] mat, long vec){
22.135 - long sum = 0;
22.136 - int index = 0;
22.137 - while (vec!=0) {
22.138 - if ((vec & 1)!=0)
22.139 - sum ^= mat[index];
22.140 - vec >>= 1;
22.141 - index++;
22.142 - }
22.143 - return sum;
22.144 - }
22.145 -
22.146 - static final void gf2_matrix_square(long[] square, long[] mat) {
22.147 - for (int n = 0; n < GF2_DIM; n++)
22.148 - square[n] = gf2_matrix_times(mat, mat[n]);
22.149 - }
22.150 -
22.151 - /*
22.152 - private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
22.153 -
22.154 - public void update(byte[] buf, int index, int len){
22.155 - if(buf==null) {crc32.reset();}
22.156 - else{crc32.update(buf, index, len);}
22.157 - }
22.158 - public void reset(){
22.159 - crc32.reset();
22.160 - }
22.161 - public void reset(long init){
22.162 - if(init==0L){
22.163 - crc32.reset();
22.164 - }
22.165 - else{
22.166 - System.err.println("unsupported operation");
22.167 - }
22.168 - }
22.169 - public long getValue(){
22.170 - return crc32.getValue();
22.171 - }
22.172 -*/
22.173 - public CRC32 copy(){
22.174 - CRC32 foo = new CRC32();
22.175 - foo.v = this.v;
22.176 - return foo;
22.177 - }
22.178 -
22.179 - public static int[] getCRC32Table(){
22.180 - int[] tmp = new int[crc_table.length];
22.181 - System.arraycopy(crc_table, 0, tmp, 0, tmp.length);
22.182 - return tmp;
22.183 - }
22.184 -}
23.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java Wed May 07 11:55:06 2014 +0200
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,43 +0,0 @@
23.4 -/* -*-mode:java; c-basic-offset:2; -*- */
23.5 -/*
23.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
23.7 -
23.8 -Redistribution and use in source and binary forms, with or without
23.9 -modification, are permitted provided that the following conditions are met:
23.10 -
23.11 - 1. Redistributions of source code must retain the above copyright notice,
23.12 - this list of conditions and the following disclaimer.
23.13 -
23.14 - 2. Redistributions in binary form must reproduce the above copyright
23.15 - notice, this list of conditions and the following disclaimer in
23.16 - the documentation and/or other materials provided with the distribution.
23.17 -
23.18 - 3. The names of the authors may not be used to endorse or promote products
23.19 - derived from this software without specific prior written permission.
23.20 -
23.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
23.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
23.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
23.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
23.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23.31 - */
23.32 -/*
23.33 - * This program is based on zlib-1.1.3, so all credit should go authors
23.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
23.35 - * and contributors of zlib.
23.36 - */
23.37 -
23.38 -package org.apidesign.bck2brwsr.emul.zip;
23.39 -
23.40 -interface Checksum {
23.41 - void update(byte[] buf, int index, int len);
23.42 - void reset();
23.43 - void reset(long init);
23.44 - long getValue();
23.45 - Checksum copy();
23.46 -}
24.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Wed May 07 11:55:06 2014 +0200
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,175 +0,0 @@
24.4 -/*
24.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
24.6 - *
24.7 - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
24.8 - *
24.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
24.10 - * Other names may be trademarks of their respective owners.
24.11 - *
24.12 - * The contents of this file are subject to the terms of either the GNU
24.13 - * General Public License Version 2 only ("GPL") or the Common
24.14 - * Development and Distribution License("CDDL") (collectively, the
24.15 - * "License"). You may not use this file except in compliance with the
24.16 - * License. You can obtain a copy of the License at
24.17 - * http://www.netbeans.org/cddl-gplv2.html
24.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
24.19 - * specific language governing permissions and limitations under the
24.20 - * License. When distributing the software, include this License Header
24.21 - * Notice in each file and include the License file at
24.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
24.23 - * particular file as subject to the "Classpath" exception as provided
24.24 - * by Oracle in the GPL Version 2 section of the License file that
24.25 - * accompanied this code. If applicable, add the following below the
24.26 - * License Header, with the fields enclosed by brackets [] replaced by
24.27 - * your own identifying information:
24.28 - * "Portions Copyrighted [year] [name of copyright owner]"
24.29 - *
24.30 - * Contributor(s):
24.31 - *
24.32 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
24.33 - */
24.34 -package org.apidesign.bck2brwsr.emul.zip;
24.35 -
24.36 -import java.io.ByteArrayInputStream;
24.37 -import java.io.IOException;
24.38 -import java.io.InputStream;
24.39 -import java.util.zip.ZipEntry;
24.40 -import java.util.zip.ZipInputStream;
24.41 -
24.42 -/**
24.43 - *
24.44 - * @author Tomas Zezula
24.45 - */
24.46 -public final class FastJar {
24.47 - private final byte[] arr;
24.48 -
24.49 - public FastJar(byte[] arr) {
24.50 - this.arr = arr;
24.51 - }
24.52 -
24.53 -
24.54 - private static final int GIVE_UP = 1<<16;
24.55 -
24.56 - public static final class Entry {
24.57 -
24.58 - public final String name;
24.59 - final long offset;
24.60 - private final long dosTime;
24.61 -
24.62 - Entry (String name, long offset, long time) {
24.63 - assert name != null;
24.64 - this.name = name;
24.65 - this.offset = offset;
24.66 - this.dosTime = time;
24.67 - }
24.68 -/*
24.69 - public long getTime () {
24.70 - Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
24.71 - (int)(((dosTime >> 21) & 0x0f) - 1),
24.72 - (int)((dosTime >> 16) & 0x1f),
24.73 - (int)((dosTime >> 11) & 0x1f),
24.74 - (int)((dosTime >> 5) & 0x3f),
24.75 - (int)((dosTime << 1) & 0x3e));
24.76 - return d.getTime();
24.77 - }
24.78 - */
24.79 - }
24.80 -
24.81 - public InputStream getInputStream (final Entry e) throws IOException {
24.82 - return getInputStream(arr, e.offset);
24.83 - }
24.84 -
24.85 - private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
24.86 - ByteArrayInputStream is = new ByteArrayInputStream(arr);
24.87 - is.skip(offset);
24.88 - ZipInputStream in = new ZipInputStream (is);
24.89 - ZipEntry e = in.getNextEntry();
24.90 - if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
24.91 - int cp = arr.length - is.available();
24.92 - return new ByteArrayInputStream(arr, cp, (int)e.getSize());
24.93 - }
24.94 - return in;
24.95 - }
24.96 -
24.97 - public Entry[] list() throws IOException {
24.98 - final int size = arr.length;
24.99 -
24.100 - int at = size - ZipInputStream.ENDHDR;
24.101 -
24.102 - byte[] data = new byte[ZipInputStream.ENDHDR];
24.103 - int giveup = 0;
24.104 -
24.105 - do {
24.106 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
24.107 - at--;
24.108 - giveup++;
24.109 - if (giveup > GIVE_UP) {
24.110 - throw new IOException ();
24.111 - }
24.112 - } while (getsig(data) != ZipInputStream.ENDSIG);
24.113 -
24.114 -
24.115 - final long censize = endsiz(data);
24.116 - final long cenoff = endoff(data);
24.117 - at = (int) cenoff;
24.118 -
24.119 - Entry[] result = new Entry[0];
24.120 - int cenread = 0;
24.121 - data = new byte[ZipInputStream.CENHDR];
24.122 - while (cenread < censize) {
24.123 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
24.124 - at += data.length;
24.125 - if (getsig(data) != ZipInputStream.CENSIG) {
24.126 - throw new IOException("No central table"); //NOI18N
24.127 - }
24.128 - int cennam = cennam(data);
24.129 - int cenext = cenext(data);
24.130 - int cencom = cencom(data);
24.131 - long lhoff = cenoff(data);
24.132 - long centim = centim(data);
24.133 - String name = new String(arr, at, cennam, "UTF-8");
24.134 - at += cennam;
24.135 - int seekby = cenext+cencom;
24.136 - int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
24.137 - cenread+=cendatalen;
24.138 - result = addEntry(result, new Entry(name,lhoff, centim));
24.139 - at += seekby;
24.140 - }
24.141 - return result;
24.142 - }
24.143 -
24.144 - private Entry[] addEntry(Entry[] result, Entry entry) {
24.145 - Entry[] e = new Entry[result.length + 1];
24.146 - e[result.length] = entry;
24.147 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(result, 0, e, 0, result.length);
24.148 - return e;
24.149 - }
24.150 -
24.151 - private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
24.152 - private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
24.153 - private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
24.154 - private static final long cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
24.155 - private static final long censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
24.156 - private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
24.157 - private static final int cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
24.158 - private static final int cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
24.159 - private static final int cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
24.160 - private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
24.161 - private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
24.162 - private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
24.163 - private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
24.164 - private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
24.165 -
24.166 - private static final int get16(final byte[] b, int off) throws IOException {
24.167 - final int b1 = b[off];
24.168 - final int b2 = b[off+1];
24.169 - return (b1 & 0xff) | ((b2 & 0xff) << 8);
24.170 - }
24.171 -
24.172 - private static final long get32(final byte[] b, int off) throws IOException {
24.173 - final int s1 = get16(b, off);
24.174 - final int s2 = get16(b, off+2);
24.175 - return s1 | ((long)s2 << 16);
24.176 - }
24.177 -
24.178 -}
25.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Wed May 07 11:55:06 2014 +0200
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,215 +0,0 @@
25.4 -/* -*-mode:java; c-basic-offset:2; -*- */
25.5 -/*
25.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
25.7 -
25.8 -Redistribution and use in source and binary forms, with or without
25.9 -modification, are permitted provided that the following conditions are met:
25.10 -
25.11 - 1. Redistributions of source code must retain the above copyright notice,
25.12 - this list of conditions and the following disclaimer.
25.13 -
25.14 - 2. Redistributions in binary form must reproduce the above copyright
25.15 - notice, this list of conditions and the following disclaimer in
25.16 - the documentation and/or other materials provided with the distribution.
25.17 -
25.18 - 3. The names of the authors may not be used to endorse or promote products
25.19 - derived from this software without specific prior written permission.
25.20 -
25.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
25.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
25.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
25.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
25.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
25.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.31 - */
25.32 -/*
25.33 - * This program is based on zlib-1.1.3, so all credit should go authors
25.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
25.35 - * and contributors of zlib.
25.36 - */
25.37 -
25.38 -package org.apidesign.bck2brwsr.emul.zip;
25.39 -
25.40 -import org.apidesign.bck2brwsr.emul.lang.System;
25.41 -import java.io.UnsupportedEncodingException;
25.42 -
25.43 -/**
25.44 - * @see "http://www.ietf.org/rfc/rfc1952.txt"
25.45 - */
25.46 -final class GZIPHeader implements Cloneable {
25.47 -
25.48 - public static final byte OS_MSDOS = (byte) 0x00;
25.49 - public static final byte OS_AMIGA = (byte) 0x01;
25.50 - public static final byte OS_VMS = (byte) 0x02;
25.51 - public static final byte OS_UNIX = (byte) 0x03;
25.52 - public static final byte OS_ATARI = (byte) 0x05;
25.53 - public static final byte OS_OS2 = (byte) 0x06;
25.54 - public static final byte OS_MACOS = (byte) 0x07;
25.55 - public static final byte OS_TOPS20 = (byte) 0x0a;
25.56 - public static final byte OS_WIN32 = (byte) 0x0b;
25.57 - public static final byte OS_VMCMS = (byte) 0x04;
25.58 - public static final byte OS_ZSYSTEM = (byte) 0x08;
25.59 - public static final byte OS_CPM = (byte) 0x09;
25.60 - public static final byte OS_QDOS = (byte) 0x0c;
25.61 - public static final byte OS_RISCOS = (byte) 0x0d;
25.62 - public static final byte OS_UNKNOWN = (byte) 0xff;
25.63 -
25.64 - boolean text = false;
25.65 - private boolean fhcrc = false;
25.66 - long time;
25.67 - int xflags;
25.68 - int os = 255;
25.69 - byte[] extra;
25.70 - byte[] name;
25.71 - byte[] comment;
25.72 - int hcrc;
25.73 - long crc;
25.74 - boolean done = false;
25.75 - long mtime = 0;
25.76 -
25.77 - public void setModifiedTime(long mtime) {
25.78 - this.mtime = mtime;
25.79 - }
25.80 -
25.81 - public long getModifiedTime() {
25.82 - return mtime;
25.83 - }
25.84 -
25.85 - public void setOS(int os) {
25.86 - if((0<=os && os <=13) || os==255)
25.87 - this.os=os;
25.88 - else
25.89 - throw new IllegalArgumentException("os: "+os);
25.90 - }
25.91 -
25.92 - public int getOS(){
25.93 - return os;
25.94 - }
25.95 -
25.96 - public void setName(String name) {
25.97 - try{
25.98 - this.name=name.getBytes("ISO-8859-1");
25.99 - }
25.100 - catch(UnsupportedEncodingException e){
25.101 - throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
25.102 - }
25.103 - }
25.104 -
25.105 - public String getName(){
25.106 - if(name==null) return "";
25.107 - try {
25.108 - return new String(name, "ISO-8859-1");
25.109 - }
25.110 - catch (UnsupportedEncodingException e) {
25.111 - throw new IllegalArgumentException(e.toString());
25.112 - }
25.113 - }
25.114 -
25.115 - public void setComment(String comment) {
25.116 - try{
25.117 - this.comment=comment.getBytes("ISO-8859-1");
25.118 - }
25.119 - catch(UnsupportedEncodingException e){
25.120 - throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
25.121 - }
25.122 - }
25.123 -
25.124 - public String getComment(){
25.125 - if(comment==null) return "";
25.126 - try {
25.127 - return new String(comment, "ISO-8859-1");
25.128 - }
25.129 - catch (UnsupportedEncodingException e) {
25.130 - throw new IllegalArgumentException(e.toString());
25.131 - }
25.132 - }
25.133 -
25.134 - public void setCRC(long crc){
25.135 - this.crc = crc;
25.136 - }
25.137 -
25.138 - public long getCRC(){
25.139 - return crc;
25.140 - }
25.141 -/*
25.142 - void put(Deflate d){
25.143 - int flag = 0;
25.144 - if(text){
25.145 - flag |= 1; // FTEXT
25.146 - }
25.147 - if(fhcrc){
25.148 - flag |= 2; // FHCRC
25.149 - }
25.150 - if(extra!=null){
25.151 - flag |= 4; // FEXTRA
25.152 - }
25.153 - if(name!=null){
25.154 - flag |= 8; // FNAME
25.155 - }
25.156 - if(comment!=null){
25.157 - flag |= 16; // FCOMMENT
25.158 - }
25.159 - int xfl = 0;
25.160 - if(d.level == JZlib.Z_BEST_SPEED){
25.161 - xfl |= 4;
25.162 - }
25.163 - else if (d.level == JZlib.Z_BEST_COMPRESSION){
25.164 - xfl |= 2;
25.165 - }
25.166 -
25.167 - d.put_short((short)0x8b1f); // ID1 ID2
25.168 - d.put_byte((byte)8); // CM(Compression Method)
25.169 - d.put_byte((byte)flag);
25.170 - d.put_byte((byte)mtime);
25.171 - d.put_byte((byte)(mtime>>8));
25.172 - d.put_byte((byte)(mtime>>16));
25.173 - d.put_byte((byte)(mtime>>24));
25.174 - d.put_byte((byte)xfl);
25.175 - d.put_byte((byte)os);
25.176 -
25.177 - if(extra!=null){
25.178 - d.put_byte((byte)extra.length);
25.179 - d.put_byte((byte)(extra.length>>8));
25.180 - d.put_byte(extra, 0, extra.length);
25.181 - }
25.182 -
25.183 - if(name!=null){
25.184 - d.put_byte(name, 0, name.length);
25.185 - d.put_byte((byte)0);
25.186 - }
25.187 -
25.188 - if(comment!=null){
25.189 - d.put_byte(comment, 0, comment.length);
25.190 - d.put_byte((byte)0);
25.191 - }
25.192 - }
25.193 -*/
25.194 - @Override
25.195 - public Object clone() throws CloneNotSupportedException {
25.196 - GZIPHeader gheader = (GZIPHeader)super.clone();
25.197 - byte[] tmp;
25.198 - if(gheader.extra!=null){
25.199 - tmp=new byte[gheader.extra.length];
25.200 - System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
25.201 - gheader.extra = tmp;
25.202 - }
25.203 -
25.204 - if(gheader.name!=null){
25.205 - tmp=new byte[gheader.name.length];
25.206 - System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
25.207 - gheader.name = tmp;
25.208 - }
25.209 -
25.210 - if(gheader.comment!=null){
25.211 - tmp=new byte[gheader.comment.length];
25.212 - System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
25.213 - gheader.comment = tmp;
25.214 - }
25.215 -
25.216 - return gheader;
25.217 - }
25.218 -}
26.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Wed May 07 11:55:06 2014 +0200
26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
26.3 @@ -1,616 +0,0 @@
26.4 -/* -*-mode:java; c-basic-offset:2; -*- */
26.5 -/*
26.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
26.7 -
26.8 -Redistribution and use in source and binary forms, with or without
26.9 -modification, are permitted provided that the following conditions are met:
26.10 -
26.11 - 1. Redistributions of source code must retain the above copyright notice,
26.12 - this list of conditions and the following disclaimer.
26.13 -
26.14 - 2. Redistributions in binary form must reproduce the above copyright
26.15 - notice, this list of conditions and the following disclaimer in
26.16 - the documentation and/or other materials provided with the distribution.
26.17 -
26.18 - 3. The names of the authors may not be used to endorse or promote products
26.19 - derived from this software without specific prior written permission.
26.20 -
26.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
26.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
26.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
26.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
26.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26.31 - */
26.32 -/*
26.33 - * This program is based on zlib-1.1.3, so all credit should go authors
26.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
26.35 - * and contributors of zlib.
26.36 - */
26.37 -
26.38 -package org.apidesign.bck2brwsr.emul.zip;
26.39 -
26.40 -import org.apidesign.bck2brwsr.emul.lang.System;
26.41 -
26.42 -final class InfBlocks{
26.43 - static final private int MANY=1440;
26.44 -
26.45 - // And'ing with mask[n] masks the lower n bits
26.46 - static final private int[] inflate_mask = {
26.47 - 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
26.48 - 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
26.49 - 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
26.50 - 0x00007fff, 0x0000ffff
26.51 - };
26.52 -
26.53 - // Table for deflate from PKZIP's appnote.txt.
26.54 - static final int[] border = { // Order of the bit length code lengths
26.55 - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
26.56 - };
26.57 -
26.58 - static final private int Z_OK=0;
26.59 - static final private int Z_STREAM_END=1;
26.60 - static final private int Z_NEED_DICT=2;
26.61 - static final private int Z_ERRNO=-1;
26.62 - static final private int Z_STREAM_ERROR=-2;
26.63 - static final private int Z_DATA_ERROR=-3;
26.64 - static final private int Z_MEM_ERROR=-4;
26.65 - static final private int Z_BUF_ERROR=-5;
26.66 - static final private int Z_VERSION_ERROR=-6;
26.67 -
26.68 - static final private int TYPE=0; // get type bits (3, including end bit)
26.69 - static final private int LENS=1; // get lengths for stored
26.70 - static final private int STORED=2;// processing stored block
26.71 - static final private int TABLE=3; // get table lengths
26.72 - static final private int BTREE=4; // get bit lengths tree for a dynamic block
26.73 - static final private int DTREE=5; // get length, distance trees for a dynamic block
26.74 - static final private int CODES=6; // processing fixed or dynamic block
26.75 - static final private int DRY=7; // output remaining window bytes
26.76 - static final private int DONE=8; // finished last block, done
26.77 - static final private int BAD=9; // ot a data error--stuck here
26.78 -
26.79 - int mode; // current inflate_block mode
26.80 -
26.81 - int left; // if STORED, bytes left to copy
26.82 -
26.83 - int table; // table lengths (14 bits)
26.84 - int index; // index into blens (or border)
26.85 - int[] blens; // bit lengths of codes
26.86 - int[] bb=new int[1]; // bit length tree depth
26.87 - int[] tb=new int[1]; // bit length decoding tree
26.88 -
26.89 - int[] bl=new int[1];
26.90 - int[] bd=new int[1];
26.91 -
26.92 - int[][] tl=new int[1][];
26.93 - int[][] td=new int[1][];
26.94 - int[] tli=new int[1]; // tl_index
26.95 - int[] tdi=new int[1]; // td_index
26.96 -
26.97 - private final InfCodes codes; // if CODES, current state
26.98 -
26.99 - int last; // true if this block is the last block
26.100 -
26.101 - // mode independent information
26.102 - int bitk; // bits in bit buffer
26.103 - int bitb; // bit buffer
26.104 - int[] hufts; // single malloc for tree space
26.105 - byte[] window; // sliding window
26.106 - int end; // one byte after sliding window
26.107 - int read; // window read pointer
26.108 - int write; // window write pointer
26.109 - private boolean check;
26.110 -
26.111 - private final InfTree inftree=new InfTree();
26.112 -
26.113 - private final ZStream z;
26.114 -
26.115 - InfBlocks(ZStream z, int w){
26.116 - this.z=z;
26.117 - this.codes=new InfCodes(this.z, this);
26.118 - hufts=new int[MANY*3];
26.119 - window=new byte[w];
26.120 - end=w;
26.121 - this.check = (z.istate.wrap==0) ? false : true;
26.122 - mode = TYPE;
26.123 - reset();
26.124 - }
26.125 -
26.126 - void reset(){
26.127 - if(mode==BTREE || mode==DTREE){
26.128 - }
26.129 - if(mode==CODES){
26.130 - codes.free(z);
26.131 - }
26.132 - mode=TYPE;
26.133 - bitk=0;
26.134 - bitb=0;
26.135 - read=write=0;
26.136 - if(check){
26.137 - z.adler.reset();
26.138 - }
26.139 - }
26.140 -
26.141 - int proc(int r){
26.142 - int t; // temporary storage
26.143 - int b; // bit buffer
26.144 - int k; // bits in bit buffer
26.145 - int p; // input data pointer
26.146 - int n; // bytes available there
26.147 - int q; // output window write pointer
26.148 - int m; // bytes to end of window or read pointer
26.149 -
26.150 - // copy input/output information to locals (UPDATE macro restores)
26.151 - {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
26.152 - {q=write;m=(int)(q<read?read-q-1:end-q);}
26.153 -
26.154 - // process input based on current state
26.155 - while(true){
26.156 - switch (mode){
26.157 - case TYPE:
26.158 -
26.159 - while(k<(3)){
26.160 - if(n!=0){
26.161 - r=Z_OK;
26.162 - }
26.163 - else{
26.164 - bitb=b; bitk=k;
26.165 - z.avail_in=n;
26.166 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.167 - write=q;
26.168 - return inflate_flush(r);
26.169 - };
26.170 - n--;
26.171 - b|=(z.next_in[p++]&0xff)<<k;
26.172 - k+=8;
26.173 - }
26.174 - t = (int)(b & 7);
26.175 - last = t & 1;
26.176 -
26.177 - switch (t >>> 1){
26.178 - case 0: // stored
26.179 - {b>>>=(3);k-=(3);}
26.180 - t = k & 7; // go to byte boundary
26.181 -
26.182 - {b>>>=(t);k-=(t);}
26.183 - mode = LENS; // get length of stored block
26.184 - break;
26.185 - case 1: // fixed
26.186 - InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
26.187 - codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
26.188 -
26.189 - {b>>>=(3);k-=(3);}
26.190 -
26.191 - mode = CODES;
26.192 - break;
26.193 - case 2: // dynamic
26.194 -
26.195 - {b>>>=(3);k-=(3);}
26.196 -
26.197 - mode = TABLE;
26.198 - break;
26.199 - case 3: // illegal
26.200 -
26.201 - {b>>>=(3);k-=(3);}
26.202 - mode = BAD;
26.203 - z.msg = "invalid block type";
26.204 - r = Z_DATA_ERROR;
26.205 -
26.206 - bitb=b; bitk=k;
26.207 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.208 - write=q;
26.209 - return inflate_flush(r);
26.210 - }
26.211 - break;
26.212 - case LENS:
26.213 -
26.214 - while(k<(32)){
26.215 - if(n!=0){
26.216 - r=Z_OK;
26.217 - }
26.218 - else{
26.219 - bitb=b; bitk=k;
26.220 - z.avail_in=n;
26.221 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.222 - write=q;
26.223 - return inflate_flush(r);
26.224 - };
26.225 - n--;
26.226 - b|=(z.next_in[p++]&0xff)<<k;
26.227 - k+=8;
26.228 - }
26.229 -
26.230 - if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)){
26.231 - mode = BAD;
26.232 - z.msg = "invalid stored block lengths";
26.233 - r = Z_DATA_ERROR;
26.234 -
26.235 - bitb=b; bitk=k;
26.236 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.237 - write=q;
26.238 - return inflate_flush(r);
26.239 - }
26.240 - left = (b & 0xffff);
26.241 - b = k = 0; // dump bits
26.242 - mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
26.243 - break;
26.244 - case STORED:
26.245 - if (n == 0){
26.246 - bitb=b; bitk=k;
26.247 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.248 - write=q;
26.249 - return inflate_flush(r);
26.250 - }
26.251 -
26.252 - if(m==0){
26.253 - if(q==end&&read!=0){
26.254 - q=0; m=(int)(q<read?read-q-1:end-q);
26.255 - }
26.256 - if(m==0){
26.257 - write=q;
26.258 - r=inflate_flush(r);
26.259 - q=write;m=(int)(q<read?read-q-1:end-q);
26.260 - if(q==end&&read!=0){
26.261 - q=0; m=(int)(q<read?read-q-1:end-q);
26.262 - }
26.263 - if(m==0){
26.264 - bitb=b; bitk=k;
26.265 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.266 - write=q;
26.267 - return inflate_flush(r);
26.268 - }
26.269 - }
26.270 - }
26.271 - r=Z_OK;
26.272 -
26.273 - t = left;
26.274 - if(t>n) t = n;
26.275 - if(t>m) t = m;
26.276 - System.arraycopy(z.next_in, p, window, q, t);
26.277 - p += t; n -= t;
26.278 - q += t; m -= t;
26.279 - if ((left -= t) != 0)
26.280 - break;
26.281 - mode = last!=0 ? DRY : TYPE;
26.282 - break;
26.283 - case TABLE:
26.284 -
26.285 - while(k<(14)){
26.286 - if(n!=0){
26.287 - r=Z_OK;
26.288 - }
26.289 - else{
26.290 - bitb=b; bitk=k;
26.291 - z.avail_in=n;
26.292 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.293 - write=q;
26.294 - return inflate_flush(r);
26.295 - };
26.296 - n--;
26.297 - b|=(z.next_in[p++]&0xff)<<k;
26.298 - k+=8;
26.299 - }
26.300 -
26.301 - table = t = (b & 0x3fff);
26.302 - if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
26.303 - {
26.304 - mode = BAD;
26.305 - z.msg = "too many length or distance symbols";
26.306 - r = Z_DATA_ERROR;
26.307 -
26.308 - bitb=b; bitk=k;
26.309 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.310 - write=q;
26.311 - return inflate_flush(r);
26.312 - }
26.313 - t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
26.314 - if(blens==null || blens.length<t){
26.315 - blens=new int[t];
26.316 - }
26.317 - else{
26.318 - for(int i=0; i<t; i++){blens[i]=0;}
26.319 - }
26.320 -
26.321 - {b>>>=(14);k-=(14);}
26.322 -
26.323 - index = 0;
26.324 - mode = BTREE;
26.325 - case BTREE:
26.326 - while (index < 4 + (table >>> 10)){
26.327 - while(k<(3)){
26.328 - if(n!=0){
26.329 - r=Z_OK;
26.330 - }
26.331 - else{
26.332 - bitb=b; bitk=k;
26.333 - z.avail_in=n;
26.334 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.335 - write=q;
26.336 - return inflate_flush(r);
26.337 - };
26.338 - n--;
26.339 - b|=(z.next_in[p++]&0xff)<<k;
26.340 - k+=8;
26.341 - }
26.342 -
26.343 - blens[border[index++]] = b&7;
26.344 -
26.345 - {b>>>=(3);k-=(3);}
26.346 - }
26.347 -
26.348 - while(index < 19){
26.349 - blens[border[index++]] = 0;
26.350 - }
26.351 -
26.352 - bb[0] = 7;
26.353 - t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
26.354 - if (t != Z_OK){
26.355 - r = t;
26.356 - if (r == Z_DATA_ERROR){
26.357 - blens=null;
26.358 - mode = BAD;
26.359 - }
26.360 -
26.361 - bitb=b; bitk=k;
26.362 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.363 - write=q;
26.364 - return inflate_flush(r);
26.365 - }
26.366 -
26.367 - index = 0;
26.368 - mode = DTREE;
26.369 - case DTREE:
26.370 - while (true){
26.371 - t = table;
26.372 - if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
26.373 - break;
26.374 - }
26.375 -
26.376 - int[] h;
26.377 - int i, j, c;
26.378 -
26.379 - t = bb[0];
26.380 -
26.381 - while(k<(t)){
26.382 - if(n!=0){
26.383 - r=Z_OK;
26.384 - }
26.385 - else{
26.386 - bitb=b; bitk=k;
26.387 - z.avail_in=n;
26.388 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.389 - write=q;
26.390 - return inflate_flush(r);
26.391 - };
26.392 - n--;
26.393 - b|=(z.next_in[p++]&0xff)<<k;
26.394 - k+=8;
26.395 - }
26.396 -
26.397 - if(tb[0]==-1){
26.398 - //System.err.println("null...");
26.399 - }
26.400 -
26.401 - t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
26.402 - c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
26.403 -
26.404 - if (c < 16){
26.405 - b>>>=(t);k-=(t);
26.406 - blens[index++] = c;
26.407 - }
26.408 - else { // c == 16..18
26.409 - i = c == 18 ? 7 : c - 14;
26.410 - j = c == 18 ? 11 : 3;
26.411 -
26.412 - while(k<(t+i)){
26.413 - if(n!=0){
26.414 - r=Z_OK;
26.415 - }
26.416 - else{
26.417 - bitb=b; bitk=k;
26.418 - z.avail_in=n;
26.419 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.420 - write=q;
26.421 - return inflate_flush(r);
26.422 - };
26.423 - n--;
26.424 - b|=(z.next_in[p++]&0xff)<<k;
26.425 - k+=8;
26.426 - }
26.427 -
26.428 - b>>>=(t);k-=(t);
26.429 -
26.430 - j += (b & inflate_mask[i]);
26.431 -
26.432 - b>>>=(i);k-=(i);
26.433 -
26.434 - i = index;
26.435 - t = table;
26.436 - if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
26.437 - (c == 16 && i < 1)){
26.438 - blens=null;
26.439 - mode = BAD;
26.440 - z.msg = "invalid bit length repeat";
26.441 - r = Z_DATA_ERROR;
26.442 -
26.443 - bitb=b; bitk=k;
26.444 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.445 - write=q;
26.446 - return inflate_flush(r);
26.447 - }
26.448 -
26.449 - c = c == 16 ? blens[i-1] : 0;
26.450 - do{
26.451 - blens[i++] = c;
26.452 - }
26.453 - while (--j!=0);
26.454 - index = i;
26.455 - }
26.456 - }
26.457 -
26.458 - tb[0]=-1;
26.459 - {
26.460 - bl[0] = 9; // must be <= 9 for lookahead assumptions
26.461 - bd[0] = 6; // must be <= 9 for lookahead assumptions
26.462 - t = table;
26.463 - t = inftree.inflate_trees_dynamic(257 + (t & 0x1f),
26.464 - 1 + ((t >> 5) & 0x1f),
26.465 - blens, bl, bd, tli, tdi, hufts, z);
26.466 -
26.467 - if (t != Z_OK){
26.468 - if (t == Z_DATA_ERROR){
26.469 - blens=null;
26.470 - mode = BAD;
26.471 - }
26.472 - r = t;
26.473 -
26.474 - bitb=b; bitk=k;
26.475 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.476 - write=q;
26.477 - return inflate_flush(r);
26.478 - }
26.479 - codes.init(bl[0], bd[0], hufts, tli[0], hufts, tdi[0]);
26.480 - }
26.481 - mode = CODES;
26.482 - case CODES:
26.483 - bitb=b; bitk=k;
26.484 - z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.485 - write=q;
26.486 -
26.487 - if ((r = codes.proc(r)) != Z_STREAM_END){
26.488 - return inflate_flush(r);
26.489 - }
26.490 - r = Z_OK;
26.491 - codes.free(z);
26.492 -
26.493 - p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
26.494 - q=write;m=(int)(q<read?read-q-1:end-q);
26.495 -
26.496 - if (last==0){
26.497 - mode = TYPE;
26.498 - break;
26.499 - }
26.500 - mode = DRY;
26.501 - case DRY:
26.502 - write=q;
26.503 - r=inflate_flush(r);
26.504 - q=write; m=(int)(q<read?read-q-1:end-q);
26.505 - if (read != write){
26.506 - bitb=b; bitk=k;
26.507 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.508 - write=q;
26.509 - return inflate_flush(r);
26.510 - }
26.511 - mode = DONE;
26.512 - case DONE:
26.513 - r = Z_STREAM_END;
26.514 -
26.515 - bitb=b; bitk=k;
26.516 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.517 - write=q;
26.518 - return inflate_flush(r);
26.519 - case BAD:
26.520 - r = Z_DATA_ERROR;
26.521 -
26.522 - bitb=b; bitk=k;
26.523 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.524 - write=q;
26.525 - return inflate_flush(r);
26.526 -
26.527 - default:
26.528 - r = Z_STREAM_ERROR;
26.529 -
26.530 - bitb=b; bitk=k;
26.531 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
26.532 - write=q;
26.533 - return inflate_flush(r);
26.534 - }
26.535 - }
26.536 - }
26.537 -
26.538 - void free(){
26.539 - reset();
26.540 - window=null;
26.541 - hufts=null;
26.542 - //ZFREE(z, s);
26.543 - }
26.544 -
26.545 - void set_dictionary(byte[] d, int start, int n){
26.546 - System.arraycopy(d, start, window, 0, n);
26.547 - read = write = n;
26.548 - }
26.549 -
26.550 - // Returns true if inflate is currently at the end of a block generated
26.551 - // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
26.552 - int sync_point(){
26.553 - return mode == LENS ? 1 : 0;
26.554 - }
26.555 -
26.556 - // copy as much as possible from the sliding window to the output area
26.557 - int inflate_flush(int r){
26.558 - int n;
26.559 - int p;
26.560 - int q;
26.561 -
26.562 - // local copies of source and destination pointers
26.563 - p = z.next_out_index;
26.564 - q = read;
26.565 -
26.566 - // compute number of bytes to copy as far as end of window
26.567 - n = (int)((q <= write ? write : end) - q);
26.568 - if(n > z.avail_out) n = z.avail_out;
26.569 - if(n!=0 && r == Z_BUF_ERROR) r = Z_OK;
26.570 -
26.571 - // update counters
26.572 - z.avail_out -= n;
26.573 - z.total_out += n;
26.574 -
26.575 - // update check information
26.576 - if(check && n>0){
26.577 - z.adler.update(window, q, n);
26.578 - }
26.579 -
26.580 - // copy as far as end of window
26.581 - System.arraycopy(window, q, z.next_out, p, n);
26.582 - p += n;
26.583 - q += n;
26.584 -
26.585 - // see if more to copy at beginning of window
26.586 - if (q == end){
26.587 - // wrap pointers
26.588 - q = 0;
26.589 - if (write == end)
26.590 - write = 0;
26.591 -
26.592 - // compute bytes to copy
26.593 - n = write - q;
26.594 - if (n > z.avail_out) n = z.avail_out;
26.595 - if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
26.596 -
26.597 - // update counters
26.598 - z.avail_out -= n;
26.599 - z.total_out += n;
26.600 -
26.601 - // update check information
26.602 - if(check && n>0){
26.603 - z.adler.update(window, q, n);
26.604 - }
26.605 -
26.606 - // copy
26.607 - System.arraycopy(window, q, z.next_out, p, n);
26.608 - p += n;
26.609 - q += n;
26.610 - }
26.611 -
26.612 - // update pointers
26.613 - z.next_out_index = p;
26.614 - read = q;
26.615 -
26.616 - // done
26.617 - return r;
26.618 - }
26.619 -}
27.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java Wed May 07 11:55:06 2014 +0200
27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
27.3 @@ -1,612 +0,0 @@
27.4 -/* -*-mode:java; c-basic-offset:2; -*- */
27.5 -/*
27.6 -Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
27.7 -
27.8 -Redistribution and use in source and binary forms, with or without
27.9 -modification, are permitted provided that the following conditions are met:
27.10 -
27.11 - 1. Redistributions of source code must retain the above copyright notice,
27.12 - this list of conditions and the following disclaimer.
27.13 -
27.14 - 2. Redistributions in binary form must reproduce the above copyright
27.15 - notice, this list of conditions and the following disclaimer in
27.16 - the documentation and/or other materials provided with the distribution.
27.17 -
27.18 - 3. The names of the authors may not be used to endorse or promote products
27.19 - derived from this software without specific prior written permission.
27.20 -
27.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
27.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
27.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
27.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
27.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.31 - */
27.32 -/*
27.33 - * This program is based on zlib-1.1.3, so all credit should go authors
27.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
27.35 - * and contributors of zlib.
27.36 - */
27.37 -
27.38 -package org.apidesign.bck2brwsr.emul.zip;
27.39 -
27.40 -import org.apidesign.bck2brwsr.emul.lang.System;
27.41 -
27.42 -final class InfCodes{
27.43 -
27.44 - static final private int[] inflate_mask = {
27.45 - 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
27.46 - 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
27.47 - 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
27.48 - 0x00007fff, 0x0000ffff
27.49 - };
27.50 -
27.51 - static final private int Z_OK=0;
27.52 - static final private int Z_STREAM_END=1;
27.53 - static final private int Z_NEED_DICT=2;
27.54 - static final private int Z_ERRNO=-1;
27.55 - static final private int Z_STREAM_ERROR=-2;
27.56 - static final private int Z_DATA_ERROR=-3;
27.57 - static final private int Z_MEM_ERROR=-4;
27.58 - static final private int Z_BUF_ERROR=-5;
27.59 - static final private int Z_VERSION_ERROR=-6;
27.60 -
27.61 - // waiting for "i:"=input,
27.62 - // "o:"=output,
27.63 - // "x:"=nothing
27.64 - static final private int START=0; // x: set up for LEN
27.65 - static final private int LEN=1; // i: get length/literal/eob next
27.66 - static final private int LENEXT=2; // i: getting length extra (have base)
27.67 - static final private int DIST=3; // i: get distance next
27.68 - static final private int DISTEXT=4;// i: getting distance extra
27.69 - static final private int COPY=5; // o: copying bytes in window, waiting for space
27.70 - static final private int LIT=6; // o: got literal, waiting for output space
27.71 - static final private int WASH=7; // o: got eob, possibly still output waiting
27.72 - static final private int END=8; // x: got eob and all data flushed
27.73 - static final private int BADCODE=9;// x: got error
27.74 -
27.75 - int mode; // current inflate_codes mode
27.76 -
27.77 - // mode dependent information
27.78 - int len;
27.79 -
27.80 - int[] tree; // pointer into tree
27.81 - int tree_index=0;
27.82 - int need; // bits needed
27.83 -
27.84 - int lit;
27.85 -
27.86 - // if EXT or COPY, where and how much
27.87 - int get; // bits to get for extra
27.88 - int dist; // distance back to copy from
27.89 -
27.90 - byte lbits; // ltree bits decoded per branch
27.91 - byte dbits; // dtree bits decoder per branch
27.92 - int[] ltree; // literal/length/eob tree
27.93 - int ltree_index; // literal/length/eob tree
27.94 - int[] dtree; // distance tree
27.95 - int dtree_index; // distance tree
27.96 -
27.97 - private final ZStream z;
27.98 - private final InfBlocks s;
27.99 - InfCodes(ZStream z, InfBlocks s){
27.100 - this.z=z;
27.101 - this.s=s;
27.102 - }
27.103 -
27.104 - void init(int bl, int bd,
27.105 - int[] tl, int tl_index,
27.106 - int[] td, int td_index){
27.107 - mode=START;
27.108 - lbits=(byte)bl;
27.109 - dbits=(byte)bd;
27.110 - ltree=tl;
27.111 - ltree_index=tl_index;
27.112 - dtree = td;
27.113 - dtree_index=td_index;
27.114 - tree=null;
27.115 - }
27.116 -
27.117 - int proc(int r){
27.118 - int j; // temporary storage
27.119 - int[] t; // temporary pointer
27.120 - int tindex; // temporary pointer
27.121 - int e; // extra bits or operation
27.122 - int b=0; // bit buffer
27.123 - int k=0; // bits in bit buffer
27.124 - int p=0; // input data pointer
27.125 - int n; // bytes available there
27.126 - int q; // output window write pointer
27.127 - int m; // bytes to end of window or read pointer
27.128 - int f; // pointer to copy strings from
27.129 -
27.130 - // copy input/output information to locals (UPDATE macro restores)
27.131 - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
27.132 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
27.133 -
27.134 - // process input and output based on current state
27.135 - while (true){
27.136 - switch (mode){
27.137 - // waiting for "i:"=input, "o:"=output, "x:"=nothing
27.138 - case START: // x: set up for LEN
27.139 - if (m >= 258 && n >= 10){
27.140 -
27.141 - s.bitb=b;s.bitk=k;
27.142 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.143 - s.write=q;
27.144 - r = inflate_fast(lbits, dbits,
27.145 - ltree, ltree_index,
27.146 - dtree, dtree_index,
27.147 - s, z);
27.148 -
27.149 - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
27.150 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
27.151 -
27.152 - if (r != Z_OK){
27.153 - mode = r == Z_STREAM_END ? WASH : BADCODE;
27.154 - break;
27.155 - }
27.156 - }
27.157 - need = lbits;
27.158 - tree = ltree;
27.159 - tree_index=ltree_index;
27.160 -
27.161 - mode = LEN;
27.162 - case LEN: // i: get length/literal/eob next
27.163 - j = need;
27.164 -
27.165 - while(k<(j)){
27.166 - if(n!=0)r=Z_OK;
27.167 - else{
27.168 -
27.169 - s.bitb=b;s.bitk=k;
27.170 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.171 - s.write=q;
27.172 - return s.inflate_flush(r);
27.173 - }
27.174 - n--;
27.175 - b|=(z.next_in[p++]&0xff)<<k;
27.176 - k+=8;
27.177 - }
27.178 -
27.179 - tindex=(tree_index+(b&inflate_mask[j]))*3;
27.180 -
27.181 - b>>>=(tree[tindex+1]);
27.182 - k-=(tree[tindex+1]);
27.183 -
27.184 - e=tree[tindex];
27.185 -
27.186 - if(e == 0){ // literal
27.187 - lit = tree[tindex+2];
27.188 - mode = LIT;
27.189 - break;
27.190 - }
27.191 - if((e & 16)!=0 ){ // length
27.192 - get = e & 15;
27.193 - len = tree[tindex+2];
27.194 - mode = LENEXT;
27.195 - break;
27.196 - }
27.197 - if ((e & 64) == 0){ // next table
27.198 - need = e;
27.199 - tree_index = tindex/3+tree[tindex+2];
27.200 - break;
27.201 - }
27.202 - if ((e & 32)!=0){ // end of block
27.203 - mode = WASH;
27.204 - break;
27.205 - }
27.206 - mode = BADCODE; // invalid code
27.207 - z.msg = "invalid literal/length code";
27.208 - r = Z_DATA_ERROR;
27.209 -
27.210 - s.bitb=b;s.bitk=k;
27.211 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.212 - s.write=q;
27.213 - return s.inflate_flush(r);
27.214 -
27.215 - case LENEXT: // i: getting length extra (have base)
27.216 - j = get;
27.217 -
27.218 - while(k<(j)){
27.219 - if(n!=0)r=Z_OK;
27.220 - else{
27.221 -
27.222 - s.bitb=b;s.bitk=k;
27.223 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.224 - s.write=q;
27.225 - return s.inflate_flush(r);
27.226 - }
27.227 - n--; b|=(z.next_in[p++]&0xff)<<k;
27.228 - k+=8;
27.229 - }
27.230 -
27.231 - len += (b & inflate_mask[j]);
27.232 -
27.233 - b>>=j;
27.234 - k-=j;
27.235 -
27.236 - need = dbits;
27.237 - tree = dtree;
27.238 - tree_index=dtree_index;
27.239 - mode = DIST;
27.240 - case DIST: // i: get distance next
27.241 - j = need;
27.242 -
27.243 - while(k<(j)){
27.244 - if(n!=0)r=Z_OK;
27.245 - else{
27.246 -
27.247 - s.bitb=b;s.bitk=k;
27.248 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.249 - s.write=q;
27.250 - return s.inflate_flush(r);
27.251 - }
27.252 - n--; b|=(z.next_in[p++]&0xff)<<k;
27.253 - k+=8;
27.254 - }
27.255 -
27.256 - tindex=(tree_index+(b & inflate_mask[j]))*3;
27.257 -
27.258 - b>>=tree[tindex+1];
27.259 - k-=tree[tindex+1];
27.260 -
27.261 - e = (tree[tindex]);
27.262 - if((e & 16)!=0){ // distance
27.263 - get = e & 15;
27.264 - dist = tree[tindex+2];
27.265 - mode = DISTEXT;
27.266 - break;
27.267 - }
27.268 - if ((e & 64) == 0){ // next table
27.269 - need = e;
27.270 - tree_index = tindex/3 + tree[tindex+2];
27.271 - break;
27.272 - }
27.273 - mode = BADCODE; // invalid code
27.274 - z.msg = "invalid distance code";
27.275 - r = Z_DATA_ERROR;
27.276 -
27.277 - s.bitb=b;s.bitk=k;
27.278 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.279 - s.write=q;
27.280 - return s.inflate_flush(r);
27.281 -
27.282 - case DISTEXT: // i: getting distance extra
27.283 - j = get;
27.284 -
27.285 - while(k<(j)){
27.286 - if(n!=0)r=Z_OK;
27.287 - else{
27.288 -
27.289 - s.bitb=b;s.bitk=k;
27.290 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.291 - s.write=q;
27.292 - return s.inflate_flush(r);
27.293 - }
27.294 - n--; b|=(z.next_in[p++]&0xff)<<k;
27.295 - k+=8;
27.296 - }
27.297 -
27.298 - dist += (b & inflate_mask[j]);
27.299 -
27.300 - b>>=j;
27.301 - k-=j;
27.302 -
27.303 - mode = COPY;
27.304 - case COPY: // o: copying bytes in window, waiting for space
27.305 - f = q - dist;
27.306 - while(f < 0){ // modulo window size-"while" instead
27.307 - f += s.end; // of "if" handles invalid distances
27.308 - }
27.309 - while (len!=0){
27.310 -
27.311 - if(m==0){
27.312 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
27.313 - if(m==0){
27.314 - s.write=q; r=s.inflate_flush(r);
27.315 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
27.316 -
27.317 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
27.318 -
27.319 - if(m==0){
27.320 - s.bitb=b;s.bitk=k;
27.321 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.322 - s.write=q;
27.323 - return s.inflate_flush(r);
27.324 - }
27.325 - }
27.326 - }
27.327 -
27.328 - s.window[q++]=s.window[f++]; m--;
27.329 -
27.330 - if (f == s.end)
27.331 - f = 0;
27.332 - len--;
27.333 - }
27.334 - mode = START;
27.335 - break;
27.336 - case LIT: // o: got literal, waiting for output space
27.337 - if(m==0){
27.338 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
27.339 - if(m==0){
27.340 - s.write=q; r=s.inflate_flush(r);
27.341 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
27.342 -
27.343 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
27.344 - if(m==0){
27.345 - s.bitb=b;s.bitk=k;
27.346 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.347 - s.write=q;
27.348 - return s.inflate_flush(r);
27.349 - }
27.350 - }
27.351 - }
27.352 - r=Z_OK;
27.353 -
27.354 - s.window[q++]=(byte)lit; m--;
27.355 -
27.356 - mode = START;
27.357 - break;
27.358 - case WASH: // o: got eob, possibly more output
27.359 - if (k > 7){ // return unused byte, if any
27.360 - k -= 8;
27.361 - n++;
27.362 - p--; // can always return one
27.363 - }
27.364 -
27.365 - s.write=q; r=s.inflate_flush(r);
27.366 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
27.367 -
27.368 - if (s.read != s.write){
27.369 - s.bitb=b;s.bitk=k;
27.370 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.371 - s.write=q;
27.372 - return s.inflate_flush(r);
27.373 - }
27.374 - mode = END;
27.375 - case END:
27.376 - r = Z_STREAM_END;
27.377 - s.bitb=b;s.bitk=k;
27.378 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.379 - s.write=q;
27.380 - return s.inflate_flush(r);
27.381 -
27.382 - case BADCODE: // x: got error
27.383 -
27.384 - r = Z_DATA_ERROR;
27.385 -
27.386 - s.bitb=b;s.bitk=k;
27.387 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.388 - s.write=q;
27.389 - return s.inflate_flush(r);
27.390 -
27.391 - default:
27.392 - r = Z_STREAM_ERROR;
27.393 -
27.394 - s.bitb=b;s.bitk=k;
27.395 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.396 - s.write=q;
27.397 - return s.inflate_flush(r);
27.398 - }
27.399 - }
27.400 - }
27.401 -
27.402 - void free(ZStream z){
27.403 - // ZFREE(z, c);
27.404 - }
27.405 -
27.406 - // Called with number of bytes left to write in window at least 258
27.407 - // (the maximum string length) and number of input bytes available
27.408 - // at least ten. The ten bytes are six bytes for the longest length/
27.409 - // distance pair plus four bytes for overloading the bit buffer.
27.410 -
27.411 - int inflate_fast(int bl, int bd,
27.412 - int[] tl, int tl_index,
27.413 - int[] td, int td_index,
27.414 - InfBlocks s, ZStream z){
27.415 - int t; // temporary pointer
27.416 - int[] tp; // temporary pointer
27.417 - int tp_index; // temporary pointer
27.418 - int e; // extra bits or operation
27.419 - int b; // bit buffer
27.420 - int k; // bits in bit buffer
27.421 - int p; // input data pointer
27.422 - int n; // bytes available there
27.423 - int q; // output window write pointer
27.424 - int m; // bytes to end of window or read pointer
27.425 - int ml; // mask for literal/length tree
27.426 - int md; // mask for distance tree
27.427 - int c; // bytes to copy
27.428 - int d; // distance back to copy from
27.429 - int r; // copy source pointer
27.430 -
27.431 - int tp_index_t_3; // (tp_index+t)*3
27.432 -
27.433 - // load input, output, bit values
27.434 - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
27.435 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
27.436 -
27.437 - // initialize masks
27.438 - ml = inflate_mask[bl];
27.439 - md = inflate_mask[bd];
27.440 -
27.441 - // do until not enough input or output space for fast loop
27.442 - do { // assume called with m >= 258 && n >= 10
27.443 - // get literal/length code
27.444 - while(k<(20)){ // max bits for literal/length code
27.445 - n--;
27.446 - b|=(z.next_in[p++]&0xff)<<k;k+=8;
27.447 - }
27.448 -
27.449 - t= b&ml;
27.450 - tp=tl;
27.451 - tp_index=tl_index;
27.452 - tp_index_t_3=(tp_index+t)*3;
27.453 - if ((e = tp[tp_index_t_3]) == 0){
27.454 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
27.455 -
27.456 - s.window[q++] = (byte)tp[tp_index_t_3+2];
27.457 - m--;
27.458 - continue;
27.459 - }
27.460 - do {
27.461 -
27.462 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
27.463 -
27.464 - if((e&16)!=0){
27.465 - e &= 15;
27.466 - c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
27.467 -
27.468 - b>>=e; k-=e;
27.469 -
27.470 - // decode distance base of block to copy
27.471 - while(k<(15)){ // max bits for distance code
27.472 - n--;
27.473 - b|=(z.next_in[p++]&0xff)<<k;k+=8;
27.474 - }
27.475 -
27.476 - t= b&md;
27.477 - tp=td;
27.478 - tp_index=td_index;
27.479 - tp_index_t_3=(tp_index+t)*3;
27.480 - e = tp[tp_index_t_3];
27.481 -
27.482 - do {
27.483 -
27.484 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
27.485 -
27.486 - if((e&16)!=0){
27.487 - // get extra bits to add to distance base
27.488 - e &= 15;
27.489 - while(k<(e)){ // get extra bits (up to 13)
27.490 - n--;
27.491 - b|=(z.next_in[p++]&0xff)<<k;k+=8;
27.492 - }
27.493 -
27.494 - d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
27.495 -
27.496 - b>>=(e); k-=(e);
27.497 -
27.498 - // do the copy
27.499 - m -= c;
27.500 - if (q >= d){ // offset before dest
27.501 - // just copy
27.502 - r=q-d;
27.503 - if(q-r>0 && 2>(q-r)){
27.504 - s.window[q++]=s.window[r++]; // minimum count is three,
27.505 - s.window[q++]=s.window[r++]; // so unroll loop a little
27.506 - c-=2;
27.507 - }
27.508 - else{
27.509 - System.arraycopy(s.window, r, s.window, q, 2);
27.510 - q+=2; r+=2; c-=2;
27.511 - }
27.512 - }
27.513 - else{ // else offset after destination
27.514 - r=q-d;
27.515 - do{
27.516 - r+=s.end; // force pointer in window
27.517 - }while(r<0); // covers invalid distances
27.518 - e=s.end-r;
27.519 - if(c>e){ // if source crosses,
27.520 - c-=e; // wrapped copy
27.521 - if(q-r>0 && e>(q-r)){
27.522 - do{s.window[q++] = s.window[r++];}
27.523 - while(--e!=0);
27.524 - }
27.525 - else{
27.526 - System.arraycopy(s.window, r, s.window, q, e);
27.527 - q+=e; r+=e; e=0;
27.528 - }
27.529 - r = 0; // copy rest from start of window
27.530 - }
27.531 -
27.532 - }
27.533 -
27.534 - // copy all or what's left
27.535 - if(q-r>0 && c>(q-r)){
27.536 - do{s.window[q++] = s.window[r++];}
27.537 - while(--c!=0);
27.538 - }
27.539 - else{
27.540 - System.arraycopy(s.window, r, s.window, q, c);
27.541 - q+=c; r+=c; c=0;
27.542 - }
27.543 - break;
27.544 - }
27.545 - else if((e&64)==0){
27.546 - t+=tp[tp_index_t_3+2];
27.547 - t+=(b&inflate_mask[e]);
27.548 - tp_index_t_3=(tp_index+t)*3;
27.549 - e=tp[tp_index_t_3];
27.550 - }
27.551 - else{
27.552 - z.msg = "invalid distance code";
27.553 -
27.554 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
27.555 -
27.556 - s.bitb=b;s.bitk=k;
27.557 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.558 - s.write=q;
27.559 -
27.560 - return Z_DATA_ERROR;
27.561 - }
27.562 - }
27.563 - while(true);
27.564 - break;
27.565 - }
27.566 -
27.567 - if((e&64)==0){
27.568 - t+=tp[tp_index_t_3+2];
27.569 - t+=(b&inflate_mask[e]);
27.570 - tp_index_t_3=(tp_index+t)*3;
27.571 - if((e=tp[tp_index_t_3])==0){
27.572 -
27.573 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
27.574 -
27.575 - s.window[q++]=(byte)tp[tp_index_t_3+2];
27.576 - m--;
27.577 - break;
27.578 - }
27.579 - }
27.580 - else if((e&32)!=0){
27.581 -
27.582 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
27.583 -
27.584 - s.bitb=b;s.bitk=k;
27.585 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.586 - s.write=q;
27.587 -
27.588 - return Z_STREAM_END;
27.589 - }
27.590 - else{
27.591 - z.msg="invalid literal/length code";
27.592 -
27.593 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
27.594 -
27.595 - s.bitb=b;s.bitk=k;
27.596 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.597 - s.write=q;
27.598 -
27.599 - return Z_DATA_ERROR;
27.600 - }
27.601 - }
27.602 - while(true);
27.603 - }
27.604 - while(m>=258 && n>= 10);
27.605 -
27.606 - // not enough input or output--restore pointers and return
27.607 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
27.608 -
27.609 - s.bitb=b;s.bitk=k;
27.610 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
27.611 - s.write=q;
27.612 -
27.613 - return Z_OK;
27.614 - }
27.615 -}
28.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java Wed May 07 11:55:06 2014 +0200
28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
28.3 @@ -1,520 +0,0 @@
28.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
28.5 -/*
28.6 -Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
28.7 -
28.8 -Redistribution and use in source and binary forms, with or without
28.9 -modification, are permitted provided that the following conditions are met:
28.10 -
28.11 - 1. Redistributions of source code must retain the above copyright notice,
28.12 - this list of conditions and the following disclaimer.
28.13 -
28.14 - 2. Redistributions in binary form must reproduce the above copyright
28.15 - notice, this list of conditions and the following disclaimer in
28.16 - the documentation and/or other materials provided with the distribution.
28.17 -
28.18 - 3. The names of the authors may not be used to endorse or promote products
28.19 - derived from this software without specific prior written permission.
28.20 -
28.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
28.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
28.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.31 - */
28.32 -/*
28.33 - * This program is based on zlib-1.1.3, so all credit should go authors
28.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
28.35 - * and contributors of zlib.
28.36 - */
28.37 -
28.38 -package org.apidesign.bck2brwsr.emul.zip;
28.39 -
28.40 -import org.apidesign.bck2brwsr.emul.lang.System;
28.41 -
28.42 -final class InfTree{
28.43 -
28.44 - static final private int MANY=1440;
28.45 -
28.46 - static final private int Z_OK=0;
28.47 - static final private int Z_STREAM_END=1;
28.48 - static final private int Z_NEED_DICT=2;
28.49 - static final private int Z_ERRNO=-1;
28.50 - static final private int Z_STREAM_ERROR=-2;
28.51 - static final private int Z_DATA_ERROR=-3;
28.52 - static final private int Z_MEM_ERROR=-4;
28.53 - static final private int Z_BUF_ERROR=-5;
28.54 - static final private int Z_VERSION_ERROR=-6;
28.55 -
28.56 - static final int fixed_bl = 9;
28.57 - static final int fixed_bd = 5;
28.58 -
28.59 - static final int[] fixed_tl = {
28.60 - 96,7,256, 0,8,80, 0,8,16, 84,8,115,
28.61 - 82,7,31, 0,8,112, 0,8,48, 0,9,192,
28.62 - 80,7,10, 0,8,96, 0,8,32, 0,9,160,
28.63 - 0,8,0, 0,8,128, 0,8,64, 0,9,224,
28.64 - 80,7,6, 0,8,88, 0,8,24, 0,9,144,
28.65 - 83,7,59, 0,8,120, 0,8,56, 0,9,208,
28.66 - 81,7,17, 0,8,104, 0,8,40, 0,9,176,
28.67 - 0,8,8, 0,8,136, 0,8,72, 0,9,240,
28.68 - 80,7,4, 0,8,84, 0,8,20, 85,8,227,
28.69 - 83,7,43, 0,8,116, 0,8,52, 0,9,200,
28.70 - 81,7,13, 0,8,100, 0,8,36, 0,9,168,
28.71 - 0,8,4, 0,8,132, 0,8,68, 0,9,232,
28.72 - 80,7,8, 0,8,92, 0,8,28, 0,9,152,
28.73 - 84,7,83, 0,8,124, 0,8,60, 0,9,216,
28.74 - 82,7,23, 0,8,108, 0,8,44, 0,9,184,
28.75 - 0,8,12, 0,8,140, 0,8,76, 0,9,248,
28.76 - 80,7,3, 0,8,82, 0,8,18, 85,8,163,
28.77 - 83,7,35, 0,8,114, 0,8,50, 0,9,196,
28.78 - 81,7,11, 0,8,98, 0,8,34, 0,9,164,
28.79 - 0,8,2, 0,8,130, 0,8,66, 0,9,228,
28.80 - 80,7,7, 0,8,90, 0,8,26, 0,9,148,
28.81 - 84,7,67, 0,8,122, 0,8,58, 0,9,212,
28.82 - 82,7,19, 0,8,106, 0,8,42, 0,9,180,
28.83 - 0,8,10, 0,8,138, 0,8,74, 0,9,244,
28.84 - 80,7,5, 0,8,86, 0,8,22, 192,8,0,
28.85 - 83,7,51, 0,8,118, 0,8,54, 0,9,204,
28.86 - 81,7,15, 0,8,102, 0,8,38, 0,9,172,
28.87 - 0,8,6, 0,8,134, 0,8,70, 0,9,236,
28.88 - 80,7,9, 0,8,94, 0,8,30, 0,9,156,
28.89 - 84,7,99, 0,8,126, 0,8,62, 0,9,220,
28.90 - 82,7,27, 0,8,110, 0,8,46, 0,9,188,
28.91 - 0,8,14, 0,8,142, 0,8,78, 0,9,252,
28.92 - 96,7,256, 0,8,81, 0,8,17, 85,8,131,
28.93 - 82,7,31, 0,8,113, 0,8,49, 0,9,194,
28.94 - 80,7,10, 0,8,97, 0,8,33, 0,9,162,
28.95 - 0,8,1, 0,8,129, 0,8,65, 0,9,226,
28.96 - 80,7,6, 0,8,89, 0,8,25, 0,9,146,
28.97 - 83,7,59, 0,8,121, 0,8,57, 0,9,210,
28.98 - 81,7,17, 0,8,105, 0,8,41, 0,9,178,
28.99 - 0,8,9, 0,8,137, 0,8,73, 0,9,242,
28.100 - 80,7,4, 0,8,85, 0,8,21, 80,8,258,
28.101 - 83,7,43, 0,8,117, 0,8,53, 0,9,202,
28.102 - 81,7,13, 0,8,101, 0,8,37, 0,9,170,
28.103 - 0,8,5, 0,8,133, 0,8,69, 0,9,234,
28.104 - 80,7,8, 0,8,93, 0,8,29, 0,9,154,
28.105 - 84,7,83, 0,8,125, 0,8,61, 0,9,218,
28.106 - 82,7,23, 0,8,109, 0,8,45, 0,9,186,
28.107 - 0,8,13, 0,8,141, 0,8,77, 0,9,250,
28.108 - 80,7,3, 0,8,83, 0,8,19, 85,8,195,
28.109 - 83,7,35, 0,8,115, 0,8,51, 0,9,198,
28.110 - 81,7,11, 0,8,99, 0,8,35, 0,9,166,
28.111 - 0,8,3, 0,8,131, 0,8,67, 0,9,230,
28.112 - 80,7,7, 0,8,91, 0,8,27, 0,9,150,
28.113 - 84,7,67, 0,8,123, 0,8,59, 0,9,214,
28.114 - 82,7,19, 0,8,107, 0,8,43, 0,9,182,
28.115 - 0,8,11, 0,8,139, 0,8,75, 0,9,246,
28.116 - 80,7,5, 0,8,87, 0,8,23, 192,8,0,
28.117 - 83,7,51, 0,8,119, 0,8,55, 0,9,206,
28.118 - 81,7,15, 0,8,103, 0,8,39, 0,9,174,
28.119 - 0,8,7, 0,8,135, 0,8,71, 0,9,238,
28.120 - 80,7,9, 0,8,95, 0,8,31, 0,9,158,
28.121 - 84,7,99, 0,8,127, 0,8,63, 0,9,222,
28.122 - 82,7,27, 0,8,111, 0,8,47, 0,9,190,
28.123 - 0,8,15, 0,8,143, 0,8,79, 0,9,254,
28.124 - 96,7,256, 0,8,80, 0,8,16, 84,8,115,
28.125 - 82,7,31, 0,8,112, 0,8,48, 0,9,193,
28.126 -
28.127 - 80,7,10, 0,8,96, 0,8,32, 0,9,161,
28.128 - 0,8,0, 0,8,128, 0,8,64, 0,9,225,
28.129 - 80,7,6, 0,8,88, 0,8,24, 0,9,145,
28.130 - 83,7,59, 0,8,120, 0,8,56, 0,9,209,
28.131 - 81,7,17, 0,8,104, 0,8,40, 0,9,177,
28.132 - 0,8,8, 0,8,136, 0,8,72, 0,9,241,
28.133 - 80,7,4, 0,8,84, 0,8,20, 85,8,227,
28.134 - 83,7,43, 0,8,116, 0,8,52, 0,9,201,
28.135 - 81,7,13, 0,8,100, 0,8,36, 0,9,169,
28.136 - 0,8,4, 0,8,132, 0,8,68, 0,9,233,
28.137 - 80,7,8, 0,8,92, 0,8,28, 0,9,153,
28.138 - 84,7,83, 0,8,124, 0,8,60, 0,9,217,
28.139 - 82,7,23, 0,8,108, 0,8,44, 0,9,185,
28.140 - 0,8,12, 0,8,140, 0,8,76, 0,9,249,
28.141 - 80,7,3, 0,8,82, 0,8,18, 85,8,163,
28.142 - 83,7,35, 0,8,114, 0,8,50, 0,9,197,
28.143 - 81,7,11, 0,8,98, 0,8,34, 0,9,165,
28.144 - 0,8,2, 0,8,130, 0,8,66, 0,9,229,
28.145 - 80,7,7, 0,8,90, 0,8,26, 0,9,149,
28.146 - 84,7,67, 0,8,122, 0,8,58, 0,9,213,
28.147 - 82,7,19, 0,8,106, 0,8,42, 0,9,181,
28.148 - 0,8,10, 0,8,138, 0,8,74, 0,9,245,
28.149 - 80,7,5, 0,8,86, 0,8,22, 192,8,0,
28.150 - 83,7,51, 0,8,118, 0,8,54, 0,9,205,
28.151 - 81,7,15, 0,8,102, 0,8,38, 0,9,173,
28.152 - 0,8,6, 0,8,134, 0,8,70, 0,9,237,
28.153 - 80,7,9, 0,8,94, 0,8,30, 0,9,157,
28.154 - 84,7,99, 0,8,126, 0,8,62, 0,9,221,
28.155 - 82,7,27, 0,8,110, 0,8,46, 0,9,189,
28.156 - 0,8,14, 0,8,142, 0,8,78, 0,9,253,
28.157 - 96,7,256, 0,8,81, 0,8,17, 85,8,131,
28.158 - 82,7,31, 0,8,113, 0,8,49, 0,9,195,
28.159 - 80,7,10, 0,8,97, 0,8,33, 0,9,163,
28.160 - 0,8,1, 0,8,129, 0,8,65, 0,9,227,
28.161 - 80,7,6, 0,8,89, 0,8,25, 0,9,147,
28.162 - 83,7,59, 0,8,121, 0,8,57, 0,9,211,
28.163 - 81,7,17, 0,8,105, 0,8,41, 0,9,179,
28.164 - 0,8,9, 0,8,137, 0,8,73, 0,9,243,
28.165 - 80,7,4, 0,8,85, 0,8,21, 80,8,258,
28.166 - 83,7,43, 0,8,117, 0,8,53, 0,9,203,
28.167 - 81,7,13, 0,8,101, 0,8,37, 0,9,171,
28.168 - 0,8,5, 0,8,133, 0,8,69, 0,9,235,
28.169 - 80,7,8, 0,8,93, 0,8,29, 0,9,155,
28.170 - 84,7,83, 0,8,125, 0,8,61, 0,9,219,
28.171 - 82,7,23, 0,8,109, 0,8,45, 0,9,187,
28.172 - 0,8,13, 0,8,141, 0,8,77, 0,9,251,
28.173 - 80,7,3, 0,8,83, 0,8,19, 85,8,195,
28.174 - 83,7,35, 0,8,115, 0,8,51, 0,9,199,
28.175 - 81,7,11, 0,8,99, 0,8,35, 0,9,167,
28.176 - 0,8,3, 0,8,131, 0,8,67, 0,9,231,
28.177 - 80,7,7, 0,8,91, 0,8,27, 0,9,151,
28.178 - 84,7,67, 0,8,123, 0,8,59, 0,9,215,
28.179 - 82,7,19, 0,8,107, 0,8,43, 0,9,183,
28.180 - 0,8,11, 0,8,139, 0,8,75, 0,9,247,
28.181 - 80,7,5, 0,8,87, 0,8,23, 192,8,0,
28.182 - 83,7,51, 0,8,119, 0,8,55, 0,9,207,
28.183 - 81,7,15, 0,8,103, 0,8,39, 0,9,175,
28.184 - 0,8,7, 0,8,135, 0,8,71, 0,9,239,
28.185 - 80,7,9, 0,8,95, 0,8,31, 0,9,159,
28.186 - 84,7,99, 0,8,127, 0,8,63, 0,9,223,
28.187 - 82,7,27, 0,8,111, 0,8,47, 0,9,191,
28.188 - 0,8,15, 0,8,143, 0,8,79, 0,9,255
28.189 - };
28.190 - static final int[] fixed_td = {
28.191 - 80,5,1, 87,5,257, 83,5,17, 91,5,4097,
28.192 - 81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
28.193 - 80,5,3, 88,5,513, 84,5,33, 92,5,8193,
28.194 - 82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
28.195 - 80,5,2, 87,5,385, 83,5,25, 91,5,6145,
28.196 - 81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
28.197 - 80,5,4, 88,5,769, 84,5,49, 92,5,12289,
28.198 - 82,5,13, 90,5,3073, 86,5,193, 192,5,24577
28.199 - };
28.200 -
28.201 - // Tables for deflate from PKZIP's appnote.txt.
28.202 - static final int[] cplens = { // Copy lengths for literal codes 257..285
28.203 - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
28.204 - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
28.205 - };
28.206 -
28.207 - // see note #13 above about 258
28.208 - static final int[] cplext = { // Extra bits for literal codes 257..285
28.209 - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
28.210 - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
28.211 - };
28.212 -
28.213 - static final int[] cpdist = { // Copy offsets for distance codes 0..29
28.214 - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
28.215 - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
28.216 - 8193, 12289, 16385, 24577
28.217 - };
28.218 -
28.219 - static final int[] cpdext = { // Extra bits for distance codes
28.220 - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
28.221 - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
28.222 - 12, 12, 13, 13};
28.223 -
28.224 - // If BMAX needs to be larger than 16, then h and x[] should be uLong.
28.225 - static final int BMAX=15; // maximum bit length of any code
28.226 -
28.227 - int[] hn = null; // hufts used in space
28.228 - int[] v = null; // work area for huft_build
28.229 - int[] c = null; // bit length count table
28.230 - int[] r = null; // table entry for structure assignment
28.231 - int[] u = null; // table stack
28.232 - int[] x = null; // bit offsets, then code stack
28.233 -
28.234 - private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
28.235 - int bindex,
28.236 - int n, // number of codes (assumed <= 288)
28.237 - int s, // number of simple-valued codes (0..s-1)
28.238 - int[] d, // list of base values for non-simple codes
28.239 - int[] e, // list of extra bits for non-simple codes
28.240 - int[] t, // result: starting table
28.241 - int[] m, // maximum lookup bits, returns actual
28.242 - int[] hp,// space for trees
28.243 - int[] hn,// hufts used in space
28.244 - int[] v // working area: values in order of bit length
28.245 - ){
28.246 - // Given a list of code lengths and a maximum table size, make a set of
28.247 - // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
28.248 - // if the given code set is incomplete (the tables are still built in this
28.249 - // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
28.250 - // lengths), or Z_MEM_ERROR if not enough memory.
28.251 -
28.252 - int a; // counter for codes of length k
28.253 - int f; // i repeats in table every f entries
28.254 - int g; // maximum code length
28.255 - int h; // table level
28.256 - int i; // counter, current code
28.257 - int j; // counter
28.258 - int k; // number of bits in current code
28.259 - int l; // bits per table (returned in m)
28.260 - int mask; // (1 << w) - 1, to avoid cc -O bug on HP
28.261 - int p; // pointer into c[], b[], or v[]
28.262 - int q; // points to current table
28.263 - int w; // bits before this table == (l * h)
28.264 - int xp; // pointer into x
28.265 - int y; // number of dummy codes added
28.266 - int z; // number of entries in current table
28.267 -
28.268 - // Generate counts for each bit length
28.269 -
28.270 - p = 0; i = n;
28.271 - do {
28.272 - c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX
28.273 - }while(i!=0);
28.274 -
28.275 - if(c[0] == n){ // null input--all zero length codes
28.276 - t[0] = -1;
28.277 - m[0] = 0;
28.278 - return Z_OK;
28.279 - }
28.280 -
28.281 - // Find minimum and maximum length, bound *m by those
28.282 - l = m[0];
28.283 - for (j = 1; j <= BMAX; j++)
28.284 - if(c[j]!=0) break;
28.285 - k = j; // minimum code length
28.286 - if(l < j){
28.287 - l = j;
28.288 - }
28.289 - for (i = BMAX; i!=0; i--){
28.290 - if(c[i]!=0) break;
28.291 - }
28.292 - g = i; // maximum code length
28.293 - if(l > i){
28.294 - l = i;
28.295 - }
28.296 - m[0] = l;
28.297 -
28.298 - // Adjust last length count to fill out codes, if needed
28.299 - for (y = 1 << j; j < i; j++, y <<= 1){
28.300 - if ((y -= c[j]) < 0){
28.301 - return Z_DATA_ERROR;
28.302 - }
28.303 - }
28.304 - if ((y -= c[i]) < 0){
28.305 - return Z_DATA_ERROR;
28.306 - }
28.307 - c[i] += y;
28.308 -
28.309 - // Generate starting offsets into the value table for each length
28.310 - x[1] = j = 0;
28.311 - p = 1; xp = 2;
28.312 - while (--i!=0) { // note that i == g from above
28.313 - x[xp] = (j += c[p]);
28.314 - xp++;
28.315 - p++;
28.316 - }
28.317 -
28.318 - // Make a table of values in order of bit lengths
28.319 - i = 0; p = 0;
28.320 - do {
28.321 - if ((j = b[bindex+p]) != 0){
28.322 - v[x[j]++] = i;
28.323 - }
28.324 - p++;
28.325 - }
28.326 - while (++i < n);
28.327 - n = x[g]; // set n to length of v
28.328 -
28.329 - // Generate the Huffman codes and for each, make the table entries
28.330 - x[0] = i = 0; // first Huffman code is zero
28.331 - p = 0; // grab values in bit order
28.332 - h = -1; // no tables yet--level -1
28.333 - w = -l; // bits decoded == (l * h)
28.334 - u[0] = 0; // just to keep compilers happy
28.335 - q = 0; // ditto
28.336 - z = 0; // ditto
28.337 -
28.338 - // go through the bit lengths (k already is bits in shortest code)
28.339 - for (; k <= g; k++){
28.340 - a = c[k];
28.341 - while (a--!=0){
28.342 - // here i is the Huffman code of length k bits for value *p
28.343 - // make tables up to required level
28.344 - while (k > w + l){
28.345 - h++;
28.346 - w += l; // previous table always l bits
28.347 - // compute minimum size table less than or equal to l bits
28.348 - z = g - w;
28.349 - z = (z > l) ? l : z; // table size upper limit
28.350 - if((f=1<<(j=k-w))>a+1){ // try a k-w bit table
28.351 - // too few codes for k-w bit table
28.352 - f -= a + 1; // deduct codes from patterns left
28.353 - xp = k;
28.354 - if(j < z){
28.355 - while (++j < z){ // try smaller tables up to z bits
28.356 - if((f <<= 1) <= c[++xp])
28.357 - break; // enough codes to use up j bits
28.358 - f -= c[xp]; // else deduct codes from patterns
28.359 - }
28.360 - }
28.361 - }
28.362 - z = 1 << j; // table entries for j-bit table
28.363 -
28.364 - // allocate new table
28.365 - if (hn[0] + z > MANY){ // (note: doesn't matter for fixed)
28.366 - return Z_DATA_ERROR; // overflow of MANY
28.367 - }
28.368 - u[h] = q = /*hp+*/ hn[0]; // DEBUG
28.369 - hn[0] += z;
28.370 -
28.371 - // connect to last table, if there is one
28.372 - if(h!=0){
28.373 - x[h]=i; // save pattern for backing up
28.374 - r[0]=(byte)j; // bits in this table
28.375 - r[1]=(byte)l; // bits to dump before this table
28.376 - j=i>>>(w - l);
28.377 - r[2] = (int)(q - u[h-1] - j); // offset to this table
28.378 - System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
28.379 - }
28.380 - else{
28.381 - t[0] = q; // first table is returned result
28.382 - }
28.383 - }
28.384 -
28.385 - // set up table entry in r
28.386 - r[1] = (byte)(k - w);
28.387 - if (p >= n){
28.388 - r[0] = 128 + 64; // out of values--invalid code
28.389 - }
28.390 - else if (v[p] < s){
28.391 - r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
28.392 - r[2] = v[p++]; // simple code is just the value
28.393 - }
28.394 - else{
28.395 - r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
28.396 - r[2]=d[v[p++] - s];
28.397 - }
28.398 -
28.399 - // fill code-like entries with r
28.400 - f=1<<(k-w);
28.401 - for (j=i>>>w;j<z;j+=f){
28.402 - System.arraycopy(r, 0, hp, (q+j)*3, 3);
28.403 - }
28.404 -
28.405 - // backwards increment the k-bit code i
28.406 - for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
28.407 - i ^= j;
28.408 - }
28.409 - i ^= j;
28.410 -
28.411 - // backup over finished tables
28.412 - mask = (1 << w) - 1; // needed on HP, cc -O bug
28.413 - while ((i & mask) != x[h]){
28.414 - h--; // don't need to update q
28.415 - w -= l;
28.416 - mask = (1 << w) - 1;
28.417 - }
28.418 - }
28.419 - }
28.420 - // Return Z_BUF_ERROR if we were given an incomplete table
28.421 - return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
28.422 - }
28.423 -
28.424 - int inflate_trees_bits(int[] c, // 19 code lengths
28.425 - int[] bb, // bits tree desired/actual depth
28.426 - int[] tb, // bits tree result
28.427 - int[] hp, // space for trees
28.428 - ZStream z // for messages
28.429 - ){
28.430 - int result;
28.431 - initWorkArea(19);
28.432 - hn[0]=0;
28.433 - result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
28.434 -
28.435 - if(result == Z_DATA_ERROR){
28.436 - z.msg = "oversubscribed dynamic bit lengths tree";
28.437 - }
28.438 - else if(result == Z_BUF_ERROR || bb[0] == 0){
28.439 - z.msg = "incomplete dynamic bit lengths tree";
28.440 - result = Z_DATA_ERROR;
28.441 - }
28.442 - return result;
28.443 - }
28.444 -
28.445 - int inflate_trees_dynamic(int nl, // number of literal/length codes
28.446 - int nd, // number of distance codes
28.447 - int[] c, // that many (total) code lengths
28.448 - int[] bl, // literal desired/actual bit depth
28.449 - int[] bd, // distance desired/actual bit depth
28.450 - int[] tl, // literal/length tree result
28.451 - int[] td, // distance tree result
28.452 - int[] hp, // space for trees
28.453 - ZStream z // for messages
28.454 - ){
28.455 - int result;
28.456 -
28.457 - // build literal/length tree
28.458 - initWorkArea(288);
28.459 - hn[0]=0;
28.460 - result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
28.461 - if (result != Z_OK || bl[0] == 0){
28.462 - if(result == Z_DATA_ERROR){
28.463 - z.msg = "oversubscribed literal/length tree";
28.464 - }
28.465 - else if (result != Z_MEM_ERROR){
28.466 - z.msg = "incomplete literal/length tree";
28.467 - result = Z_DATA_ERROR;
28.468 - }
28.469 - return result;
28.470 - }
28.471 -
28.472 - // build distance tree
28.473 - initWorkArea(288);
28.474 - result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
28.475 -
28.476 - if (result != Z_OK || (bd[0] == 0 && nl > 257)){
28.477 - if (result == Z_DATA_ERROR){
28.478 - z.msg = "oversubscribed distance tree";
28.479 - }
28.480 - else if (result == Z_BUF_ERROR) {
28.481 - z.msg = "incomplete distance tree";
28.482 - result = Z_DATA_ERROR;
28.483 - }
28.484 - else if (result != Z_MEM_ERROR){
28.485 - z.msg = "empty distance tree with lengths";
28.486 - result = Z_DATA_ERROR;
28.487 - }
28.488 - return result;
28.489 - }
28.490 -
28.491 - return Z_OK;
28.492 - }
28.493 -
28.494 - static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
28.495 - int[] bd, //distance desired/actual bit depth
28.496 - int[][] tl,//literal/length tree result
28.497 - int[][] td,//distance tree result
28.498 - ZStream z //for memory allocation
28.499 - ){
28.500 - bl[0]=fixed_bl;
28.501 - bd[0]=fixed_bd;
28.502 - tl[0]=fixed_tl;
28.503 - td[0]=fixed_td;
28.504 - return Z_OK;
28.505 - }
28.506 -
28.507 - private void initWorkArea(int vsize){
28.508 - if(hn==null){
28.509 - hn=new int[1];
28.510 - v=new int[vsize];
28.511 - c=new int[BMAX+1];
28.512 - r=new int[3];
28.513 - u=new int[BMAX];
28.514 - x=new int[BMAX+1];
28.515 - }
28.516 - if(v.length<vsize){ v=new int[vsize]; }
28.517 - for(int i=0; i<vsize; i++){v[i]=0;}
28.518 - for(int i=0; i<BMAX+1; i++){c[i]=0;}
28.519 - for(int i=0; i<3; i++){r[i]=0;}
28.520 - System.arraycopy(c, 0, u, 0, BMAX);
28.521 - System.arraycopy(c, 0, x, 0, BMAX+1);
28.522 - }
28.523 -}
29.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflate.java Wed May 07 11:55:06 2014 +0200
29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
29.3 @@ -1,727 +0,0 @@
29.4 -/* -*-mode:java; c-basic-offset:2; -*- */
29.5 -/*
29.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
29.7 -
29.8 -Redistribution and use in source and binary forms, with or without
29.9 -modification, are permitted provided that the following conditions are met:
29.10 -
29.11 - 1. Redistributions of source code must retain the above copyright notice,
29.12 - this list of conditions and the following disclaimer.
29.13 -
29.14 - 2. Redistributions in binary form must reproduce the above copyright
29.15 - notice, this list of conditions and the following disclaimer in
29.16 - the documentation and/or other materials provided with the distribution.
29.17 -
29.18 - 3. The names of the authors may not be used to endorse or promote products
29.19 - derived from this software without specific prior written permission.
29.20 -
29.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
29.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
29.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
29.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29.31 - */
29.32 -/*
29.33 - * This program is based on zlib-1.1.3, so all credit should go authors
29.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
29.35 - * and contributors of zlib.
29.36 - */
29.37 -
29.38 -package org.apidesign.bck2brwsr.emul.zip;
29.39 -
29.40 -import org.apidesign.bck2brwsr.emul.lang.System;
29.41 -
29.42 -final class Inflate{
29.43 -
29.44 - static final private int MAX_WBITS=15; // 32K LZ77 window
29.45 -
29.46 - // preset dictionary flag in zlib header
29.47 - static final private int PRESET_DICT=0x20;
29.48 -
29.49 - static final int Z_NO_FLUSH=0;
29.50 - static final int Z_PARTIAL_FLUSH=1;
29.51 - static final int Z_SYNC_FLUSH=2;
29.52 - static final int Z_FULL_FLUSH=3;
29.53 - static final int Z_FINISH=4;
29.54 -
29.55 - static final private int Z_DEFLATED=8;
29.56 -
29.57 - static final private int Z_OK=0;
29.58 - static final private int Z_STREAM_END=1;
29.59 - static final private int Z_NEED_DICT=2;
29.60 - static final private int Z_ERRNO=-1;
29.61 - static final private int Z_STREAM_ERROR=-2;
29.62 - static final private int Z_DATA_ERROR=-3;
29.63 - static final private int Z_MEM_ERROR=-4;
29.64 - static final private int Z_BUF_ERROR=-5;
29.65 - static final private int Z_VERSION_ERROR=-6;
29.66 -
29.67 - static final private int METHOD=0; // waiting for method byte
29.68 - static final private int FLAG=1; // waiting for flag byte
29.69 - static final private int DICT4=2; // four dictionary check bytes to go
29.70 - static final private int DICT3=3; // three dictionary check bytes to go
29.71 - static final private int DICT2=4; // two dictionary check bytes to go
29.72 - static final private int DICT1=5; // one dictionary check byte to go
29.73 - static final int DICT0=6; // waiting for inflateSetDictionary
29.74 - static final private int BLOCKS=7; // decompressing blocks
29.75 - static final private int CHECK4=8; // four check bytes to go
29.76 - static final private int CHECK3=9; // three check bytes to go
29.77 - static final private int CHECK2=10; // two check bytes to go
29.78 - static final private int CHECK1=11; // one check byte to go
29.79 - static final private int DONE=12; // finished check, done
29.80 - static final private int BAD=13; // got an error--stay here
29.81 -
29.82 - static final private int HEAD=14;
29.83 - static final private int LENGTH=15;
29.84 - static final private int TIME=16;
29.85 - static final private int OS=17;
29.86 - static final private int EXLEN=18;
29.87 - static final private int EXTRA=19;
29.88 - static final private int NAME=20;
29.89 - static final private int COMMENT=21;
29.90 - static final private int HCRC=22;
29.91 - static final private int FLAGS=23;
29.92 -
29.93 - int mode; // current inflate mode
29.94 -
29.95 - // mode dependent information
29.96 - int method; // if FLAGS, method byte
29.97 -
29.98 - // if CHECK, check values to compare
29.99 - long was = -1; // computed check value
29.100 - long need; // stream check value
29.101 -
29.102 - // if BAD, inflateSync's marker bytes count
29.103 - int marker;
29.104 -
29.105 - // mode independent information
29.106 - int wrap; // flag for no wrapper
29.107 - int wbits; // log2(window size) (8..15, defaults to 15)
29.108 -
29.109 - InfBlocks blocks; // current inflate_blocks state
29.110 -
29.111 - private final ZStream z;
29.112 -
29.113 - private int flags;
29.114 -
29.115 - private int need_bytes = -1;
29.116 - private byte[] crcbuf=new byte[4];
29.117 -
29.118 - GZIPHeader gheader = null;
29.119 -
29.120 - int inflateReset(){
29.121 - if(z == null) return Z_STREAM_ERROR;
29.122 -
29.123 - z.total_in = z.total_out = 0;
29.124 - z.msg = null;
29.125 - this.mode = HEAD;
29.126 - this.need_bytes = -1;
29.127 - this.blocks.reset();
29.128 - return Z_OK;
29.129 - }
29.130 -
29.131 - int inflateEnd(){
29.132 - if(blocks != null){
29.133 - blocks.free();
29.134 - }
29.135 - return Z_OK;
29.136 - }
29.137 -
29.138 - Inflate(ZStream z){
29.139 - this.z=z;
29.140 - }
29.141 -
29.142 - int inflateInit(int w){
29.143 - z.msg = null;
29.144 - blocks = null;
29.145 -
29.146 - // handle undocumented wrap option (no zlib header or check)
29.147 - wrap = 0;
29.148 - if(w < 0){
29.149 - w = - w;
29.150 - }
29.151 - else {
29.152 - wrap = (w >> 4) + 1;
29.153 - if(w < 48)
29.154 - w &= 15;
29.155 - }
29.156 -
29.157 - if(w<8 ||w>15){
29.158 - inflateEnd();
29.159 - return Z_STREAM_ERROR;
29.160 - }
29.161 - if(blocks != null && wbits != w){
29.162 - blocks.free();
29.163 - blocks=null;
29.164 - }
29.165 -
29.166 - // set window size
29.167 - wbits=w;
29.168 -
29.169 - this.blocks=new InfBlocks(z, 1<<w);
29.170 -
29.171 - // reset state
29.172 - inflateReset();
29.173 -
29.174 - return Z_OK;
29.175 - }
29.176 -
29.177 - int inflate(int f){
29.178 - int hold = 0;
29.179 -
29.180 - int r;
29.181 - int b;
29.182 -
29.183 - if(z == null || z.next_in == null){
29.184 - if(f == Z_FINISH && this.mode==HEAD)
29.185 - return Z_OK;
29.186 - return Z_STREAM_ERROR;
29.187 - }
29.188 -
29.189 - f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
29.190 - r = Z_BUF_ERROR;
29.191 - while (true){
29.192 -
29.193 - switch (this.mode){
29.194 - case HEAD:
29.195 - if(wrap==0){
29.196 - this.mode = BLOCKS;
29.197 - break;
29.198 - }
29.199 -
29.200 - try { r=readBytes(2, r, f); }
29.201 - catch(Return e){ return e.r; }
29.202 -
29.203 - if((wrap&2)!=0 && this.need == 0x8b1fL) { // gzip header
29.204 - z.adler=new CRC32();
29.205 - checksum(2, this.need);
29.206 -
29.207 - if(gheader==null)
29.208 - gheader=new GZIPHeader();
29.209 -
29.210 - this.mode = FLAGS;
29.211 - break;
29.212 - }
29.213 -
29.214 - flags = 0;
29.215 -
29.216 - this.method = ((int)this.need)&0xff;
29.217 - b=((int)(this.need>>8))&0xff;
29.218 -
29.219 - if((wrap&1)==0 || // check if zlib header allowed
29.220 - (((this.method << 8)+b) % 31)!=0){
29.221 - this.mode = BAD;
29.222 - z.msg = "incorrect header check";
29.223 - // since zlib 1.2, it is allowted to inflateSync for this case.
29.224 - /*
29.225 - this.marker = 5; // can't try inflateSync
29.226 - */
29.227 - break;
29.228 - }
29.229 -
29.230 - if((this.method&0xf)!=Z_DEFLATED){
29.231 - this.mode = BAD;
29.232 - z.msg="unknown compression method";
29.233 - // since zlib 1.2, it is allowted to inflateSync for this case.
29.234 - /*
29.235 - this.marker = 5; // can't try inflateSync
29.236 - */
29.237 - break;
29.238 - }
29.239 -
29.240 - if((this.method>>4)+8>this.wbits){
29.241 - this.mode = BAD;
29.242 - z.msg="invalid window size";
29.243 - // since zlib 1.2, it is allowted to inflateSync for this case.
29.244 - /*
29.245 - this.marker = 5; // can't try inflateSync
29.246 - */
29.247 - break;
29.248 - }
29.249 -
29.250 - z.adler=new Adler32();
29.251 -
29.252 - if((b&PRESET_DICT)==0){
29.253 - this.mode = BLOCKS;
29.254 - break;
29.255 - }
29.256 - this.mode = DICT4;
29.257 - case DICT4:
29.258 -
29.259 - if(z.avail_in==0)return r;r=f;
29.260 -
29.261 - z.avail_in--; z.total_in++;
29.262 - this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
29.263 - this.mode=DICT3;
29.264 - case DICT3:
29.265 -
29.266 - if(z.avail_in==0)return r;r=f;
29.267 -
29.268 - z.avail_in--; z.total_in++;
29.269 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
29.270 - this.mode=DICT2;
29.271 - case DICT2:
29.272 -
29.273 - if(z.avail_in==0)return r;r=f;
29.274 -
29.275 - z.avail_in--; z.total_in++;
29.276 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
29.277 - this.mode=DICT1;
29.278 - case DICT1:
29.279 -
29.280 - if(z.avail_in==0)return r;r=f;
29.281 -
29.282 - z.avail_in--; z.total_in++;
29.283 - this.need += (z.next_in[z.next_in_index++]&0xffL);
29.284 - z.adler.reset(this.need);
29.285 - this.mode = DICT0;
29.286 - return Z_NEED_DICT;
29.287 - case DICT0:
29.288 - this.mode = BAD;
29.289 - z.msg = "need dictionary";
29.290 - this.marker = 0; // can try inflateSync
29.291 - return Z_STREAM_ERROR;
29.292 - case BLOCKS:
29.293 - r = this.blocks.proc(r);
29.294 - if(r == Z_DATA_ERROR){
29.295 - this.mode = BAD;
29.296 - this.marker = 0; // can try inflateSync
29.297 - break;
29.298 - }
29.299 - if(r == Z_OK){
29.300 - r = f;
29.301 - }
29.302 - if(r != Z_STREAM_END){
29.303 - return r;
29.304 - }
29.305 - r = f;
29.306 - this.was=z.adler.getValue();
29.307 - this.blocks.reset();
29.308 - if(this.wrap==0){
29.309 - this.mode=DONE;
29.310 - break;
29.311 - }
29.312 - this.mode=CHECK4;
29.313 - case CHECK4:
29.314 -
29.315 - if(z.avail_in==0)return r;r=f;
29.316 -
29.317 - z.avail_in--; z.total_in++;
29.318 - this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
29.319 - this.mode=CHECK3;
29.320 - case CHECK3:
29.321 -
29.322 - if(z.avail_in==0)return r;r=f;
29.323 -
29.324 - z.avail_in--; z.total_in++;
29.325 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
29.326 - this.mode = CHECK2;
29.327 - case CHECK2:
29.328 -
29.329 - if(z.avail_in==0)return r;r=f;
29.330 -
29.331 - z.avail_in--; z.total_in++;
29.332 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
29.333 - this.mode = CHECK1;
29.334 - case CHECK1:
29.335 -
29.336 - if(z.avail_in==0)return r;r=f;
29.337 -
29.338 - z.avail_in--; z.total_in++;
29.339 - this.need+=(z.next_in[z.next_in_index++]&0xffL);
29.340 -
29.341 - if(flags!=0){ // gzip
29.342 - this.need = ((this.need&0xff000000)>>24 |
29.343 - (this.need&0x00ff0000)>>8 |
29.344 - (this.need&0x0000ff00)<<8 |
29.345 - (this.need&0x0000ffff)<<24)&0xffffffffL;
29.346 - }
29.347 -
29.348 - if(((int)(this.was)) != ((int)(this.need))){
29.349 - z.msg = "incorrect data check";
29.350 - // chack is delayed
29.351 - /*
29.352 - this.mode = BAD;
29.353 - this.marker = 5; // can't try inflateSync
29.354 - break;
29.355 - */
29.356 - }
29.357 - else if(flags!=0 && gheader!=null){
29.358 - gheader.crc = this.need;
29.359 - }
29.360 -
29.361 - this.mode = LENGTH;
29.362 - case LENGTH:
29.363 - if (wrap!=0 && flags!=0) {
29.364 -
29.365 - try { r=readBytes(4, r, f); }
29.366 - catch(Return e){ return e.r; }
29.367 -
29.368 - if(z.msg!=null && z.msg.equals("incorrect data check")){
29.369 - this.mode = BAD;
29.370 - this.marker = 5; // can't try inflateSync
29.371 - break;
29.372 - }
29.373 -
29.374 - if (this.need != (z.total_out & 0xffffffffL)) {
29.375 - z.msg = "incorrect length check";
29.376 - this.mode = BAD;
29.377 - break;
29.378 - }
29.379 - z.msg = null;
29.380 - }
29.381 - else {
29.382 - if(z.msg!=null && z.msg.equals("incorrect data check")){
29.383 - this.mode = BAD;
29.384 - this.marker = 5; // can't try inflateSync
29.385 - break;
29.386 - }
29.387 - }
29.388 -
29.389 - this.mode = DONE;
29.390 - case DONE:
29.391 - return Z_STREAM_END;
29.392 - case BAD:
29.393 - return Z_DATA_ERROR;
29.394 -
29.395 - case FLAGS:
29.396 -
29.397 - try { r=readBytes(2, r, f); }
29.398 - catch(Return e){ return e.r; }
29.399 -
29.400 - flags = ((int)this.need)&0xffff;
29.401 -
29.402 - if ((flags & 0xff) != Z_DEFLATED) {
29.403 - z.msg = "unknown compression method";
29.404 - this.mode = BAD;
29.405 - break;
29.406 - }
29.407 - if ((flags & 0xe000)!=0) {
29.408 - z.msg = "unknown header flags set";
29.409 - this.mode = BAD;
29.410 - break;
29.411 - }
29.412 -
29.413 - if ((flags & 0x0200)!=0){
29.414 - checksum(2, this.need);
29.415 - }
29.416 -
29.417 - this.mode = TIME;
29.418 -
29.419 - case TIME:
29.420 - try { r=readBytes(4, r, f); }
29.421 - catch(Return e){ return e.r; }
29.422 - if(gheader!=null)
29.423 - gheader.time = this.need;
29.424 - if ((flags & 0x0200)!=0){
29.425 - checksum(4, this.need);
29.426 - }
29.427 - this.mode = OS;
29.428 - case OS:
29.429 - try { r=readBytes(2, r, f); }
29.430 - catch(Return e){ return e.r; }
29.431 - if(gheader!=null){
29.432 - gheader.xflags = ((int)this.need)&0xff;
29.433 - gheader.os = (((int)this.need)>>8)&0xff;
29.434 - }
29.435 - if ((flags & 0x0200)!=0){
29.436 - checksum(2, this.need);
29.437 - }
29.438 - this.mode = EXLEN;
29.439 - case EXLEN:
29.440 - if ((flags & 0x0400)!=0) {
29.441 - try { r=readBytes(2, r, f); }
29.442 - catch(Return e){ return e.r; }
29.443 - if(gheader!=null){
29.444 - gheader.extra = new byte[((int)this.need)&0xffff];
29.445 - }
29.446 - if ((flags & 0x0200)!=0){
29.447 - checksum(2, this.need);
29.448 - }
29.449 - }
29.450 - else if(gheader!=null){
29.451 - gheader.extra=null;
29.452 - }
29.453 - this.mode = EXTRA;
29.454 -
29.455 - case EXTRA:
29.456 - if ((flags & 0x0400)!=0) {
29.457 - try {
29.458 - r=readBytes(r, f);
29.459 - if(gheader!=null){
29.460 - byte[] foo = tmp_array;
29.461 - tmp_array=null;
29.462 - if(foo.length == gheader.extra.length){
29.463 - System.arraycopy(foo, 0, gheader.extra, 0, foo.length);
29.464 - }
29.465 - else{
29.466 - z.msg = "bad extra field length";
29.467 - this.mode = BAD;
29.468 - break;
29.469 - }
29.470 - }
29.471 - }
29.472 - catch(Return e){ return e.r; }
29.473 - }
29.474 - else if(gheader!=null){
29.475 - gheader.extra=null;
29.476 - }
29.477 - this.mode = NAME;
29.478 - case NAME:
29.479 - if ((flags & 0x0800)!=0) {
29.480 - try {
29.481 - r=readString(r, f);
29.482 - if(gheader!=null){
29.483 - gheader.name=tmp_array;
29.484 - }
29.485 - tmp_array=null;
29.486 - }
29.487 - catch(Return e){ return e.r; }
29.488 - }
29.489 - else if(gheader!=null){
29.490 - gheader.name=null;
29.491 - }
29.492 - this.mode = COMMENT;
29.493 - case COMMENT:
29.494 - if ((flags & 0x1000)!=0) {
29.495 - try {
29.496 - r=readString(r, f);
29.497 - if(gheader!=null){
29.498 - gheader.comment=tmp_array;
29.499 - }
29.500 - tmp_array=null;
29.501 - }
29.502 - catch(Return e){ return e.r; }
29.503 - }
29.504 - else if(gheader!=null){
29.505 - gheader.comment=null;
29.506 - }
29.507 - this.mode = HCRC;
29.508 - case HCRC:
29.509 - if ((flags & 0x0200)!=0) {
29.510 - try { r=readBytes(2, r, f); }
29.511 - catch(Return e){ return e.r; }
29.512 - if(gheader!=null){
29.513 - gheader.hcrc=(int)(this.need&0xffff);
29.514 - }
29.515 - if(this.need != (z.adler.getValue()&0xffffL)){
29.516 - this.mode = BAD;
29.517 - z.msg = "header crc mismatch";
29.518 - this.marker = 5; // can't try inflateSync
29.519 - break;
29.520 - }
29.521 - }
29.522 - z.adler = new CRC32();
29.523 -
29.524 - this.mode = BLOCKS;
29.525 - break;
29.526 - default:
29.527 - return Z_STREAM_ERROR;
29.528 - }
29.529 - }
29.530 - }
29.531 -
29.532 - int inflateSetDictionary(byte[] dictionary, int dictLength){
29.533 - if(z==null || (this.mode != DICT0 && this.wrap != 0)){
29.534 - return Z_STREAM_ERROR;
29.535 - }
29.536 -
29.537 - int index=0;
29.538 - int length = dictLength;
29.539 -
29.540 - if(this.mode==DICT0){
29.541 - long adler_need=z.adler.getValue();
29.542 - z.adler.reset();
29.543 - z.adler.update(dictionary, 0, dictLength);
29.544 - if(z.adler.getValue()!=adler_need){
29.545 - return Z_DATA_ERROR;
29.546 - }
29.547 - }
29.548 -
29.549 - z.adler.reset();
29.550 -
29.551 - if(length >= (1<<this.wbits)){
29.552 - length = (1<<this.wbits)-1;
29.553 - index=dictLength - length;
29.554 - }
29.555 - this.blocks.set_dictionary(dictionary, index, length);
29.556 - this.mode = BLOCKS;
29.557 - return Z_OK;
29.558 - }
29.559 -
29.560 - static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
29.561 -
29.562 - int inflateSync(){
29.563 - int n; // number of bytes to look at
29.564 - int p; // pointer to bytes
29.565 - int m; // number of marker bytes found in a row
29.566 - long r, w; // temporaries to save total_in and total_out
29.567 -
29.568 - // set up
29.569 - if(z == null)
29.570 - return Z_STREAM_ERROR;
29.571 - if(this.mode != BAD){
29.572 - this.mode = BAD;
29.573 - this.marker = 0;
29.574 - }
29.575 - if((n=z.avail_in)==0)
29.576 - return Z_BUF_ERROR;
29.577 -
29.578 - p=z.next_in_index;
29.579 - m=this.marker;
29.580 - // search
29.581 - while (n!=0 && m < 4){
29.582 - if(z.next_in[p] == mark[m]){
29.583 - m++;
29.584 - }
29.585 - else if(z.next_in[p]!=0){
29.586 - m = 0;
29.587 - }
29.588 - else{
29.589 - m = 4 - m;
29.590 - }
29.591 - p++; n--;
29.592 - }
29.593 -
29.594 - // restore
29.595 - z.total_in += p-z.next_in_index;
29.596 - z.next_in_index = p;
29.597 - z.avail_in = n;
29.598 - this.marker = m;
29.599 -
29.600 - // return no joy or set up to restart on a new block
29.601 - if(m != 4){
29.602 - return Z_DATA_ERROR;
29.603 - }
29.604 - r=z.total_in; w=z.total_out;
29.605 - inflateReset();
29.606 - z.total_in=r; z.total_out = w;
29.607 - this.mode = BLOCKS;
29.608 -
29.609 - return Z_OK;
29.610 - }
29.611 -
29.612 - // Returns true if inflate is currently at the end of a block generated
29.613 - // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
29.614 - // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
29.615 - // but removes the length bytes of the resulting empty stored block. When
29.616 - // decompressing, PPP checks that at the end of input packet, inflate is
29.617 - // waiting for these length bytes.
29.618 - int inflateSyncPoint(){
29.619 - if(z == null || this.blocks == null)
29.620 - return Z_STREAM_ERROR;
29.621 - return this.blocks.sync_point();
29.622 - }
29.623 -
29.624 - private int readBytes(int n, int r, int f) throws Return{
29.625 - if(need_bytes == -1){
29.626 - need_bytes=n;
29.627 - this.need=0;
29.628 - }
29.629 - while(need_bytes>0){
29.630 - if(z.avail_in==0){ throw new Return(r); }; r=f;
29.631 - z.avail_in--; z.total_in++;
29.632 - this.need = this.need |
29.633 - ((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8));
29.634 - need_bytes--;
29.635 - }
29.636 - if(n==2){
29.637 - this.need&=0xffffL;
29.638 - }
29.639 - else if(n==4) {
29.640 - this.need&=0xffffffffL;
29.641 - }
29.642 - need_bytes=-1;
29.643 - return r;
29.644 - }
29.645 - class Return extends Exception{
29.646 - int r;
29.647 - Return(int r){this.r=r; }
29.648 - }
29.649 -
29.650 - private byte[] tmp_array;
29.651 - private int readString(int r, int f) throws Return{
29.652 - int b=0;
29.653 - byte[] arr = new byte[4092];
29.654 - int at = 0;
29.655 - do {
29.656 - if(z.avail_in==0){ throw new Return(r); }; r=f;
29.657 - z.avail_in--; z.total_in++;
29.658 - b = z.next_in[z.next_in_index];
29.659 - if(b!=0) arr = append(arr, z.next_in[z.next_in_index], at++);
29.660 - z.adler.update(z.next_in, z.next_in_index, 1);
29.661 - z.next_in_index++;
29.662 - }while(b!=0);
29.663 -
29.664 - tmp_array = copy(arr, at);
29.665 -
29.666 - return r;
29.667 - }
29.668 -
29.669 - private int readBytes(int r, int f) throws Return{
29.670 - int b=0;
29.671 - byte[] arr = new byte[4092];
29.672 - int at = 0;
29.673 - while(this.need>0){
29.674 - if(z.avail_in==0){ throw new Return(r); }; r=f;
29.675 - z.avail_in--; z.total_in++;
29.676 - b = z.next_in[z.next_in_index];
29.677 - arr = append(arr, z.next_in[z.next_in_index], at++);
29.678 - z.adler.update(z.next_in, z.next_in_index, 1);
29.679 - z.next_in_index++;
29.680 - this.need--;
29.681 - }
29.682 -
29.683 - tmp_array = copy(arr, at);
29.684 -
29.685 - return r;
29.686 - }
29.687 -
29.688 - private static byte[] copy(byte[] arr, int len) {
29.689 - byte[] ret = new byte[len];
29.690 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, 0, ret, 0, len);
29.691 - return ret;
29.692 - }
29.693 - private static byte[] append(byte[] arr, byte b, int index) {
29.694 - arr[index] = b;
29.695 - return arr;
29.696 - }
29.697 -
29.698 - private void checksum(int n, long v){
29.699 - for(int i=0; i<n; i++){
29.700 - crcbuf[i]=(byte)(v&0xff);
29.701 - v>>=8;
29.702 - }
29.703 - z.adler.update(crcbuf, 0, n);
29.704 - }
29.705 -
29.706 - public GZIPHeader getGZIPHeader(){
29.707 - return gheader;
29.708 - }
29.709 -
29.710 - boolean inParsingHeader(){
29.711 - switch(mode){
29.712 - case HEAD:
29.713 - case DICT4:
29.714 - case DICT3:
29.715 - case DICT2:
29.716 - case DICT1:
29.717 - case FLAGS:
29.718 - case TIME:
29.719 - case OS:
29.720 - case EXLEN:
29.721 - case EXTRA:
29.722 - case NAME:
29.723 - case COMMENT:
29.724 - case HCRC:
29.725 - return true;
29.726 - default:
29.727 - return false;
29.728 - }
29.729 - }
29.730 -}
30.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java Wed May 07 11:55:06 2014 +0200
30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
30.3 @@ -1,338 +0,0 @@
30.4 -/*
30.5 - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
30.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30.7 - *
30.8 - * This code is free software; you can redistribute it and/or modify it
30.9 - * under the terms of the GNU General Public License version 2 only, as
30.10 - * published by the Free Software Foundation. Oracle designates this
30.11 - * particular file as subject to the "Classpath" exception as provided
30.12 - * by Oracle in the LICENSE file that accompanied this code.
30.13 - *
30.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
30.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30.17 - * version 2 for more details (a copy is included in the LICENSE file that
30.18 - * accompanied this code).
30.19 - *
30.20 - * You should have received a copy of the GNU General Public License version
30.21 - * 2 along with this work; if not, write to the Free Software Foundation,
30.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
30.23 - *
30.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
30.25 - * or visit www.oracle.com if you need additional information or have any
30.26 - * questions.
30.27 - */
30.28 -
30.29 -package org.apidesign.bck2brwsr.emul.zip;
30.30 -
30.31 -import java.util.zip.*;
30.32 -import java.io.IOException;
30.33 -
30.34 -/**
30.35 - * This class provides support for general purpose decompression using the
30.36 - * popular ZLIB compression library. The ZLIB compression library was
30.37 - * initially developed as part of the PNG graphics standard and is not
30.38 - * protected by patents. It is fully described in the specifications at
30.39 - * the <a href="package-summary.html#package_description">java.util.zip
30.40 - * package description</a>.
30.41 - *
30.42 - * <p>The following code fragment demonstrates a trivial compression
30.43 - * and decompression of a string using <tt>Deflater</tt> and
30.44 - * <tt>Inflater</tt>.
30.45 - *
30.46 - * <blockquote><pre>
30.47 - * try {
30.48 - * // Encode a String into bytes
30.49 - * String inputString = "blahblahblah\u20AC\u20AC";
30.50 - * byte[] input = inputString.getBytes("UTF-8");
30.51 - *
30.52 - * // Compress the bytes
30.53 - * byte[] output = new byte[100];
30.54 - * Deflater compresser = new Deflater();
30.55 - * compresser.setInput(input);
30.56 - * compresser.finish();
30.57 - * int compressedDataLength = compresser.deflate(output);
30.58 - *
30.59 - * // Decompress the bytes
30.60 - * Inflater decompresser = new Inflater();
30.61 - * decompresser.setInput(output, 0, compressedDataLength);
30.62 - * byte[] result = new byte[100];
30.63 - * int resultLength = decompresser.inflate(result);
30.64 - * decompresser.end();
30.65 - *
30.66 - * // Decode the bytes into a String
30.67 - * String outputString = new String(result, 0, resultLength, "UTF-8");
30.68 - * } catch(java.io.UnsupportedEncodingException ex) {
30.69 - * // handle
30.70 - * } catch (java.util.zip.DataFormatException ex) {
30.71 - * // handle
30.72 - * }
30.73 - * </pre></blockquote>
30.74 - *
30.75 - * @see Deflater
30.76 - * @author David Connelly
30.77 - *
30.78 - */
30.79 -public
30.80 -class Inflater extends java.util.zip.Inflater {
30.81 - private final boolean nowrap;
30.82 - private JzLibInflater impl;
30.83 -
30.84 - /**
30.85 - * Creates a new decompressor. If the parameter 'nowrap' is true then
30.86 - * the ZLIB header and checksum fields will not be used. This provides
30.87 - * compatibility with the compression format used by both GZIP and PKZIP.
30.88 - * <p>
30.89 - * Note: When using the 'nowrap' option it is also necessary to provide
30.90 - * an extra "dummy" byte as input. This is required by the ZLIB native
30.91 - * library in order to support certain optimizations.
30.92 - *
30.93 - * @param nowrap if true then support GZIP compatible compression
30.94 - */
30.95 - public Inflater(boolean nowrap) {
30.96 - this.nowrap = nowrap;
30.97 - reset();
30.98 - }
30.99 -
30.100 - /**
30.101 - * Creates a new decompressor.
30.102 - */
30.103 - public Inflater() {
30.104 - this(false);
30.105 - }
30.106 -
30.107 - /**
30.108 - * Sets input data for decompression. Should be called whenever
30.109 - * needsInput() returns true indicating that more input data is
30.110 - * required.
30.111 - * @param b the input data bytes
30.112 - * @param off the start offset of the input data
30.113 - * @param len the length of the input data
30.114 - * @see Inflater#needsInput
30.115 - */
30.116 - public void setInput(byte[] b, int off, int len) {
30.117 - if (b == null) {
30.118 - throw new NullPointerException();
30.119 - }
30.120 - if (off < 0 || len < 0 || off > b.length - len) {
30.121 - throw new ArrayIndexOutOfBoundsException();
30.122 - }
30.123 - impl.setInput(b, off, len, false);
30.124 - }
30.125 -
30.126 - /**
30.127 - * Sets input data for decompression. Should be called whenever
30.128 - * needsInput() returns true indicating that more input data is
30.129 - * required.
30.130 - * @param b the input data bytes
30.131 - * @see Inflater#needsInput
30.132 - */
30.133 - public void setInput(byte[] b) {
30.134 - setInput(b, 0, b.length);
30.135 - }
30.136 -
30.137 - /**
30.138 - * Sets the preset dictionary to the given array of bytes. Should be
30.139 - * called when inflate() returns 0 and needsDictionary() returns true
30.140 - * indicating that a preset dictionary is required. The method getAdler()
30.141 - * can be used to get the Adler-32 value of the dictionary needed.
30.142 - * @param b the dictionary data bytes
30.143 - * @param off the start offset of the data
30.144 - * @param len the length of the data
30.145 - * @see Inflater#needsDictionary
30.146 - * @see Inflater#getAdler
30.147 - */
30.148 - public void setDictionary(byte[] b, int off, int len) {
30.149 - if (b == null) {
30.150 - throw new NullPointerException();
30.151 - }
30.152 - if (off < 0 || len < 0 || off > b.length - len) {
30.153 - throw new ArrayIndexOutOfBoundsException();
30.154 - }
30.155 - byte[] arr;
30.156 - if (off == 0) {
30.157 - arr = b;
30.158 - } else {
30.159 - arr = new byte[len];
30.160 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(b, off, arr, 0, len);
30.161 - }
30.162 - impl.setDictionary(arr, len);
30.163 - }
30.164 -
30.165 - /**
30.166 - * Sets the preset dictionary to the given array of bytes. Should be
30.167 - * called when inflate() returns 0 and needsDictionary() returns true
30.168 - * indicating that a preset dictionary is required. The method getAdler()
30.169 - * can be used to get the Adler-32 value of the dictionary needed.
30.170 - * @param b the dictionary data bytes
30.171 - * @see Inflater#needsDictionary
30.172 - * @see Inflater#getAdler
30.173 - */
30.174 - public void setDictionary(byte[] b) {
30.175 - impl.setDictionary(b, b.length);
30.176 - }
30.177 -
30.178 - /**
30.179 - * Returns the total number of bytes remaining in the input buffer.
30.180 - * This can be used to find out what bytes still remain in the input
30.181 - * buffer after decompression has finished.
30.182 - * @return the total number of bytes remaining in the input buffer
30.183 - */
30.184 - public int getRemaining() {
30.185 - return impl.getAvailIn();
30.186 - }
30.187 -
30.188 - /**
30.189 - * Returns true if no data remains in the input buffer. This can
30.190 - * be used to determine if #setInput should be called in order
30.191 - * to provide more input.
30.192 - * @return true if no data remains in the input buffer
30.193 - */
30.194 - public boolean needsInput() {
30.195 - return getRemaining() <= 0;
30.196 - }
30.197 -
30.198 - /**
30.199 - * Returns true if a preset dictionary is needed for decompression.
30.200 - * @return true if a preset dictionary is needed for decompression
30.201 - * @see Inflater#setDictionary
30.202 - */
30.203 - public boolean needsDictionary() {
30.204 - return impl.needDict();
30.205 - }
30.206 -
30.207 - /**
30.208 - * Returns true if the end of the compressed data stream has been
30.209 - * reached.
30.210 - * @return true if the end of the compressed data stream has been
30.211 - * reached
30.212 - */
30.213 - public boolean finished() {
30.214 - return impl.finished();
30.215 - }
30.216 -
30.217 - /**
30.218 - * Uncompresses bytes into specified buffer. Returns actual number
30.219 - * of bytes uncompressed. A return value of 0 indicates that
30.220 - * needsInput() or needsDictionary() should be called in order to
30.221 - * determine if more input data or a preset dictionary is required.
30.222 - * In the latter case, getAdler() can be used to get the Adler-32
30.223 - * value of the dictionary required.
30.224 - * @param b the buffer for the uncompressed data
30.225 - * @param off the start offset of the data
30.226 - * @param len the maximum number of uncompressed bytes
30.227 - * @return the actual number of uncompressed bytes
30.228 - * @exception DataFormatException if the compressed data format is invalid
30.229 - * @see Inflater#needsInput
30.230 - * @see Inflater#needsDictionary
30.231 - */
30.232 - public int inflate(byte[] b, int off, int len)
30.233 - throws DataFormatException
30.234 - {
30.235 - if (b == null) {
30.236 - throw new NullPointerException();
30.237 - }
30.238 - if (off < 0 || len < 0 || off > b.length - len) {
30.239 - throw new ArrayIndexOutOfBoundsException();
30.240 - }
30.241 - impl.setOutput(b, off, len);
30.242 - int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
30.243 - return impl.next_out_index - off;
30.244 - }
30.245 -
30.246 - /**
30.247 - * Uncompresses bytes into specified buffer. Returns actual number
30.248 - * of bytes uncompressed. A return value of 0 indicates that
30.249 - * needsInput() or needsDictionary() should be called in order to
30.250 - * determine if more input data or a preset dictionary is required.
30.251 - * In the latter case, getAdler() can be used to get the Adler-32
30.252 - * value of the dictionary required.
30.253 - * @param b the buffer for the uncompressed data
30.254 - * @return the actual number of uncompressed bytes
30.255 - * @exception DataFormatException if the compressed data format is invalid
30.256 - * @see Inflater#needsInput
30.257 - * @see Inflater#needsDictionary
30.258 - */
30.259 - public int inflate(byte[] b) throws DataFormatException {
30.260 - return inflate(b, 0, b.length);
30.261 - }
30.262 -
30.263 - /**
30.264 - * Returns the ADLER-32 value of the uncompressed data.
30.265 - * @return the ADLER-32 value of the uncompressed data
30.266 - */
30.267 - public int getAdler() {
30.268 - return (int) impl.getAdler();
30.269 - }
30.270 -
30.271 - /**
30.272 - * Returns the total number of compressed bytes input so far.
30.273 - *
30.274 - * <p>Since the number of bytes may be greater than
30.275 - * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
30.276 - * the preferred means of obtaining this information.</p>
30.277 - *
30.278 - * @return the total number of compressed bytes input so far
30.279 - */
30.280 - public int getTotalIn() {
30.281 - return (int) getBytesRead();
30.282 - }
30.283 -
30.284 - /**
30.285 - * Returns the total number of compressed bytes input so far.</p>
30.286 - *
30.287 - * @return the total (non-negative) number of compressed bytes input so far
30.288 - * @since 1.5
30.289 - */
30.290 - public long getBytesRead() {
30.291 - return impl.total_in;
30.292 - }
30.293 -
30.294 - /**
30.295 - * Returns the total number of uncompressed bytes output so far.
30.296 - *
30.297 - * <p>Since the number of bytes may be greater than
30.298 - * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
30.299 - * the preferred means of obtaining this information.</p>
30.300 - *
30.301 - * @return the total number of uncompressed bytes output so far
30.302 - */
30.303 - public int getTotalOut() {
30.304 - return (int) getBytesWritten();
30.305 - }
30.306 -
30.307 - /**
30.308 - * Returns the total number of uncompressed bytes output so far.</p>
30.309 - *
30.310 - * @return the total (non-negative) number of uncompressed bytes output so far
30.311 - * @since 1.5
30.312 - */
30.313 - public long getBytesWritten() {
30.314 - return impl.total_out;
30.315 - }
30.316 -
30.317 - /**
30.318 - * Resets inflater so that a new set of input data can be processed.
30.319 - */
30.320 - public void reset() {
30.321 - impl = new JzLibInflater(15, nowrap);
30.322 - }
30.323 -
30.324 - /**
30.325 - * Closes the decompressor and discards any unprocessed input.
30.326 - * This method should be called when the decompressor is no longer
30.327 - * being used, but will also be called automatically by the finalize()
30.328 - * method. Once this method is called, the behavior of the Inflater
30.329 - * object is undefined.
30.330 - */
30.331 - public void end() {
30.332 - impl.end();
30.333 - }
30.334 -
30.335 - /**
30.336 - * Closes the decompressor when garbage is collected.
30.337 - */
30.338 - protected void finalize() {
30.339 - end();
30.340 - }
30.341 -}
31.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java Wed May 07 11:55:06 2014 +0200
31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
31.3 @@ -1,137 +0,0 @@
31.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
31.5 -/*
31.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
31.7 -
31.8 -Redistribution and use in source and binary forms, with or without
31.9 -modification, are permitted provided that the following conditions are met:
31.10 -
31.11 - 1. Redistributions of source code must retain the above copyright notice,
31.12 - this list of conditions and the following disclaimer.
31.13 -
31.14 - 2. Redistributions in binary form must reproduce the above copyright
31.15 - notice, this list of conditions and the following disclaimer in
31.16 - the documentation and/or other materials provided with the distribution.
31.17 -
31.18 - 3. The names of the authors may not be used to endorse or promote products
31.19 - derived from this software without specific prior written permission.
31.20 -
31.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
31.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
31.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
31.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.31 - */
31.32 -/*
31.33 - * This program is based on zlib-1.1.3, so all credit should go authors
31.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
31.35 - * and contributors of zlib.
31.36 - */
31.37 -
31.38 -package org.apidesign.bck2brwsr.emul.zip;
31.39 -
31.40 -final class JzLibInflater extends ZStream{
31.41 -
31.42 - static final private int MAX_WBITS=15; // 32K LZ77 window
31.43 - static final private int DEF_WBITS=MAX_WBITS;
31.44 -
31.45 - public static final int Z_NO_FLUSH=0;
31.46 - static final private int Z_PARTIAL_FLUSH=1;
31.47 - static final private int Z_SYNC_FLUSH=2;
31.48 - static final private int Z_FULL_FLUSH=3;
31.49 - static final private int Z_FINISH=4;
31.50 -
31.51 - static final private int MAX_MEM_LEVEL=9;
31.52 -
31.53 - static final private int Z_OK=0;
31.54 - static final private int Z_STREAM_END=1;
31.55 - static final private int Z_NEED_DICT=2;
31.56 - static final private int Z_ERRNO=-1;
31.57 - static final private int Z_STREAM_ERROR=-2;
31.58 - static final private int Z_DATA_ERROR=-3;
31.59 - static final private int Z_MEM_ERROR=-4;
31.60 - static final private int Z_BUF_ERROR=-5;
31.61 - static final private int Z_VERSION_ERROR=-6;
31.62 -
31.63 - public JzLibInflater() {
31.64 - super();
31.65 - init();
31.66 - }
31.67 -
31.68 - public JzLibInflater(int w) {
31.69 - this(w, false);
31.70 - }
31.71 -
31.72 - public JzLibInflater(int w, boolean nowrap) {
31.73 - super();
31.74 - int ret = init(w, nowrap);
31.75 - if(ret!=Z_OK)
31.76 - throw new IllegalStateException(ret+": "+msg);
31.77 - }
31.78 -
31.79 - private boolean finished = false;
31.80 -
31.81 - public int init(){
31.82 - return init(DEF_WBITS);
31.83 - }
31.84 -
31.85 - public int init(boolean nowrap){
31.86 - return init(DEF_WBITS, nowrap);
31.87 - }
31.88 -
31.89 - public int init(int w){
31.90 - return init(w, false);
31.91 - }
31.92 -
31.93 - public int init(int w, boolean nowrap){
31.94 - finished = false;
31.95 - istate=new Inflate(this);
31.96 - return istate.inflateInit(nowrap?-w:w);
31.97 - }
31.98 -
31.99 - public int inflate(int f){
31.100 - if(istate==null) return Z_STREAM_ERROR;
31.101 - int ret = istate.inflate(f);
31.102 - if(ret == Z_STREAM_END)
31.103 - finished = true;
31.104 - return ret;
31.105 - }
31.106 -
31.107 - public int end(){
31.108 - finished = true;
31.109 - if(istate==null) return Z_STREAM_ERROR;
31.110 - int ret=istate.inflateEnd();
31.111 -// istate = null;
31.112 - return ret;
31.113 - }
31.114 -
31.115 - public int sync(){
31.116 - if(istate == null)
31.117 - return Z_STREAM_ERROR;
31.118 - return istate.inflateSync();
31.119 - }
31.120 -
31.121 - public int syncPoint(){
31.122 - if(istate == null)
31.123 - return Z_STREAM_ERROR;
31.124 - return istate.inflateSyncPoint();
31.125 - }
31.126 -
31.127 - public int setDictionary(byte[] dictionary, int dictLength){
31.128 - if(istate == null)
31.129 - return Z_STREAM_ERROR;
31.130 - return istate.inflateSetDictionary(dictionary, dictLength);
31.131 - }
31.132 -
31.133 - public boolean finished(){
31.134 - return istate.mode==12 /*DONE*/;
31.135 - }
31.136 -
31.137 - public boolean needDict() {
31.138 - return istate == null ? false : istate.mode == Inflate.DICT0;
31.139 - }
31.140 -}
32.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java Wed May 07 11:55:06 2014 +0200
32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
32.3 @@ -1,253 +0,0 @@
32.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
32.5 -/*
32.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
32.7 -
32.8 -Redistribution and use in source and binary forms, with or without
32.9 -modification, are permitted provided that the following conditions are met:
32.10 -
32.11 - 1. Redistributions of source code must retain the above copyright notice,
32.12 - this list of conditions and the following disclaimer.
32.13 -
32.14 - 2. Redistributions in binary form must reproduce the above copyright
32.15 - notice, this list of conditions and the following disclaimer in
32.16 - the documentation and/or other materials provided with the distribution.
32.17 -
32.18 - 3. The names of the authors may not be used to endorse or promote products
32.19 - derived from this software without specific prior written permission.
32.20 -
32.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
32.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
32.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.31 - */
32.32 -/*
32.33 - * This program is based on zlib-1.1.3, so all credit should go authors
32.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
32.35 - * and contributors of zlib.
32.36 - */
32.37 -
32.38 -package org.apidesign.bck2brwsr.emul.zip;
32.39 -
32.40 -import org.apidesign.bck2brwsr.emul.lang.System;
32.41 -
32.42 -/**
32.43 - * ZStream
32.44 - *
32.45 - * @deprecated Not for public use in the future.
32.46 - */
32.47 -@Deprecated
32.48 -class ZStream{
32.49 -
32.50 - static final private int MAX_WBITS=15; // 32K LZ77 window
32.51 - static final private int DEF_WBITS=MAX_WBITS;
32.52 -
32.53 - static final private int Z_NO_FLUSH=0;
32.54 - static final private int Z_PARTIAL_FLUSH=1;
32.55 - static final private int Z_SYNC_FLUSH=2;
32.56 - static final private int Z_FULL_FLUSH=3;
32.57 - static final private int Z_FINISH=4;
32.58 -
32.59 - static final private int MAX_MEM_LEVEL=9;
32.60 -
32.61 - static final private int Z_OK=0;
32.62 - static final private int Z_STREAM_END=1;
32.63 - static final private int Z_NEED_DICT=2;
32.64 - static final private int Z_ERRNO=-1;
32.65 - static final private int Z_STREAM_ERROR=-2;
32.66 - static final private int Z_DATA_ERROR=-3;
32.67 - static final private int Z_MEM_ERROR=-4;
32.68 - static final private int Z_BUF_ERROR=-5;
32.69 - static final private int Z_VERSION_ERROR=-6;
32.70 -
32.71 - public byte[] next_in; // next input byte
32.72 - public int next_in_index;
32.73 - public int avail_in; // number of bytes available at next_in
32.74 - public long total_in; // total nb of input bytes read so far
32.75 -
32.76 - public byte[] next_out; // next output byte should be put there
32.77 - public int next_out_index;
32.78 - public int avail_out; // remaining free space at next_out
32.79 - public long total_out; // total nb of bytes output so far
32.80 -
32.81 - public String msg;
32.82 -
32.83 - Inflate istate;
32.84 -
32.85 - int data_type; // best guess about the data type: ascii or binary
32.86 -
32.87 - Checksum adler;
32.88 -
32.89 - public ZStream(){
32.90 - this(new Adler32());
32.91 - }
32.92 -
32.93 - public ZStream(Checksum adler){
32.94 - this.adler=adler;
32.95 - }
32.96 -
32.97 - public int inflateInit(){
32.98 - return inflateInit(DEF_WBITS);
32.99 - }
32.100 - public int inflateInit(boolean nowrap){
32.101 - return inflateInit(DEF_WBITS, nowrap);
32.102 - }
32.103 - public int inflateInit(int w){
32.104 - return inflateInit(w, false);
32.105 - }
32.106 -
32.107 - public int inflateInit(int w, boolean nowrap){
32.108 - istate=new Inflate(this);
32.109 - return istate.inflateInit(nowrap?-w:w);
32.110 - }
32.111 -
32.112 - public int inflate(int f){
32.113 - if(istate==null) return Z_STREAM_ERROR;
32.114 - return istate.inflate(f);
32.115 - }
32.116 - public int inflateEnd(){
32.117 - if(istate==null) return Z_STREAM_ERROR;
32.118 - int ret=istate.inflateEnd();
32.119 -// istate = null;
32.120 - return ret;
32.121 - }
32.122 -
32.123 - public int inflateSync(){
32.124 - if(istate == null)
32.125 - return Z_STREAM_ERROR;
32.126 - return istate.inflateSync();
32.127 - }
32.128 - public int inflateSyncPoint(){
32.129 - if(istate == null)
32.130 - return Z_STREAM_ERROR;
32.131 - return istate.inflateSyncPoint();
32.132 - }
32.133 - public int inflateSetDictionary(byte[] dictionary, int dictLength){
32.134 - if(istate == null)
32.135 - return Z_STREAM_ERROR;
32.136 - return istate.inflateSetDictionary(dictionary, dictLength);
32.137 - }
32.138 - public boolean inflateFinished(){
32.139 - return istate.mode==12 /*DONE*/;
32.140 - }
32.141 -
32.142 -
32.143 - public long getAdler(){
32.144 - return adler.getValue();
32.145 - }
32.146 -
32.147 - public void free(){
32.148 - next_in=null;
32.149 - next_out=null;
32.150 - msg=null;
32.151 - }
32.152 -
32.153 - public void setOutput(byte[] buf){
32.154 - setOutput(buf, 0, buf.length);
32.155 - }
32.156 -
32.157 - public void setOutput(byte[] buf, int off, int len){
32.158 - next_out = buf;
32.159 - next_out_index = off;
32.160 - avail_out = len;
32.161 - }
32.162 -
32.163 - public void setInput(byte[] buf){
32.164 - setInput(buf, 0, buf.length, false);
32.165 - }
32.166 -
32.167 - public void setInput(byte[] buf, boolean append){
32.168 - setInput(buf, 0, buf.length, append);
32.169 - }
32.170 -
32.171 - public void setInput(byte[] buf, int off, int len, boolean append){
32.172 - if(len<=0 && append && next_in!=null) return;
32.173 -
32.174 - if(avail_in>0 && append){
32.175 - byte[] tmp = new byte[avail_in+len];
32.176 - System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
32.177 - System.arraycopy(buf, off, tmp, avail_in, len);
32.178 - next_in=tmp;
32.179 - next_in_index=0;
32.180 - avail_in+=len;
32.181 - }
32.182 - else{
32.183 - next_in=buf;
32.184 - next_in_index=off;
32.185 - avail_in=len;
32.186 - }
32.187 - }
32.188 -
32.189 - public byte[] getNextIn(){
32.190 - return next_in;
32.191 - }
32.192 -
32.193 - public void setNextIn(byte[] next_in){
32.194 - this.next_in = next_in;
32.195 - }
32.196 -
32.197 - public int getNextInIndex(){
32.198 - return next_in_index;
32.199 - }
32.200 -
32.201 - public void setNextInIndex(int next_in_index){
32.202 - this.next_in_index = next_in_index;
32.203 - }
32.204 -
32.205 - public int getAvailIn(){
32.206 - return avail_in;
32.207 - }
32.208 -
32.209 - public void setAvailIn(int avail_in){
32.210 - this.avail_in = avail_in;
32.211 - }
32.212 -
32.213 - public byte[] getNextOut(){
32.214 - return next_out;
32.215 - }
32.216 -
32.217 - public void setNextOut(byte[] next_out){
32.218 - this.next_out = next_out;
32.219 - }
32.220 -
32.221 - public int getNextOutIndex(){
32.222 - return next_out_index;
32.223 - }
32.224 -
32.225 - public void setNextOutIndex(int next_out_index){
32.226 - this.next_out_index = next_out_index;
32.227 - }
32.228 -
32.229 - public int getAvailOut(){
32.230 - return avail_out;
32.231 -
32.232 - }
32.233 -
32.234 - public void setAvailOut(int avail_out){
32.235 - this.avail_out = avail_out;
32.236 - }
32.237 -
32.238 - public long getTotalOut(){
32.239 - return total_out;
32.240 - }
32.241 -
32.242 - public long getTotalIn(){
32.243 - return total_in;
32.244 - }
32.245 -
32.246 - public String getMessage(){
32.247 - return msg;
32.248 - }
32.249 -
32.250 - /**
32.251 - * Those methods are expected to be override by Inflater and Deflater.
32.252 - * In the future, they will become abstract methods.
32.253 - */
32.254 - public int end(){ return Z_OK; }
32.255 - public boolean finished(){ return false; }
32.256 -}
33.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java Wed May 07 11:55:06 2014 +0200
33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
33.3 @@ -1,84 +0,0 @@
33.4 -/*
33.5 - * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
33.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33.7 - *
33.8 - * This code is free software; you can redistribute it and/or modify it
33.9 - * under the terms of the GNU General Public License version 2 only, as
33.10 - * published by the Free Software Foundation. Oracle designates this
33.11 - * particular file as subject to the "Classpath" exception as provided
33.12 - * by Oracle in the LICENSE file that accompanied this code.
33.13 - *
33.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
33.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33.17 - * version 2 for more details (a copy is included in the LICENSE file that
33.18 - * accompanied this code).
33.19 - *
33.20 - * You should have received a copy of the GNU General Public License version
33.21 - * 2 along with this work; if not, write to the Free Software Foundation,
33.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33.23 - *
33.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33.25 - * or visit www.oracle.com if you need additional information or have any
33.26 - * questions.
33.27 - */
33.28 -
33.29 -package org.apidesign.bck2brwsr.emul.zip;
33.30 -
33.31 -/*
33.32 - * This class defines the constants that are used by the classes
33.33 - * which manipulate Zip64 files.
33.34 - */
33.35 -
33.36 -public class ZipConstants64 {
33.37 -
33.38 - /*
33.39 - * ZIP64 constants
33.40 - */
33.41 - static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006"
33.42 - static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007"
33.43 - static final int ZIP64_ENDHDR = 56; // ZIP64 end header size
33.44 - static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size
33.45 - static final int ZIP64_EXTHDR = 24; // EXT header size
33.46 - static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID
33.47 -
33.48 - static final int ZIP64_MAGICCOUNT = 0xFFFF;
33.49 - static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
33.50 -
33.51 - /*
33.52 - * Zip64 End of central directory (END) header field offsets
33.53 - */
33.54 - static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir
33.55 - static final int ZIP64_ENDVEM = 12; // version made by
33.56 - static final int ZIP64_ENDVER = 14; // version needed to extract
33.57 - static final int ZIP64_ENDNMD = 16; // number of this disk
33.58 - static final int ZIP64_ENDDSK = 20; // disk number of start
33.59 - static final int ZIP64_ENDTOD = 24; // total number of entries on this disk
33.60 - static final int ZIP64_ENDTOT = 32; // total number of entries
33.61 - static final int ZIP64_ENDSIZ = 40; // central directory size in bytes
33.62 - static final int ZIP64_ENDOFF = 48; // offset of first CEN header
33.63 - static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector
33.64 -
33.65 - /*
33.66 - * Zip64 End of central directory locator field offsets
33.67 - */
33.68 - static final int ZIP64_LOCDSK = 4; // disk number start
33.69 - static final int ZIP64_LOCOFF = 8; // offset of zip64 end
33.70 - static final int ZIP64_LOCTOT = 16; // total number of disks
33.71 -
33.72 - /*
33.73 - * Zip64 Extra local (EXT) header field offsets
33.74 - */
33.75 - static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value
33.76 - static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte
33.77 - static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte
33.78 -
33.79 - /*
33.80 - * Language encoding flag EFS
33.81 - */
33.82 - static final int EFS = 0x800; // If this bit is set the filename and
33.83 - // comment fields for this file must be
33.84 - // encoded using UTF-8.
33.85 -
33.86 - private ZipConstants64() {}
33.87 -}
34.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java Wed May 07 11:55:06 2014 +0200
34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
34.3 @@ -1,468 +0,0 @@
34.4 -/*
34.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
34.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
34.7 - *
34.8 - * This code is free software; you can redistribute it and/or modify it
34.9 - * under the terms of the GNU General Public License version 2 only, as
34.10 - * published by the Free Software Foundation. Oracle designates this
34.11 - * particular file as subject to the "Classpath" exception as provided
34.12 - * by Oracle in the LICENSE file that accompanied this code.
34.13 - *
34.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
34.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34.17 - * version 2 for more details (a copy is included in the LICENSE file that
34.18 - * accompanied this code).
34.19 - *
34.20 - * You should have received a copy of the GNU General Public License version
34.21 - * 2 along with this work; if not, write to the Free Software Foundation,
34.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
34.23 - *
34.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
34.25 - * or visit www.oracle.com if you need additional information or have any
34.26 - * questions.
34.27 - */
34.28 -
34.29 -package org.apidesign.bck2brwsr.emul.zip;
34.30 -
34.31 -import java.util.zip.*;
34.32 -import java.io.InputStream;
34.33 -import java.io.IOException;
34.34 -import java.io.EOFException;
34.35 -import java.io.PushbackInputStream;
34.36 -import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*;
34.37 -import static java.util.zip.ZipInputStream.*;
34.38 -
34.39 -/**
34.40 - * This class implements an input stream filter for reading files in the
34.41 - * ZIP file format. Includes support for both compressed and uncompressed
34.42 - * entries.
34.43 - *
34.44 - * @author David Connelly
34.45 - */
34.46 -public
34.47 -class ZipInputStream extends InflaterInputStream {
34.48 - private ZipEntry entry;
34.49 - private int flag;
34.50 - private CRC32 crc = new CRC32();
34.51 - private long remaining;
34.52 - private byte[] tmpbuf = new byte[512];
34.53 -
34.54 - private static final int STORED = ZipEntry.STORED;
34.55 - private static final int DEFLATED = ZipEntry.DEFLATED;
34.56 -
34.57 - private boolean closed = false;
34.58 - // this flag is set to true after EOF has reached for
34.59 - // one entry
34.60 - private boolean entryEOF = false;
34.61 -
34.62 - /**
34.63 - * Check to make sure that this stream has not been closed
34.64 - */
34.65 - private void ensureOpen() throws IOException {
34.66 - if (closed) {
34.67 - throw new IOException("Stream closed");
34.68 - }
34.69 - }
34.70 -
34.71 - /**
34.72 - * Creates a new ZIP input stream.
34.73 - *
34.74 - * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
34.75 - * decode the entry names.
34.76 - *
34.77 - * @param in the actual input stream
34.78 - */
34.79 - public ZipInputStream(InputStream in) {
34.80 -// this(in, "UTF-8");
34.81 - super(new PushbackInputStream(in, 512), new Inflater(true), 512);
34.82 - //usesDefaultInflater = true;
34.83 - if(in == null) {
34.84 - throw new NullPointerException("in is null");
34.85 - }
34.86 - }
34.87 -
34.88 - /**
34.89 - * Creates a new ZIP input stream.
34.90 - *
34.91 - * @param in the actual input stream
34.92 - *
34.93 - * @param charset
34.94 - * The {@linkplain java.nio.charset.Charset charset} to be
34.95 - * used to decode the ZIP entry name (ignored if the
34.96 - * <a href="package-summary.html#lang_encoding"> language
34.97 - * encoding bit</a> of the ZIP entry's general purpose bit
34.98 - * flag is set).
34.99 - *
34.100 - * @since 1.7
34.101 - *
34.102 - public ZipInputStream(InputStream in, Charset charset) {
34.103 - super(new PushbackInputStream(in, 512), new Inflater(true), 512);
34.104 - usesDefaultInflater = true;
34.105 - if(in == null) {
34.106 - throw new NullPointerException("in is null");
34.107 - }
34.108 - if (charset == null)
34.109 - throw new NullPointerException("charset is null");
34.110 - this.zc = ZipCoder.get(charset);
34.111 - }
34.112 - */
34.113 -
34.114 - /**
34.115 - * Reads the next ZIP file entry and positions the stream at the
34.116 - * beginning of the entry data.
34.117 - * @return the next ZIP file entry, or null if there are no more entries
34.118 - * @exception ZipException if a ZIP file error has occurred
34.119 - * @exception IOException if an I/O error has occurred
34.120 - */
34.121 - public ZipEntry getNextEntry() throws IOException {
34.122 - ensureOpen();
34.123 - if (entry != null) {
34.124 - closeEntry();
34.125 - }
34.126 - crc.reset();
34.127 - inf.reset();
34.128 - if ((entry = readLOC()) == null) {
34.129 - return null;
34.130 - }
34.131 - if (entry.getMethod() == STORED) {
34.132 - remaining = entry.getSize();
34.133 - }
34.134 - entryEOF = false;
34.135 - return entry;
34.136 - }
34.137 -
34.138 - /**
34.139 - * Closes the current ZIP entry and positions the stream for reading the
34.140 - * next entry.
34.141 - * @exception ZipException if a ZIP file error has occurred
34.142 - * @exception IOException if an I/O error has occurred
34.143 - */
34.144 - public void closeEntry() throws IOException {
34.145 - ensureOpen();
34.146 - while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
34.147 - entryEOF = true;
34.148 - }
34.149 -
34.150 - /**
34.151 - * Returns 0 after EOF has reached for the current entry data,
34.152 - * otherwise always return 1.
34.153 - * <p>
34.154 - * Programs should not count on this method to return the actual number
34.155 - * of bytes that could be read without blocking.
34.156 - *
34.157 - * @return 1 before EOF and 0 after EOF has reached for current entry.
34.158 - * @exception IOException if an I/O error occurs.
34.159 - *
34.160 - */
34.161 - public int available() throws IOException {
34.162 - ensureOpen();
34.163 - if (entryEOF) {
34.164 - return 0;
34.165 - } else {
34.166 - return 1;
34.167 - }
34.168 - }
34.169 -
34.170 - /**
34.171 - * Reads from the current ZIP entry into an array of bytes.
34.172 - * If <code>len</code> is not zero, the method
34.173 - * blocks until some input is available; otherwise, no
34.174 - * bytes are read and <code>0</code> is returned.
34.175 - * @param b the buffer into which the data is read
34.176 - * @param off the start offset in the destination array <code>b</code>
34.177 - * @param len the maximum number of bytes read
34.178 - * @return the actual number of bytes read, or -1 if the end of the
34.179 - * entry is reached
34.180 - * @exception NullPointerException if <code>b</code> is <code>null</code>.
34.181 - * @exception IndexOutOfBoundsException if <code>off</code> is negative,
34.182 - * <code>len</code> is negative, or <code>len</code> is greater than
34.183 - * <code>b.length - off</code>
34.184 - * @exception ZipException if a ZIP file error has occurred
34.185 - * @exception IOException if an I/O error has occurred
34.186 - */
34.187 - public int read(byte[] b, int off, int len) throws IOException {
34.188 - ensureOpen();
34.189 - if (off < 0 || len < 0 || off > b.length - len) {
34.190 - throw new IndexOutOfBoundsException();
34.191 - } else if (len == 0) {
34.192 - return 0;
34.193 - }
34.194 -
34.195 - if (entry == null) {
34.196 - return -1;
34.197 - }
34.198 - switch (entry.getMethod()) {
34.199 - case DEFLATED:
34.200 - len = super.read(b, off, len);
34.201 - if (len == -1) {
34.202 - readEnd(entry);
34.203 - entryEOF = true;
34.204 - entry = null;
34.205 - } else {
34.206 - crc.update(b, off, len);
34.207 - }
34.208 - return len;
34.209 - case STORED:
34.210 - if (remaining <= 0) {
34.211 - entryEOF = true;
34.212 - entry = null;
34.213 - return -1;
34.214 - }
34.215 - if (len > remaining) {
34.216 - len = (int)remaining;
34.217 - }
34.218 - len = in.read(b, off, len);
34.219 - if (len == -1) {
34.220 - throw new ZipException("unexpected EOF");
34.221 - }
34.222 - crc.update(b, off, len);
34.223 - remaining -= len;
34.224 - if (remaining == 0 && entry.getCrc() != crc.getValue()) {
34.225 - throw new ZipException(
34.226 - "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
34.227 - " but got 0x" + Long.toHexString(crc.getValue()) + ")");
34.228 - }
34.229 - return len;
34.230 - default:
34.231 - throw new ZipException("invalid compression method");
34.232 - }
34.233 - }
34.234 -
34.235 - /**
34.236 - * Skips specified number of bytes in the current ZIP entry.
34.237 - * @param n the number of bytes to skip
34.238 - * @return the actual number of bytes skipped
34.239 - * @exception ZipException if a ZIP file error has occurred
34.240 - * @exception IOException if an I/O error has occurred
34.241 - * @exception IllegalArgumentException if n < 0
34.242 - */
34.243 - public long skip(long n) throws IOException {
34.244 - if (n < 0) {
34.245 - throw new IllegalArgumentException("negative skip length");
34.246 - }
34.247 - ensureOpen();
34.248 - int max = (int)Math.min(n, Integer.MAX_VALUE);
34.249 - int total = 0;
34.250 - while (total < max) {
34.251 - int len = max - total;
34.252 - if (len > tmpbuf.length) {
34.253 - len = tmpbuf.length;
34.254 - }
34.255 - len = read(tmpbuf, 0, len);
34.256 - if (len == -1) {
34.257 - entryEOF = true;
34.258 - break;
34.259 - }
34.260 - total += len;
34.261 - }
34.262 - return total;
34.263 - }
34.264 -
34.265 - /**
34.266 - * Closes this input stream and releases any system resources associated
34.267 - * with the stream.
34.268 - * @exception IOException if an I/O error has occurred
34.269 - */
34.270 - public void close() throws IOException {
34.271 - if (!closed) {
34.272 - super.close();
34.273 - closed = true;
34.274 - }
34.275 - }
34.276 -
34.277 - private byte[] b = new byte[256];
34.278 -
34.279 - /*
34.280 - * Reads local file (LOC) header for next entry.
34.281 - */
34.282 - private ZipEntry readLOC() throws IOException {
34.283 - try {
34.284 - readFully(tmpbuf, 0, LOCHDR);
34.285 - } catch (EOFException e) {
34.286 - return null;
34.287 - }
34.288 - if (get32(tmpbuf, 0) != LOCSIG) {
34.289 - return null;
34.290 - }
34.291 - // get flag first, we need check EFS.
34.292 - flag = get16(tmpbuf, LOCFLG);
34.293 - // get the entry name and create the ZipEntry first
34.294 - int len = get16(tmpbuf, LOCNAM);
34.295 - int blen = b.length;
34.296 - if (len > blen) {
34.297 - do
34.298 - blen = blen * 2;
34.299 - while (len > blen);
34.300 - b = new byte[blen];
34.301 - }
34.302 - readFully(b, 0, len);
34.303 - // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
34.304 - ZipEntry e = createZipEntry(((flag & EFS) != 0)
34.305 - ? toStringUTF8(b, len)
34.306 - : toString(b, len));
34.307 - // now get the remaining fields for the entry
34.308 - if ((flag & 1) == 1) {
34.309 - throw new ZipException("encrypted ZIP entry not supported");
34.310 - }
34.311 - e.setMethod(get16(tmpbuf, LOCHOW));
34.312 - e.setTime(get32(tmpbuf, LOCTIM));
34.313 - if ((flag & 8) == 8) {
34.314 - /* "Data Descriptor" present */
34.315 - if (e.getMethod() != DEFLATED) {
34.316 - throw new ZipException(
34.317 - "only DEFLATED entries can have EXT descriptor");
34.318 - }
34.319 - } else {
34.320 - e.setCrc(get32(tmpbuf, LOCCRC));
34.321 - e.setCompressedSize(get32(tmpbuf, LOCSIZ));
34.322 - e.setSize(get32(tmpbuf, LOCLEN));
34.323 - }
34.324 - len = get16(tmpbuf, LOCEXT);
34.325 - if (len > 0) {
34.326 - byte[] bb = new byte[len];
34.327 - readFully(bb, 0, len);
34.328 - e.setExtra(bb);
34.329 - // extra fields are in "HeaderID(2)DataSize(2)Data... format
34.330 - if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
34.331 - int off = 0;
34.332 - while (off + 4 < len) {
34.333 - int sz = get16(bb, off + 2);
34.334 - if (get16(bb, off) == ZIP64_EXTID) {
34.335 - off += 4;
34.336 - // LOC extra zip64 entry MUST include BOTH original and
34.337 - // compressed file size fields
34.338 - if (sz < 16 || (off + sz) > len ) {
34.339 - // Invalid zip64 extra fields, simply skip. Even it's
34.340 - // rare, it's possible the entry size happens to be
34.341 - // the magic value and it "accidnetly" has some bytes
34.342 - // in extra match the id.
34.343 - return e;
34.344 - }
34.345 - e.setSize(get64(bb, off));
34.346 - e.setCompressedSize(get64(bb, off + 8));
34.347 - break;
34.348 - }
34.349 - off += (sz + 4);
34.350 - }
34.351 - }
34.352 - }
34.353 - return e;
34.354 - }
34.355 -
34.356 - /**
34.357 - * Creates a new <code>ZipEntry</code> object for the specified
34.358 - * entry name.
34.359 - *
34.360 - * @param name the ZIP file entry name
34.361 - * @return the ZipEntry just created
34.362 - */
34.363 - protected ZipEntry createZipEntry(String name) {
34.364 - return new ZipEntry(name);
34.365 - }
34.366 -
34.367 - /*
34.368 - * Reads end of deflated entry as well as EXT descriptor if present.
34.369 - */
34.370 - private void readEnd(ZipEntry e) throws IOException {
34.371 - int n = inf.getRemaining();
34.372 - if (n > 0) {
34.373 - ((PushbackInputStream)in).unread(buf, len - n, n);
34.374 - }
34.375 - if ((flag & 8) == 8) {
34.376 - /* "Data Descriptor" present */
34.377 - if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
34.378 - inf.getBytesRead() > ZIP64_MAGICVAL) {
34.379 - // ZIP64 format
34.380 - readFully(tmpbuf, 0, ZIP64_EXTHDR);
34.381 - long sig = get32(tmpbuf, 0);
34.382 - if (sig != EXTSIG) { // no EXTSIG present
34.383 - e.setCrc(sig);
34.384 - e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
34.385 - e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
34.386 - ((PushbackInputStream)in).unread(
34.387 - tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
34.388 - } else {
34.389 - e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
34.390 - e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
34.391 - e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
34.392 - }
34.393 - } else {
34.394 - readFully(tmpbuf, 0, EXTHDR);
34.395 - long sig = get32(tmpbuf, 0);
34.396 - if (sig != EXTSIG) { // no EXTSIG present
34.397 - e.setCrc(sig);
34.398 - e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
34.399 - e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
34.400 - ((PushbackInputStream)in).unread(
34.401 - tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
34.402 - } else {
34.403 - e.setCrc(get32(tmpbuf, EXTCRC));
34.404 - e.setCompressedSize(get32(tmpbuf, EXTSIZ));
34.405 - e.setSize(get32(tmpbuf, EXTLEN));
34.406 - }
34.407 - }
34.408 - }
34.409 - if (e.getSize() != inf.getBytesWritten()) {
34.410 - throw new ZipException(
34.411 - "invalid entry size (expected " + e.getSize() +
34.412 - " but got " + inf.getBytesWritten() + " bytes)");
34.413 - }
34.414 - if (e.getCompressedSize() != inf.getBytesRead()) {
34.415 - throw new ZipException(
34.416 - "invalid entry compressed size (expected " + e.getCompressedSize() +
34.417 - " but got " + inf.getBytesRead() + " bytes)");
34.418 - }
34.419 - if (e.getCrc() != crc.getValue()) {
34.420 - throw new ZipException(
34.421 - "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
34.422 - " but got 0x" + Long.toHexString(crc.getValue()) + ")");
34.423 - }
34.424 - }
34.425 -
34.426 - /*
34.427 - * Reads bytes, blocking until all bytes are read.
34.428 - */
34.429 - private void readFully(byte[] b, int off, int len) throws IOException {
34.430 - while (len > 0) {
34.431 - int n = in.read(b, off, len);
34.432 - if (n == -1) {
34.433 - throw new EOFException();
34.434 - }
34.435 - off += n;
34.436 - len -= n;
34.437 - }
34.438 - }
34.439 -
34.440 - /*
34.441 - * Fetches unsigned 16-bit value from byte array at specified offset.
34.442 - * The bytes are assumed to be in Intel (little-endian) byte order.
34.443 - */
34.444 - private static final int get16(byte b[], int off) {
34.445 - return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
34.446 - }
34.447 -
34.448 - /*
34.449 - * Fetches unsigned 32-bit value from byte array at specified offset.
34.450 - * The bytes are assumed to be in Intel (little-endian) byte order.
34.451 - */
34.452 - private static final long get32(byte b[], int off) {
34.453 - return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
34.454 - }
34.455 -
34.456 - /*
34.457 - * Fetches signed 64-bit value from byte array at specified offset.
34.458 - * The bytes are assumed to be in Intel (little-endian) byte order.
34.459 - */
34.460 - private static final long get64(byte b[], int off) {
34.461 - return get32(b, off) | (get32(b, off+4) << 32);
34.462 - }
34.463 -
34.464 - private static String toStringUTF8(byte[] arr, int len) {
34.465 - return new String(arr, 0, len);
34.466 - }
34.467 -
34.468 - private static String toString(byte[] b, int len) {
34.469 - return new String(b, 0, len);
34.470 - }
34.471 -}
35.1 --- a/rt/emul/pom.xml Wed May 07 11:55:06 2014 +0200
35.2 +++ b/rt/emul/pom.xml Wed May 07 16:47:24 2014 +0200
35.3 @@ -16,5 +16,6 @@
35.4 <module>compact</module>
35.5 <module>brwsrtest</module>
35.6 <module>fake</module>
35.7 + <module>zip</module>
35.8 </modules>
35.9 </project>
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/rt/emul/zip/pom.xml Wed May 07 16:47:24 2014 +0200
36.3 @@ -0,0 +1,51 @@
36.4 +<?xml version="1.0" encoding="UTF-8"?>
36.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
36.6 + <modelVersion>4.0.0</modelVersion>
36.7 + <parent>
36.8 + <groupId>org.apidesign.bck2brwsr</groupId>
36.9 + <artifactId>emul.pom</artifactId>
36.10 + <version>0.9-SNAPSHOT</version>
36.11 + </parent>
36.12 + <artifactId>emul.zip</artifactId>
36.13 + <name>Unzip by JCraft for Bck2Brwsr</name>
36.14 + <description>>
36.15 + 100% pure Java re-implementation of Zlib
36.16 + that allows usage of JAR files with Bck2Brwsr
36.17 + virtual machine.
36.18 + </description>
36.19 + <packaging>jar</packaging>
36.20 + <dependencies>
36.21 + <dependency>
36.22 + <groupId>org.apidesign.bck2brwsr</groupId>
36.23 + <artifactId>core</artifactId>
36.24 + <version>${project.version}</version>
36.25 + <type>jar</type>
36.26 + </dependency>
36.27 + <dependency>
36.28 + <groupId>org.testng</groupId>
36.29 + <artifactId>testng</artifactId>
36.30 + <scope>test</scope>
36.31 + </dependency>
36.32 + <dependency>
36.33 + <groupId>org.apidesign.bck2brwsr</groupId>
36.34 + <artifactId>emul.mini</artifactId>
36.35 + <version>${project.version}</version>
36.36 + <scope>compile</scope>
36.37 + <type>jar</type>
36.38 + </dependency>
36.39 + <dependency>
36.40 + <groupId>org.apidesign.bck2brwsr</groupId>
36.41 + <artifactId>vmtest</artifactId>
36.42 + <version>${project.version}</version>
36.43 + <scope>test</scope>
36.44 + <type>jar</type>
36.45 + </dependency>
36.46 + <dependency>
36.47 + <groupId>org.apidesign.bck2brwsr</groupId>
36.48 + <artifactId>launcher.http</artifactId>
36.49 + <version>${project.version}</version>
36.50 + <scope>test</scope>
36.51 + <type>jar</type>
36.52 + </dependency>
36.53 + </dependencies>
36.54 +</project>
36.55 \ No newline at end of file
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
37.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/Adler32.java Wed May 07 16:47:24 2014 +0200
37.3 @@ -0,0 +1,205 @@
37.4 +/* Adler32.java - Computes Adler32 data checksum of a data stream
37.5 + Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
37.6 +
37.7 +This file is part of GNU Classpath.
37.8 +
37.9 +GNU Classpath is free software; you can redistribute it and/or modify
37.10 +it under the terms of the GNU General Public License as published by
37.11 +the Free Software Foundation; either version 2, or (at your option)
37.12 +any later version.
37.13 +
37.14 +GNU Classpath is distributed in the hope that it will be useful, but
37.15 +WITHOUT ANY WARRANTY; without even the implied warranty of
37.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37.17 +General Public License for more details.
37.18 +
37.19 +You should have received a copy of the GNU General Public License
37.20 +along with GNU Classpath; see the file COPYING. If not, write to the
37.21 +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
37.22 +02111-1307 USA.
37.23 +
37.24 +Linking this library statically or dynamically with other modules is
37.25 +making a combined work based on this library. Thus, the terms and
37.26 +conditions of the GNU General Public License cover the whole
37.27 +combination.
37.28 +
37.29 +As a special exception, the copyright holders of this library give you
37.30 +permission to link this library with independent modules to produce an
37.31 +executable, regardless of the license terms of these independent
37.32 +modules, and to copy and distribute the resulting executable under
37.33 +terms of your choice, provided that you also meet, for each linked
37.34 +independent module, the terms and conditions of the license of that
37.35 +module. An independent module is a module which is not derived from
37.36 +or based on this library. If you modify this library, you may extend
37.37 +this exception to your version of the library, but you are not
37.38 +obligated to do so. If you do not wish to do so, delete this
37.39 +exception statement from your version. */
37.40 +
37.41 +package java.util.zip;
37.42 +
37.43 +/*
37.44 + * Written using on-line Java Platform 1.2 API Specification, as well
37.45 + * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
37.46 + * The actual Adler32 algorithm is taken from RFC 1950.
37.47 + * Status: Believed complete and correct.
37.48 + */
37.49 +
37.50 +/**
37.51 + * Computes Adler32 checksum for a stream of data. An Adler32
37.52 + * checksum is not as reliable as a CRC32 checksum, but a lot faster to
37.53 + * compute.
37.54 + *<p>
37.55 + * The specification for Adler32 may be found in RFC 1950.
37.56 + * (ZLIB Compressed Data Format Specification version 3.3)
37.57 + *<p>
37.58 + *<p>
37.59 + * From that document:
37.60 + *<p>
37.61 + * "ADLER32 (Adler-32 checksum)
37.62 + * This contains a checksum value of the uncompressed data
37.63 + * (excluding any dictionary data) computed according to Adler-32
37.64 + * algorithm. This algorithm is a 32-bit extension and improvement
37.65 + * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
37.66 + * standard.
37.67 + *<p>
37.68 + * Adler-32 is composed of two sums accumulated per byte: s1 is
37.69 + * the sum of all bytes, s2 is the sum of all s1 values. Both sums
37.70 + * are done modulo 65521. s1 is initialized to 1, s2 to zero. The
37.71 + * Adler-32 checksum is stored as s2*65536 + s1 in most-
37.72 + * significant-byte first (network) order."
37.73 + *<p>
37.74 + * "8.2. The Adler-32 algorithm
37.75 + *<p>
37.76 + * The Adler-32 algorithm is much faster than the CRC32 algorithm yet
37.77 + * still provides an extremely low probability of undetected errors.
37.78 + *<p>
37.79 + * The modulo on unsigned long accumulators can be delayed for 5552
37.80 + * bytes, so the modulo operation time is negligible. If the bytes
37.81 + * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
37.82 + * and order sensitive, unlike the first sum, which is just a
37.83 + * checksum. That 65521 is prime is important to avoid a possible
37.84 + * large class of two-byte errors that leave the check unchanged.
37.85 + * (The Fletcher checksum uses 255, which is not prime and which also
37.86 + * makes the Fletcher check insensitive to single byte changes 0 <->
37.87 + * 255.)
37.88 + *<p>
37.89 + * The sum s1 is initialized to 1 instead of zero to make the length
37.90 + * of the sequence part of s2, so that the length does not have to be
37.91 + * checked separately. (Any sequence of zeroes has a Fletcher
37.92 + * checksum of zero.)"
37.93 + *
37.94 + * @author John Leuner, Per Bothner
37.95 + * @since JDK 1.1
37.96 + *
37.97 + * @see InflaterInputStream
37.98 + * @see DeflaterOutputStream
37.99 + */
37.100 +public class Adler32 implements Checksum
37.101 +{
37.102 +
37.103 + /** largest prime smaller than 65536 */
37.104 + private static final int BASE = 65521;
37.105 +
37.106 + private int checksum; //we do all in int.
37.107 +
37.108 + //Note that java doesn't have unsigned integers,
37.109 + //so we have to be careful with what arithmetic
37.110 + //we do. We return the checksum as a long to
37.111 + //avoid sign confusion.
37.112 +
37.113 + /**
37.114 + * Creates a new instance of the <code>Adler32</code> class.
37.115 + * The checksum starts off with a value of 1.
37.116 + */
37.117 + public Adler32 ()
37.118 + {
37.119 + reset();
37.120 + }
37.121 +
37.122 + /**
37.123 + * Resets the Adler32 checksum to the initial value.
37.124 + */
37.125 + public void reset ()
37.126 + {
37.127 + checksum = 1; //Initialize to 1
37.128 + }
37.129 +
37.130 + /**
37.131 + * Updates the checksum with the byte b.
37.132 + *
37.133 + * @param bval the data value to add. The high byte of the int is ignored.
37.134 + */
37.135 + public void update (int bval)
37.136 + {
37.137 + //We could make a length 1 byte array and call update again, but I
37.138 + //would rather not have that overhead
37.139 + int s1 = checksum & 0xffff;
37.140 + int s2 = checksum >>> 16;
37.141 +
37.142 + s1 = (s1 + (bval & 0xFF)) % BASE;
37.143 + s2 = (s1 + s2) % BASE;
37.144 +
37.145 + checksum = (s2 << 16) + s1;
37.146 + }
37.147 +
37.148 + /**
37.149 + * Updates the checksum with the bytes taken from the array.
37.150 + *
37.151 + * @param buffer an array of bytes
37.152 + */
37.153 + public void update (byte[] buffer)
37.154 + {
37.155 + update(buffer, 0, buffer.length);
37.156 + }
37.157 +
37.158 + /**
37.159 + * Updates the checksum with the bytes taken from the array.
37.160 + *
37.161 + * @param buf an array of bytes
37.162 + * @param off the start of the data used for this update
37.163 + * @param len the number of bytes to use for this update
37.164 + */
37.165 + public void update (byte[] buf, int off, int len)
37.166 + {
37.167 + //(By Per Bothner)
37.168 + int s1 = checksum & 0xffff;
37.169 + int s2 = checksum >>> 16;
37.170 +
37.171 + while (len > 0)
37.172 + {
37.173 + // We can defer the modulo operation:
37.174 + // s1 maximally grows from 65521 to 65521 + 255 * 3800
37.175 + // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
37.176 + int n = 3800;
37.177 + if (n > len)
37.178 + n = len;
37.179 + len -= n;
37.180 + while (--n >= 0)
37.181 + {
37.182 + s1 = s1 + (buf[off++] & 0xFF);
37.183 + s2 = s2 + s1;
37.184 + }
37.185 + s1 %= BASE;
37.186 + s2 %= BASE;
37.187 + }
37.188 +
37.189 + /*Old implementation, borrowed from somewhere:
37.190 + int n;
37.191 +
37.192 + while (len-- > 0) {
37.193 +
37.194 + s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
37.195 + s2 = (s2 + s1) % BASE;
37.196 + }*/
37.197 +
37.198 + checksum = (s2 << 16) | s1;
37.199 + }
37.200 +
37.201 + /**
37.202 + * Returns the Adler32 data checksum computed so far.
37.203 + */
37.204 + public long getValue()
37.205 + {
37.206 + return (long) checksum & 0xffffffffL;
37.207 + }
37.208 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/CRC32.java Wed May 07 16:47:24 2014 +0200
38.3 @@ -0,0 +1,132 @@
38.4 +/* CRC32.java - Computes CRC32 data checksum of a data stream
38.5 + Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
38.6 +
38.7 +This file is part of GNU Classpath.
38.8 +
38.9 +GNU Classpath is free software; you can redistribute it and/or modify
38.10 +it under the terms of the GNU General Public License as published by
38.11 +the Free Software Foundation; either version 2, or (at your option)
38.12 +any later version.
38.13 +
38.14 +GNU Classpath is distributed in the hope that it will be useful, but
38.15 +WITHOUT ANY WARRANTY; without even the implied warranty of
38.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38.17 +General Public License for more details.
38.18 +
38.19 +You should have received a copy of the GNU General Public License
38.20 +along with GNU Classpath; see the file COPYING. If not, write to the
38.21 +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
38.22 +02111-1307 USA.
38.23 +
38.24 +Linking this library statically or dynamically with other modules is
38.25 +making a combined work based on this library. Thus, the terms and
38.26 +conditions of the GNU General Public License cover the whole
38.27 +combination.
38.28 +
38.29 +As a special exception, the copyright holders of this library give you
38.30 +permission to link this library with independent modules to produce an
38.31 +executable, regardless of the license terms of these independent
38.32 +modules, and to copy and distribute the resulting executable under
38.33 +terms of your choice, provided that you also meet, for each linked
38.34 +independent module, the terms and conditions of the license of that
38.35 +module. An independent module is a module which is not derived from
38.36 +or based on this library. If you modify this library, you may extend
38.37 +this exception to your version of the library, but you are not
38.38 +obligated to do so. If you do not wish to do so, delete this
38.39 +exception statement from your version. */
38.40 +
38.41 +package java.util.zip;
38.42 +
38.43 +/*
38.44 + * Written using on-line Java Platform 1.2 API Specification, as well
38.45 + * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
38.46 + * The actual CRC32 algorithm is taken from RFC 1952.
38.47 + * Status: Believed complete and correct.
38.48 + */
38.49 +
38.50 +/**
38.51 + * Computes CRC32 data checksum of a data stream.
38.52 + * The actual CRC32 algorithm is described in RFC 1952
38.53 + * (GZIP file format specification version 4.3).
38.54 + * Can be used to get the CRC32 over a stream if used with checked input/output
38.55 + * streams.
38.56 + *
38.57 + * @see InflaterInputStream
38.58 + * @see DeflaterOutputStream
38.59 + *
38.60 + * @author Per Bothner
38.61 + * @date April 1, 1999.
38.62 + */
38.63 +public class CRC32 implements Checksum
38.64 +{
38.65 + /** The crc data checksum so far. */
38.66 + private int crc = 0;
38.67 +
38.68 + /** The fast CRC table. Computed once when the CRC32 class is loaded. */
38.69 + private static int[] crc_table = make_crc_table();
38.70 +
38.71 + /** Make the table for a fast CRC. */
38.72 + private static int[] make_crc_table ()
38.73 + {
38.74 + int[] crc_table = new int[256];
38.75 + for (int n = 0; n < 256; n++)
38.76 + {
38.77 + int c = n;
38.78 + for (int k = 8; --k >= 0; )
38.79 + {
38.80 + if ((c & 1) != 0)
38.81 + c = 0xedb88320 ^ (c >>> 1);
38.82 + else
38.83 + c = c >>> 1;
38.84 + }
38.85 + crc_table[n] = c;
38.86 + }
38.87 + return crc_table;
38.88 + }
38.89 +
38.90 + /**
38.91 + * Returns the CRC32 data checksum computed so far.
38.92 + */
38.93 + public long getValue ()
38.94 + {
38.95 + return (long) crc & 0xffffffffL;
38.96 + }
38.97 +
38.98 + /**
38.99 + * Resets the CRC32 data checksum as if no update was ever called.
38.100 + */
38.101 + public void reset () { crc = 0; }
38.102 +
38.103 + /**
38.104 + * Updates the checksum with the int bval.
38.105 + *
38.106 + * @param bval (the byte is taken as the lower 8 bits of bval)
38.107 + */
38.108 +
38.109 + public void update (int bval)
38.110 + {
38.111 + int c = ~crc;
38.112 + c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
38.113 + crc = ~c;
38.114 + }
38.115 +
38.116 + /**
38.117 + * Adds the byte array to the data checksum.
38.118 + *
38.119 + * @param buf the buffer which contains the data
38.120 + * @param off the offset in the buffer where the data starts
38.121 + * @param len the length of the data
38.122 + */
38.123 + public void update (byte[] buf, int off, int len)
38.124 + {
38.125 + int c = ~crc;
38.126 + while (--len >= 0)
38.127 + c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
38.128 + crc = ~c;
38.129 + }
38.130 +
38.131 + /**
38.132 + * Adds the complete byte array to the data checksum.
38.133 + */
38.134 + public void update (byte[] buf) { update(buf, 0, buf.length); }
38.135 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/Checksum.java Wed May 07 16:47:24 2014 +0200
39.3 @@ -0,0 +1,60 @@
39.4 +/*
39.5 + * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39.7 + *
39.8 + * This code is free software; you can redistribute it and/or modify it
39.9 + * under the terms of the GNU General Public License version 2 only, as
39.10 + * published by the Free Software Foundation. Oracle designates this
39.11 + * particular file as subject to the "Classpath" exception as provided
39.12 + * by Oracle in the LICENSE file that accompanied this code.
39.13 + *
39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39.17 + * version 2 for more details (a copy is included in the LICENSE file that
39.18 + * accompanied this code).
39.19 + *
39.20 + * You should have received a copy of the GNU General Public License version
39.21 + * 2 along with this work; if not, write to the Free Software Foundation,
39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39.23 + *
39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39.25 + * or visit www.oracle.com if you need additional information or have any
39.26 + * questions.
39.27 + */
39.28 +
39.29 +package java.util.zip;
39.30 +
39.31 +/**
39.32 + * An interface representing a data checksum.
39.33 + *
39.34 + * @author David Connelly
39.35 + */
39.36 +public
39.37 +interface Checksum {
39.38 + /**
39.39 + * Updates the current checksum with the specified byte.
39.40 + *
39.41 + * @param b the byte to update the checksum with
39.42 + */
39.43 + public void update(int b);
39.44 +
39.45 + /**
39.46 + * Updates the current checksum with the specified array of bytes.
39.47 + * @param b the byte array to update the checksum with
39.48 + * @param off the start offset of the data
39.49 + * @param len the number of bytes to use for the update
39.50 + */
39.51 + public void update(byte[] b, int off, int len);
39.52 +
39.53 + /**
39.54 + * Returns the current checksum value.
39.55 + * @return the current checksum value
39.56 + */
39.57 + public long getValue();
39.58 +
39.59 + /**
39.60 + * Resets the checksum to its initial value.
39.61 + */
39.62 + public void reset();
39.63 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
40.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/DataFormatException.java Wed May 07 16:47:24 2014 +0200
40.3 @@ -0,0 +1,52 @@
40.4 +/*
40.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40.7 + *
40.8 + * This code is free software; you can redistribute it and/or modify it
40.9 + * under the terms of the GNU General Public License version 2 only, as
40.10 + * published by the Free Software Foundation. Oracle designates this
40.11 + * particular file as subject to the "Classpath" exception as provided
40.12 + * by Oracle in the LICENSE file that accompanied this code.
40.13 + *
40.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
40.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
40.17 + * version 2 for more details (a copy is included in the LICENSE file that
40.18 + * accompanied this code).
40.19 + *
40.20 + * You should have received a copy of the GNU General Public License version
40.21 + * 2 along with this work; if not, write to the Free Software Foundation,
40.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
40.23 + *
40.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
40.25 + * or visit www.oracle.com if you need additional information or have any
40.26 + * questions.
40.27 + */
40.28 +
40.29 +package java.util.zip;
40.30 +
40.31 +/**
40.32 + * Signals that a data format error has occurred.
40.33 + *
40.34 + * @author David Connelly
40.35 + */
40.36 +public
40.37 +class DataFormatException extends Exception {
40.38 + private static final long serialVersionUID = 2219632870893641452L;
40.39 +
40.40 + /**
40.41 + * Constructs a DataFormatException with no detail message.
40.42 + */
40.43 + public DataFormatException() {
40.44 + super();
40.45 + }
40.46 +
40.47 + /**
40.48 + * Constructs a DataFormatException with the specified detail message.
40.49 + * A detail message is a String that describes this particular exception.
40.50 + * @param s the String containing a detail message
40.51 + */
40.52 + public DataFormatException(String s) {
40.53 + super(s);
40.54 + }
40.55 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
41.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/Inflater.java Wed May 07 16:47:24 2014 +0200
41.3 @@ -0,0 +1,310 @@
41.4 +/*
41.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41.7 + *
41.8 + * This code is free software; you can redistribute it and/or modify it
41.9 + * under the terms of the GNU General Public License version 2 only, as
41.10 + * published by the Free Software Foundation. Oracle designates this
41.11 + * particular file as subject to the "Classpath" exception as provided
41.12 + * by Oracle in the LICENSE file that accompanied this code.
41.13 + *
41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
41.17 + * version 2 for more details (a copy is included in the LICENSE file that
41.18 + * accompanied this code).
41.19 + *
41.20 + * You should have received a copy of the GNU General Public License version
41.21 + * 2 along with this work; if not, write to the Free Software Foundation,
41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41.23 + *
41.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41.25 + * or visit www.oracle.com if you need additional information or have any
41.26 + * questions.
41.27 + */
41.28 +
41.29 +package java.util.zip;
41.30 +
41.31 +/**
41.32 + * This class provides support for general purpose decompression using the
41.33 + * popular ZLIB compression library. The ZLIB compression library was
41.34 + * initially developed as part of the PNG graphics standard and is not
41.35 + * protected by patents. It is fully described in the specifications at
41.36 + * the <a href="package-summary.html#package_description">java.util.zip
41.37 + * package description</a>.
41.38 + *
41.39 + * <p>The following code fragment demonstrates a trivial compression
41.40 + * and decompression of a string using <tt>Deflater</tt> and
41.41 + * <tt>Inflater</tt>.
41.42 + *
41.43 + * <blockquote><pre>
41.44 + * try {
41.45 + * // Encode a String into bytes
41.46 + * String inputString = "blahblahblah\u20AC\u20AC";
41.47 + * byte[] input = inputString.getBytes("UTF-8");
41.48 + *
41.49 + * // Compress the bytes
41.50 + * byte[] output = new byte[100];
41.51 + * Deflater compresser = new Deflater();
41.52 + * compresser.setInput(input);
41.53 + * compresser.finish();
41.54 + * int compressedDataLength = compresser.deflate(output);
41.55 + *
41.56 + * // Decompress the bytes
41.57 + * Inflater decompresser = new Inflater();
41.58 + * decompresser.setInput(output, 0, compressedDataLength);
41.59 + * byte[] result = new byte[100];
41.60 + * int resultLength = decompresser.inflate(result);
41.61 + * decompresser.end();
41.62 + *
41.63 + * // Decode the bytes into a String
41.64 + * String outputString = new String(result, 0, resultLength, "UTF-8");
41.65 + * } catch(java.io.UnsupportedEncodingException ex) {
41.66 + * // handle
41.67 + * } catch (java.util.zip.DataFormatException ex) {
41.68 + * // handle
41.69 + * }
41.70 + * </pre></blockquote>
41.71 + *
41.72 + * @see Deflater
41.73 + * @author David Connelly
41.74 + *
41.75 + */
41.76 +public
41.77 +class Inflater {
41.78 + private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
41.79 +
41.80 + /**
41.81 + * Creates a new decompressor. If the parameter 'nowrap' is true then
41.82 + * the ZLIB header and checksum fields will not be used. This provides
41.83 + * compatibility with the compression format used by both GZIP and PKZIP.
41.84 + * <p>
41.85 + * Note: When using the 'nowrap' option it is also necessary to provide
41.86 + * an extra "dummy" byte as input. This is required by the ZLIB native
41.87 + * library in order to support certain optimizations.
41.88 + *
41.89 + * @param nowrap if true then support GZIP compatible compression
41.90 + */
41.91 + public Inflater(boolean nowrap) {
41.92 + if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
41.93 + impl = null;
41.94 + } else {
41.95 + impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
41.96 + }
41.97 + }
41.98 +
41.99 + /**
41.100 + * Creates a new decompressor.
41.101 + */
41.102 + public Inflater() {
41.103 + this(false);
41.104 + }
41.105 +
41.106 + /**
41.107 + * Sets input data for decompression. Should be called whenever
41.108 + * needsInput() returns true indicating that more input data is
41.109 + * required.
41.110 + * @param b the input data bytes
41.111 + * @param off the start offset of the input data
41.112 + * @param len the length of the input data
41.113 + * @see Inflater#needsInput
41.114 + */
41.115 + public void setInput(byte[] b, int off, int len) {
41.116 + impl.setInput(b, off, len);
41.117 + }
41.118 +
41.119 + /**
41.120 + * Sets input data for decompression. Should be called whenever
41.121 + * needsInput() returns true indicating that more input data is
41.122 + * required.
41.123 + * @param b the input data bytes
41.124 + * @see Inflater#needsInput
41.125 + */
41.126 + public void setInput(byte[] b) {
41.127 + impl.setInput(b);
41.128 + }
41.129 +
41.130 + /**
41.131 + * Sets the preset dictionary to the given array of bytes. Should be
41.132 + * called when inflate() returns 0 and needsDictionary() returns true
41.133 + * indicating that a preset dictionary is required. The method getAdler()
41.134 + * can be used to get the Adler-32 value of the dictionary needed.
41.135 + * @param b the dictionary data bytes
41.136 + * @param off the start offset of the data
41.137 + * @param len the length of the data
41.138 + * @see Inflater#needsDictionary
41.139 + * @see Inflater#getAdler
41.140 + */
41.141 + public void setDictionary(byte[] b, int off, int len) {
41.142 + impl.setDictionary(b, off, len);
41.143 + }
41.144 +
41.145 + /**
41.146 + * Sets the preset dictionary to the given array of bytes. Should be
41.147 + * called when inflate() returns 0 and needsDictionary() returns true
41.148 + * indicating that a preset dictionary is required. The method getAdler()
41.149 + * can be used to get the Adler-32 value of the dictionary needed.
41.150 + * @param b the dictionary data bytes
41.151 + * @see Inflater#needsDictionary
41.152 + * @see Inflater#getAdler
41.153 + */
41.154 + public void setDictionary(byte[] b) {
41.155 + impl.setDictionary(b);
41.156 + }
41.157 +
41.158 + /**
41.159 + * Returns the total number of bytes remaining in the input buffer.
41.160 + * This can be used to find out what bytes still remain in the input
41.161 + * buffer after decompression has finished.
41.162 + * @return the total number of bytes remaining in the input buffer
41.163 + */
41.164 + public int getRemaining() {
41.165 + return impl.getRemaining();
41.166 + }
41.167 +
41.168 + /**
41.169 + * Returns true if no data remains in the input buffer. This can
41.170 + * be used to determine if #setInput should be called in order
41.171 + * to provide more input.
41.172 + * @return true if no data remains in the input buffer
41.173 + */
41.174 + public boolean needsInput() {
41.175 + return impl.needsInput();
41.176 + }
41.177 +
41.178 + /**
41.179 + * Returns true if a preset dictionary is needed for decompression.
41.180 + * @return true if a preset dictionary is needed for decompression
41.181 + * @see Inflater#setDictionary
41.182 + */
41.183 + public boolean needsDictionary() {
41.184 + return impl.needsDictionary();
41.185 + }
41.186 +
41.187 + /**
41.188 + * Returns true if the end of the compressed data stream has been
41.189 + * reached.
41.190 + * @return true if the end of the compressed data stream has been
41.191 + * reached
41.192 + */
41.193 + public boolean finished() {
41.194 + return impl.finished();
41.195 + }
41.196 +
41.197 + /**
41.198 + * Uncompresses bytes into specified buffer. Returns actual number
41.199 + * of bytes uncompressed. A return value of 0 indicates that
41.200 + * needsInput() or needsDictionary() should be called in order to
41.201 + * determine if more input data or a preset dictionary is required.
41.202 + * In the latter case, getAdler() can be used to get the Adler-32
41.203 + * value of the dictionary required.
41.204 + * @param b the buffer for the uncompressed data
41.205 + * @param off the start offset of the data
41.206 + * @param len the maximum number of uncompressed bytes
41.207 + * @return the actual number of uncompressed bytes
41.208 + * @exception DataFormatException if the compressed data format is invalid
41.209 + * @see Inflater#needsInput
41.210 + * @see Inflater#needsDictionary
41.211 + */
41.212 + public int inflate(byte[] b, int off, int len)
41.213 + throws DataFormatException
41.214 + {
41.215 + return impl.inflate(b, off, len);
41.216 + }
41.217 +
41.218 + /**
41.219 + * Uncompresses bytes into specified buffer. Returns actual number
41.220 + * of bytes uncompressed. A return value of 0 indicates that
41.221 + * needsInput() or needsDictionary() should be called in order to
41.222 + * determine if more input data or a preset dictionary is required.
41.223 + * In the latter case, getAdler() can be used to get the Adler-32
41.224 + * value of the dictionary required.
41.225 + * @param b the buffer for the uncompressed data
41.226 + * @return the actual number of uncompressed bytes
41.227 + * @exception DataFormatException if the compressed data format is invalid
41.228 + * @see Inflater#needsInput
41.229 + * @see Inflater#needsDictionary
41.230 + */
41.231 + public int inflate(byte[] b) throws DataFormatException {
41.232 + return impl.inflate(b);
41.233 + }
41.234 +
41.235 + /**
41.236 + * Returns the ADLER-32 value of the uncompressed data.
41.237 + * @return the ADLER-32 value of the uncompressed data
41.238 + */
41.239 + public int getAdler() {
41.240 + return impl.getAdler();
41.241 + }
41.242 +
41.243 + /**
41.244 + * Returns the total number of compressed bytes input so far.
41.245 + *
41.246 + * <p>Since the number of bytes may be greater than
41.247 + * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
41.248 + * the preferred means of obtaining this information.</p>
41.249 + *
41.250 + * @return the total number of compressed bytes input so far
41.251 + */
41.252 + public int getTotalIn() {
41.253 + return impl.getTotalIn();
41.254 + }
41.255 +
41.256 + /**
41.257 + * Returns the total number of compressed bytes input so far.</p>
41.258 + *
41.259 + * @return the total (non-negative) number of compressed bytes input so far
41.260 + * @since 1.5
41.261 + */
41.262 + public long getBytesRead() {
41.263 + return impl.getBytesRead();
41.264 + }
41.265 +
41.266 + /**
41.267 + * Returns the total number of uncompressed bytes output so far.
41.268 + *
41.269 + * <p>Since the number of bytes may be greater than
41.270 + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
41.271 + * the preferred means of obtaining this information.</p>
41.272 + *
41.273 + * @return the total number of uncompressed bytes output so far
41.274 + */
41.275 + public int getTotalOut() {
41.276 + return impl.getTotalOut();
41.277 + }
41.278 +
41.279 + /**
41.280 + * Returns the total number of uncompressed bytes output so far.</p>
41.281 + *
41.282 + * @return the total (non-negative) number of uncompressed bytes output so far
41.283 + * @since 1.5
41.284 + */
41.285 + public long getBytesWritten() {
41.286 + return impl.getBytesWritten();
41.287 + }
41.288 +
41.289 + /**
41.290 + * Resets inflater so that a new set of input data can be processed.
41.291 + */
41.292 + public void reset() {
41.293 + impl.reset();
41.294 + }
41.295 +
41.296 + /**
41.297 + * Closes the decompressor and discards any unprocessed input.
41.298 + * This method should be called when the decompressor is no longer
41.299 + * being used, but will also be called automatically by the finalize()
41.300 + * method. Once this method is called, the behavior of the Inflater
41.301 + * object is undefined.
41.302 + */
41.303 + public void end() {
41.304 + impl.end();
41.305 + }
41.306 +
41.307 + /**
41.308 + * Closes the decompressor when garbage is collected.
41.309 + */
41.310 + protected void finalize() {
41.311 + end();
41.312 + }
41.313 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
42.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/InflaterInputStream.java Wed May 07 16:47:24 2014 +0200
42.3 @@ -0,0 +1,288 @@
42.4 +/*
42.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42.7 + *
42.8 + * This code is free software; you can redistribute it and/or modify it
42.9 + * under the terms of the GNU General Public License version 2 only, as
42.10 + * published by the Free Software Foundation. Oracle designates this
42.11 + * particular file as subject to the "Classpath" exception as provided
42.12 + * by Oracle in the LICENSE file that accompanied this code.
42.13 + *
42.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
42.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42.17 + * version 2 for more details (a copy is included in the LICENSE file that
42.18 + * accompanied this code).
42.19 + *
42.20 + * You should have received a copy of the GNU General Public License version
42.21 + * 2 along with this work; if not, write to the Free Software Foundation,
42.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42.23 + *
42.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42.25 + * or visit www.oracle.com if you need additional information or have any
42.26 + * questions.
42.27 + */
42.28 +
42.29 +package java.util.zip;
42.30 +
42.31 +import java.io.FilterInputStream;
42.32 +import java.io.InputStream;
42.33 +import java.io.IOException;
42.34 +import java.io.EOFException;
42.35 +
42.36 +/**
42.37 + * This class implements a stream filter for uncompressing data in the
42.38 + * "deflate" compression format. It is also used as the basis for other
42.39 + * decompression filters, such as GZIPInputStream.
42.40 + *
42.41 + * @see Inflater
42.42 + * @author David Connelly
42.43 + */
42.44 +public
42.45 +class InflaterInputStream extends FilterInputStream {
42.46 + /**
42.47 + * Decompressor for this stream.
42.48 + */
42.49 + protected Inflater inf;
42.50 +
42.51 + /**
42.52 + * Input buffer for decompression.
42.53 + */
42.54 + protected byte[] buf;
42.55 +
42.56 + /**
42.57 + * Length of input buffer.
42.58 + */
42.59 + protected int len;
42.60 +
42.61 + private boolean closed = false;
42.62 + // this flag is set to true after EOF has reached
42.63 + private boolean reachEOF = false;
42.64 +
42.65 + /**
42.66 + * Check to make sure that this stream has not been closed
42.67 + */
42.68 + private void ensureOpen() throws IOException {
42.69 + if (closed) {
42.70 + throw new IOException("Stream closed");
42.71 + }
42.72 + }
42.73 +
42.74 +
42.75 + /**
42.76 + * Creates a new input stream with the specified decompressor and
42.77 + * buffer size.
42.78 + * @param in the input stream
42.79 + * @param inf the decompressor ("inflater")
42.80 + * @param size the input buffer size
42.81 + * @exception IllegalArgumentException if size is <= 0
42.82 + */
42.83 + public InflaterInputStream(InputStream in, Inflater inf, int size) {
42.84 + super(in);
42.85 + if (in == null || inf == null) {
42.86 + throw new NullPointerException();
42.87 + } else if (size <= 0) {
42.88 + throw new IllegalArgumentException("buffer size <= 0");
42.89 + }
42.90 + this.inf = inf;
42.91 + buf = new byte[size];
42.92 + }
42.93 +
42.94 + /**
42.95 + * Creates a new input stream with the specified decompressor and a
42.96 + * default buffer size.
42.97 + * @param in the input stream
42.98 + * @param inf the decompressor ("inflater")
42.99 + */
42.100 + public InflaterInputStream(InputStream in, Inflater inf) {
42.101 + this(in, inf, 512);
42.102 + }
42.103 +
42.104 + boolean usesDefaultInflater = false;
42.105 +
42.106 + /**
42.107 + * Creates a new input stream with a default decompressor and buffer size.
42.108 + * @param in the input stream
42.109 + */
42.110 + public InflaterInputStream(InputStream in) {
42.111 + this(in, new Inflater());
42.112 + usesDefaultInflater = true;
42.113 + }
42.114 +
42.115 + private byte[] singleByteBuf = new byte[1];
42.116 +
42.117 + /**
42.118 + * Reads a byte of uncompressed data. This method will block until
42.119 + * enough input is available for decompression.
42.120 + * @return the byte read, or -1 if end of compressed input is reached
42.121 + * @exception IOException if an I/O error has occurred
42.122 + */
42.123 + public int read() throws IOException {
42.124 + ensureOpen();
42.125 + return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
42.126 + }
42.127 +
42.128 + /**
42.129 + * Reads uncompressed data into an array of bytes. If <code>len</code> is not
42.130 + * zero, the method will block until some input can be decompressed; otherwise,
42.131 + * no bytes are read and <code>0</code> is returned.
42.132 + * @param b the buffer into which the data is read
42.133 + * @param off the start offset in the destination array <code>b</code>
42.134 + * @param len the maximum number of bytes read
42.135 + * @return the actual number of bytes read, or -1 if the end of the
42.136 + * compressed input is reached or a preset dictionary is needed
42.137 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
42.138 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
42.139 + * <code>len</code> is negative, or <code>len</code> is greater than
42.140 + * <code>b.length - off</code>
42.141 + * @exception ZipException if a ZIP format error has occurred
42.142 + * @exception IOException if an I/O error has occurred
42.143 + */
42.144 + public int read(byte[] b, int off, int len) throws IOException {
42.145 + ensureOpen();
42.146 + if (b == null) {
42.147 + throw new NullPointerException();
42.148 + } else if (off < 0 || len < 0 || len > b.length - off) {
42.149 + throw new IndexOutOfBoundsException();
42.150 + } else if (len == 0) {
42.151 + return 0;
42.152 + }
42.153 + try {
42.154 + int n;
42.155 + while ((n = inf.inflate(b, off, len)) == 0) {
42.156 + if (inf.finished() || inf.needsDictionary()) {
42.157 + reachEOF = true;
42.158 + return -1;
42.159 + }
42.160 + if (inf.needsInput()) {
42.161 + fill();
42.162 + }
42.163 + }
42.164 + return n;
42.165 + } catch (DataFormatException e) {
42.166 + String s = e.getMessage();
42.167 + throw new ZipException(s != null ? s : "Invalid ZLIB data format");
42.168 + }
42.169 + }
42.170 +
42.171 + /**
42.172 + * Returns 0 after EOF has been reached, otherwise always return 1.
42.173 + * <p>
42.174 + * Programs should not count on this method to return the actual number
42.175 + * of bytes that could be read without blocking.
42.176 + *
42.177 + * @return 1 before EOF and 0 after EOF.
42.178 + * @exception IOException if an I/O error occurs.
42.179 + *
42.180 + */
42.181 + public int available() throws IOException {
42.182 + ensureOpen();
42.183 + if (reachEOF) {
42.184 + return 0;
42.185 + } else {
42.186 + return 1;
42.187 + }
42.188 + }
42.189 +
42.190 + private byte[] b = new byte[512];
42.191 +
42.192 + /**
42.193 + * Skips specified number of bytes of uncompressed data.
42.194 + * @param n the number of bytes to skip
42.195 + * @return the actual number of bytes skipped.
42.196 + * @exception IOException if an I/O error has occurred
42.197 + * @exception IllegalArgumentException if n < 0
42.198 + */
42.199 + public long skip(long n) throws IOException {
42.200 + if (n < 0) {
42.201 + throw new IllegalArgumentException("negative skip length");
42.202 + }
42.203 + ensureOpen();
42.204 + int max = (int)Math.min(n, Integer.MAX_VALUE);
42.205 + int total = 0;
42.206 + while (total < max) {
42.207 + int len = max - total;
42.208 + if (len > b.length) {
42.209 + len = b.length;
42.210 + }
42.211 + len = read(b, 0, len);
42.212 + if (len == -1) {
42.213 + reachEOF = true;
42.214 + break;
42.215 + }
42.216 + total += len;
42.217 + }
42.218 + return total;
42.219 + }
42.220 +
42.221 + /**
42.222 + * Closes this input stream and releases any system resources associated
42.223 + * with the stream.
42.224 + * @exception IOException if an I/O error has occurred
42.225 + */
42.226 + public void close() throws IOException {
42.227 + if (!closed) {
42.228 + if (usesDefaultInflater)
42.229 + inf.end();
42.230 + in.close();
42.231 + closed = true;
42.232 + }
42.233 + }
42.234 +
42.235 + /**
42.236 + * Fills input buffer with more data to decompress.
42.237 + * @exception IOException if an I/O error has occurred
42.238 + */
42.239 + protected void fill() throws IOException {
42.240 + ensureOpen();
42.241 + len = in.read(buf, 0, buf.length);
42.242 + if (len == -1) {
42.243 + throw new EOFException("Unexpected end of ZLIB input stream");
42.244 + }
42.245 + inf.setInput(buf, 0, len);
42.246 + }
42.247 +
42.248 + /**
42.249 + * Tests if this input stream supports the <code>mark</code> and
42.250 + * <code>reset</code> methods. The <code>markSupported</code>
42.251 + * method of <code>InflaterInputStream</code> returns
42.252 + * <code>false</code>.
42.253 + *
42.254 + * @return a <code>boolean</code> indicating if this stream type supports
42.255 + * the <code>mark</code> and <code>reset</code> methods.
42.256 + * @see java.io.InputStream#mark(int)
42.257 + * @see java.io.InputStream#reset()
42.258 + */
42.259 + public boolean markSupported() {
42.260 + return false;
42.261 + }
42.262 +
42.263 + /**
42.264 + * Marks the current position in this input stream.
42.265 + *
42.266 + * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
42.267 + * does nothing.
42.268 + *
42.269 + * @param readlimit the maximum limit of bytes that can be read before
42.270 + * the mark position becomes invalid.
42.271 + * @see java.io.InputStream#reset()
42.272 + */
42.273 + public synchronized void mark(int readlimit) {
42.274 + }
42.275 +
42.276 + /**
42.277 + * Repositions this stream to the position at the time the
42.278 + * <code>mark</code> method was last called on this input stream.
42.279 + *
42.280 + * <p> The method <code>reset</code> for class
42.281 + * <code>InflaterInputStream</code> does nothing except throw an
42.282 + * <code>IOException</code>.
42.283 + *
42.284 + * @exception IOException if this method is invoked.
42.285 + * @see java.io.InputStream#mark(int)
42.286 + * @see java.io.IOException
42.287 + */
42.288 + public synchronized void reset() throws IOException {
42.289 + throw new IOException("mark/reset not supported");
42.290 + }
42.291 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZStreamRef.java Wed May 07 16:47:24 2014 +0200
43.3 @@ -0,0 +1,46 @@
43.4 +/*
43.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43.7 + *
43.8 + * This code is free software; you can redistribute it and/or modify it
43.9 + * under the terms of the GNU General Public License version 2 only, as
43.10 + * published by the Free Software Foundation. Oracle designates this
43.11 + * particular file as subject to the "Classpath" exception as provided
43.12 + * by Oracle in the LICENSE file that accompanied this code.
43.13 + *
43.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
43.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43.17 + * version 2 for more details (a copy is included in the LICENSE file that
43.18 + * accompanied this code).
43.19 + *
43.20 + * You should have received a copy of the GNU General Public License version
43.21 + * 2 along with this work; if not, write to the Free Software Foundation,
43.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43.23 + *
43.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43.25 + * or visit www.oracle.com if you need additional information or have any
43.26 + * questions.
43.27 + */
43.28 +
43.29 +package java.util.zip;
43.30 +
43.31 +/**
43.32 + * A reference to the native zlib's z_stream structure.
43.33 + */
43.34 +
43.35 +class ZStreamRef {
43.36 +
43.37 + private long address;
43.38 + ZStreamRef (long address) {
43.39 + this.address = address;
43.40 + }
43.41 +
43.42 + long address() {
43.43 + return address;
43.44 + }
43.45 +
43.46 + void clear() {
43.47 + address = 0;
43.48 + }
43.49 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipConstants.java Wed May 07 16:47:24 2014 +0200
44.3 @@ -0,0 +1,98 @@
44.4 +/*
44.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44.7 + *
44.8 + * This code is free software; you can redistribute it and/or modify it
44.9 + * under the terms of the GNU General Public License version 2 only, as
44.10 + * published by the Free Software Foundation. Oracle designates this
44.11 + * particular file as subject to the "Classpath" exception as provided
44.12 + * by Oracle in the LICENSE file that accompanied this code.
44.13 + *
44.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
44.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
44.17 + * version 2 for more details (a copy is included in the LICENSE file that
44.18 + * accompanied this code).
44.19 + *
44.20 + * You should have received a copy of the GNU General Public License version
44.21 + * 2 along with this work; if not, write to the Free Software Foundation,
44.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44.23 + *
44.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44.25 + * or visit www.oracle.com if you need additional information or have any
44.26 + * questions.
44.27 + */
44.28 +
44.29 +package java.util.zip;
44.30 +
44.31 +/*
44.32 + * This interface defines the constants that are used by the classes
44.33 + * which manipulate ZIP files.
44.34 + *
44.35 + * @author David Connelly
44.36 + */
44.37 +interface ZipConstants {
44.38 + /*
44.39 + * Header signatures
44.40 + */
44.41 + static long LOCSIG = 0x04034b50L; // "PK\003\004"
44.42 + static long EXTSIG = 0x08074b50L; // "PK\007\008"
44.43 + static long CENSIG = 0x02014b50L; // "PK\001\002"
44.44 + static long ENDSIG = 0x06054b50L; // "PK\005\006"
44.45 +
44.46 + /*
44.47 + * Header sizes in bytes (including signatures)
44.48 + */
44.49 + static final int LOCHDR = 30; // LOC header size
44.50 + static final int EXTHDR = 16; // EXT header size
44.51 + static final int CENHDR = 46; // CEN header size
44.52 + static final int ENDHDR = 22; // END header size
44.53 +
44.54 + /*
44.55 + * Local file (LOC) header field offsets
44.56 + */
44.57 + static final int LOCVER = 4; // version needed to extract
44.58 + static final int LOCFLG = 6; // general purpose bit flag
44.59 + static final int LOCHOW = 8; // compression method
44.60 + static final int LOCTIM = 10; // modification time
44.61 + static final int LOCCRC = 14; // uncompressed file crc-32 value
44.62 + static final int LOCSIZ = 18; // compressed size
44.63 + static final int LOCLEN = 22; // uncompressed size
44.64 + static final int LOCNAM = 26; // filename length
44.65 + static final int LOCEXT = 28; // extra field length
44.66 +
44.67 + /*
44.68 + * Extra local (EXT) header field offsets
44.69 + */
44.70 + static final int EXTCRC = 4; // uncompressed file crc-32 value
44.71 + static final int EXTSIZ = 8; // compressed size
44.72 + static final int EXTLEN = 12; // uncompressed size
44.73 +
44.74 + /*
44.75 + * Central directory (CEN) header field offsets
44.76 + */
44.77 + static final int CENVEM = 4; // version made by
44.78 + static final int CENVER = 6; // version needed to extract
44.79 + static final int CENFLG = 8; // encrypt, decrypt flags
44.80 + static final int CENHOW = 10; // compression method
44.81 + static final int CENTIM = 12; // modification time
44.82 + static final int CENCRC = 16; // uncompressed file crc-32 value
44.83 + static final int CENSIZ = 20; // compressed size
44.84 + static final int CENLEN = 24; // uncompressed size
44.85 + static final int CENNAM = 28; // filename length
44.86 + static final int CENEXT = 30; // extra field length
44.87 + static final int CENCOM = 32; // comment length
44.88 + static final int CENDSK = 34; // disk number start
44.89 + static final int CENATT = 36; // internal file attributes
44.90 + static final int CENATX = 38; // external file attributes
44.91 + static final int CENOFF = 42; // LOC header offset
44.92 +
44.93 + /*
44.94 + * End of central directory (END) header field offsets
44.95 + */
44.96 + static final int ENDSUB = 8; // number of entries on this disk
44.97 + static final int ENDTOT = 10; // total number of entries
44.98 + static final int ENDSIZ = 12; // central directory size in bytes
44.99 + static final int ENDOFF = 16; // offset of first CEN header
44.100 + static final int ENDCOM = 20; // zip file comment length
44.101 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
45.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipEntry.java Wed May 07 16:47:24 2014 +0200
45.3 @@ -0,0 +1,331 @@
45.4 +/*
45.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45.7 + *
45.8 + * This code is free software; you can redistribute it and/or modify it
45.9 + * under the terms of the GNU General Public License version 2 only, as
45.10 + * published by the Free Software Foundation. Oracle designates this
45.11 + * particular file as subject to the "Classpath" exception as provided
45.12 + * by Oracle in the LICENSE file that accompanied this code.
45.13 + *
45.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
45.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45.17 + * version 2 for more details (a copy is included in the LICENSE file that
45.18 + * accompanied this code).
45.19 + *
45.20 + * You should have received a copy of the GNU General Public License version
45.21 + * 2 along with this work; if not, write to the Free Software Foundation,
45.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45.23 + *
45.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45.25 + * or visit www.oracle.com if you need additional information or have any
45.26 + * questions.
45.27 + */
45.28 +
45.29 +package java.util.zip;
45.30 +
45.31 +/**
45.32 + * This class is used to represent a ZIP file entry.
45.33 + *
45.34 + * @author David Connelly
45.35 + */
45.36 +public
45.37 +class ZipEntry implements ZipConstants, Cloneable {
45.38 + String name; // entry name
45.39 + long time = -1; // modification time (in DOS time)
45.40 + long crc = -1; // crc-32 of entry data
45.41 + long size = -1; // uncompressed size of entry data
45.42 + long csize = -1; // compressed size of entry data
45.43 + int method = -1; // compression method
45.44 + int flag = 0; // general purpose flag
45.45 + byte[] extra; // optional extra field data for entry
45.46 + String comment; // optional comment string for entry
45.47 +
45.48 + /**
45.49 + * Compression method for uncompressed entries.
45.50 + */
45.51 + public static final int STORED = 0;
45.52 +
45.53 + /**
45.54 + * Compression method for compressed (deflated) entries.
45.55 + */
45.56 + public static final int DEFLATED = 8;
45.57 +
45.58 + /**
45.59 + * Creates a new zip entry with the specified name.
45.60 + *
45.61 + * @param name the entry name
45.62 + * @exception NullPointerException if the entry name is null
45.63 + * @exception IllegalArgumentException if the entry name is longer than
45.64 + * 0xFFFF bytes
45.65 + */
45.66 + public ZipEntry(String name) {
45.67 + if (name == null) {
45.68 + throw new NullPointerException();
45.69 + }
45.70 + if (name.length() > 0xFFFF) {
45.71 + throw new IllegalArgumentException("entry name too long");
45.72 + }
45.73 + this.name = name;
45.74 + }
45.75 +
45.76 + /**
45.77 + * Creates a new zip entry with fields taken from the specified
45.78 + * zip entry.
45.79 + * @param e a zip Entry object
45.80 + */
45.81 + public ZipEntry(ZipEntry e) {
45.82 + name = e.name;
45.83 + time = e.time;
45.84 + crc = e.crc;
45.85 + size = e.size;
45.86 + csize = e.csize;
45.87 + method = e.method;
45.88 + flag = e.flag;
45.89 + extra = e.extra;
45.90 + comment = e.comment;
45.91 + }
45.92 +
45.93 + /*
45.94 + * Creates a new un-initialized zip entry
45.95 + */
45.96 + ZipEntry() {}
45.97 +
45.98 + /**
45.99 + * Returns the name of the entry.
45.100 + * @return the name of the entry
45.101 + */
45.102 + public String getName() {
45.103 + return name;
45.104 + }
45.105 +
45.106 + /**
45.107 + * Sets the modification time of the entry.
45.108 + * @param time the entry modification time in number of milliseconds
45.109 + * since the epoch
45.110 + * @see #getTime()
45.111 + */
45.112 + public void setTime(long time) {
45.113 + this.time = javaToDosTime(time);
45.114 + }
45.115 +
45.116 + /**
45.117 + * Returns the modification time of the entry, or -1 if not specified.
45.118 + * @return the modification time of the entry, or -1 if not specified
45.119 + * @see #setTime(long)
45.120 + */
45.121 + public long getTime() {
45.122 + return time != -1 ? dosToJavaTime(time) : -1;
45.123 + }
45.124 +
45.125 + /**
45.126 + * Sets the uncompressed size of the entry data.
45.127 + * @param size the uncompressed size in bytes
45.128 + * @exception IllegalArgumentException if the specified size is less
45.129 + * than 0, is greater than 0xFFFFFFFF when
45.130 + * <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
45.131 + * or is less than 0 when ZIP64 is supported
45.132 + * @see #getSize()
45.133 + */
45.134 + public void setSize(long size) {
45.135 + if (size < 0) {
45.136 + throw new IllegalArgumentException("invalid entry size");
45.137 + }
45.138 + this.size = size;
45.139 + }
45.140 +
45.141 + /**
45.142 + * Returns the uncompressed size of the entry data, or -1 if not known.
45.143 + * @return the uncompressed size of the entry data, or -1 if not known
45.144 + * @see #setSize(long)
45.145 + */
45.146 + public long getSize() {
45.147 + return size;
45.148 + }
45.149 +
45.150 + /**
45.151 + * Returns the size of the compressed entry data, or -1 if not known.
45.152 + * In the case of a stored entry, the compressed size will be the same
45.153 + * as the uncompressed size of the entry.
45.154 + * @return the size of the compressed entry data, or -1 if not known
45.155 + * @see #setCompressedSize(long)
45.156 + */
45.157 + public long getCompressedSize() {
45.158 + return csize;
45.159 + }
45.160 +
45.161 + /**
45.162 + * Sets the size of the compressed entry data.
45.163 + * @param csize the compressed size to set to
45.164 + * @see #getCompressedSize()
45.165 + */
45.166 + public void setCompressedSize(long csize) {
45.167 + this.csize = csize;
45.168 + }
45.169 +
45.170 + /**
45.171 + * Sets the CRC-32 checksum of the uncompressed entry data.
45.172 + * @param crc the CRC-32 value
45.173 + * @exception IllegalArgumentException if the specified CRC-32 value is
45.174 + * less than 0 or greater than 0xFFFFFFFF
45.175 + * @see #getCrc()
45.176 + */
45.177 + public void setCrc(long crc) {
45.178 + if (crc < 0 || crc > 0xFFFFFFFFL) {
45.179 + throw new IllegalArgumentException("invalid entry crc-32");
45.180 + }
45.181 + this.crc = crc;
45.182 + }
45.183 +
45.184 + /**
45.185 + * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
45.186 + * not known.
45.187 + * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
45.188 + * not known
45.189 + * @see #setCrc(long)
45.190 + */
45.191 + public long getCrc() {
45.192 + return crc;
45.193 + }
45.194 +
45.195 + /**
45.196 + * Sets the compression method for the entry.
45.197 + * @param method the compression method, either STORED or DEFLATED
45.198 + * @exception IllegalArgumentException if the specified compression
45.199 + * method is invalid
45.200 + * @see #getMethod()
45.201 + */
45.202 + public void setMethod(int method) {
45.203 + if (method != STORED && method != DEFLATED) {
45.204 + throw new IllegalArgumentException("invalid compression method");
45.205 + }
45.206 + this.method = method;
45.207 + }
45.208 +
45.209 + /**
45.210 + * Returns the compression method of the entry, or -1 if not specified.
45.211 + * @return the compression method of the entry, or -1 if not specified
45.212 + * @see #setMethod(int)
45.213 + */
45.214 + public int getMethod() {
45.215 + return method;
45.216 + }
45.217 +
45.218 + /**
45.219 + * Sets the optional extra field data for the entry.
45.220 + * @param extra the extra field data bytes
45.221 + * @exception IllegalArgumentException if the length of the specified
45.222 + * extra field data is greater than 0xFFFF bytes
45.223 + * @see #getExtra()
45.224 + */
45.225 + public void setExtra(byte[] extra) {
45.226 + if (extra != null && extra.length > 0xFFFF) {
45.227 + throw new IllegalArgumentException("invalid extra field length");
45.228 + }
45.229 + this.extra = extra;
45.230 + }
45.231 +
45.232 + /**
45.233 + * Returns the extra field data for the entry, or null if none.
45.234 + * @return the extra field data for the entry, or null if none
45.235 + * @see #setExtra(byte[])
45.236 + */
45.237 + public byte[] getExtra() {
45.238 + return extra;
45.239 + }
45.240 +
45.241 + /**
45.242 + * Sets the optional comment string for the entry.
45.243 + *
45.244 + * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
45.245 + * specified comment string is greater than 0xFFFF bytes after encoding, only
45.246 + * the first 0xFFFF bytes are output to the ZIP file entry.
45.247 + *
45.248 + * @param comment the comment string
45.249 + *
45.250 + * @see #getComment()
45.251 + */
45.252 + public void setComment(String comment) {
45.253 + this.comment = comment;
45.254 + }
45.255 +
45.256 + /**
45.257 + * Returns the comment string for the entry, or null if none.
45.258 + * @return the comment string for the entry, or null if none
45.259 + * @see #setComment(String)
45.260 + */
45.261 + public String getComment() {
45.262 + return comment;
45.263 + }
45.264 +
45.265 + /**
45.266 + * Returns true if this is a directory entry. A directory entry is
45.267 + * defined to be one whose name ends with a '/'.
45.268 + * @return true if this is a directory entry
45.269 + */
45.270 + public boolean isDirectory() {
45.271 + return name.endsWith("/");
45.272 + }
45.273 +
45.274 + /**
45.275 + * Returns a string representation of the ZIP entry.
45.276 + */
45.277 + public String toString() {
45.278 + return getName();
45.279 + }
45.280 +
45.281 + /*
45.282 + * Converts DOS time to Java time (number of milliseconds since epoch).
45.283 + */
45.284 + private static long dosToJavaTime(long dtime) {
45.285 + return dtime;
45.286 + /* XXX:
45.287 + Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
45.288 + (int)(((dtime >> 21) & 0x0f) - 1),
45.289 + (int)((dtime >> 16) & 0x1f),
45.290 + (int)((dtime >> 11) & 0x1f),
45.291 + (int)((dtime >> 5) & 0x3f),
45.292 + (int)((dtime << 1) & 0x3e));
45.293 + return d.getTime();
45.294 + */
45.295 + }
45.296 +
45.297 + /*
45.298 + * Converts Java time to DOS time.
45.299 + */
45.300 + private static long javaToDosTime(long time) {
45.301 + return time;
45.302 + /* XXX:
45.303 + Date d = new Date(time);
45.304 + int year = d.getYear() + 1900;
45.305 + if (year < 1980) {
45.306 + return (1 << 21) | (1 << 16);
45.307 + }
45.308 + return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
45.309 + d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
45.310 + d.getSeconds() >> 1;
45.311 + */
45.312 + }
45.313 +
45.314 + /**
45.315 + * Returns the hash code value for this entry.
45.316 + */
45.317 + public int hashCode() {
45.318 + return name.hashCode();
45.319 + }
45.320 +
45.321 + /**
45.322 + * Returns a copy of this entry.
45.323 + */
45.324 + public Object clone() {
45.325 + try {
45.326 + ZipEntry e = (ZipEntry)super.clone();
45.327 + e.extra = (extra == null) ? null : extra.clone();
45.328 + return e;
45.329 + } catch (CloneNotSupportedException e) {
45.330 + // This should never happen, since we are Cloneable
45.331 + throw new IllegalStateException();
45.332 + }
45.333 + }
45.334 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
46.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipException.java Wed May 07 16:47:24 2014 +0200
46.3 @@ -0,0 +1,60 @@
46.4 +/*
46.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46.7 + *
46.8 + * This code is free software; you can redistribute it and/or modify it
46.9 + * under the terms of the GNU General Public License version 2 only, as
46.10 + * published by the Free Software Foundation. Oracle designates this
46.11 + * particular file as subject to the "Classpath" exception as provided
46.12 + * by Oracle in the LICENSE file that accompanied this code.
46.13 + *
46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46.17 + * version 2 for more details (a copy is included in the LICENSE file that
46.18 + * accompanied this code).
46.19 + *
46.20 + * You should have received a copy of the GNU General Public License version
46.21 + * 2 along with this work; if not, write to the Free Software Foundation,
46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46.23 + *
46.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46.25 + * or visit www.oracle.com if you need additional information or have any
46.26 + * questions.
46.27 + */
46.28 +
46.29 +package java.util.zip;
46.30 +
46.31 +import java.io.IOException;
46.32 +
46.33 +/**
46.34 + * Signals that a Zip exception of some sort has occurred.
46.35 + *
46.36 + * @author unascribed
46.37 + * @see java.io.IOException
46.38 + * @since JDK1.0
46.39 + */
46.40 +
46.41 +public
46.42 +class ZipException extends IOException {
46.43 + private static final long serialVersionUID = 8000196834066748623L;
46.44 +
46.45 + /**
46.46 + * Constructs a <code>ZipException</code> with <code>null</code>
46.47 + * as its error detail message.
46.48 + */
46.49 + public ZipException() {
46.50 + super();
46.51 + }
46.52 +
46.53 + /**
46.54 + * Constructs a <code>ZipException</code> with the specified detail
46.55 + * message.
46.56 + *
46.57 + * @param s the detail message.
46.58 + */
46.59 +
46.60 + public ZipException(String s) {
46.61 + super(s);
46.62 + }
46.63 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
47.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipInputStream.java Wed May 07 16:47:24 2014 +0200
47.3 @@ -0,0 +1,194 @@
47.4 +/*
47.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47.7 + *
47.8 + * This code is free software; you can redistribute it and/or modify it
47.9 + * under the terms of the GNU General Public License version 2 only, as
47.10 + * published by the Free Software Foundation. Oracle designates this
47.11 + * particular file as subject to the "Classpath" exception as provided
47.12 + * by Oracle in the LICENSE file that accompanied this code.
47.13 + *
47.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
47.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
47.17 + * version 2 for more details (a copy is included in the LICENSE file that
47.18 + * accompanied this code).
47.19 + *
47.20 + * You should have received a copy of the GNU General Public License version
47.21 + * 2 along with this work; if not, write to the Free Software Foundation,
47.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47.23 + *
47.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
47.25 + * or visit www.oracle.com if you need additional information or have any
47.26 + * questions.
47.27 + */
47.28 +
47.29 +package java.util.zip;
47.30 +
47.31 +import java.io.InputStream;
47.32 +import java.io.IOException;
47.33 +
47.34 +/**
47.35 + * This class implements an input stream filter for reading files in the
47.36 + * ZIP file format. Includes support for both compressed and uncompressed
47.37 + * entries.
47.38 + *
47.39 + * @author David Connelly
47.40 + */
47.41 +public
47.42 +class ZipInputStream extends InflaterInputStream implements ZipConstants {
47.43 + private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
47.44 +
47.45 + /**
47.46 + * Creates a new ZIP input stream.
47.47 + *
47.48 + * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
47.49 + * decode the entry names.
47.50 + *
47.51 + * @param in the actual input stream
47.52 + */
47.53 + public ZipInputStream(InputStream in) {
47.54 + super(in);
47.55 + impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
47.56 + }
47.57 +
47.58 + /**
47.59 + * Creates a new ZIP input stream.
47.60 + *
47.61 + * @param in the actual input stream
47.62 + *
47.63 + * @param charset
47.64 + * The {@linkplain java.nio.charset.Charset charset} to be
47.65 + * used to decode the ZIP entry name (ignored if the
47.66 + * <a href="package-summary.html#lang_encoding"> language
47.67 + * encoding bit</a> of the ZIP entry's general purpose bit
47.68 + * flag is set).
47.69 + *
47.70 + * @since 1.7
47.71 + *
47.72 + public ZipInputStream(InputStream in, Charset charset) {
47.73 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
47.74 + usesDefaultInflater = true;
47.75 + if(in == null) {
47.76 + throw new NullPointerException("in is null");
47.77 + }
47.78 + if (charset == null)
47.79 + throw new NullPointerException("charset is null");
47.80 + this.zc = ZipCoder.get(charset);
47.81 + }
47.82 + */
47.83 +
47.84 + /**
47.85 + * Reads the next ZIP file entry and positions the stream at the
47.86 + * beginning of the entry data.
47.87 + * @return the next ZIP file entry, or null if there are no more entries
47.88 + * @exception ZipException if a ZIP file error has occurred
47.89 + * @exception IOException if an I/O error has occurred
47.90 + */
47.91 + public ZipEntry getNextEntry() throws IOException {
47.92 + return impl.getNextEntry();
47.93 + }
47.94 +
47.95 + /**
47.96 + * Closes the current ZIP entry and positions the stream for reading the
47.97 + * next entry.
47.98 + * @exception ZipException if a ZIP file error has occurred
47.99 + * @exception IOException if an I/O error has occurred
47.100 + */
47.101 + public void closeEntry() throws IOException {
47.102 + impl.closeEntry();
47.103 + }
47.104 +
47.105 + /**
47.106 + * Returns 0 after EOF has reached for the current entry data,
47.107 + * otherwise always return 1.
47.108 + * <p>
47.109 + * Programs should not count on this method to return the actual number
47.110 + * of bytes that could be read without blocking.
47.111 + *
47.112 + * @return 1 before EOF and 0 after EOF has reached for current entry.
47.113 + * @exception IOException if an I/O error occurs.
47.114 + *
47.115 + */
47.116 + public int available() throws IOException {
47.117 + return impl.available();
47.118 + }
47.119 +
47.120 + /**
47.121 + * Reads from the current ZIP entry into an array of bytes.
47.122 + * If <code>len</code> is not zero, the method
47.123 + * blocks until some input is available; otherwise, no
47.124 + * bytes are read and <code>0</code> is returned.
47.125 + * @param b the buffer into which the data is read
47.126 + * @param off the start offset in the destination array <code>b</code>
47.127 + * @param len the maximum number of bytes read
47.128 + * @return the actual number of bytes read, or -1 if the end of the
47.129 + * entry is reached
47.130 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
47.131 + * @exception IndexOutOfBoundsException if <code>off</code> is negative,
47.132 + * <code>len</code> is negative, or <code>len</code> is greater than
47.133 + * <code>b.length - off</code>
47.134 + * @exception ZipException if a ZIP file error has occurred
47.135 + * @exception IOException if an I/O error has occurred
47.136 + */
47.137 + public int read(byte[] b, int off, int len) throws IOException {
47.138 + return impl.read(b, off, len);
47.139 + }
47.140 +
47.141 + /**
47.142 + * Skips specified number of bytes in the current ZIP entry.
47.143 + * @param n the number of bytes to skip
47.144 + * @return the actual number of bytes skipped
47.145 + * @exception ZipException if a ZIP file error has occurred
47.146 + * @exception IOException if an I/O error has occurred
47.147 + * @exception IllegalArgumentException if n < 0
47.148 + */
47.149 + public long skip(long n) throws IOException {
47.150 + return impl.skip(n);
47.151 + }
47.152 +
47.153 + /**
47.154 + * Closes this input stream and releases any system resources associated
47.155 + * with the stream.
47.156 + * @exception IOException if an I/O error has occurred
47.157 + */
47.158 + public void close() throws IOException {
47.159 + impl.close();
47.160 + }
47.161 +
47.162 + /**
47.163 + * Creates a new <code>ZipEntry</code> object for the specified
47.164 + * entry name.
47.165 + *
47.166 + * @param name the ZIP file entry name
47.167 + * @return the ZipEntry just created
47.168 + */
47.169 + protected ZipEntry createZipEntry(String name) {
47.170 + return new ZipEntry(name);
47.171 + }
47.172 +
47.173 + @Override
47.174 + public int read() throws IOException {
47.175 + return impl.read();
47.176 + }
47.177 +
47.178 + @Override
47.179 + public boolean markSupported() {
47.180 + return impl.markSupported();
47.181 + }
47.182 +
47.183 + @Override
47.184 + public void mark(int readlimit) {
47.185 + impl.mark(readlimit);
47.186 + }
47.187 +
47.188 + @Override
47.189 + public void reset() throws IOException {
47.190 + impl.reset();
47.191 + }
47.192 +
47.193 + @Override
47.194 + public int read(byte[] b) throws IOException {
47.195 + return impl.read(b);
47.196 + }
47.197 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
48.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/package-info.java Wed May 07 16:47:24 2014 +0200
48.3 @@ -0,0 +1,22 @@
48.4 +/**
48.5 + * Back 2 Browser Bytecode Translator
48.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
48.7 + *
48.8 + * This program is free software: you can redistribute it and/or modify
48.9 + * it under the terms of the GNU General Public License as published by
48.10 + * the Free Software Foundation, version 2 of the License.
48.11 + *
48.12 + * This program is distributed in the hope that it will be useful,
48.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48.15 + * GNU General Public License for more details.
48.16 + *
48.17 + * You should have received a copy of the GNU General Public License
48.18 + * along with this program. Look for COPYING file in the top folder.
48.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
48.20 + */
48.21 +@Exported
48.22 +package java.util.zip;
48.23 +
48.24 +import org.apidesign.bck2brwsr.core.Exported;
48.25 +
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
49.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/package.html Wed May 07 16:47:24 2014 +0200
49.3 @@ -0,0 +1,98 @@
49.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
49.5 +<html>
49.6 +<head>
49.7 +<!--
49.8 +Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
49.9 +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49.10 +
49.11 +This code is free software; you can redistribute it and/or modify it
49.12 +under the terms of the GNU General Public License version 2 only, as
49.13 +published by the Free Software Foundation. Oracle designates this
49.14 +particular file as subject to the "Classpath" exception as provided
49.15 +by Oracle in the LICENSE file that accompanied this code.
49.16 +
49.17 +This code is distributed in the hope that it will be useful, but WITHOUT
49.18 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49.19 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
49.20 +version 2 for more details (a copy is included in the LICENSE file that
49.21 +accompanied this code).
49.22 +
49.23 +You should have received a copy of the GNU General Public License version
49.24 +2 along with this work; if not, write to the Free Software Foundation,
49.25 +Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49.26 +
49.27 +Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49.28 +or visit www.oracle.com if you need additional information or have any
49.29 +questions.
49.30 +-->
49.31 +
49.32 +</head>
49.33 +<body bgcolor="white">
49.34 +
49.35 +Provides classes for reading and writing the standard ZIP and GZIP
49.36 +file formats. Also includes classes for compressing and decompressing
49.37 +data using the DEFLATE compression algorithm, which is used by the
49.38 +ZIP and GZIP file formats. Additionally, there are utility classes
49.39 +for computing the CRC-32 and Adler-32 checksums of arbitrary
49.40 +input streams.
49.41 +
49.42 +
49.43 +<h2>Package Specification</h2>
49.44 +
49.45 +</a>
49.46 +<ul>
49.47 + <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
49.48 + Info-ZIP Application Note 970311
49.49 + </a> - a detailed description of the Info-ZIP format upon which
49.50 + the <code>java.util.zip</code> classes are based.
49.51 +<p>
49.52 + <a name="zip64">
49.53 + <li>An implementation may optionally support the ZIP64(tm) format extensions
49.54 + defined by the
49.55 + <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
49.56 + PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
49.57 + are used to overcome the size limitations of the original ZIP format.
49.58 +<p>
49.59 + <a name="lang_encoding">
49.60 + <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
49.61 + PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
49.62 + encode ZIP entry filename and comment fields using UTF-8.
49.63 +<p>
49.64 + <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
49.65 + ZLIB Compressed Data Format Specification version 3.3</a>
49.66 +
49.67 + <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
49.68 + (RFC 1950)
49.69 +<p>
49.70 + <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
49.71 + DEFLATE Compressed Data Format Specification version 1.3</a>
49.72 +
49.73 + <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
49.74 + (RFC 1951)
49.75 +<p>
49.76 + <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
49.77 + GZIP file format specification version 4.3</a>
49.78 +
49.79 + <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
49.80 + (RFC 1952)
49.81 +<p>
49.82 + <li>CRC-32 checksum is described in RFC 1952 (above)
49.83 +<p>
49.84 + <li>Adler-32 checksum is described in RFC 1950 (above)
49.85 +</ul>
49.86 +
49.87 +
49.88 +<!--
49.89 +<h2>Related Documentation</h2>
49.90 +
49.91 +For overviews, tutorials, examples, guides, and tool documentation, please see:
49.92 +<ul>
49.93 + <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
49.94 +</ul>
49.95 +-->
49.96 +
49.97 +@since JDK1.1
49.98 +</body>
49.99 +</html>
49.100 +
49.101 +
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
50.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java Wed May 07 16:47:24 2014 +0200
50.3 @@ -0,0 +1,139 @@
50.4 +/* -*-mode:java; c-basic-offset:2; -*- */
50.5 +/*
50.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
50.7 +
50.8 +Redistribution and use in source and binary forms, with or without
50.9 +modification, are permitted provided that the following conditions are met:
50.10 +
50.11 + 1. Redistributions of source code must retain the above copyright notice,
50.12 + this list of conditions and the following disclaimer.
50.13 +
50.14 + 2. Redistributions in binary form must reproduce the above copyright
50.15 + notice, this list of conditions and the following disclaimer in
50.16 + the documentation and/or other materials provided with the distribution.
50.17 +
50.18 + 3. The names of the authors may not be used to endorse or promote products
50.19 + derived from this software without specific prior written permission.
50.20 +
50.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
50.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
50.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
50.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
50.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
50.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
50.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
50.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
50.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50.31 + */
50.32 +/*
50.33 + * This program is based on zlib-1.1.3, so all credit should go authors
50.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
50.35 + * and contributors of zlib.
50.36 + */
50.37 +
50.38 +package org.apidesign.bck2brwsr.emul.zip;
50.39 +
50.40 +final class Adler32 implements Checksum {
50.41 +
50.42 + // largest prime smaller than 65536
50.43 + static final private int BASE=65521;
50.44 + // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
50.45 + static final private int NMAX=5552;
50.46 +
50.47 + private long s1=1L;
50.48 + private long s2=0L;
50.49 +
50.50 + public void reset(long init){
50.51 + s1=init&0xffff;
50.52 + s2=(init>>16)&0xffff;
50.53 + }
50.54 +
50.55 + public void reset(){
50.56 + s1=1L;
50.57 + s2=0L;
50.58 + }
50.59 +
50.60 + public long getValue(){
50.61 + return ((s2<<16)|s1);
50.62 + }
50.63 +
50.64 + public void update(byte[] buf, int index, int len){
50.65 +
50.66 + if(len==1){
50.67 + s1+=buf[index++]&0xff; s2+=s1;
50.68 + s1%=BASE;
50.69 + s2%=BASE;
50.70 + return;
50.71 + }
50.72 +
50.73 + int len1 = len/NMAX;
50.74 + int len2 = len%NMAX;
50.75 + while(len1-->0) {
50.76 + int k=NMAX;
50.77 + len-=k;
50.78 + while(k-->0){
50.79 + s1+=buf[index++]&0xff; s2+=s1;
50.80 + }
50.81 + s1%=BASE;
50.82 + s2%=BASE;
50.83 + }
50.84 +
50.85 + int k=len2;
50.86 + len-=k;
50.87 + while(k-->0){
50.88 + s1+=buf[index++]&0xff; s2+=s1;
50.89 + }
50.90 + s1%=BASE;
50.91 + s2%=BASE;
50.92 + }
50.93 +
50.94 + public Adler32 copy(){
50.95 + Adler32 foo = new Adler32();
50.96 + foo.s1 = this.s1;
50.97 + foo.s2 = this.s2;
50.98 + return foo;
50.99 + }
50.100 +
50.101 + // The following logic has come from zlib.1.2.
50.102 + static long combine(long adler1, long adler2, long len2){
50.103 + long BASEL = (long)BASE;
50.104 + long sum1;
50.105 + long sum2;
50.106 + long rem; // unsigned int
50.107 +
50.108 + rem = len2 % BASEL;
50.109 + sum1 = adler1 & 0xffffL;
50.110 + sum2 = rem * sum1;
50.111 + sum2 %= BASEL; // MOD(sum2);
50.112 + sum1 += (adler2 & 0xffffL) + BASEL - 1;
50.113 + sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
50.114 + if (sum1 >= BASEL) sum1 -= BASEL;
50.115 + if (sum1 >= BASEL) sum1 -= BASEL;
50.116 + if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
50.117 + if (sum2 >= BASEL) sum2 -= BASEL;
50.118 + return sum1 | (sum2 << 16);
50.119 + }
50.120 +
50.121 +/*
50.122 + private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
50.123 + public void update(byte[] buf, int index, int len){
50.124 + if(buf==null) {adler.reset();}
50.125 + else{adler.update(buf, index, len);}
50.126 + }
50.127 + public void reset(){
50.128 + adler.reset();
50.129 + }
50.130 + public void reset(long init){
50.131 + if(init==1L){
50.132 + adler.reset();
50.133 + }
50.134 + else{
50.135 + System.err.println("unsupported operation");
50.136 + }
50.137 + }
50.138 + public long getValue(){
50.139 + return adler.getValue();
50.140 + }
50.141 +*/
50.142 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Wed May 07 16:47:24 2014 +0200
51.3 @@ -0,0 +1,181 @@
51.4 +/* -*-mode:java; c-basic-offset:2; -*- */
51.5 +/*
51.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
51.7 +
51.8 +Redistribution and use in source and binary forms, with or without
51.9 +modification, are permitted provided that the following conditions are met:
51.10 +
51.11 + 1. Redistributions of source code must retain the above copyright notice,
51.12 + this list of conditions and the following disclaimer.
51.13 +
51.14 + 2. Redistributions in binary form must reproduce the above copyright
51.15 + notice, this list of conditions and the following disclaimer in
51.16 + the documentation and/or other materials provided with the distribution.
51.17 +
51.18 + 3. The names of the authors may not be used to endorse or promote products
51.19 + derived from this software without specific prior written permission.
51.20 +
51.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
51.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
51.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
51.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
51.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
51.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
51.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
51.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51.31 + */
51.32 +/*
51.33 + * This program is based on zlib-1.1.3, so all credit should go authors
51.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
51.35 + * and contributors of zlib.
51.36 + */
51.37 +
51.38 +package org.apidesign.bck2brwsr.emul.zip;
51.39 +
51.40 +
51.41 +
51.42 +final class CRC32 implements Checksum {
51.43 +
51.44 + /*
51.45 + * The following logic has come from RFC1952.
51.46 + */
51.47 + private int v = 0;
51.48 + private static int[] crc_table = null;
51.49 + static {
51.50 + crc_table = new int[256];
51.51 + for (int n = 0; n < 256; n++) {
51.52 + int c = n;
51.53 + for (int k = 8; --k >= 0; ) {
51.54 + if ((c & 1) != 0)
51.55 + c = 0xedb88320 ^ (c >>> 1);
51.56 + else
51.57 + c = c >>> 1;
51.58 + }
51.59 + crc_table[n] = c;
51.60 + }
51.61 + }
51.62 +
51.63 + public void update (byte[] buf, int index, int len) {
51.64 + int c = ~v;
51.65 + while (--len >= 0)
51.66 + c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
51.67 + v = ~c;
51.68 + }
51.69 +
51.70 + public void reset(){
51.71 + v = 0;
51.72 + }
51.73 +
51.74 + public void reset(long vv){
51.75 + v = (int)(vv&0xffffffffL);
51.76 + }
51.77 +
51.78 + public long getValue(){
51.79 + return (long)(v&0xffffffffL);
51.80 + }
51.81 +
51.82 + // The following logic has come from zlib.1.2.
51.83 + private static final int GF2_DIM = 32;
51.84 + static long combine(long crc1, long crc2, long len2){
51.85 + long row;
51.86 + long[] even = new long[GF2_DIM];
51.87 + long[] odd = new long[GF2_DIM];
51.88 +
51.89 + // degenerate case (also disallow negative lengths)
51.90 + if (len2 <= 0)
51.91 + return crc1;
51.92 +
51.93 + // put operator for one zero bit in odd
51.94 + odd[0] = 0xedb88320L; // CRC-32 polynomial
51.95 + row = 1;
51.96 + for (int n = 1; n < GF2_DIM; n++) {
51.97 + odd[n] = row;
51.98 + row <<= 1;
51.99 + }
51.100 +
51.101 + // put operator for two zero bits in even
51.102 + gf2_matrix_square(even, odd);
51.103 +
51.104 + // put operator for four zero bits in odd
51.105 + gf2_matrix_square(odd, even);
51.106 +
51.107 + // apply len2 zeros to crc1 (first square will put the operator for one
51.108 + // zero byte, eight zero bits, in even)
51.109 + do {
51.110 + // apply zeros operator for this bit of len2
51.111 + gf2_matrix_square(even, odd);
51.112 + if ((len2 & 1)!=0)
51.113 + crc1 = gf2_matrix_times(even, crc1);
51.114 + len2 >>= 1;
51.115 +
51.116 + // if no more bits set, then done
51.117 + if (len2 == 0)
51.118 + break;
51.119 +
51.120 + // another iteration of the loop with odd and even swapped
51.121 + gf2_matrix_square(odd, even);
51.122 + if ((len2 & 1)!=0)
51.123 + crc1 = gf2_matrix_times(odd, crc1);
51.124 + len2 >>= 1;
51.125 +
51.126 + // if no more bits set, then done
51.127 + } while (len2 != 0);
51.128 +
51.129 + /* return combined crc */
51.130 + crc1 ^= crc2;
51.131 + return crc1;
51.132 + }
51.133 +
51.134 + private static long gf2_matrix_times(long[] mat, long vec){
51.135 + long sum = 0;
51.136 + int index = 0;
51.137 + while (vec!=0) {
51.138 + if ((vec & 1)!=0)
51.139 + sum ^= mat[index];
51.140 + vec >>= 1;
51.141 + index++;
51.142 + }
51.143 + return sum;
51.144 + }
51.145 +
51.146 + static final void gf2_matrix_square(long[] square, long[] mat) {
51.147 + for (int n = 0; n < GF2_DIM; n++)
51.148 + square[n] = gf2_matrix_times(mat, mat[n]);
51.149 + }
51.150 +
51.151 + /*
51.152 + private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
51.153 +
51.154 + public void update(byte[] buf, int index, int len){
51.155 + if(buf==null) {crc32.reset();}
51.156 + else{crc32.update(buf, index, len);}
51.157 + }
51.158 + public void reset(){
51.159 + crc32.reset();
51.160 + }
51.161 + public void reset(long init){
51.162 + if(init==0L){
51.163 + crc32.reset();
51.164 + }
51.165 + else{
51.166 + System.err.println("unsupported operation");
51.167 + }
51.168 + }
51.169 + public long getValue(){
51.170 + return crc32.getValue();
51.171 + }
51.172 +*/
51.173 + public CRC32 copy(){
51.174 + CRC32 foo = new CRC32();
51.175 + foo.v = this.v;
51.176 + return foo;
51.177 + }
51.178 +
51.179 + public static int[] getCRC32Table(){
51.180 + int[] tmp = new int[crc_table.length];
51.181 + System.arraycopy(crc_table, 0, tmp, 0, tmp.length);
51.182 + return tmp;
51.183 + }
51.184 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
52.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java Wed May 07 16:47:24 2014 +0200
52.3 @@ -0,0 +1,43 @@
52.4 +/* -*-mode:java; c-basic-offset:2; -*- */
52.5 +/*
52.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
52.7 +
52.8 +Redistribution and use in source and binary forms, with or without
52.9 +modification, are permitted provided that the following conditions are met:
52.10 +
52.11 + 1. Redistributions of source code must retain the above copyright notice,
52.12 + this list of conditions and the following disclaimer.
52.13 +
52.14 + 2. Redistributions in binary form must reproduce the above copyright
52.15 + notice, this list of conditions and the following disclaimer in
52.16 + the documentation and/or other materials provided with the distribution.
52.17 +
52.18 + 3. The names of the authors may not be used to endorse or promote products
52.19 + derived from this software without specific prior written permission.
52.20 +
52.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
52.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
52.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
52.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
52.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
52.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
52.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
52.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52.31 + */
52.32 +/*
52.33 + * This program is based on zlib-1.1.3, so all credit should go authors
52.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
52.35 + * and contributors of zlib.
52.36 + */
52.37 +
52.38 +package org.apidesign.bck2brwsr.emul.zip;
52.39 +
52.40 +interface Checksum {
52.41 + void update(byte[] buf, int index, int len);
52.42 + void reset();
52.43 + void reset(long init);
52.44 + long getValue();
52.45 + Checksum copy();
52.46 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
53.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Wed May 07 16:47:24 2014 +0200
53.3 @@ -0,0 +1,175 @@
53.4 +/*
53.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
53.6 + *
53.7 + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
53.8 + *
53.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
53.10 + * Other names may be trademarks of their respective owners.
53.11 + *
53.12 + * The contents of this file are subject to the terms of either the GNU
53.13 + * General Public License Version 2 only ("GPL") or the Common
53.14 + * Development and Distribution License("CDDL") (collectively, the
53.15 + * "License"). You may not use this file except in compliance with the
53.16 + * License. You can obtain a copy of the License at
53.17 + * http://www.netbeans.org/cddl-gplv2.html
53.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
53.19 + * specific language governing permissions and limitations under the
53.20 + * License. When distributing the software, include this License Header
53.21 + * Notice in each file and include the License file at
53.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
53.23 + * particular file as subject to the "Classpath" exception as provided
53.24 + * by Oracle in the GPL Version 2 section of the License file that
53.25 + * accompanied this code. If applicable, add the following below the
53.26 + * License Header, with the fields enclosed by brackets [] replaced by
53.27 + * your own identifying information:
53.28 + * "Portions Copyrighted [year] [name of copyright owner]"
53.29 + *
53.30 + * Contributor(s):
53.31 + *
53.32 + * Portions Copyrighted 2007 Sun Microsystems, Inc.
53.33 + */
53.34 +package org.apidesign.bck2brwsr.emul.zip;
53.35 +
53.36 +import java.io.ByteArrayInputStream;
53.37 +import java.io.IOException;
53.38 +import java.io.InputStream;
53.39 +import java.util.zip.ZipEntry;
53.40 +import java.util.zip.ZipInputStream;
53.41 +
53.42 +/**
53.43 + *
53.44 + * @author Tomas Zezula
53.45 + */
53.46 +public final class FastJar {
53.47 + private final byte[] arr;
53.48 +
53.49 + public FastJar(byte[] arr) {
53.50 + this.arr = arr;
53.51 + }
53.52 +
53.53 +
53.54 + private static final int GIVE_UP = 1<<16;
53.55 +
53.56 + public static final class Entry {
53.57 +
53.58 + public final String name;
53.59 + final long offset;
53.60 + private final long dosTime;
53.61 +
53.62 + Entry (String name, long offset, long time) {
53.63 + assert name != null;
53.64 + this.name = name;
53.65 + this.offset = offset;
53.66 + this.dosTime = time;
53.67 + }
53.68 +/*
53.69 + public long getTime () {
53.70 + Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
53.71 + (int)(((dosTime >> 21) & 0x0f) - 1),
53.72 + (int)((dosTime >> 16) & 0x1f),
53.73 + (int)((dosTime >> 11) & 0x1f),
53.74 + (int)((dosTime >> 5) & 0x3f),
53.75 + (int)((dosTime << 1) & 0x3e));
53.76 + return d.getTime();
53.77 + }
53.78 + */
53.79 + }
53.80 +
53.81 + public InputStream getInputStream (final Entry e) throws IOException {
53.82 + return getInputStream(arr, e.offset);
53.83 + }
53.84 +
53.85 + private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
53.86 + ByteArrayInputStream is = new ByteArrayInputStream(arr);
53.87 + is.skip(offset);
53.88 + ZipInputStream in = new ZipInputStream (is);
53.89 + ZipEntry e = in.getNextEntry();
53.90 + if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
53.91 + int cp = arr.length - is.available();
53.92 + return new ByteArrayInputStream(arr, cp, (int)e.getSize());
53.93 + }
53.94 + return in;
53.95 + }
53.96 +
53.97 + public Entry[] list() throws IOException {
53.98 + final int size = arr.length;
53.99 +
53.100 + int at = size - ZipInputStream.ENDHDR;
53.101 +
53.102 + byte[] data = new byte[ZipInputStream.ENDHDR];
53.103 + int giveup = 0;
53.104 +
53.105 + do {
53.106 + System.arraycopy(arr, at, data, 0, data.length);
53.107 + at--;
53.108 + giveup++;
53.109 + if (giveup > GIVE_UP) {
53.110 + throw new IOException ();
53.111 + }
53.112 + } while (getsig(data) != ZipInputStream.ENDSIG);
53.113 +
53.114 +
53.115 + final long censize = endsiz(data);
53.116 + final long cenoff = endoff(data);
53.117 + at = (int) cenoff;
53.118 +
53.119 + Entry[] result = new Entry[0];
53.120 + int cenread = 0;
53.121 + data = new byte[ZipInputStream.CENHDR];
53.122 + while (cenread < censize) {
53.123 + System.arraycopy(arr, at, data, 0, data.length);
53.124 + at += data.length;
53.125 + if (getsig(data) != ZipInputStream.CENSIG) {
53.126 + throw new IOException("No central table"); //NOI18N
53.127 + }
53.128 + int cennam = cennam(data);
53.129 + int cenext = cenext(data);
53.130 + int cencom = cencom(data);
53.131 + long lhoff = cenoff(data);
53.132 + long centim = centim(data);
53.133 + String name = new String(arr, at, cennam, "UTF-8");
53.134 + at += cennam;
53.135 + int seekby = cenext+cencom;
53.136 + int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
53.137 + cenread+=cendatalen;
53.138 + result = addEntry(result, new Entry(name,lhoff, centim));
53.139 + at += seekby;
53.140 + }
53.141 + return result;
53.142 + }
53.143 +
53.144 + private Entry[] addEntry(Entry[] result, Entry entry) {
53.145 + Entry[] e = new Entry[result.length + 1];
53.146 + e[result.length] = entry;
53.147 + System.arraycopy(result, 0, e, 0, result.length);
53.148 + return e;
53.149 + }
53.150 +
53.151 + private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
53.152 + private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
53.153 + private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
53.154 + private static final long cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
53.155 + private static final long censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
53.156 + private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
53.157 + private static final int cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
53.158 + private static final int cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
53.159 + private static final int cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
53.160 + private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
53.161 + private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
53.162 + private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
53.163 + private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
53.164 + private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
53.165 +
53.166 + private static final int get16(final byte[] b, int off) throws IOException {
53.167 + final int b1 = b[off];
53.168 + final int b2 = b[off+1];
53.169 + return (b1 & 0xff) | ((b2 & 0xff) << 8);
53.170 + }
53.171 +
53.172 + private static final long get32(final byte[] b, int off) throws IOException {
53.173 + final int s1 = get16(b, off);
53.174 + final int s2 = get16(b, off+2);
53.175 + return s1 | ((long)s2 << 16);
53.176 + }
53.177 +
53.178 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
54.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Wed May 07 16:47:24 2014 +0200
54.3 @@ -0,0 +1,215 @@
54.4 +/* -*-mode:java; c-basic-offset:2; -*- */
54.5 +/*
54.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
54.7 +
54.8 +Redistribution and use in source and binary forms, with or without
54.9 +modification, are permitted provided that the following conditions are met:
54.10 +
54.11 + 1. Redistributions of source code must retain the above copyright notice,
54.12 + this list of conditions and the following disclaimer.
54.13 +
54.14 + 2. Redistributions in binary form must reproduce the above copyright
54.15 + notice, this list of conditions and the following disclaimer in
54.16 + the documentation and/or other materials provided with the distribution.
54.17 +
54.18 + 3. The names of the authors may not be used to endorse or promote products
54.19 + derived from this software without specific prior written permission.
54.20 +
54.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
54.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
54.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
54.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
54.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
54.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
54.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
54.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
54.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54.31 + */
54.32 +/*
54.33 + * This program is based on zlib-1.1.3, so all credit should go authors
54.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
54.35 + * and contributors of zlib.
54.36 + */
54.37 +
54.38 +package org.apidesign.bck2brwsr.emul.zip;
54.39 +
54.40 +
54.41 +import java.io.UnsupportedEncodingException;
54.42 +
54.43 +/**
54.44 + * @see "http://www.ietf.org/rfc/rfc1952.txt"
54.45 + */
54.46 +final class GZIPHeader implements Cloneable {
54.47 +
54.48 + public static final byte OS_MSDOS = (byte) 0x00;
54.49 + public static final byte OS_AMIGA = (byte) 0x01;
54.50 + public static final byte OS_VMS = (byte) 0x02;
54.51 + public static final byte OS_UNIX = (byte) 0x03;
54.52 + public static final byte OS_ATARI = (byte) 0x05;
54.53 + public static final byte OS_OS2 = (byte) 0x06;
54.54 + public static final byte OS_MACOS = (byte) 0x07;
54.55 + public static final byte OS_TOPS20 = (byte) 0x0a;
54.56 + public static final byte OS_WIN32 = (byte) 0x0b;
54.57 + public static final byte OS_VMCMS = (byte) 0x04;
54.58 + public static final byte OS_ZSYSTEM = (byte) 0x08;
54.59 + public static final byte OS_CPM = (byte) 0x09;
54.60 + public static final byte OS_QDOS = (byte) 0x0c;
54.61 + public static final byte OS_RISCOS = (byte) 0x0d;
54.62 + public static final byte OS_UNKNOWN = (byte) 0xff;
54.63 +
54.64 + boolean text = false;
54.65 + private boolean fhcrc = false;
54.66 + long time;
54.67 + int xflags;
54.68 + int os = 255;
54.69 + byte[] extra;
54.70 + byte[] name;
54.71 + byte[] comment;
54.72 + int hcrc;
54.73 + long crc;
54.74 + boolean done = false;
54.75 + long mtime = 0;
54.76 +
54.77 + public void setModifiedTime(long mtime) {
54.78 + this.mtime = mtime;
54.79 + }
54.80 +
54.81 + public long getModifiedTime() {
54.82 + return mtime;
54.83 + }
54.84 +
54.85 + public void setOS(int os) {
54.86 + if((0<=os && os <=13) || os==255)
54.87 + this.os=os;
54.88 + else
54.89 + throw new IllegalArgumentException("os: "+os);
54.90 + }
54.91 +
54.92 + public int getOS(){
54.93 + return os;
54.94 + }
54.95 +
54.96 + public void setName(String name) {
54.97 + try{
54.98 + this.name=name.getBytes("ISO-8859-1");
54.99 + }
54.100 + catch(UnsupportedEncodingException e){
54.101 + throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
54.102 + }
54.103 + }
54.104 +
54.105 + public String getName(){
54.106 + if(name==null) return "";
54.107 + try {
54.108 + return new String(name, "ISO-8859-1");
54.109 + }
54.110 + catch (UnsupportedEncodingException e) {
54.111 + throw new IllegalArgumentException(e.toString());
54.112 + }
54.113 + }
54.114 +
54.115 + public void setComment(String comment) {
54.116 + try{
54.117 + this.comment=comment.getBytes("ISO-8859-1");
54.118 + }
54.119 + catch(UnsupportedEncodingException e){
54.120 + throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
54.121 + }
54.122 + }
54.123 +
54.124 + public String getComment(){
54.125 + if(comment==null) return "";
54.126 + try {
54.127 + return new String(comment, "ISO-8859-1");
54.128 + }
54.129 + catch (UnsupportedEncodingException e) {
54.130 + throw new IllegalArgumentException(e.toString());
54.131 + }
54.132 + }
54.133 +
54.134 + public void setCRC(long crc){
54.135 + this.crc = crc;
54.136 + }
54.137 +
54.138 + public long getCRC(){
54.139 + return crc;
54.140 + }
54.141 +/*
54.142 + void put(Deflate d){
54.143 + int flag = 0;
54.144 + if(text){
54.145 + flag |= 1; // FTEXT
54.146 + }
54.147 + if(fhcrc){
54.148 + flag |= 2; // FHCRC
54.149 + }
54.150 + if(extra!=null){
54.151 + flag |= 4; // FEXTRA
54.152 + }
54.153 + if(name!=null){
54.154 + flag |= 8; // FNAME
54.155 + }
54.156 + if(comment!=null){
54.157 + flag |= 16; // FCOMMENT
54.158 + }
54.159 + int xfl = 0;
54.160 + if(d.level == JZlib.Z_BEST_SPEED){
54.161 + xfl |= 4;
54.162 + }
54.163 + else if (d.level == JZlib.Z_BEST_COMPRESSION){
54.164 + xfl |= 2;
54.165 + }
54.166 +
54.167 + d.put_short((short)0x8b1f); // ID1 ID2
54.168 + d.put_byte((byte)8); // CM(Compression Method)
54.169 + d.put_byte((byte)flag);
54.170 + d.put_byte((byte)mtime);
54.171 + d.put_byte((byte)(mtime>>8));
54.172 + d.put_byte((byte)(mtime>>16));
54.173 + d.put_byte((byte)(mtime>>24));
54.174 + d.put_byte((byte)xfl);
54.175 + d.put_byte((byte)os);
54.176 +
54.177 + if(extra!=null){
54.178 + d.put_byte((byte)extra.length);
54.179 + d.put_byte((byte)(extra.length>>8));
54.180 + d.put_byte(extra, 0, extra.length);
54.181 + }
54.182 +
54.183 + if(name!=null){
54.184 + d.put_byte(name, 0, name.length);
54.185 + d.put_byte((byte)0);
54.186 + }
54.187 +
54.188 + if(comment!=null){
54.189 + d.put_byte(comment, 0, comment.length);
54.190 + d.put_byte((byte)0);
54.191 + }
54.192 + }
54.193 +*/
54.194 + @Override
54.195 + public Object clone() throws CloneNotSupportedException {
54.196 + GZIPHeader gheader = (GZIPHeader)super.clone();
54.197 + byte[] tmp;
54.198 + if(gheader.extra!=null){
54.199 + tmp=new byte[gheader.extra.length];
54.200 + System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
54.201 + gheader.extra = tmp;
54.202 + }
54.203 +
54.204 + if(gheader.name!=null){
54.205 + tmp=new byte[gheader.name.length];
54.206 + System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
54.207 + gheader.name = tmp;
54.208 + }
54.209 +
54.210 + if(gheader.comment!=null){
54.211 + tmp=new byte[gheader.comment.length];
54.212 + System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
54.213 + gheader.comment = tmp;
54.214 + }
54.215 +
54.216 + return gheader;
54.217 + }
54.218 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
55.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Wed May 07 16:47:24 2014 +0200
55.3 @@ -0,0 +1,616 @@
55.4 +/* -*-mode:java; c-basic-offset:2; -*- */
55.5 +/*
55.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
55.7 +
55.8 +Redistribution and use in source and binary forms, with or without
55.9 +modification, are permitted provided that the following conditions are met:
55.10 +
55.11 + 1. Redistributions of source code must retain the above copyright notice,
55.12 + this list of conditions and the following disclaimer.
55.13 +
55.14 + 2. Redistributions in binary form must reproduce the above copyright
55.15 + notice, this list of conditions and the following disclaimer in
55.16 + the documentation and/or other materials provided with the distribution.
55.17 +
55.18 + 3. The names of the authors may not be used to endorse or promote products
55.19 + derived from this software without specific prior written permission.
55.20 +
55.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
55.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
55.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
55.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
55.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
55.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
55.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
55.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
55.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55.31 + */
55.32 +/*
55.33 + * This program is based on zlib-1.1.3, so all credit should go authors
55.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
55.35 + * and contributors of zlib.
55.36 + */
55.37 +
55.38 +package org.apidesign.bck2brwsr.emul.zip;
55.39 +
55.40 +
55.41 +
55.42 +final class InfBlocks{
55.43 + static final private int MANY=1440;
55.44 +
55.45 + // And'ing with mask[n] masks the lower n bits
55.46 + static final private int[] inflate_mask = {
55.47 + 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
55.48 + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
55.49 + 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
55.50 + 0x00007fff, 0x0000ffff
55.51 + };
55.52 +
55.53 + // Table for deflate from PKZIP's appnote.txt.
55.54 + static final int[] border = { // Order of the bit length code lengths
55.55 + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
55.56 + };
55.57 +
55.58 + static final private int Z_OK=0;
55.59 + static final private int Z_STREAM_END=1;
55.60 + static final private int Z_NEED_DICT=2;
55.61 + static final private int Z_ERRNO=-1;
55.62 + static final private int Z_STREAM_ERROR=-2;
55.63 + static final private int Z_DATA_ERROR=-3;
55.64 + static final private int Z_MEM_ERROR=-4;
55.65 + static final private int Z_BUF_ERROR=-5;
55.66 + static final private int Z_VERSION_ERROR=-6;
55.67 +
55.68 + static final private int TYPE=0; // get type bits (3, including end bit)
55.69 + static final private int LENS=1; // get lengths for stored
55.70 + static final private int STORED=2;// processing stored block
55.71 + static final private int TABLE=3; // get table lengths
55.72 + static final private int BTREE=4; // get bit lengths tree for a dynamic block
55.73 + static final private int DTREE=5; // get length, distance trees for a dynamic block
55.74 + static final private int CODES=6; // processing fixed or dynamic block
55.75 + static final private int DRY=7; // output remaining window bytes
55.76 + static final private int DONE=8; // finished last block, done
55.77 + static final private int BAD=9; // ot a data error--stuck here
55.78 +
55.79 + int mode; // current inflate_block mode
55.80 +
55.81 + int left; // if STORED, bytes left to copy
55.82 +
55.83 + int table; // table lengths (14 bits)
55.84 + int index; // index into blens (or border)
55.85 + int[] blens; // bit lengths of codes
55.86 + int[] bb=new int[1]; // bit length tree depth
55.87 + int[] tb=new int[1]; // bit length decoding tree
55.88 +
55.89 + int[] bl=new int[1];
55.90 + int[] bd=new int[1];
55.91 +
55.92 + int[][] tl=new int[1][];
55.93 + int[][] td=new int[1][];
55.94 + int[] tli=new int[1]; // tl_index
55.95 + int[] tdi=new int[1]; // td_index
55.96 +
55.97 + private final InfCodes codes; // if CODES, current state
55.98 +
55.99 + int last; // true if this block is the last block
55.100 +
55.101 + // mode independent information
55.102 + int bitk; // bits in bit buffer
55.103 + int bitb; // bit buffer
55.104 + int[] hufts; // single malloc for tree space
55.105 + byte[] window; // sliding window
55.106 + int end; // one byte after sliding window
55.107 + int read; // window read pointer
55.108 + int write; // window write pointer
55.109 + private boolean check;
55.110 +
55.111 + private final InfTree inftree=new InfTree();
55.112 +
55.113 + private final ZStream z;
55.114 +
55.115 + InfBlocks(ZStream z, int w){
55.116 + this.z=z;
55.117 + this.codes=new InfCodes(this.z, this);
55.118 + hufts=new int[MANY*3];
55.119 + window=new byte[w];
55.120 + end=w;
55.121 + this.check = (z.istate.wrap==0) ? false : true;
55.122 + mode = TYPE;
55.123 + reset();
55.124 + }
55.125 +
55.126 + void reset(){
55.127 + if(mode==BTREE || mode==DTREE){
55.128 + }
55.129 + if(mode==CODES){
55.130 + codes.free(z);
55.131 + }
55.132 + mode=TYPE;
55.133 + bitk=0;
55.134 + bitb=0;
55.135 + read=write=0;
55.136 + if(check){
55.137 + z.adler.reset();
55.138 + }
55.139 + }
55.140 +
55.141 + int proc(int r){
55.142 + int t; // temporary storage
55.143 + int b; // bit buffer
55.144 + int k; // bits in bit buffer
55.145 + int p; // input data pointer
55.146 + int n; // bytes available there
55.147 + int q; // output window write pointer
55.148 + int m; // bytes to end of window or read pointer
55.149 +
55.150 + // copy input/output information to locals (UPDATE macro restores)
55.151 + {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
55.152 + {q=write;m=(int)(q<read?read-q-1:end-q);}
55.153 +
55.154 + // process input based on current state
55.155 + while(true){
55.156 + switch (mode){
55.157 + case TYPE:
55.158 +
55.159 + while(k<(3)){
55.160 + if(n!=0){
55.161 + r=Z_OK;
55.162 + }
55.163 + else{
55.164 + bitb=b; bitk=k;
55.165 + z.avail_in=n;
55.166 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.167 + write=q;
55.168 + return inflate_flush(r);
55.169 + };
55.170 + n--;
55.171 + b|=(z.next_in[p++]&0xff)<<k;
55.172 + k+=8;
55.173 + }
55.174 + t = (int)(b & 7);
55.175 + last = t & 1;
55.176 +
55.177 + switch (t >>> 1){
55.178 + case 0: // stored
55.179 + {b>>>=(3);k-=(3);}
55.180 + t = k & 7; // go to byte boundary
55.181 +
55.182 + {b>>>=(t);k-=(t);}
55.183 + mode = LENS; // get length of stored block
55.184 + break;
55.185 + case 1: // fixed
55.186 + InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
55.187 + codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
55.188 +
55.189 + {b>>>=(3);k-=(3);}
55.190 +
55.191 + mode = CODES;
55.192 + break;
55.193 + case 2: // dynamic
55.194 +
55.195 + {b>>>=(3);k-=(3);}
55.196 +
55.197 + mode = TABLE;
55.198 + break;
55.199 + case 3: // illegal
55.200 +
55.201 + {b>>>=(3);k-=(3);}
55.202 + mode = BAD;
55.203 + z.msg = "invalid block type";
55.204 + r = Z_DATA_ERROR;
55.205 +
55.206 + bitb=b; bitk=k;
55.207 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.208 + write=q;
55.209 + return inflate_flush(r);
55.210 + }
55.211 + break;
55.212 + case LENS:
55.213 +
55.214 + while(k<(32)){
55.215 + if(n!=0){
55.216 + r=Z_OK;
55.217 + }
55.218 + else{
55.219 + bitb=b; bitk=k;
55.220 + z.avail_in=n;
55.221 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.222 + write=q;
55.223 + return inflate_flush(r);
55.224 + };
55.225 + n--;
55.226 + b|=(z.next_in[p++]&0xff)<<k;
55.227 + k+=8;
55.228 + }
55.229 +
55.230 + if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)){
55.231 + mode = BAD;
55.232 + z.msg = "invalid stored block lengths";
55.233 + r = Z_DATA_ERROR;
55.234 +
55.235 + bitb=b; bitk=k;
55.236 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.237 + write=q;
55.238 + return inflate_flush(r);
55.239 + }
55.240 + left = (b & 0xffff);
55.241 + b = k = 0; // dump bits
55.242 + mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
55.243 + break;
55.244 + case STORED:
55.245 + if (n == 0){
55.246 + bitb=b; bitk=k;
55.247 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.248 + write=q;
55.249 + return inflate_flush(r);
55.250 + }
55.251 +
55.252 + if(m==0){
55.253 + if(q==end&&read!=0){
55.254 + q=0; m=(int)(q<read?read-q-1:end-q);
55.255 + }
55.256 + if(m==0){
55.257 + write=q;
55.258 + r=inflate_flush(r);
55.259 + q=write;m=(int)(q<read?read-q-1:end-q);
55.260 + if(q==end&&read!=0){
55.261 + q=0; m=(int)(q<read?read-q-1:end-q);
55.262 + }
55.263 + if(m==0){
55.264 + bitb=b; bitk=k;
55.265 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.266 + write=q;
55.267 + return inflate_flush(r);
55.268 + }
55.269 + }
55.270 + }
55.271 + r=Z_OK;
55.272 +
55.273 + t = left;
55.274 + if(t>n) t = n;
55.275 + if(t>m) t = m;
55.276 + System.arraycopy(z.next_in, p, window, q, t);
55.277 + p += t; n -= t;
55.278 + q += t; m -= t;
55.279 + if ((left -= t) != 0)
55.280 + break;
55.281 + mode = last!=0 ? DRY : TYPE;
55.282 + break;
55.283 + case TABLE:
55.284 +
55.285 + while(k<(14)){
55.286 + if(n!=0){
55.287 + r=Z_OK;
55.288 + }
55.289 + else{
55.290 + bitb=b; bitk=k;
55.291 + z.avail_in=n;
55.292 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.293 + write=q;
55.294 + return inflate_flush(r);
55.295 + };
55.296 + n--;
55.297 + b|=(z.next_in[p++]&0xff)<<k;
55.298 + k+=8;
55.299 + }
55.300 +
55.301 + table = t = (b & 0x3fff);
55.302 + if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
55.303 + {
55.304 + mode = BAD;
55.305 + z.msg = "too many length or distance symbols";
55.306 + r = Z_DATA_ERROR;
55.307 +
55.308 + bitb=b; bitk=k;
55.309 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.310 + write=q;
55.311 + return inflate_flush(r);
55.312 + }
55.313 + t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
55.314 + if(blens==null || blens.length<t){
55.315 + blens=new int[t];
55.316 + }
55.317 + else{
55.318 + for(int i=0; i<t; i++){blens[i]=0;}
55.319 + }
55.320 +
55.321 + {b>>>=(14);k-=(14);}
55.322 +
55.323 + index = 0;
55.324 + mode = BTREE;
55.325 + case BTREE:
55.326 + while (index < 4 + (table >>> 10)){
55.327 + while(k<(3)){
55.328 + if(n!=0){
55.329 + r=Z_OK;
55.330 + }
55.331 + else{
55.332 + bitb=b; bitk=k;
55.333 + z.avail_in=n;
55.334 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.335 + write=q;
55.336 + return inflate_flush(r);
55.337 + };
55.338 + n--;
55.339 + b|=(z.next_in[p++]&0xff)<<k;
55.340 + k+=8;
55.341 + }
55.342 +
55.343 + blens[border[index++]] = b&7;
55.344 +
55.345 + {b>>>=(3);k-=(3);}
55.346 + }
55.347 +
55.348 + while(index < 19){
55.349 + blens[border[index++]] = 0;
55.350 + }
55.351 +
55.352 + bb[0] = 7;
55.353 + t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
55.354 + if (t != Z_OK){
55.355 + r = t;
55.356 + if (r == Z_DATA_ERROR){
55.357 + blens=null;
55.358 + mode = BAD;
55.359 + }
55.360 +
55.361 + bitb=b; bitk=k;
55.362 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.363 + write=q;
55.364 + return inflate_flush(r);
55.365 + }
55.366 +
55.367 + index = 0;
55.368 + mode = DTREE;
55.369 + case DTREE:
55.370 + while (true){
55.371 + t = table;
55.372 + if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
55.373 + break;
55.374 + }
55.375 +
55.376 + int[] h;
55.377 + int i, j, c;
55.378 +
55.379 + t = bb[0];
55.380 +
55.381 + while(k<(t)){
55.382 + if(n!=0){
55.383 + r=Z_OK;
55.384 + }
55.385 + else{
55.386 + bitb=b; bitk=k;
55.387 + z.avail_in=n;
55.388 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.389 + write=q;
55.390 + return inflate_flush(r);
55.391 + };
55.392 + n--;
55.393 + b|=(z.next_in[p++]&0xff)<<k;
55.394 + k+=8;
55.395 + }
55.396 +
55.397 + if(tb[0]==-1){
55.398 + //System.err.println("null...");
55.399 + }
55.400 +
55.401 + t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
55.402 + c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
55.403 +
55.404 + if (c < 16){
55.405 + b>>>=(t);k-=(t);
55.406 + blens[index++] = c;
55.407 + }
55.408 + else { // c == 16..18
55.409 + i = c == 18 ? 7 : c - 14;
55.410 + j = c == 18 ? 11 : 3;
55.411 +
55.412 + while(k<(t+i)){
55.413 + if(n!=0){
55.414 + r=Z_OK;
55.415 + }
55.416 + else{
55.417 + bitb=b; bitk=k;
55.418 + z.avail_in=n;
55.419 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.420 + write=q;
55.421 + return inflate_flush(r);
55.422 + };
55.423 + n--;
55.424 + b|=(z.next_in[p++]&0xff)<<k;
55.425 + k+=8;
55.426 + }
55.427 +
55.428 + b>>>=(t);k-=(t);
55.429 +
55.430 + j += (b & inflate_mask[i]);
55.431 +
55.432 + b>>>=(i);k-=(i);
55.433 +
55.434 + i = index;
55.435 + t = table;
55.436 + if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
55.437 + (c == 16 && i < 1)){
55.438 + blens=null;
55.439 + mode = BAD;
55.440 + z.msg = "invalid bit length repeat";
55.441 + r = Z_DATA_ERROR;
55.442 +
55.443 + bitb=b; bitk=k;
55.444 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.445 + write=q;
55.446 + return inflate_flush(r);
55.447 + }
55.448 +
55.449 + c = c == 16 ? blens[i-1] : 0;
55.450 + do{
55.451 + blens[i++] = c;
55.452 + }
55.453 + while (--j!=0);
55.454 + index = i;
55.455 + }
55.456 + }
55.457 +
55.458 + tb[0]=-1;
55.459 + {
55.460 + bl[0] = 9; // must be <= 9 for lookahead assumptions
55.461 + bd[0] = 6; // must be <= 9 for lookahead assumptions
55.462 + t = table;
55.463 + t = inftree.inflate_trees_dynamic(257 + (t & 0x1f),
55.464 + 1 + ((t >> 5) & 0x1f),
55.465 + blens, bl, bd, tli, tdi, hufts, z);
55.466 +
55.467 + if (t != Z_OK){
55.468 + if (t == Z_DATA_ERROR){
55.469 + blens=null;
55.470 + mode = BAD;
55.471 + }
55.472 + r = t;
55.473 +
55.474 + bitb=b; bitk=k;
55.475 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.476 + write=q;
55.477 + return inflate_flush(r);
55.478 + }
55.479 + codes.init(bl[0], bd[0], hufts, tli[0], hufts, tdi[0]);
55.480 + }
55.481 + mode = CODES;
55.482 + case CODES:
55.483 + bitb=b; bitk=k;
55.484 + z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.485 + write=q;
55.486 +
55.487 + if ((r = codes.proc(r)) != Z_STREAM_END){
55.488 + return inflate_flush(r);
55.489 + }
55.490 + r = Z_OK;
55.491 + codes.free(z);
55.492 +
55.493 + p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
55.494 + q=write;m=(int)(q<read?read-q-1:end-q);
55.495 +
55.496 + if (last==0){
55.497 + mode = TYPE;
55.498 + break;
55.499 + }
55.500 + mode = DRY;
55.501 + case DRY:
55.502 + write=q;
55.503 + r=inflate_flush(r);
55.504 + q=write; m=(int)(q<read?read-q-1:end-q);
55.505 + if (read != write){
55.506 + bitb=b; bitk=k;
55.507 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.508 + write=q;
55.509 + return inflate_flush(r);
55.510 + }
55.511 + mode = DONE;
55.512 + case DONE:
55.513 + r = Z_STREAM_END;
55.514 +
55.515 + bitb=b; bitk=k;
55.516 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.517 + write=q;
55.518 + return inflate_flush(r);
55.519 + case BAD:
55.520 + r = Z_DATA_ERROR;
55.521 +
55.522 + bitb=b; bitk=k;
55.523 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.524 + write=q;
55.525 + return inflate_flush(r);
55.526 +
55.527 + default:
55.528 + r = Z_STREAM_ERROR;
55.529 +
55.530 + bitb=b; bitk=k;
55.531 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
55.532 + write=q;
55.533 + return inflate_flush(r);
55.534 + }
55.535 + }
55.536 + }
55.537 +
55.538 + void free(){
55.539 + reset();
55.540 + window=null;
55.541 + hufts=null;
55.542 + //ZFREE(z, s);
55.543 + }
55.544 +
55.545 + void set_dictionary(byte[] d, int start, int n){
55.546 + System.arraycopy(d, start, window, 0, n);
55.547 + read = write = n;
55.548 + }
55.549 +
55.550 + // Returns true if inflate is currently at the end of a block generated
55.551 + // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
55.552 + int sync_point(){
55.553 + return mode == LENS ? 1 : 0;
55.554 + }
55.555 +
55.556 + // copy as much as possible from the sliding window to the output area
55.557 + int inflate_flush(int r){
55.558 + int n;
55.559 + int p;
55.560 + int q;
55.561 +
55.562 + // local copies of source and destination pointers
55.563 + p = z.next_out_index;
55.564 + q = read;
55.565 +
55.566 + // compute number of bytes to copy as far as end of window
55.567 + n = (int)((q <= write ? write : end) - q);
55.568 + if(n > z.avail_out) n = z.avail_out;
55.569 + if(n!=0 && r == Z_BUF_ERROR) r = Z_OK;
55.570 +
55.571 + // update counters
55.572 + z.avail_out -= n;
55.573 + z.total_out += n;
55.574 +
55.575 + // update check information
55.576 + if(check && n>0){
55.577 + z.adler.update(window, q, n);
55.578 + }
55.579 +
55.580 + // copy as far as end of window
55.581 + System.arraycopy(window, q, z.next_out, p, n);
55.582 + p += n;
55.583 + q += n;
55.584 +
55.585 + // see if more to copy at beginning of window
55.586 + if (q == end){
55.587 + // wrap pointers
55.588 + q = 0;
55.589 + if (write == end)
55.590 + write = 0;
55.591 +
55.592 + // compute bytes to copy
55.593 + n = write - q;
55.594 + if (n > z.avail_out) n = z.avail_out;
55.595 + if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
55.596 +
55.597 + // update counters
55.598 + z.avail_out -= n;
55.599 + z.total_out += n;
55.600 +
55.601 + // update check information
55.602 + if(check && n>0){
55.603 + z.adler.update(window, q, n);
55.604 + }
55.605 +
55.606 + // copy
55.607 + System.arraycopy(window, q, z.next_out, p, n);
55.608 + p += n;
55.609 + q += n;
55.610 + }
55.611 +
55.612 + // update pointers
55.613 + z.next_out_index = p;
55.614 + read = q;
55.615 +
55.616 + // done
55.617 + return r;
55.618 + }
55.619 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
56.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java Wed May 07 16:47:24 2014 +0200
56.3 @@ -0,0 +1,612 @@
56.4 +/* -*-mode:java; c-basic-offset:2; -*- */
56.5 +/*
56.6 +Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
56.7 +
56.8 +Redistribution and use in source and binary forms, with or without
56.9 +modification, are permitted provided that the following conditions are met:
56.10 +
56.11 + 1. Redistributions of source code must retain the above copyright notice,
56.12 + this list of conditions and the following disclaimer.
56.13 +
56.14 + 2. Redistributions in binary form must reproduce the above copyright
56.15 + notice, this list of conditions and the following disclaimer in
56.16 + the documentation and/or other materials provided with the distribution.
56.17 +
56.18 + 3. The names of the authors may not be used to endorse or promote products
56.19 + derived from this software without specific prior written permission.
56.20 +
56.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
56.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
56.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
56.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
56.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
56.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
56.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
56.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
56.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56.31 + */
56.32 +/*
56.33 + * This program is based on zlib-1.1.3, so all credit should go authors
56.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
56.35 + * and contributors of zlib.
56.36 + */
56.37 +
56.38 +package org.apidesign.bck2brwsr.emul.zip;
56.39 +
56.40 +
56.41 +
56.42 +final class InfCodes{
56.43 +
56.44 + static final private int[] inflate_mask = {
56.45 + 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
56.46 + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
56.47 + 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
56.48 + 0x00007fff, 0x0000ffff
56.49 + };
56.50 +
56.51 + static final private int Z_OK=0;
56.52 + static final private int Z_STREAM_END=1;
56.53 + static final private int Z_NEED_DICT=2;
56.54 + static final private int Z_ERRNO=-1;
56.55 + static final private int Z_STREAM_ERROR=-2;
56.56 + static final private int Z_DATA_ERROR=-3;
56.57 + static final private int Z_MEM_ERROR=-4;
56.58 + static final private int Z_BUF_ERROR=-5;
56.59 + static final private int Z_VERSION_ERROR=-6;
56.60 +
56.61 + // waiting for "i:"=input,
56.62 + // "o:"=output,
56.63 + // "x:"=nothing
56.64 + static final private int START=0; // x: set up for LEN
56.65 + static final private int LEN=1; // i: get length/literal/eob next
56.66 + static final private int LENEXT=2; // i: getting length extra (have base)
56.67 + static final private int DIST=3; // i: get distance next
56.68 + static final private int DISTEXT=4;// i: getting distance extra
56.69 + static final private int COPY=5; // o: copying bytes in window, waiting for space
56.70 + static final private int LIT=6; // o: got literal, waiting for output space
56.71 + static final private int WASH=7; // o: got eob, possibly still output waiting
56.72 + static final private int END=8; // x: got eob and all data flushed
56.73 + static final private int BADCODE=9;// x: got error
56.74 +
56.75 + int mode; // current inflate_codes mode
56.76 +
56.77 + // mode dependent information
56.78 + int len;
56.79 +
56.80 + int[] tree; // pointer into tree
56.81 + int tree_index=0;
56.82 + int need; // bits needed
56.83 +
56.84 + int lit;
56.85 +
56.86 + // if EXT or COPY, where and how much
56.87 + int get; // bits to get for extra
56.88 + int dist; // distance back to copy from
56.89 +
56.90 + byte lbits; // ltree bits decoded per branch
56.91 + byte dbits; // dtree bits decoder per branch
56.92 + int[] ltree; // literal/length/eob tree
56.93 + int ltree_index; // literal/length/eob tree
56.94 + int[] dtree; // distance tree
56.95 + int dtree_index; // distance tree
56.96 +
56.97 + private final ZStream z;
56.98 + private final InfBlocks s;
56.99 + InfCodes(ZStream z, InfBlocks s){
56.100 + this.z=z;
56.101 + this.s=s;
56.102 + }
56.103 +
56.104 + void init(int bl, int bd,
56.105 + int[] tl, int tl_index,
56.106 + int[] td, int td_index){
56.107 + mode=START;
56.108 + lbits=(byte)bl;
56.109 + dbits=(byte)bd;
56.110 + ltree=tl;
56.111 + ltree_index=tl_index;
56.112 + dtree = td;
56.113 + dtree_index=td_index;
56.114 + tree=null;
56.115 + }
56.116 +
56.117 + int proc(int r){
56.118 + int j; // temporary storage
56.119 + int[] t; // temporary pointer
56.120 + int tindex; // temporary pointer
56.121 + int e; // extra bits or operation
56.122 + int b=0; // bit buffer
56.123 + int k=0; // bits in bit buffer
56.124 + int p=0; // input data pointer
56.125 + int n; // bytes available there
56.126 + int q; // output window write pointer
56.127 + int m; // bytes to end of window or read pointer
56.128 + int f; // pointer to copy strings from
56.129 +
56.130 + // copy input/output information to locals (UPDATE macro restores)
56.131 + p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
56.132 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
56.133 +
56.134 + // process input and output based on current state
56.135 + while (true){
56.136 + switch (mode){
56.137 + // waiting for "i:"=input, "o:"=output, "x:"=nothing
56.138 + case START: // x: set up for LEN
56.139 + if (m >= 258 && n >= 10){
56.140 +
56.141 + s.bitb=b;s.bitk=k;
56.142 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.143 + s.write=q;
56.144 + r = inflate_fast(lbits, dbits,
56.145 + ltree, ltree_index,
56.146 + dtree, dtree_index,
56.147 + s, z);
56.148 +
56.149 + p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
56.150 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
56.151 +
56.152 + if (r != Z_OK){
56.153 + mode = r == Z_STREAM_END ? WASH : BADCODE;
56.154 + break;
56.155 + }
56.156 + }
56.157 + need = lbits;
56.158 + tree = ltree;
56.159 + tree_index=ltree_index;
56.160 +
56.161 + mode = LEN;
56.162 + case LEN: // i: get length/literal/eob next
56.163 + j = need;
56.164 +
56.165 + while(k<(j)){
56.166 + if(n!=0)r=Z_OK;
56.167 + else{
56.168 +
56.169 + s.bitb=b;s.bitk=k;
56.170 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.171 + s.write=q;
56.172 + return s.inflate_flush(r);
56.173 + }
56.174 + n--;
56.175 + b|=(z.next_in[p++]&0xff)<<k;
56.176 + k+=8;
56.177 + }
56.178 +
56.179 + tindex=(tree_index+(b&inflate_mask[j]))*3;
56.180 +
56.181 + b>>>=(tree[tindex+1]);
56.182 + k-=(tree[tindex+1]);
56.183 +
56.184 + e=tree[tindex];
56.185 +
56.186 + if(e == 0){ // literal
56.187 + lit = tree[tindex+2];
56.188 + mode = LIT;
56.189 + break;
56.190 + }
56.191 + if((e & 16)!=0 ){ // length
56.192 + get = e & 15;
56.193 + len = tree[tindex+2];
56.194 + mode = LENEXT;
56.195 + break;
56.196 + }
56.197 + if ((e & 64) == 0){ // next table
56.198 + need = e;
56.199 + tree_index = tindex/3+tree[tindex+2];
56.200 + break;
56.201 + }
56.202 + if ((e & 32)!=0){ // end of block
56.203 + mode = WASH;
56.204 + break;
56.205 + }
56.206 + mode = BADCODE; // invalid code
56.207 + z.msg = "invalid literal/length code";
56.208 + r = Z_DATA_ERROR;
56.209 +
56.210 + s.bitb=b;s.bitk=k;
56.211 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.212 + s.write=q;
56.213 + return s.inflate_flush(r);
56.214 +
56.215 + case LENEXT: // i: getting length extra (have base)
56.216 + j = get;
56.217 +
56.218 + while(k<(j)){
56.219 + if(n!=0)r=Z_OK;
56.220 + else{
56.221 +
56.222 + s.bitb=b;s.bitk=k;
56.223 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.224 + s.write=q;
56.225 + return s.inflate_flush(r);
56.226 + }
56.227 + n--; b|=(z.next_in[p++]&0xff)<<k;
56.228 + k+=8;
56.229 + }
56.230 +
56.231 + len += (b & inflate_mask[j]);
56.232 +
56.233 + b>>=j;
56.234 + k-=j;
56.235 +
56.236 + need = dbits;
56.237 + tree = dtree;
56.238 + tree_index=dtree_index;
56.239 + mode = DIST;
56.240 + case DIST: // i: get distance next
56.241 + j = need;
56.242 +
56.243 + while(k<(j)){
56.244 + if(n!=0)r=Z_OK;
56.245 + else{
56.246 +
56.247 + s.bitb=b;s.bitk=k;
56.248 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.249 + s.write=q;
56.250 + return s.inflate_flush(r);
56.251 + }
56.252 + n--; b|=(z.next_in[p++]&0xff)<<k;
56.253 + k+=8;
56.254 + }
56.255 +
56.256 + tindex=(tree_index+(b & inflate_mask[j]))*3;
56.257 +
56.258 + b>>=tree[tindex+1];
56.259 + k-=tree[tindex+1];
56.260 +
56.261 + e = (tree[tindex]);
56.262 + if((e & 16)!=0){ // distance
56.263 + get = e & 15;
56.264 + dist = tree[tindex+2];
56.265 + mode = DISTEXT;
56.266 + break;
56.267 + }
56.268 + if ((e & 64) == 0){ // next table
56.269 + need = e;
56.270 + tree_index = tindex/3 + tree[tindex+2];
56.271 + break;
56.272 + }
56.273 + mode = BADCODE; // invalid code
56.274 + z.msg = "invalid distance code";
56.275 + r = Z_DATA_ERROR;
56.276 +
56.277 + s.bitb=b;s.bitk=k;
56.278 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.279 + s.write=q;
56.280 + return s.inflate_flush(r);
56.281 +
56.282 + case DISTEXT: // i: getting distance extra
56.283 + j = get;
56.284 +
56.285 + while(k<(j)){
56.286 + if(n!=0)r=Z_OK;
56.287 + else{
56.288 +
56.289 + s.bitb=b;s.bitk=k;
56.290 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.291 + s.write=q;
56.292 + return s.inflate_flush(r);
56.293 + }
56.294 + n--; b|=(z.next_in[p++]&0xff)<<k;
56.295 + k+=8;
56.296 + }
56.297 +
56.298 + dist += (b & inflate_mask[j]);
56.299 +
56.300 + b>>=j;
56.301 + k-=j;
56.302 +
56.303 + mode = COPY;
56.304 + case COPY: // o: copying bytes in window, waiting for space
56.305 + f = q - dist;
56.306 + while(f < 0){ // modulo window size-"while" instead
56.307 + f += s.end; // of "if" handles invalid distances
56.308 + }
56.309 + while (len!=0){
56.310 +
56.311 + if(m==0){
56.312 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
56.313 + if(m==0){
56.314 + s.write=q; r=s.inflate_flush(r);
56.315 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
56.316 +
56.317 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
56.318 +
56.319 + if(m==0){
56.320 + s.bitb=b;s.bitk=k;
56.321 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.322 + s.write=q;
56.323 + return s.inflate_flush(r);
56.324 + }
56.325 + }
56.326 + }
56.327 +
56.328 + s.window[q++]=s.window[f++]; m--;
56.329 +
56.330 + if (f == s.end)
56.331 + f = 0;
56.332 + len--;
56.333 + }
56.334 + mode = START;
56.335 + break;
56.336 + case LIT: // o: got literal, waiting for output space
56.337 + if(m==0){
56.338 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
56.339 + if(m==0){
56.340 + s.write=q; r=s.inflate_flush(r);
56.341 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
56.342 +
56.343 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
56.344 + if(m==0){
56.345 + s.bitb=b;s.bitk=k;
56.346 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.347 + s.write=q;
56.348 + return s.inflate_flush(r);
56.349 + }
56.350 + }
56.351 + }
56.352 + r=Z_OK;
56.353 +
56.354 + s.window[q++]=(byte)lit; m--;
56.355 +
56.356 + mode = START;
56.357 + break;
56.358 + case WASH: // o: got eob, possibly more output
56.359 + if (k > 7){ // return unused byte, if any
56.360 + k -= 8;
56.361 + n++;
56.362 + p--; // can always return one
56.363 + }
56.364 +
56.365 + s.write=q; r=s.inflate_flush(r);
56.366 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
56.367 +
56.368 + if (s.read != s.write){
56.369 + s.bitb=b;s.bitk=k;
56.370 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.371 + s.write=q;
56.372 + return s.inflate_flush(r);
56.373 + }
56.374 + mode = END;
56.375 + case END:
56.376 + r = Z_STREAM_END;
56.377 + s.bitb=b;s.bitk=k;
56.378 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.379 + s.write=q;
56.380 + return s.inflate_flush(r);
56.381 +
56.382 + case BADCODE: // x: got error
56.383 +
56.384 + r = Z_DATA_ERROR;
56.385 +
56.386 + s.bitb=b;s.bitk=k;
56.387 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.388 + s.write=q;
56.389 + return s.inflate_flush(r);
56.390 +
56.391 + default:
56.392 + r = Z_STREAM_ERROR;
56.393 +
56.394 + s.bitb=b;s.bitk=k;
56.395 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.396 + s.write=q;
56.397 + return s.inflate_flush(r);
56.398 + }
56.399 + }
56.400 + }
56.401 +
56.402 + void free(ZStream z){
56.403 + // ZFREE(z, c);
56.404 + }
56.405 +
56.406 + // Called with number of bytes left to write in window at least 258
56.407 + // (the maximum string length) and number of input bytes available
56.408 + // at least ten. The ten bytes are six bytes for the longest length/
56.409 + // distance pair plus four bytes for overloading the bit buffer.
56.410 +
56.411 + int inflate_fast(int bl, int bd,
56.412 + int[] tl, int tl_index,
56.413 + int[] td, int td_index,
56.414 + InfBlocks s, ZStream z){
56.415 + int t; // temporary pointer
56.416 + int[] tp; // temporary pointer
56.417 + int tp_index; // temporary pointer
56.418 + int e; // extra bits or operation
56.419 + int b; // bit buffer
56.420 + int k; // bits in bit buffer
56.421 + int p; // input data pointer
56.422 + int n; // bytes available there
56.423 + int q; // output window write pointer
56.424 + int m; // bytes to end of window or read pointer
56.425 + int ml; // mask for literal/length tree
56.426 + int md; // mask for distance tree
56.427 + int c; // bytes to copy
56.428 + int d; // distance back to copy from
56.429 + int r; // copy source pointer
56.430 +
56.431 + int tp_index_t_3; // (tp_index+t)*3
56.432 +
56.433 + // load input, output, bit values
56.434 + p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
56.435 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
56.436 +
56.437 + // initialize masks
56.438 + ml = inflate_mask[bl];
56.439 + md = inflate_mask[bd];
56.440 +
56.441 + // do until not enough input or output space for fast loop
56.442 + do { // assume called with m >= 258 && n >= 10
56.443 + // get literal/length code
56.444 + while(k<(20)){ // max bits for literal/length code
56.445 + n--;
56.446 + b|=(z.next_in[p++]&0xff)<<k;k+=8;
56.447 + }
56.448 +
56.449 + t= b&ml;
56.450 + tp=tl;
56.451 + tp_index=tl_index;
56.452 + tp_index_t_3=(tp_index+t)*3;
56.453 + if ((e = tp[tp_index_t_3]) == 0){
56.454 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
56.455 +
56.456 + s.window[q++] = (byte)tp[tp_index_t_3+2];
56.457 + m--;
56.458 + continue;
56.459 + }
56.460 + do {
56.461 +
56.462 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
56.463 +
56.464 + if((e&16)!=0){
56.465 + e &= 15;
56.466 + c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
56.467 +
56.468 + b>>=e; k-=e;
56.469 +
56.470 + // decode distance base of block to copy
56.471 + while(k<(15)){ // max bits for distance code
56.472 + n--;
56.473 + b|=(z.next_in[p++]&0xff)<<k;k+=8;
56.474 + }
56.475 +
56.476 + t= b&md;
56.477 + tp=td;
56.478 + tp_index=td_index;
56.479 + tp_index_t_3=(tp_index+t)*3;
56.480 + e = tp[tp_index_t_3];
56.481 +
56.482 + do {
56.483 +
56.484 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
56.485 +
56.486 + if((e&16)!=0){
56.487 + // get extra bits to add to distance base
56.488 + e &= 15;
56.489 + while(k<(e)){ // get extra bits (up to 13)
56.490 + n--;
56.491 + b|=(z.next_in[p++]&0xff)<<k;k+=8;
56.492 + }
56.493 +
56.494 + d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
56.495 +
56.496 + b>>=(e); k-=(e);
56.497 +
56.498 + // do the copy
56.499 + m -= c;
56.500 + if (q >= d){ // offset before dest
56.501 + // just copy
56.502 + r=q-d;
56.503 + if(q-r>0 && 2>(q-r)){
56.504 + s.window[q++]=s.window[r++]; // minimum count is three,
56.505 + s.window[q++]=s.window[r++]; // so unroll loop a little
56.506 + c-=2;
56.507 + }
56.508 + else{
56.509 + System.arraycopy(s.window, r, s.window, q, 2);
56.510 + q+=2; r+=2; c-=2;
56.511 + }
56.512 + }
56.513 + else{ // else offset after destination
56.514 + r=q-d;
56.515 + do{
56.516 + r+=s.end; // force pointer in window
56.517 + }while(r<0); // covers invalid distances
56.518 + e=s.end-r;
56.519 + if(c>e){ // if source crosses,
56.520 + c-=e; // wrapped copy
56.521 + if(q-r>0 && e>(q-r)){
56.522 + do{s.window[q++] = s.window[r++];}
56.523 + while(--e!=0);
56.524 + }
56.525 + else{
56.526 + System.arraycopy(s.window, r, s.window, q, e);
56.527 + q+=e; r+=e; e=0;
56.528 + }
56.529 + r = 0; // copy rest from start of window
56.530 + }
56.531 +
56.532 + }
56.533 +
56.534 + // copy all or what's left
56.535 + if(q-r>0 && c>(q-r)){
56.536 + do{s.window[q++] = s.window[r++];}
56.537 + while(--c!=0);
56.538 + }
56.539 + else{
56.540 + System.arraycopy(s.window, r, s.window, q, c);
56.541 + q+=c; r+=c; c=0;
56.542 + }
56.543 + break;
56.544 + }
56.545 + else if((e&64)==0){
56.546 + t+=tp[tp_index_t_3+2];
56.547 + t+=(b&inflate_mask[e]);
56.548 + tp_index_t_3=(tp_index+t)*3;
56.549 + e=tp[tp_index_t_3];
56.550 + }
56.551 + else{
56.552 + z.msg = "invalid distance code";
56.553 +
56.554 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
56.555 +
56.556 + s.bitb=b;s.bitk=k;
56.557 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.558 + s.write=q;
56.559 +
56.560 + return Z_DATA_ERROR;
56.561 + }
56.562 + }
56.563 + while(true);
56.564 + break;
56.565 + }
56.566 +
56.567 + if((e&64)==0){
56.568 + t+=tp[tp_index_t_3+2];
56.569 + t+=(b&inflate_mask[e]);
56.570 + tp_index_t_3=(tp_index+t)*3;
56.571 + if((e=tp[tp_index_t_3])==0){
56.572 +
56.573 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
56.574 +
56.575 + s.window[q++]=(byte)tp[tp_index_t_3+2];
56.576 + m--;
56.577 + break;
56.578 + }
56.579 + }
56.580 + else if((e&32)!=0){
56.581 +
56.582 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
56.583 +
56.584 + s.bitb=b;s.bitk=k;
56.585 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.586 + s.write=q;
56.587 +
56.588 + return Z_STREAM_END;
56.589 + }
56.590 + else{
56.591 + z.msg="invalid literal/length code";
56.592 +
56.593 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
56.594 +
56.595 + s.bitb=b;s.bitk=k;
56.596 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.597 + s.write=q;
56.598 +
56.599 + return Z_DATA_ERROR;
56.600 + }
56.601 + }
56.602 + while(true);
56.603 + }
56.604 + while(m>=258 && n>= 10);
56.605 +
56.606 + // not enough input or output--restore pointers and return
56.607 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
56.608 +
56.609 + s.bitb=b;s.bitk=k;
56.610 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
56.611 + s.write=q;
56.612 +
56.613 + return Z_OK;
56.614 + }
56.615 +}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
57.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java Wed May 07 16:47:24 2014 +0200
57.3 @@ -0,0 +1,520 @@
57.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
57.5 +/*
57.6 +Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
57.7 +
57.8 +Redistribution and use in source and binary forms, with or without
57.9 +modification, are permitted provided that the following conditions are met:
57.10 +
57.11 + 1. Redistributions of source code must retain the above copyright notice,
57.12 + this list of conditions and the following disclaimer.
57.13 +
57.14 + 2. Redistributions in binary form must reproduce the above copyright
57.15 + notice, this list of conditions and the following disclaimer in
57.16 + the documentation and/or other materials provided with the distribution.
57.17 +
57.18 + 3. The names of the authors may not be used to endorse or promote products
57.19 + derived from this software without specific prior written permission.
57.20 +
57.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
57.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
57.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
57.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
57.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
57.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
57.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
57.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
57.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57.31 + */
57.32 +/*
57.33 + * This program is based on zlib-1.1.3, so all credit should go authors
57.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
57.35 + * and contributors of zlib.
57.36 + */
57.37 +
57.38 +package org.apidesign.bck2brwsr.emul.zip;
57.39 +
57.40 +
57.41 +
57.42 +final class InfTree{
57.43 +
57.44 + static final private int MANY=1440;
57.45 +
57.46 + static final private int Z_OK=0;
57.47 + static final private int Z_STREAM_END=1;
57.48 + static final private int Z_NEED_DICT=2;
57.49 + static final private int Z_ERRNO=-1;
57.50 + static final private int Z_STREAM_ERROR=-2;
57.51 + static final private int Z_DATA_ERROR=-3;
57.52 + static final private int Z_MEM_ERROR=-4;
57.53 + static final private int Z_BUF_ERROR=-5;
57.54 + static final private int Z_VERSION_ERROR=-6;
57.55 +
57.56 + static final int fixed_bl = 9;
57.57 + static final int fixed_bd = 5;
57.58 +
57.59 + static final int[] fixed_tl = {
57.60 + 96,7,256, 0,8,80, 0,8,16, 84,8,115,
57.61 + 82,7,31, 0,8,112, 0,8,48, 0,9,192,
57.62 + 80,7,10, 0,8,96, 0,8,32, 0,9,160,
57.63 + 0,8,0, 0,8,128, 0,8,64, 0,9,224,
57.64 + 80,7,6, 0,8,88, 0,8,24, 0,9,144,
57.65 + 83,7,59, 0,8,120, 0,8,56, 0,9,208,
57.66 + 81,7,17, 0,8,104, 0,8,40, 0,9,176,
57.67 + 0,8,8, 0,8,136, 0,8,72, 0,9,240,
57.68 + 80,7,4, 0,8,84, 0,8,20, 85,8,227,
57.69 + 83,7,43, 0,8,116, 0,8,52, 0,9,200,
57.70 + 81,7,13, 0,8,100, 0,8,36, 0,9,168,
57.71 + 0,8,4, 0,8,132, 0,8,68, 0,9,232,
57.72 + 80,7,8, 0,8,92, 0,8,28, 0,9,152,
57.73 + 84,7,83, 0,8,124, 0,8,60, 0,9,216,
57.74 + 82,7,23, 0,8,108, 0,8,44, 0,9,184,
57.75 + 0,8,12, 0,8,140, 0,8,76, 0,9,248,
57.76 + 80,7,3, 0,8,82, 0,8,18, 85,8,163,
57.77 + 83,7,35, 0,8,114, 0,8,50, 0,9,196,
57.78 + 81,7,11, 0,8,98, 0,8,34, 0,9,164,
57.79 + 0,8,2, 0,8,130, 0,8,66, 0,9,228,
57.80 + 80,7,7, 0,8,90, 0,8,26, 0,9,148,
57.81 + 84,7,67, 0,8,122, 0,8,58, 0,9,212,
57.82 + 82,7,19, 0,8,106, 0,8,42, 0,9,180,
57.83 + 0,8,10, 0,8,138, 0,8,74, 0,9,244,
57.84 + 80,7,5, 0,8,86, 0,8,22, 192,8,0,
57.85 + 83,7,51, 0,8,118, 0,8,54, 0,9,204,
57.86 + 81,7,15, 0,8,102, 0,8,38, 0,9,172,
57.87 + 0,8,6, 0,8,134, 0,8,70, 0,9,236,
57.88 + 80,7,9, 0,8,94, 0,8,30, 0,9,156,
57.89 + 84,7,99, 0,8,126, 0,8,62, 0,9,220,
57.90 + 82,7,27, 0,8,110, 0,8,46, 0,9,188,
57.91 + 0,8,14, 0,8,142, 0,8,78, 0,9,252,
57.92 + 96,7,256, 0,8,81, 0,8,17, 85,8,131,
57.93 + 82,7,31, 0,8,113, 0,8,49, 0,9,194,
57.94 + 80,7,10, 0,8,97, 0,8,33, 0,9,162,
57.95 + 0,8,1, 0,8,129, 0,8,65, 0,9,226,
57.96 + 80,7,6, 0,8,89, 0,8,25, 0,9,146,
57.97 + 83,7,59, 0,8,121, 0,8,57, 0,9,210,
57.98 + 81,7,17, 0,8,105, 0,8,41, 0,9,178,
57.99 + 0,8,9, 0,8,137, 0,8,73, 0,9,242,
57.100 + 80,7,4, 0,8,85, 0,8,21, 80,8,258,
57.101 + 83,7,43, 0,8,117, 0,8,53, 0,9,202,
57.102 + 81,7,13, 0,8,101, 0,8,37, 0,9,170,
57.103 + 0,8,5, 0,8,133, 0,8,69, 0,9,234,
57.104 + 80,7,8, 0,8,93, 0,8,29, 0,9,154,
57.105 + 84,7,83, 0,8,125, 0,8,61, 0,9,218,
57.106 + 82,7,23, 0,8,109, 0,8,45, 0,9,186,
57.107 + 0,8,13, 0,8,141, 0,8,77, 0,9,250,
57.108 + 80,7,3, 0,8,83, 0,8,19, 85,8,195,
57.109 + 83,7,35, 0,8,115, 0,8,51, 0,9,198,
57.110 + 81,7,11, 0,8,99, 0,8,35, 0,9,166,
57.111 + 0,8,3, 0,8,131, 0,8,67, 0,9,230,
57.112 + 80,7,7, 0,8,91, 0,8,27, 0,9,150,
57.113 + 84,7,67, 0,8,123, 0,8,59, 0,9,214,
57.114 + 82,7,19, 0,8,107, 0,8,43, 0,9,182,
57.115 + 0,8,11, 0,8,139, 0,8,75, 0,9,246,
57.116 + 80,7,5, 0,8,87, 0,8,23, 192,8,0,
57.117 + 83,7,51, 0,8,119, 0,8,55, 0,9,206,
57.118 + 81,7,15, 0,8,103, 0,8,39, 0,9,174,
57.119 + 0,8,7, 0,8,135, 0,8,71, 0,9,238,
57.120 + 80,7,9, 0,8,95, 0,8,31, 0,9,158,
57.121 + 84,7,99, 0,8,127, 0,8,63, 0,9,222,
57.122 + 82,7,27, 0,8,111, 0,8,47, 0,9,190,
57.123 + 0,8,15, 0,8,143, 0,8,79, 0,9,254,
57.124 + 96,7,256, 0,8,80, 0,8,16, 84,8,115,
57.125 + 82,7,31, 0,8,112, 0,8,48, 0,9,193,
57.126 +
57.127 + 80,7,10, 0,8,96, 0,8,32, 0,9,161,
57.128 + 0,8,0, 0,8,128, 0,8,64, 0,9,225,
57.129 + 80,7,6, 0,8,88, 0,8,24, 0,9,145,
57.130 + 83,7,59, 0,8,120, 0,8,56, 0,9,209,
57.131 + 81,7,17, 0,8,104, 0,8,40, 0,9,177,
57.132 + 0,8,8, 0,8,136, 0,8,72, 0,9,241,
57.133 + 80,7,4, 0,8,84, 0,8,20, 85,8,227,
57.134 + 83,7,43, 0,8,116, 0,8,52, 0,9,201,
57.135 + 81,7,13, 0,8,100, 0,8,36, 0,9,169,
57.136 + 0,8,4, 0,8,132, 0,8,68, 0,9,233,
57.137 + 80,7,8, 0,8,92, 0,8,28, 0,9,153,
57.138 + 84,7,83, 0,8,124, 0,8,60, 0,9,217,
57.139 + 82,7,23, 0,8,108, 0,8,44, 0,9,185,
57.140 + 0,8,12, 0,8,140, 0,8,76, 0,9,249,
57.141 + 80,7,3, 0,8,82, 0,8,18, 85,8,163,
57.142 + 83,7,35, 0,8,114, 0,8,50, 0,9,197,
57.143 + 81,7,11, 0,8,98, 0,8,34, 0,9,165,
57.144 + 0,8,2, 0,8,130, 0,8,66, 0,9,229,
57.145 + 80,7,7, 0,8,90, 0,8,26, 0,9,149,
57.146 + 84,7,67, 0,8,122, 0,8,58, 0,9,213,
57.147 + 82,7,19, 0,8,106, 0,8,42, 0,9,181,
57.148 + 0,8,10, 0,8,138, 0,8,74, 0,9,245,
57.149 + 80,7,5, 0,8,86, 0,8,22, 192,8,0,
57.150 + 83,7,51, 0,8,118, 0,8,54, 0,9,205,
57.151 + 81,7,15, 0,8,102, 0,8,38, 0,9,173,
57.152 + 0,8,6, 0,8,134, 0,8,70, 0,9,237,
57.153 + 80,7,9, 0,8,94, 0,8,30, 0,9,157,
57.154 + 84,7,99, 0,8,126, 0,8,62, 0,9,221,
57.155 + 82,7,27, 0,8,110, 0,8,46, 0,9,189,
57.156 + 0,8,14, 0,8,142, 0,8,78, 0,9,253,
57.157 + 96,7,256, 0,8,81, 0,8,17, 85,8,131,
57.158 + 82,7,31, 0,8,113, 0,8,49, 0,9,195,
57.159 + 80,7,10, 0,8,97, 0,8,33, 0,9,163,
57.160 + 0,8,1, 0,8,129, 0,8,65, 0,9,227,
57.161 + 80,7,6, 0,8,89, 0,8,25, 0,9,147,
57.162 + 83,7,59, 0,8,121, 0,8,57, 0,9,211,
57.163 + 81,7,17, 0,8,105, 0,8,41, 0,9,179,
57.164 + 0,8,9, 0,8,137, 0,8,73, 0,9,243,
57.165 + 80,7,4, 0,8,85, 0,8,21, 80,8,258,
57.166 + 83,7,43, 0,8,117, 0,8,53, 0,9,203,
57.167 + 81,7,13, 0,8,101, 0,8,37, 0,9,171,
57.168 + 0,8,5, 0,8,133, 0,8,69, 0,9,235,
57.169 + 80,7,8, 0,8,93, 0,8,29, 0,9,155,
57.170 + 84,7,83, 0,8,125, 0,8,61, 0,9,219,
57.171 + 82,7,23, 0,8,109, 0,8,45, 0,9,187,
57.172 + 0,8,13, 0,8,141, 0,8,77, 0,9,251,
57.173 + 80,7,3, 0,8,83, 0,8,19, 85,8,195,
57.174 + 83,7,35, 0,8,115, 0,8,51, 0,9,199,
57.175 + 81,7,11, 0,8,99, 0,8,35, 0,9,167,
57.176 + 0,8,3, 0,8,131, 0,8,67, 0,9,231,
57.177 + 80,7,7, 0,8,91, 0,8,27, 0,9,151,
57.178 + 84,7,67, 0,8,123, 0,8,59, 0,9,215,
57.179 + 82,7,19, 0,8,107, 0,8,43, 0,9,183,
57.180 + 0,8,11, 0,8,139, 0,8,75, 0,9,247,
57.181 + 80,7,5, 0,8,87, 0,8,23, 192,8,0,
57.182 + 83,7,51, 0,8,119, 0,8,55, 0,9,207,
57.183 + 81,7,15, 0,8,103, 0,8,39, 0,9,175,
57.184 + 0,8,7, 0,8,135, 0,8,71, 0,9,239,
57.185 + 80,7,9, 0,8,95, 0,8,31, 0,9,159,
57.186 + 84,7,99, 0,8,127, 0,8,63, 0,9,223,
57.187 + 82,7,27, 0,8,111, 0,8,47, 0,9,191,
57.188 + 0,8,15, 0,8,143, 0,8,79, 0,9,255
57.189 + };
57.190 + static final int[] fixed_td = {
57.191 + 80,5,1, 87,5,257, 83,5,17, 91,5,4097,
57.192 + 81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
57.193 + 80,5,3, 88,5,513, 84,5,33, 92,5,8193,
57.194 + 82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
57.195 + 80,5,2, 87,5,385, 83,5,25, 91,5,6145,
57.196 + 81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
57.197 + 80,5,4, 88,5,769, 84,5,49, 92,5,12289,
57.198 + 82,5,13, 90,5,3073, 86,5,193, 192,5,24577
57.199 + };
57.200 +
57.201 + // Tables for deflate from PKZIP's appnote.txt.
57.202 + static final int[] cplens = { // Copy lengths for literal codes 257..285
57.203 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
57.204 + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
57.205 + };
57.206 +
57.207 + // see note #13 above about 258
57.208 + static final int[] cplext = { // Extra bits for literal codes 257..285
57.209 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
57.210 + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
57.211 + };
57.212 +
57.213 + static final int[] cpdist = { // Copy offsets for distance codes 0..29
57.214 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
57.215 + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
57.216 + 8193, 12289, 16385, 24577
57.217 + };
57.218 +
57.219 + static final int[] cpdext = { // Extra bits for distance codes
57.220 + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
57.221 + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
57.222 + 12, 12, 13, 13};
57.223 +
57.224 + // If BMAX needs to be larger than 16, then h and x[] should be uLong.
57.225 + static final int BMAX=15; // maximum bit length of any code
57.226 +
57.227 + int[] hn = null; // hufts used in space
57.228 + int[] v = null; // work area for huft_build
57.229 + int[] c = null; // bit length count table
57.230 + int[] r = null; // table entry for structure assignment
57.231 + int[] u = null; // table stack
57.232 + int[] x = null; // bit offsets, then code stack
57.233 +
57.234 + private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
57.235 + int bindex,
57.236 + int n, // number of codes (assumed <= 288)
57.237 + int s, // number of simple-valued codes (0..s-1)
57.238 + int[] d, // list of base values for non-simple codes
57.239 + int[] e, // list of extra bits for non-simple codes
57.240 + int[] t, // result: starting table
57.241 + int[] m, // maximum lookup bits, returns actual
57.242 + int[] hp,// space for trees
57.243 + int[] hn,// hufts used in space
57.244 + int[] v // working area: values in order of bit length
57.245 + ){
57.246 + // Given a list of code lengths and a maximum table size, make a set of
57.247 + // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
57.248 + // if the given code set is incomplete (the tables are still built in this
57.249 + // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
57.250 + // lengths), or Z_MEM_ERROR if not enough memory.
57.251 +
57.252 + int a; // counter for codes of length k
57.253 + int f; // i repeats in table every f entries
57.254 + int g; // maximum code length
57.255 + int h; // table level
57.256 + int i; // counter, current code
57.257 + int j; // counter
57.258 + int k; // number of bits in current code
57.259 + int l; // bits per table (returned in m)
57.260 + int mask; // (1 << w) - 1, to avoid cc -O bug on HP
57.261 + int p; // pointer into c[], b[], or v[]
57.262 + int q; // points to current table
57.263 + int w; // bits before this table == (l * h)
57.264 + int xp; // pointer into x
57.265 + int y; // number of dummy codes added
57.266 + int z; // number of entries in current table
57.267 +
57.268 + // Generate counts for each bit length
57.269 +
57.270 + p = 0; i = n;
57.271 + do {
57.272 + c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX
57.273 + }while(i!=0);
57.274 +
57.275 + if(c[0] == n){ // null input--all zero length codes
57.276 + t[0] = -1;
57.277 + m[0] = 0;
57.278 + return Z_OK;
57.279 + }
57.280 +
57.281 + // Find minimum and maximum length, bound *m by those
57.282 + l = m[0];
57.283 + for (j = 1; j <= BMAX; j++)
57.284 + if(c[j]!=0) break;
57.285 + k = j; // minimum code length
57.286 + if(l < j){
57.287 + l = j;
57.288 + }
57.289 + for (i = BMAX; i!=0; i--){
57.290 + if(c[i]!=0) break;
57.291 + }
57.292 + g = i; // maximum code length
57.293 + if(l > i){
57.294 + l = i;
57.295 + }
57.296 + m[0] = l;
57.297 +
57.298 + // Adjust last length count to fill out codes, if needed
57.299 + for (y = 1 << j; j < i; j++, y <<= 1){
57.300 + if ((y -= c[j]) < 0){
57.301 + return Z_DATA_ERROR;
57.302 + }
57.303 + }
57.304 + if ((y -= c[i]) < 0){
57.305 + return Z_DATA_ERROR;
57.306 + }
57.307 + c[i] += y;
57.308 +
57.309 + // Generate starting offsets into the value table for each length
57.310 + x[1] = j = 0;
57.311 + p = 1; xp = 2;
57.312 + while (--i!=0) { // note that i == g from above
57.313 + x[xp] = (j += c[p]);
57.314 + xp++;
57.315 + p++;
57.316 + }
57.317 +
57.318 + // Make a table of values in order of bit lengths
57.319 + i = 0; p = 0;
57.320 + do {
57.321 + if ((j = b[bindex+p]) != 0){
57.322 + v[x[j]++] = i;
57.323 + }
57.324 + p++;
57.325 + }
57.326 + while (++i < n);
57.327 + n = x[g]; // set n to length of v
57.328 +
57.329 + // Generate the Huffman codes and for each, make the table entries
57.330 + x[0] = i = 0; // first Huffman code is zero
57.331 + p = 0; // grab values in bit order
57.332 + h = -1; // no tables yet--level -1
57.333 + w = -l; // bits decoded == (l * h)
57.334 + u[0] = 0; // just to keep compilers happy
57.335 + q = 0; // ditto
57.336 + z = 0; // ditto
57.337 +
57.338 + // go through the bit lengths (k already is bits in shortest code)
57.339 + for (; k <= g; k++){
57.340 + a = c[k];
57.341 + while (a--!=0){
57.342 + // here i is the Huffman code of length k bits for value *p
57.343 + // make tables up to required level
57.344 + while (k > w + l){
57.345 + h++;
57.346 + w += l; // previous table always l bits
57.347 + // compute minimum size table less than or equal to l bits
57.348 + z = g - w;
57.349 + z = (z > l) ? l : z; // table size upper limit
57.350 + if((f=1<<(j=k-w))>a+1){ // try a k-w bit table
57.351 + // too few codes for k-w bit table
57.352 + f -= a + 1; // deduct codes from patterns left
57.353 + xp = k;
57.354 + if(j < z){
57.355 + while (++j < z){ // try smaller tables up to z bits
57.356 + if((f <<= 1) <= c[++xp])
57.357 + break; // enough codes to use up j bits
57.358 + f -= c[xp]; // else deduct codes from patterns
57.359 + }
57.360 + }
57.361 + }
57.362 + z = 1 << j; // table entries for j-bit table
57.363 +
57.364 + // allocate new table
57.365 + if (hn[0] + z > MANY){ // (note: doesn't matter for fixed)
57.366 + return Z_DATA_ERROR; // overflow of MANY
57.367 + }
57.368 + u[h] = q = /*hp+*/ hn[0]; // DEBUG
57.369 + hn[0] += z;
57.370 +
57.371 + // connect to last table, if there is one
57.372 + if(h!=0){
57.373 + x[h]=i; // save pattern for backing up
57.374 + r[0]=(byte)j; // bits in this table
57.375 + r[1]=(byte)l; // bits to dump before this table
57.376 + j=i>>>(w - l);
57.377 + r[2] = (int)(q - u[h-1] - j); // offset to this table
57.378 + System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
57.379 + }
57.380 + else{
57.381 + t[0] = q; // first table is returned result
57.382 + }
57.383 + }
57.384 +
57.385 + // set up table entry in r
57.386 + r[1] = (byte)(k - w);
57.387 + if (p >= n){
57.388 + r[0] = 128 + 64; // out of values--invalid code
57.389 + }
57.390 + else if (v[p] < s){
57.391 + r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
57.392 + r[2] = v[p++]; // simple code is just the value
57.393 + }
57.394 + else{
57.395 + r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
57.396 + r[2]=d[v[p++] - s];
57.397 + }
57.398 +
57.399 + // fill code-like entries with r
57.400 + f=1<<(k-w);
57.401 + for (j=i>>>w;j<z;j+=f){
57.402 + System.arraycopy(r, 0, hp, (q+j)*3, 3);
57.403 + }
57.404 +
57.405 + // backwards increment the k-bit code i
57.406 + for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
57.407 + i ^= j;
57.408 + }
57.409 + i ^= j;
57.410 +
57.411 + // backup over finished tables
57.412 + mask = (1 << w) - 1; // needed on HP, cc -O bug
57.413 + while ((i & mask) != x[h]){
57.414 + h--; // don't need to update q
57.415 + w -= l;
57.416 + mask = (1 << w) - 1;
57.417 + }
57.418 + }
57.419 + }
57.420 + // Return Z_BUF_ERROR if we were given an incomplete table
57.421 + return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
57.422 + }
57.423 +
57.424 + int inflate_trees_bits(int[] c, // 19 code lengths
57.425 + int[] bb, // bits tree desired/actual depth
57.426 + int[] tb, // bits tree result
57.427 + int[] hp, // space for trees
57.428 + ZStream z // for messages
57.429 + ){
57.430 + int result;
57.431 + initWorkArea(19);
57.432 + hn[0]=0;
57.433 + result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
57.434 +
57.435 + if(result == Z_DATA_ERROR){
57.436 + z.msg = "oversubscribed dynamic bit lengths tree";
57.437 + }
57.438 + else if(result == Z_BUF_ERROR || bb[0] == 0){
57.439 + z.msg = "incomplete dynamic bit lengths tree";
57.440 + result = Z_DATA_ERROR;
57.441 + }
57.442 + return result;
57.443 + }
57.444 +
57.445 + int inflate_trees_dynamic(int nl, // number of literal/length codes
57.446 + int nd, // number of distance codes
57.447 + int[] c, // that many (total) code lengths
57.448 + int[] bl, // literal desired/actual bit depth
57.449 + int[] bd, // distance desired/actual bit depth
57.450 + int[] tl, // literal/length tree result
57.451 + int[] td, // distance tree result
57.452 + int[] hp, // space for trees
57.453 + ZStream z // for messages
57.454 + ){
57.455 + int result;
57.456 +
57.457 + // build literal/length tree
57.458 + initWorkArea(288);
57.459 + hn[0]=0;
57.460 + result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
57.461 + if (result != Z_OK || bl[0] == 0){
57.462 + if(result == Z_DATA_ERROR){
57.463 + z.msg = "oversubscribed literal/length tree";
57.464 + }
57.465 + else if (result != Z_MEM_ERROR){
57.466 + z.msg = "incomplete literal/length tree";
57.467 + result = Z_DATA_ERROR;
57.468 + }
57.469 + return result;
57.470 + }
57.471 +
57.472 + // build distance tree
57.473 + initWorkArea(288);
57.474 + result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
57.475 +
57.476 + if (result != Z_OK || (bd[0] == 0 && nl > 257)){
57.477 + if (result == Z_DATA_ERROR){
57.478 + z.msg = "oversubscribed distance tree";
57.479 + }
57.480 + else if (result == Z_BUF_ERROR) {
57.481 + z.msg = "incomplete distance tree";
57.482 + result = Z_DATA_ERROR;
57.483 + }
57.484 + else if (result != Z_MEM_ERROR){
57.485 + z.msg = "empty distance tree with lengths";
57.486 + result = Z_DATA_ERROR;
57.487 + }
57.488 + return result;
57.489 + }
57.490 +
57.491 + return Z_OK;
57.492 + }
57.493 +
57.494 + static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
57.495 + int[] bd, //distance desired/actual bit depth
57.496 + int[][] tl,//literal/length tree result
57.497 + int[][] td,//distance tree result
57.498 + ZStream z //for memory allocation
57.499 + ){
57.500 + bl[0]=fixed_bl;
57.501 + bd[0]=fixed_bd;
57.502 + tl[0]=fixed_tl;
57.503 + td[0]=fixed_td;
57.504 + return Z_OK;
57.505 + }
57.506 +
57.507 + private void initWorkArea(int vsize){
57.508 + if(hn==null){
57.509 + hn=new int[1];
57.510 + v=new int[vsize];
57.511 + c=new int[BMAX+1];
57.512 + r=new int[3];
57.513 + u=new int[BMAX];
57.514 + x=new int[BMAX+1];
57.515 + }
57.516 + if(v.length<vsize){ v=new int[vsize]; }
57.517 + for(int i=0; i<vsize; i++){v[i]=0;}
57.518 + for(int i=0; i<BMAX+1; i++){c[i]=0;}
57.519 + for(int i=0; i<3; i++){r[i]=0;}
57.520 + System.arraycopy(c, 0, u, 0, BMAX);
57.521 + System.arraycopy(c, 0, x, 0, BMAX+1);
57.522 + }
57.523 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
58.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflate.java Wed May 07 16:47:24 2014 +0200
58.3 @@ -0,0 +1,727 @@
58.4 +/* -*-mode:java; c-basic-offset:2; -*- */
58.5 +/*
58.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
58.7 +
58.8 +Redistribution and use in source and binary forms, with or without
58.9 +modification, are permitted provided that the following conditions are met:
58.10 +
58.11 + 1. Redistributions of source code must retain the above copyright notice,
58.12 + this list of conditions and the following disclaimer.
58.13 +
58.14 + 2. Redistributions in binary form must reproduce the above copyright
58.15 + notice, this list of conditions and the following disclaimer in
58.16 + the documentation and/or other materials provided with the distribution.
58.17 +
58.18 + 3. The names of the authors may not be used to endorse or promote products
58.19 + derived from this software without specific prior written permission.
58.20 +
58.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
58.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
58.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
58.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
58.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
58.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
58.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
58.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58.31 + */
58.32 +/*
58.33 + * This program is based on zlib-1.1.3, so all credit should go authors
58.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
58.35 + * and contributors of zlib.
58.36 + */
58.37 +
58.38 +package org.apidesign.bck2brwsr.emul.zip;
58.39 +
58.40 +
58.41 +
58.42 +final class Inflate{
58.43 +
58.44 + static final private int MAX_WBITS=15; // 32K LZ77 window
58.45 +
58.46 + // preset dictionary flag in zlib header
58.47 + static final private int PRESET_DICT=0x20;
58.48 +
58.49 + static final int Z_NO_FLUSH=0;
58.50 + static final int Z_PARTIAL_FLUSH=1;
58.51 + static final int Z_SYNC_FLUSH=2;
58.52 + static final int Z_FULL_FLUSH=3;
58.53 + static final int Z_FINISH=4;
58.54 +
58.55 + static final private int Z_DEFLATED=8;
58.56 +
58.57 + static final private int Z_OK=0;
58.58 + static final private int Z_STREAM_END=1;
58.59 + static final private int Z_NEED_DICT=2;
58.60 + static final private int Z_ERRNO=-1;
58.61 + static final private int Z_STREAM_ERROR=-2;
58.62 + static final private int Z_DATA_ERROR=-3;
58.63 + static final private int Z_MEM_ERROR=-4;
58.64 + static final private int Z_BUF_ERROR=-5;
58.65 + static final private int Z_VERSION_ERROR=-6;
58.66 +
58.67 + static final private int METHOD=0; // waiting for method byte
58.68 + static final private int FLAG=1; // waiting for flag byte
58.69 + static final private int DICT4=2; // four dictionary check bytes to go
58.70 + static final private int DICT3=3; // three dictionary check bytes to go
58.71 + static final private int DICT2=4; // two dictionary check bytes to go
58.72 + static final private int DICT1=5; // one dictionary check byte to go
58.73 + static final int DICT0=6; // waiting for inflateSetDictionary
58.74 + static final private int BLOCKS=7; // decompressing blocks
58.75 + static final private int CHECK4=8; // four check bytes to go
58.76 + static final private int CHECK3=9; // three check bytes to go
58.77 + static final private int CHECK2=10; // two check bytes to go
58.78 + static final private int CHECK1=11; // one check byte to go
58.79 + static final private int DONE=12; // finished check, done
58.80 + static final private int BAD=13; // got an error--stay here
58.81 +
58.82 + static final private int HEAD=14;
58.83 + static final private int LENGTH=15;
58.84 + static final private int TIME=16;
58.85 + static final private int OS=17;
58.86 + static final private int EXLEN=18;
58.87 + static final private int EXTRA=19;
58.88 + static final private int NAME=20;
58.89 + static final private int COMMENT=21;
58.90 + static final private int HCRC=22;
58.91 + static final private int FLAGS=23;
58.92 +
58.93 + int mode; // current inflate mode
58.94 +
58.95 + // mode dependent information
58.96 + int method; // if FLAGS, method byte
58.97 +
58.98 + // if CHECK, check values to compare
58.99 + long was = -1; // computed check value
58.100 + long need; // stream check value
58.101 +
58.102 + // if BAD, inflateSync's marker bytes count
58.103 + int marker;
58.104 +
58.105 + // mode independent information
58.106 + int wrap; // flag for no wrapper
58.107 + int wbits; // log2(window size) (8..15, defaults to 15)
58.108 +
58.109 + InfBlocks blocks; // current inflate_blocks state
58.110 +
58.111 + private final ZStream z;
58.112 +
58.113 + private int flags;
58.114 +
58.115 + private int need_bytes = -1;
58.116 + private byte[] crcbuf=new byte[4];
58.117 +
58.118 + GZIPHeader gheader = null;
58.119 +
58.120 + int inflateReset(){
58.121 + if(z == null) return Z_STREAM_ERROR;
58.122 +
58.123 + z.total_in = z.total_out = 0;
58.124 + z.msg = null;
58.125 + this.mode = HEAD;
58.126 + this.need_bytes = -1;
58.127 + this.blocks.reset();
58.128 + return Z_OK;
58.129 + }
58.130 +
58.131 + int inflateEnd(){
58.132 + if(blocks != null){
58.133 + blocks.free();
58.134 + }
58.135 + return Z_OK;
58.136 + }
58.137 +
58.138 + Inflate(ZStream z){
58.139 + this.z=z;
58.140 + }
58.141 +
58.142 + int inflateInit(int w){
58.143 + z.msg = null;
58.144 + blocks = null;
58.145 +
58.146 + // handle undocumented wrap option (no zlib header or check)
58.147 + wrap = 0;
58.148 + if(w < 0){
58.149 + w = - w;
58.150 + }
58.151 + else {
58.152 + wrap = (w >> 4) + 1;
58.153 + if(w < 48)
58.154 + w &= 15;
58.155 + }
58.156 +
58.157 + if(w<8 ||w>15){
58.158 + inflateEnd();
58.159 + return Z_STREAM_ERROR;
58.160 + }
58.161 + if(blocks != null && wbits != w){
58.162 + blocks.free();
58.163 + blocks=null;
58.164 + }
58.165 +
58.166 + // set window size
58.167 + wbits=w;
58.168 +
58.169 + this.blocks=new InfBlocks(z, 1<<w);
58.170 +
58.171 + // reset state
58.172 + inflateReset();
58.173 +
58.174 + return Z_OK;
58.175 + }
58.176 +
58.177 + int inflate(int f){
58.178 + int hold = 0;
58.179 +
58.180 + int r;
58.181 + int b;
58.182 +
58.183 + if(z == null || z.next_in == null){
58.184 + if(f == Z_FINISH && this.mode==HEAD)
58.185 + return Z_OK;
58.186 + return Z_STREAM_ERROR;
58.187 + }
58.188 +
58.189 + f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
58.190 + r = Z_BUF_ERROR;
58.191 + while (true){
58.192 +
58.193 + switch (this.mode){
58.194 + case HEAD:
58.195 + if(wrap==0){
58.196 + this.mode = BLOCKS;
58.197 + break;
58.198 + }
58.199 +
58.200 + try { r=readBytes(2, r, f); }
58.201 + catch(Return e){ return e.r; }
58.202 +
58.203 + if((wrap&2)!=0 && this.need == 0x8b1fL) { // gzip header
58.204 + z.adler=new CRC32();
58.205 + checksum(2, this.need);
58.206 +
58.207 + if(gheader==null)
58.208 + gheader=new GZIPHeader();
58.209 +
58.210 + this.mode = FLAGS;
58.211 + break;
58.212 + }
58.213 +
58.214 + flags = 0;
58.215 +
58.216 + this.method = ((int)this.need)&0xff;
58.217 + b=((int)(this.need>>8))&0xff;
58.218 +
58.219 + if((wrap&1)==0 || // check if zlib header allowed
58.220 + (((this.method << 8)+b) % 31)!=0){
58.221 + this.mode = BAD;
58.222 + z.msg = "incorrect header check";
58.223 + // since zlib 1.2, it is allowted to inflateSync for this case.
58.224 + /*
58.225 + this.marker = 5; // can't try inflateSync
58.226 + */
58.227 + break;
58.228 + }
58.229 +
58.230 + if((this.method&0xf)!=Z_DEFLATED){
58.231 + this.mode = BAD;
58.232 + z.msg="unknown compression method";
58.233 + // since zlib 1.2, it is allowted to inflateSync for this case.
58.234 + /*
58.235 + this.marker = 5; // can't try inflateSync
58.236 + */
58.237 + break;
58.238 + }
58.239 +
58.240 + if((this.method>>4)+8>this.wbits){
58.241 + this.mode = BAD;
58.242 + z.msg="invalid window size";
58.243 + // since zlib 1.2, it is allowted to inflateSync for this case.
58.244 + /*
58.245 + this.marker = 5; // can't try inflateSync
58.246 + */
58.247 + break;
58.248 + }
58.249 +
58.250 + z.adler=new Adler32();
58.251 +
58.252 + if((b&PRESET_DICT)==0){
58.253 + this.mode = BLOCKS;
58.254 + break;
58.255 + }
58.256 + this.mode = DICT4;
58.257 + case DICT4:
58.258 +
58.259 + if(z.avail_in==0)return r;r=f;
58.260 +
58.261 + z.avail_in--; z.total_in++;
58.262 + this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
58.263 + this.mode=DICT3;
58.264 + case DICT3:
58.265 +
58.266 + if(z.avail_in==0)return r;r=f;
58.267 +
58.268 + z.avail_in--; z.total_in++;
58.269 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
58.270 + this.mode=DICT2;
58.271 + case DICT2:
58.272 +
58.273 + if(z.avail_in==0)return r;r=f;
58.274 +
58.275 + z.avail_in--; z.total_in++;
58.276 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
58.277 + this.mode=DICT1;
58.278 + case DICT1:
58.279 +
58.280 + if(z.avail_in==0)return r;r=f;
58.281 +
58.282 + z.avail_in--; z.total_in++;
58.283 + this.need += (z.next_in[z.next_in_index++]&0xffL);
58.284 + z.adler.reset(this.need);
58.285 + this.mode = DICT0;
58.286 + return Z_NEED_DICT;
58.287 + case DICT0:
58.288 + this.mode = BAD;
58.289 + z.msg = "need dictionary";
58.290 + this.marker = 0; // can try inflateSync
58.291 + return Z_STREAM_ERROR;
58.292 + case BLOCKS:
58.293 + r = this.blocks.proc(r);
58.294 + if(r == Z_DATA_ERROR){
58.295 + this.mode = BAD;
58.296 + this.marker = 0; // can try inflateSync
58.297 + break;
58.298 + }
58.299 + if(r == Z_OK){
58.300 + r = f;
58.301 + }
58.302 + if(r != Z_STREAM_END){
58.303 + return r;
58.304 + }
58.305 + r = f;
58.306 + this.was=z.adler.getValue();
58.307 + this.blocks.reset();
58.308 + if(this.wrap==0){
58.309 + this.mode=DONE;
58.310 + break;
58.311 + }
58.312 + this.mode=CHECK4;
58.313 + case CHECK4:
58.314 +
58.315 + if(z.avail_in==0)return r;r=f;
58.316 +
58.317 + z.avail_in--; z.total_in++;
58.318 + this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
58.319 + this.mode=CHECK3;
58.320 + case CHECK3:
58.321 +
58.322 + if(z.avail_in==0)return r;r=f;
58.323 +
58.324 + z.avail_in--; z.total_in++;
58.325 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
58.326 + this.mode = CHECK2;
58.327 + case CHECK2:
58.328 +
58.329 + if(z.avail_in==0)return r;r=f;
58.330 +
58.331 + z.avail_in--; z.total_in++;
58.332 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
58.333 + this.mode = CHECK1;
58.334 + case CHECK1:
58.335 +
58.336 + if(z.avail_in==0)return r;r=f;
58.337 +
58.338 + z.avail_in--; z.total_in++;
58.339 + this.need+=(z.next_in[z.next_in_index++]&0xffL);
58.340 +
58.341 + if(flags!=0){ // gzip
58.342 + this.need = ((this.need&0xff000000)>>24 |
58.343 + (this.need&0x00ff0000)>>8 |
58.344 + (this.need&0x0000ff00)<<8 |
58.345 + (this.need&0x0000ffff)<<24)&0xffffffffL;
58.346 + }
58.347 +
58.348 + if(((int)(this.was)) != ((int)(this.need))){
58.349 + z.msg = "incorrect data check";
58.350 + // chack is delayed
58.351 + /*
58.352 + this.mode = BAD;
58.353 + this.marker = 5; // can't try inflateSync
58.354 + break;
58.355 + */
58.356 + }
58.357 + else if(flags!=0 && gheader!=null){
58.358 + gheader.crc = this.need;
58.359 + }
58.360 +
58.361 + this.mode = LENGTH;
58.362 + case LENGTH:
58.363 + if (wrap!=0 && flags!=0) {
58.364 +
58.365 + try { r=readBytes(4, r, f); }
58.366 + catch(Return e){ return e.r; }
58.367 +
58.368 + if(z.msg!=null && z.msg.equals("incorrect data check")){
58.369 + this.mode = BAD;
58.370 + this.marker = 5; // can't try inflateSync
58.371 + break;
58.372 + }
58.373 +
58.374 + if (this.need != (z.total_out & 0xffffffffL)) {
58.375 + z.msg = "incorrect length check";
58.376 + this.mode = BAD;
58.377 + break;
58.378 + }
58.379 + z.msg = null;
58.380 + }
58.381 + else {
58.382 + if(z.msg!=null && z.msg.equals("incorrect data check")){
58.383 + this.mode = BAD;
58.384 + this.marker = 5; // can't try inflateSync
58.385 + break;
58.386 + }
58.387 + }
58.388 +
58.389 + this.mode = DONE;
58.390 + case DONE:
58.391 + return Z_STREAM_END;
58.392 + case BAD:
58.393 + return Z_DATA_ERROR;
58.394 +
58.395 + case FLAGS:
58.396 +
58.397 + try { r=readBytes(2, r, f); }
58.398 + catch(Return e){ return e.r; }
58.399 +
58.400 + flags = ((int)this.need)&0xffff;
58.401 +
58.402 + if ((flags & 0xff) != Z_DEFLATED) {
58.403 + z.msg = "unknown compression method";
58.404 + this.mode = BAD;
58.405 + break;
58.406 + }
58.407 + if ((flags & 0xe000)!=0) {
58.408 + z.msg = "unknown header flags set";
58.409 + this.mode = BAD;
58.410 + break;
58.411 + }
58.412 +
58.413 + if ((flags & 0x0200)!=0){
58.414 + checksum(2, this.need);
58.415 + }
58.416 +
58.417 + this.mode = TIME;
58.418 +
58.419 + case TIME:
58.420 + try { r=readBytes(4, r, f); }
58.421 + catch(Return e){ return e.r; }
58.422 + if(gheader!=null)
58.423 + gheader.time = this.need;
58.424 + if ((flags & 0x0200)!=0){
58.425 + checksum(4, this.need);
58.426 + }
58.427 + this.mode = OS;
58.428 + case OS:
58.429 + try { r=readBytes(2, r, f); }
58.430 + catch(Return e){ return e.r; }
58.431 + if(gheader!=null){
58.432 + gheader.xflags = ((int)this.need)&0xff;
58.433 + gheader.os = (((int)this.need)>>8)&0xff;
58.434 + }
58.435 + if ((flags & 0x0200)!=0){
58.436 + checksum(2, this.need);
58.437 + }
58.438 + this.mode = EXLEN;
58.439 + case EXLEN:
58.440 + if ((flags & 0x0400)!=0) {
58.441 + try { r=readBytes(2, r, f); }
58.442 + catch(Return e){ return e.r; }
58.443 + if(gheader!=null){
58.444 + gheader.extra = new byte[((int)this.need)&0xffff];
58.445 + }
58.446 + if ((flags & 0x0200)!=0){
58.447 + checksum(2, this.need);
58.448 + }
58.449 + }
58.450 + else if(gheader!=null){
58.451 + gheader.extra=null;
58.452 + }
58.453 + this.mode = EXTRA;
58.454 +
58.455 + case EXTRA:
58.456 + if ((flags & 0x0400)!=0) {
58.457 + try {
58.458 + r=readBytes(r, f);
58.459 + if(gheader!=null){
58.460 + byte[] foo = tmp_array;
58.461 + tmp_array=null;
58.462 + if(foo.length == gheader.extra.length){
58.463 + System.arraycopy(foo, 0, gheader.extra, 0, foo.length);
58.464 + }
58.465 + else{
58.466 + z.msg = "bad extra field length";
58.467 + this.mode = BAD;
58.468 + break;
58.469 + }
58.470 + }
58.471 + }
58.472 + catch(Return e){ return e.r; }
58.473 + }
58.474 + else if(gheader!=null){
58.475 + gheader.extra=null;
58.476 + }
58.477 + this.mode = NAME;
58.478 + case NAME:
58.479 + if ((flags & 0x0800)!=0) {
58.480 + try {
58.481 + r=readString(r, f);
58.482 + if(gheader!=null){
58.483 + gheader.name=tmp_array;
58.484 + }
58.485 + tmp_array=null;
58.486 + }
58.487 + catch(Return e){ return e.r; }
58.488 + }
58.489 + else if(gheader!=null){
58.490 + gheader.name=null;
58.491 + }
58.492 + this.mode = COMMENT;
58.493 + case COMMENT:
58.494 + if ((flags & 0x1000)!=0) {
58.495 + try {
58.496 + r=readString(r, f);
58.497 + if(gheader!=null){
58.498 + gheader.comment=tmp_array;
58.499 + }
58.500 + tmp_array=null;
58.501 + }
58.502 + catch(Return e){ return e.r; }
58.503 + }
58.504 + else if(gheader!=null){
58.505 + gheader.comment=null;
58.506 + }
58.507 + this.mode = HCRC;
58.508 + case HCRC:
58.509 + if ((flags & 0x0200)!=0) {
58.510 + try { r=readBytes(2, r, f); }
58.511 + catch(Return e){ return e.r; }
58.512 + if(gheader!=null){
58.513 + gheader.hcrc=(int)(this.need&0xffff);
58.514 + }
58.515 + if(this.need != (z.adler.getValue()&0xffffL)){
58.516 + this.mode = BAD;
58.517 + z.msg = "header crc mismatch";
58.518 + this.marker = 5; // can't try inflateSync
58.519 + break;
58.520 + }
58.521 + }
58.522 + z.adler = new CRC32();
58.523 +
58.524 + this.mode = BLOCKS;
58.525 + break;
58.526 + default:
58.527 + return Z_STREAM_ERROR;
58.528 + }
58.529 + }
58.530 + }
58.531 +
58.532 + int inflateSetDictionary(byte[] dictionary, int dictLength){
58.533 + if(z==null || (this.mode != DICT0 && this.wrap != 0)){
58.534 + return Z_STREAM_ERROR;
58.535 + }
58.536 +
58.537 + int index=0;
58.538 + int length = dictLength;
58.539 +
58.540 + if(this.mode==DICT0){
58.541 + long adler_need=z.adler.getValue();
58.542 + z.adler.reset();
58.543 + z.adler.update(dictionary, 0, dictLength);
58.544 + if(z.adler.getValue()!=adler_need){
58.545 + return Z_DATA_ERROR;
58.546 + }
58.547 + }
58.548 +
58.549 + z.adler.reset();
58.550 +
58.551 + if(length >= (1<<this.wbits)){
58.552 + length = (1<<this.wbits)-1;
58.553 + index=dictLength - length;
58.554 + }
58.555 + this.blocks.set_dictionary(dictionary, index, length);
58.556 + this.mode = BLOCKS;
58.557 + return Z_OK;
58.558 + }
58.559 +
58.560 + static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
58.561 +
58.562 + int inflateSync(){
58.563 + int n; // number of bytes to look at
58.564 + int p; // pointer to bytes
58.565 + int m; // number of marker bytes found in a row
58.566 + long r, w; // temporaries to save total_in and total_out
58.567 +
58.568 + // set up
58.569 + if(z == null)
58.570 + return Z_STREAM_ERROR;
58.571 + if(this.mode != BAD){
58.572 + this.mode = BAD;
58.573 + this.marker = 0;
58.574 + }
58.575 + if((n=z.avail_in)==0)
58.576 + return Z_BUF_ERROR;
58.577 +
58.578 + p=z.next_in_index;
58.579 + m=this.marker;
58.580 + // search
58.581 + while (n!=0 && m < 4){
58.582 + if(z.next_in[p] == mark[m]){
58.583 + m++;
58.584 + }
58.585 + else if(z.next_in[p]!=0){
58.586 + m = 0;
58.587 + }
58.588 + else{
58.589 + m = 4 - m;
58.590 + }
58.591 + p++; n--;
58.592 + }
58.593 +
58.594 + // restore
58.595 + z.total_in += p-z.next_in_index;
58.596 + z.next_in_index = p;
58.597 + z.avail_in = n;
58.598 + this.marker = m;
58.599 +
58.600 + // return no joy or set up to restart on a new block
58.601 + if(m != 4){
58.602 + return Z_DATA_ERROR;
58.603 + }
58.604 + r=z.total_in; w=z.total_out;
58.605 + inflateReset();
58.606 + z.total_in=r; z.total_out = w;
58.607 + this.mode = BLOCKS;
58.608 +
58.609 + return Z_OK;
58.610 + }
58.611 +
58.612 + // Returns true if inflate is currently at the end of a block generated
58.613 + // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
58.614 + // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
58.615 + // but removes the length bytes of the resulting empty stored block. When
58.616 + // decompressing, PPP checks that at the end of input packet, inflate is
58.617 + // waiting for these length bytes.
58.618 + int inflateSyncPoint(){
58.619 + if(z == null || this.blocks == null)
58.620 + return Z_STREAM_ERROR;
58.621 + return this.blocks.sync_point();
58.622 + }
58.623 +
58.624 + private int readBytes(int n, int r, int f) throws Return{
58.625 + if(need_bytes == -1){
58.626 + need_bytes=n;
58.627 + this.need=0;
58.628 + }
58.629 + while(need_bytes>0){
58.630 + if(z.avail_in==0){ throw new Return(r); }; r=f;
58.631 + z.avail_in--; z.total_in++;
58.632 + this.need = this.need |
58.633 + ((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8));
58.634 + need_bytes--;
58.635 + }
58.636 + if(n==2){
58.637 + this.need&=0xffffL;
58.638 + }
58.639 + else if(n==4) {
58.640 + this.need&=0xffffffffL;
58.641 + }
58.642 + need_bytes=-1;
58.643 + return r;
58.644 + }
58.645 + class Return extends Exception{
58.646 + int r;
58.647 + Return(int r){this.r=r; }
58.648 + }
58.649 +
58.650 + private byte[] tmp_array;
58.651 + private int readString(int r, int f) throws Return{
58.652 + int b=0;
58.653 + byte[] arr = new byte[4092];
58.654 + int at = 0;
58.655 + do {
58.656 + if(z.avail_in==0){ throw new Return(r); }; r=f;
58.657 + z.avail_in--; z.total_in++;
58.658 + b = z.next_in[z.next_in_index];
58.659 + if(b!=0) arr = append(arr, z.next_in[z.next_in_index], at++);
58.660 + z.adler.update(z.next_in, z.next_in_index, 1);
58.661 + z.next_in_index++;
58.662 + }while(b!=0);
58.663 +
58.664 + tmp_array = copy(arr, at);
58.665 +
58.666 + return r;
58.667 + }
58.668 +
58.669 + private int readBytes(int r, int f) throws Return{
58.670 + int b=0;
58.671 + byte[] arr = new byte[4092];
58.672 + int at = 0;
58.673 + while(this.need>0){
58.674 + if(z.avail_in==0){ throw new Return(r); }; r=f;
58.675 + z.avail_in--; z.total_in++;
58.676 + b = z.next_in[z.next_in_index];
58.677 + arr = append(arr, z.next_in[z.next_in_index], at++);
58.678 + z.adler.update(z.next_in, z.next_in_index, 1);
58.679 + z.next_in_index++;
58.680 + this.need--;
58.681 + }
58.682 +
58.683 + tmp_array = copy(arr, at);
58.684 +
58.685 + return r;
58.686 + }
58.687 +
58.688 + private static byte[] copy(byte[] arr, int len) {
58.689 + byte[] ret = new byte[len];
58.690 + System.arraycopy(arr, 0, ret, 0, len);
58.691 + return ret;
58.692 + }
58.693 + private static byte[] append(byte[] arr, byte b, int index) {
58.694 + arr[index] = b;
58.695 + return arr;
58.696 + }
58.697 +
58.698 + private void checksum(int n, long v){
58.699 + for(int i=0; i<n; i++){
58.700 + crcbuf[i]=(byte)(v&0xff);
58.701 + v>>=8;
58.702 + }
58.703 + z.adler.update(crcbuf, 0, n);
58.704 + }
58.705 +
58.706 + public GZIPHeader getGZIPHeader(){
58.707 + return gheader;
58.708 + }
58.709 +
58.710 + boolean inParsingHeader(){
58.711 + switch(mode){
58.712 + case HEAD:
58.713 + case DICT4:
58.714 + case DICT3:
58.715 + case DICT2:
58.716 + case DICT1:
58.717 + case FLAGS:
58.718 + case TIME:
58.719 + case OS:
58.720 + case EXLEN:
58.721 + case EXTRA:
58.722 + case NAME:
58.723 + case COMMENT:
58.724 + case HCRC:
58.725 + return true;
58.726 + default:
58.727 + return false;
58.728 + }
58.729 + }
58.730 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
59.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java Wed May 07 16:47:24 2014 +0200
59.3 @@ -0,0 +1,338 @@
59.4 +/*
59.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59.7 + *
59.8 + * This code is free software; you can redistribute it and/or modify it
59.9 + * under the terms of the GNU General Public License version 2 only, as
59.10 + * published by the Free Software Foundation. Oracle designates this
59.11 + * particular file as subject to the "Classpath" exception as provided
59.12 + * by Oracle in the LICENSE file that accompanied this code.
59.13 + *
59.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
59.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
59.17 + * version 2 for more details (a copy is included in the LICENSE file that
59.18 + * accompanied this code).
59.19 + *
59.20 + * You should have received a copy of the GNU General Public License version
59.21 + * 2 along with this work; if not, write to the Free Software Foundation,
59.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59.23 + *
59.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59.25 + * or visit www.oracle.com if you need additional information or have any
59.26 + * questions.
59.27 + */
59.28 +
59.29 +package org.apidesign.bck2brwsr.emul.zip;
59.30 +
59.31 +import java.util.zip.*;
59.32 +import java.io.IOException;
59.33 +
59.34 +/**
59.35 + * This class provides support for general purpose decompression using the
59.36 + * popular ZLIB compression library. The ZLIB compression library was
59.37 + * initially developed as part of the PNG graphics standard and is not
59.38 + * protected by patents. It is fully described in the specifications at
59.39 + * the <a href="package-summary.html#package_description">java.util.zip
59.40 + * package description</a>.
59.41 + *
59.42 + * <p>The following code fragment demonstrates a trivial compression
59.43 + * and decompression of a string using <tt>Deflater</tt> and
59.44 + * <tt>Inflater</tt>.
59.45 + *
59.46 + * <blockquote><pre>
59.47 + * try {
59.48 + * // Encode a String into bytes
59.49 + * String inputString = "blahblahblah\u20AC\u20AC";
59.50 + * byte[] input = inputString.getBytes("UTF-8");
59.51 + *
59.52 + * // Compress the bytes
59.53 + * byte[] output = new byte[100];
59.54 + * Deflater compresser = new Deflater();
59.55 + * compresser.setInput(input);
59.56 + * compresser.finish();
59.57 + * int compressedDataLength = compresser.deflate(output);
59.58 + *
59.59 + * // Decompress the bytes
59.60 + * Inflater decompresser = new Inflater();
59.61 + * decompresser.setInput(output, 0, compressedDataLength);
59.62 + * byte[] result = new byte[100];
59.63 + * int resultLength = decompresser.inflate(result);
59.64 + * decompresser.end();
59.65 + *
59.66 + * // Decode the bytes into a String
59.67 + * String outputString = new String(result, 0, resultLength, "UTF-8");
59.68 + * } catch(java.io.UnsupportedEncodingException ex) {
59.69 + * // handle
59.70 + * } catch (java.util.zip.DataFormatException ex) {
59.71 + * // handle
59.72 + * }
59.73 + * </pre></blockquote>
59.74 + *
59.75 + * @see Deflater
59.76 + * @author David Connelly
59.77 + *
59.78 + */
59.79 +public
59.80 +class Inflater extends java.util.zip.Inflater {
59.81 + private final boolean nowrap;
59.82 + private JzLibInflater impl;
59.83 +
59.84 + /**
59.85 + * Creates a new decompressor. If the parameter 'nowrap' is true then
59.86 + * the ZLIB header and checksum fields will not be used. This provides
59.87 + * compatibility with the compression format used by both GZIP and PKZIP.
59.88 + * <p>
59.89 + * Note: When using the 'nowrap' option it is also necessary to provide
59.90 + * an extra "dummy" byte as input. This is required by the ZLIB native
59.91 + * library in order to support certain optimizations.
59.92 + *
59.93 + * @param nowrap if true then support GZIP compatible compression
59.94 + */
59.95 + public Inflater(boolean nowrap) {
59.96 + this.nowrap = nowrap;
59.97 + reset();
59.98 + }
59.99 +
59.100 + /**
59.101 + * Creates a new decompressor.
59.102 + */
59.103 + public Inflater() {
59.104 + this(false);
59.105 + }
59.106 +
59.107 + /**
59.108 + * Sets input data for decompression. Should be called whenever
59.109 + * needsInput() returns true indicating that more input data is
59.110 + * required.
59.111 + * @param b the input data bytes
59.112 + * @param off the start offset of the input data
59.113 + * @param len the length of the input data
59.114 + * @see Inflater#needsInput
59.115 + */
59.116 + public void setInput(byte[] b, int off, int len) {
59.117 + if (b == null) {
59.118 + throw new NullPointerException();
59.119 + }
59.120 + if (off < 0 || len < 0 || off > b.length - len) {
59.121 + throw new ArrayIndexOutOfBoundsException();
59.122 + }
59.123 + impl.setInput(b, off, len, false);
59.124 + }
59.125 +
59.126 + /**
59.127 + * Sets input data for decompression. Should be called whenever
59.128 + * needsInput() returns true indicating that more input data is
59.129 + * required.
59.130 + * @param b the input data bytes
59.131 + * @see Inflater#needsInput
59.132 + */
59.133 + public void setInput(byte[] b) {
59.134 + setInput(b, 0, b.length);
59.135 + }
59.136 +
59.137 + /**
59.138 + * Sets the preset dictionary to the given array of bytes. Should be
59.139 + * called when inflate() returns 0 and needsDictionary() returns true
59.140 + * indicating that a preset dictionary is required. The method getAdler()
59.141 + * can be used to get the Adler-32 value of the dictionary needed.
59.142 + * @param b the dictionary data bytes
59.143 + * @param off the start offset of the data
59.144 + * @param len the length of the data
59.145 + * @see Inflater#needsDictionary
59.146 + * @see Inflater#getAdler
59.147 + */
59.148 + public void setDictionary(byte[] b, int off, int len) {
59.149 + if (b == null) {
59.150 + throw new NullPointerException();
59.151 + }
59.152 + if (off < 0 || len < 0 || off > b.length - len) {
59.153 + throw new ArrayIndexOutOfBoundsException();
59.154 + }
59.155 + byte[] arr;
59.156 + if (off == 0) {
59.157 + arr = b;
59.158 + } else {
59.159 + arr = new byte[len];
59.160 + System.arraycopy(b, off, arr, 0, len);
59.161 + }
59.162 + impl.setDictionary(arr, len);
59.163 + }
59.164 +
59.165 + /**
59.166 + * Sets the preset dictionary to the given array of bytes. Should be
59.167 + * called when inflate() returns 0 and needsDictionary() returns true
59.168 + * indicating that a preset dictionary is required. The method getAdler()
59.169 + * can be used to get the Adler-32 value of the dictionary needed.
59.170 + * @param b the dictionary data bytes
59.171 + * @see Inflater#needsDictionary
59.172 + * @see Inflater#getAdler
59.173 + */
59.174 + public void setDictionary(byte[] b) {
59.175 + impl.setDictionary(b, b.length);
59.176 + }
59.177 +
59.178 + /**
59.179 + * Returns the total number of bytes remaining in the input buffer.
59.180 + * This can be used to find out what bytes still remain in the input
59.181 + * buffer after decompression has finished.
59.182 + * @return the total number of bytes remaining in the input buffer
59.183 + */
59.184 + public int getRemaining() {
59.185 + return impl.getAvailIn();
59.186 + }
59.187 +
59.188 + /**
59.189 + * Returns true if no data remains in the input buffer. This can
59.190 + * be used to determine if #setInput should be called in order
59.191 + * to provide more input.
59.192 + * @return true if no data remains in the input buffer
59.193 + */
59.194 + public boolean needsInput() {
59.195 + return getRemaining() <= 0;
59.196 + }
59.197 +
59.198 + /**
59.199 + * Returns true if a preset dictionary is needed for decompression.
59.200 + * @return true if a preset dictionary is needed for decompression
59.201 + * @see Inflater#setDictionary
59.202 + */
59.203 + public boolean needsDictionary() {
59.204 + return impl.needDict();
59.205 + }
59.206 +
59.207 + /**
59.208 + * Returns true if the end of the compressed data stream has been
59.209 + * reached.
59.210 + * @return true if the end of the compressed data stream has been
59.211 + * reached
59.212 + */
59.213 + public boolean finished() {
59.214 + return impl.finished();
59.215 + }
59.216 +
59.217 + /**
59.218 + * Uncompresses bytes into specified buffer. Returns actual number
59.219 + * of bytes uncompressed. A return value of 0 indicates that
59.220 + * needsInput() or needsDictionary() should be called in order to
59.221 + * determine if more input data or a preset dictionary is required.
59.222 + * In the latter case, getAdler() can be used to get the Adler-32
59.223 + * value of the dictionary required.
59.224 + * @param b the buffer for the uncompressed data
59.225 + * @param off the start offset of the data
59.226 + * @param len the maximum number of uncompressed bytes
59.227 + * @return the actual number of uncompressed bytes
59.228 + * @exception DataFormatException if the compressed data format is invalid
59.229 + * @see Inflater#needsInput
59.230 + * @see Inflater#needsDictionary
59.231 + */
59.232 + public int inflate(byte[] b, int off, int len)
59.233 + throws DataFormatException
59.234 + {
59.235 + if (b == null) {
59.236 + throw new NullPointerException();
59.237 + }
59.238 + if (off < 0 || len < 0 || off > b.length - len) {
59.239 + throw new ArrayIndexOutOfBoundsException();
59.240 + }
59.241 + impl.setOutput(b, off, len);
59.242 + int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
59.243 + return impl.next_out_index - off;
59.244 + }
59.245 +
59.246 + /**
59.247 + * Uncompresses bytes into specified buffer. Returns actual number
59.248 + * of bytes uncompressed. A return value of 0 indicates that
59.249 + * needsInput() or needsDictionary() should be called in order to
59.250 + * determine if more input data or a preset dictionary is required.
59.251 + * In the latter case, getAdler() can be used to get the Adler-32
59.252 + * value of the dictionary required.
59.253 + * @param b the buffer for the uncompressed data
59.254 + * @return the actual number of uncompressed bytes
59.255 + * @exception DataFormatException if the compressed data format is invalid
59.256 + * @see Inflater#needsInput
59.257 + * @see Inflater#needsDictionary
59.258 + */
59.259 + public int inflate(byte[] b) throws DataFormatException {
59.260 + return inflate(b, 0, b.length);
59.261 + }
59.262 +
59.263 + /**
59.264 + * Returns the ADLER-32 value of the uncompressed data.
59.265 + * @return the ADLER-32 value of the uncompressed data
59.266 + */
59.267 + public int getAdler() {
59.268 + return (int) impl.getAdler();
59.269 + }
59.270 +
59.271 + /**
59.272 + * Returns the total number of compressed bytes input so far.
59.273 + *
59.274 + * <p>Since the number of bytes may be greater than
59.275 + * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
59.276 + * the preferred means of obtaining this information.</p>
59.277 + *
59.278 + * @return the total number of compressed bytes input so far
59.279 + */
59.280 + public int getTotalIn() {
59.281 + return (int) getBytesRead();
59.282 + }
59.283 +
59.284 + /**
59.285 + * Returns the total number of compressed bytes input so far.</p>
59.286 + *
59.287 + * @return the total (non-negative) number of compressed bytes input so far
59.288 + * @since 1.5
59.289 + */
59.290 + public long getBytesRead() {
59.291 + return impl.total_in;
59.292 + }
59.293 +
59.294 + /**
59.295 + * Returns the total number of uncompressed bytes output so far.
59.296 + *
59.297 + * <p>Since the number of bytes may be greater than
59.298 + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
59.299 + * the preferred means of obtaining this information.</p>
59.300 + *
59.301 + * @return the total number of uncompressed bytes output so far
59.302 + */
59.303 + public int getTotalOut() {
59.304 + return (int) getBytesWritten();
59.305 + }
59.306 +
59.307 + /**
59.308 + * Returns the total number of uncompressed bytes output so far.</p>
59.309 + *
59.310 + * @return the total (non-negative) number of uncompressed bytes output so far
59.311 + * @since 1.5
59.312 + */
59.313 + public long getBytesWritten() {
59.314 + return impl.total_out;
59.315 + }
59.316 +
59.317 + /**
59.318 + * Resets inflater so that a new set of input data can be processed.
59.319 + */
59.320 + public void reset() {
59.321 + impl = new JzLibInflater(15, nowrap);
59.322 + }
59.323 +
59.324 + /**
59.325 + * Closes the decompressor and discards any unprocessed input.
59.326 + * This method should be called when the decompressor is no longer
59.327 + * being used, but will also be called automatically by the finalize()
59.328 + * method. Once this method is called, the behavior of the Inflater
59.329 + * object is undefined.
59.330 + */
59.331 + public void end() {
59.332 + impl.end();
59.333 + }
59.334 +
59.335 + /**
59.336 + * Closes the decompressor when garbage is collected.
59.337 + */
59.338 + protected void finalize() {
59.339 + end();
59.340 + }
59.341 +}
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
60.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java Wed May 07 16:47:24 2014 +0200
60.3 @@ -0,0 +1,137 @@
60.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
60.5 +/*
60.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
60.7 +
60.8 +Redistribution and use in source and binary forms, with or without
60.9 +modification, are permitted provided that the following conditions are met:
60.10 +
60.11 + 1. Redistributions of source code must retain the above copyright notice,
60.12 + this list of conditions and the following disclaimer.
60.13 +
60.14 + 2. Redistributions in binary form must reproduce the above copyright
60.15 + notice, this list of conditions and the following disclaimer in
60.16 + the documentation and/or other materials provided with the distribution.
60.17 +
60.18 + 3. The names of the authors may not be used to endorse or promote products
60.19 + derived from this software without specific prior written permission.
60.20 +
60.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
60.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
60.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
60.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
60.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
60.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
60.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
60.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
60.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60.31 + */
60.32 +/*
60.33 + * This program is based on zlib-1.1.3, so all credit should go authors
60.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
60.35 + * and contributors of zlib.
60.36 + */
60.37 +
60.38 +package org.apidesign.bck2brwsr.emul.zip;
60.39 +
60.40 +final class JzLibInflater extends ZStream{
60.41 +
60.42 + static final private int MAX_WBITS=15; // 32K LZ77 window
60.43 + static final private int DEF_WBITS=MAX_WBITS;
60.44 +
60.45 + public static final int Z_NO_FLUSH=0;
60.46 + static final private int Z_PARTIAL_FLUSH=1;
60.47 + static final private int Z_SYNC_FLUSH=2;
60.48 + static final private int Z_FULL_FLUSH=3;
60.49 + static final private int Z_FINISH=4;
60.50 +
60.51 + static final private int MAX_MEM_LEVEL=9;
60.52 +
60.53 + static final private int Z_OK=0;
60.54 + static final private int Z_STREAM_END=1;
60.55 + static final private int Z_NEED_DICT=2;
60.56 + static final private int Z_ERRNO=-1;
60.57 + static final private int Z_STREAM_ERROR=-2;
60.58 + static final private int Z_DATA_ERROR=-3;
60.59 + static final private int Z_MEM_ERROR=-4;
60.60 + static final private int Z_BUF_ERROR=-5;
60.61 + static final private int Z_VERSION_ERROR=-6;
60.62 +
60.63 + public JzLibInflater() {
60.64 + super();
60.65 + init();
60.66 + }
60.67 +
60.68 + public JzLibInflater(int w) {
60.69 + this(w, false);
60.70 + }
60.71 +
60.72 + public JzLibInflater(int w, boolean nowrap) {
60.73 + super();
60.74 + int ret = init(w, nowrap);
60.75 + if(ret!=Z_OK)
60.76 + throw new IllegalStateException(ret+": "+msg);
60.77 + }
60.78 +
60.79 + private boolean finished = false;
60.80 +
60.81 + public int init(){
60.82 + return init(DEF_WBITS);
60.83 + }
60.84 +
60.85 + public int init(boolean nowrap){
60.86 + return init(DEF_WBITS, nowrap);
60.87 + }
60.88 +
60.89 + public int init(int w){
60.90 + return init(w, false);
60.91 + }
60.92 +
60.93 + public int init(int w, boolean nowrap){
60.94 + finished = false;
60.95 + istate=new Inflate(this);
60.96 + return istate.inflateInit(nowrap?-w:w);
60.97 + }
60.98 +
60.99 + public int inflate(int f){
60.100 + if(istate==null) return Z_STREAM_ERROR;
60.101 + int ret = istate.inflate(f);
60.102 + if(ret == Z_STREAM_END)
60.103 + finished = true;
60.104 + return ret;
60.105 + }
60.106 +
60.107 + public int end(){
60.108 + finished = true;
60.109 + if(istate==null) return Z_STREAM_ERROR;
60.110 + int ret=istate.inflateEnd();
60.111 +// istate = null;
60.112 + return ret;
60.113 + }
60.114 +
60.115 + public int sync(){
60.116 + if(istate == null)
60.117 + return Z_STREAM_ERROR;
60.118 + return istate.inflateSync();
60.119 + }
60.120 +
60.121 + public int syncPoint(){
60.122 + if(istate == null)
60.123 + return Z_STREAM_ERROR;
60.124 + return istate.inflateSyncPoint();
60.125 + }
60.126 +
60.127 + public int setDictionary(byte[] dictionary, int dictLength){
60.128 + if(istate == null)
60.129 + return Z_STREAM_ERROR;
60.130 + return istate.inflateSetDictionary(dictionary, dictLength);
60.131 + }
60.132 +
60.133 + public boolean finished(){
60.134 + return istate.mode==12 /*DONE*/;
60.135 + }
60.136 +
60.137 + public boolean needDict() {
60.138 + return istate == null ? false : istate.mode == Inflate.DICT0;
60.139 + }
60.140 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
61.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java Wed May 07 16:47:24 2014 +0200
61.3 @@ -0,0 +1,253 @@
61.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
61.5 +/*
61.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
61.7 +
61.8 +Redistribution and use in source and binary forms, with or without
61.9 +modification, are permitted provided that the following conditions are met:
61.10 +
61.11 + 1. Redistributions of source code must retain the above copyright notice,
61.12 + this list of conditions and the following disclaimer.
61.13 +
61.14 + 2. Redistributions in binary form must reproduce the above copyright
61.15 + notice, this list of conditions and the following disclaimer in
61.16 + the documentation and/or other materials provided with the distribution.
61.17 +
61.18 + 3. The names of the authors may not be used to endorse or promote products
61.19 + derived from this software without specific prior written permission.
61.20 +
61.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
61.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
61.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
61.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
61.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
61.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
61.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
61.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
61.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61.31 + */
61.32 +/*
61.33 + * This program is based on zlib-1.1.3, so all credit should go authors
61.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
61.35 + * and contributors of zlib.
61.36 + */
61.37 +
61.38 +package org.apidesign.bck2brwsr.emul.zip;
61.39 +
61.40 +
61.41 +
61.42 +/**
61.43 + * ZStream
61.44 + *
61.45 + * @deprecated Not for public use in the future.
61.46 + */
61.47 +@Deprecated
61.48 +class ZStream{
61.49 +
61.50 + static final private int MAX_WBITS=15; // 32K LZ77 window
61.51 + static final private int DEF_WBITS=MAX_WBITS;
61.52 +
61.53 + static final private int Z_NO_FLUSH=0;
61.54 + static final private int Z_PARTIAL_FLUSH=1;
61.55 + static final private int Z_SYNC_FLUSH=2;
61.56 + static final private int Z_FULL_FLUSH=3;
61.57 + static final private int Z_FINISH=4;
61.58 +
61.59 + static final private int MAX_MEM_LEVEL=9;
61.60 +
61.61 + static final private int Z_OK=0;
61.62 + static final private int Z_STREAM_END=1;
61.63 + static final private int Z_NEED_DICT=2;
61.64 + static final private int Z_ERRNO=-1;
61.65 + static final private int Z_STREAM_ERROR=-2;
61.66 + static final private int Z_DATA_ERROR=-3;
61.67 + static final private int Z_MEM_ERROR=-4;
61.68 + static final private int Z_BUF_ERROR=-5;
61.69 + static final private int Z_VERSION_ERROR=-6;
61.70 +
61.71 + public byte[] next_in; // next input byte
61.72 + public int next_in_index;
61.73 + public int avail_in; // number of bytes available at next_in
61.74 + public long total_in; // total nb of input bytes read so far
61.75 +
61.76 + public byte[] next_out; // next output byte should be put there
61.77 + public int next_out_index;
61.78 + public int avail_out; // remaining free space at next_out
61.79 + public long total_out; // total nb of bytes output so far
61.80 +
61.81 + public String msg;
61.82 +
61.83 + Inflate istate;
61.84 +
61.85 + int data_type; // best guess about the data type: ascii or binary
61.86 +
61.87 + Checksum adler;
61.88 +
61.89 + public ZStream(){
61.90 + this(new Adler32());
61.91 + }
61.92 +
61.93 + public ZStream(Checksum adler){
61.94 + this.adler=adler;
61.95 + }
61.96 +
61.97 + public int inflateInit(){
61.98 + return inflateInit(DEF_WBITS);
61.99 + }
61.100 + public int inflateInit(boolean nowrap){
61.101 + return inflateInit(DEF_WBITS, nowrap);
61.102 + }
61.103 + public int inflateInit(int w){
61.104 + return inflateInit(w, false);
61.105 + }
61.106 +
61.107 + public int inflateInit(int w, boolean nowrap){
61.108 + istate=new Inflate(this);
61.109 + return istate.inflateInit(nowrap?-w:w);
61.110 + }
61.111 +
61.112 + public int inflate(int f){
61.113 + if(istate==null) return Z_STREAM_ERROR;
61.114 + return istate.inflate(f);
61.115 + }
61.116 + public int inflateEnd(){
61.117 + if(istate==null) return Z_STREAM_ERROR;
61.118 + int ret=istate.inflateEnd();
61.119 +// istate = null;
61.120 + return ret;
61.121 + }
61.122 +
61.123 + public int inflateSync(){
61.124 + if(istate == null)
61.125 + return Z_STREAM_ERROR;
61.126 + return istate.inflateSync();
61.127 + }
61.128 + public int inflateSyncPoint(){
61.129 + if(istate == null)
61.130 + return Z_STREAM_ERROR;
61.131 + return istate.inflateSyncPoint();
61.132 + }
61.133 + public int inflateSetDictionary(byte[] dictionary, int dictLength){
61.134 + if(istate == null)
61.135 + return Z_STREAM_ERROR;
61.136 + return istate.inflateSetDictionary(dictionary, dictLength);
61.137 + }
61.138 + public boolean inflateFinished(){
61.139 + return istate.mode==12 /*DONE*/;
61.140 + }
61.141 +
61.142 +
61.143 + public long getAdler(){
61.144 + return adler.getValue();
61.145 + }
61.146 +
61.147 + public void free(){
61.148 + next_in=null;
61.149 + next_out=null;
61.150 + msg=null;
61.151 + }
61.152 +
61.153 + public void setOutput(byte[] buf){
61.154 + setOutput(buf, 0, buf.length);
61.155 + }
61.156 +
61.157 + public void setOutput(byte[] buf, int off, int len){
61.158 + next_out = buf;
61.159 + next_out_index = off;
61.160 + avail_out = len;
61.161 + }
61.162 +
61.163 + public void setInput(byte[] buf){
61.164 + setInput(buf, 0, buf.length, false);
61.165 + }
61.166 +
61.167 + public void setInput(byte[] buf, boolean append){
61.168 + setInput(buf, 0, buf.length, append);
61.169 + }
61.170 +
61.171 + public void setInput(byte[] buf, int off, int len, boolean append){
61.172 + if(len<=0 && append && next_in!=null) return;
61.173 +
61.174 + if(avail_in>0 && append){
61.175 + byte[] tmp = new byte[avail_in+len];
61.176 + System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
61.177 + System.arraycopy(buf, off, tmp, avail_in, len);
61.178 + next_in=tmp;
61.179 + next_in_index=0;
61.180 + avail_in+=len;
61.181 + }
61.182 + else{
61.183 + next_in=buf;
61.184 + next_in_index=off;
61.185 + avail_in=len;
61.186 + }
61.187 + }
61.188 +
61.189 + public byte[] getNextIn(){
61.190 + return next_in;
61.191 + }
61.192 +
61.193 + public void setNextIn(byte[] next_in){
61.194 + this.next_in = next_in;
61.195 + }
61.196 +
61.197 + public int getNextInIndex(){
61.198 + return next_in_index;
61.199 + }
61.200 +
61.201 + public void setNextInIndex(int next_in_index){
61.202 + this.next_in_index = next_in_index;
61.203 + }
61.204 +
61.205 + public int getAvailIn(){
61.206 + return avail_in;
61.207 + }
61.208 +
61.209 + public void setAvailIn(int avail_in){
61.210 + this.avail_in = avail_in;
61.211 + }
61.212 +
61.213 + public byte[] getNextOut(){
61.214 + return next_out;
61.215 + }
61.216 +
61.217 + public void setNextOut(byte[] next_out){
61.218 + this.next_out = next_out;
61.219 + }
61.220 +
61.221 + public int getNextOutIndex(){
61.222 + return next_out_index;
61.223 + }
61.224 +
61.225 + public void setNextOutIndex(int next_out_index){
61.226 + this.next_out_index = next_out_index;
61.227 + }
61.228 +
61.229 + public int getAvailOut(){
61.230 + return avail_out;
61.231 +
61.232 + }
61.233 +
61.234 + public void setAvailOut(int avail_out){
61.235 + this.avail_out = avail_out;
61.236 + }
61.237 +
61.238 + public long getTotalOut(){
61.239 + return total_out;
61.240 + }
61.241 +
61.242 + public long getTotalIn(){
61.243 + return total_in;
61.244 + }
61.245 +
61.246 + public String getMessage(){
61.247 + return msg;
61.248 + }
61.249 +
61.250 + /**
61.251 + * Those methods are expected to be override by Inflater and Deflater.
61.252 + * In the future, they will become abstract methods.
61.253 + */
61.254 + public int end(){ return Z_OK; }
61.255 + public boolean finished(){ return false; }
61.256 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
62.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java Wed May 07 16:47:24 2014 +0200
62.3 @@ -0,0 +1,84 @@
62.4 +/*
62.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62.7 + *
62.8 + * This code is free software; you can redistribute it and/or modify it
62.9 + * under the terms of the GNU General Public License version 2 only, as
62.10 + * published by the Free Software Foundation. Oracle designates this
62.11 + * particular file as subject to the "Classpath" exception as provided
62.12 + * by Oracle in the LICENSE file that accompanied this code.
62.13 + *
62.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
62.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
62.17 + * version 2 for more details (a copy is included in the LICENSE file that
62.18 + * accompanied this code).
62.19 + *
62.20 + * You should have received a copy of the GNU General Public License version
62.21 + * 2 along with this work; if not, write to the Free Software Foundation,
62.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62.23 + *
62.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62.25 + * or visit www.oracle.com if you need additional information or have any
62.26 + * questions.
62.27 + */
62.28 +
62.29 +package org.apidesign.bck2brwsr.emul.zip;
62.30 +
62.31 +/*
62.32 + * This class defines the constants that are used by the classes
62.33 + * which manipulate Zip64 files.
62.34 + */
62.35 +
62.36 +public class ZipConstants64 {
62.37 +
62.38 + /*
62.39 + * ZIP64 constants
62.40 + */
62.41 + static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006"
62.42 + static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007"
62.43 + static final int ZIP64_ENDHDR = 56; // ZIP64 end header size
62.44 + static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size
62.45 + static final int ZIP64_EXTHDR = 24; // EXT header size
62.46 + static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID
62.47 +
62.48 + static final int ZIP64_MAGICCOUNT = 0xFFFF;
62.49 + static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
62.50 +
62.51 + /*
62.52 + * Zip64 End of central directory (END) header field offsets
62.53 + */
62.54 + static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir
62.55 + static final int ZIP64_ENDVEM = 12; // version made by
62.56 + static final int ZIP64_ENDVER = 14; // version needed to extract
62.57 + static final int ZIP64_ENDNMD = 16; // number of this disk
62.58 + static final int ZIP64_ENDDSK = 20; // disk number of start
62.59 + static final int ZIP64_ENDTOD = 24; // total number of entries on this disk
62.60 + static final int ZIP64_ENDTOT = 32; // total number of entries
62.61 + static final int ZIP64_ENDSIZ = 40; // central directory size in bytes
62.62 + static final int ZIP64_ENDOFF = 48; // offset of first CEN header
62.63 + static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector
62.64 +
62.65 + /*
62.66 + * Zip64 End of central directory locator field offsets
62.67 + */
62.68 + static final int ZIP64_LOCDSK = 4; // disk number start
62.69 + static final int ZIP64_LOCOFF = 8; // offset of zip64 end
62.70 + static final int ZIP64_LOCTOT = 16; // total number of disks
62.71 +
62.72 + /*
62.73 + * Zip64 Extra local (EXT) header field offsets
62.74 + */
62.75 + static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value
62.76 + static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte
62.77 + static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte
62.78 +
62.79 + /*
62.80 + * Language encoding flag EFS
62.81 + */
62.82 + static final int EFS = 0x800; // If this bit is set the filename and
62.83 + // comment fields for this file must be
62.84 + // encoded using UTF-8.
62.85 +
62.86 + private ZipConstants64() {}
62.87 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
63.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java Wed May 07 16:47:24 2014 +0200
63.3 @@ -0,0 +1,468 @@
63.4 +/*
63.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63.7 + *
63.8 + * This code is free software; you can redistribute it and/or modify it
63.9 + * under the terms of the GNU General Public License version 2 only, as
63.10 + * published by the Free Software Foundation. Oracle designates this
63.11 + * particular file as subject to the "Classpath" exception as provided
63.12 + * by Oracle in the LICENSE file that accompanied this code.
63.13 + *
63.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
63.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63.17 + * version 2 for more details (a copy is included in the LICENSE file that
63.18 + * accompanied this code).
63.19 + *
63.20 + * You should have received a copy of the GNU General Public License version
63.21 + * 2 along with this work; if not, write to the Free Software Foundation,
63.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63.23 + *
63.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
63.25 + * or visit www.oracle.com if you need additional information or have any
63.26 + * questions.
63.27 + */
63.28 +
63.29 +package org.apidesign.bck2brwsr.emul.zip;
63.30 +
63.31 +import java.util.zip.*;
63.32 +import java.io.InputStream;
63.33 +import java.io.IOException;
63.34 +import java.io.EOFException;
63.35 +import java.io.PushbackInputStream;
63.36 +import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*;
63.37 +import static java.util.zip.ZipInputStream.*;
63.38 +
63.39 +/**
63.40 + * This class implements an input stream filter for reading files in the
63.41 + * ZIP file format. Includes support for both compressed and uncompressed
63.42 + * entries.
63.43 + *
63.44 + * @author David Connelly
63.45 + */
63.46 +public
63.47 +class ZipInputStream extends InflaterInputStream {
63.48 + private ZipEntry entry;
63.49 + private int flag;
63.50 + private CRC32 crc = new CRC32();
63.51 + private long remaining;
63.52 + private byte[] tmpbuf = new byte[512];
63.53 +
63.54 + private static final int STORED = ZipEntry.STORED;
63.55 + private static final int DEFLATED = ZipEntry.DEFLATED;
63.56 +
63.57 + private boolean closed = false;
63.58 + // this flag is set to true after EOF has reached for
63.59 + // one entry
63.60 + private boolean entryEOF = false;
63.61 +
63.62 + /**
63.63 + * Check to make sure that this stream has not been closed
63.64 + */
63.65 + private void ensureOpen() throws IOException {
63.66 + if (closed) {
63.67 + throw new IOException("Stream closed");
63.68 + }
63.69 + }
63.70 +
63.71 + /**
63.72 + * Creates a new ZIP input stream.
63.73 + *
63.74 + * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
63.75 + * decode the entry names.
63.76 + *
63.77 + * @param in the actual input stream
63.78 + */
63.79 + public ZipInputStream(InputStream in) {
63.80 +// this(in, "UTF-8");
63.81 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
63.82 + //usesDefaultInflater = true;
63.83 + if(in == null) {
63.84 + throw new NullPointerException("in is null");
63.85 + }
63.86 + }
63.87 +
63.88 + /**
63.89 + * Creates a new ZIP input stream.
63.90 + *
63.91 + * @param in the actual input stream
63.92 + *
63.93 + * @param charset
63.94 + * The {@linkplain java.nio.charset.Charset charset} to be
63.95 + * used to decode the ZIP entry name (ignored if the
63.96 + * <a href="package-summary.html#lang_encoding"> language
63.97 + * encoding bit</a> of the ZIP entry's general purpose bit
63.98 + * flag is set).
63.99 + *
63.100 + * @since 1.7
63.101 + *
63.102 + public ZipInputStream(InputStream in, Charset charset) {
63.103 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
63.104 + usesDefaultInflater = true;
63.105 + if(in == null) {
63.106 + throw new NullPointerException("in is null");
63.107 + }
63.108 + if (charset == null)
63.109 + throw new NullPointerException("charset is null");
63.110 + this.zc = ZipCoder.get(charset);
63.111 + }
63.112 + */
63.113 +
63.114 + /**
63.115 + * Reads the next ZIP file entry and positions the stream at the
63.116 + * beginning of the entry data.
63.117 + * @return the next ZIP file entry, or null if there are no more entries
63.118 + * @exception ZipException if a ZIP file error has occurred
63.119 + * @exception IOException if an I/O error has occurred
63.120 + */
63.121 + public ZipEntry getNextEntry() throws IOException {
63.122 + ensureOpen();
63.123 + if (entry != null) {
63.124 + closeEntry();
63.125 + }
63.126 + crc.reset();
63.127 + inf.reset();
63.128 + if ((entry = readLOC()) == null) {
63.129 + return null;
63.130 + }
63.131 + if (entry.getMethod() == STORED) {
63.132 + remaining = entry.getSize();
63.133 + }
63.134 + entryEOF = false;
63.135 + return entry;
63.136 + }
63.137 +
63.138 + /**
63.139 + * Closes the current ZIP entry and positions the stream for reading the
63.140 + * next entry.
63.141 + * @exception ZipException if a ZIP file error has occurred
63.142 + * @exception IOException if an I/O error has occurred
63.143 + */
63.144 + public void closeEntry() throws IOException {
63.145 + ensureOpen();
63.146 + while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
63.147 + entryEOF = true;
63.148 + }
63.149 +
63.150 + /**
63.151 + * Returns 0 after EOF has reached for the current entry data,
63.152 + * otherwise always return 1.
63.153 + * <p>
63.154 + * Programs should not count on this method to return the actual number
63.155 + * of bytes that could be read without blocking.
63.156 + *
63.157 + * @return 1 before EOF and 0 after EOF has reached for current entry.
63.158 + * @exception IOException if an I/O error occurs.
63.159 + *
63.160 + */
63.161 + public int available() throws IOException {
63.162 + ensureOpen();
63.163 + if (entryEOF) {
63.164 + return 0;
63.165 + } else {
63.166 + return 1;
63.167 + }
63.168 + }
63.169 +
63.170 + /**
63.171 + * Reads from the current ZIP entry into an array of bytes.
63.172 + * If <code>len</code> is not zero, the method
63.173 + * blocks until some input is available; otherwise, no
63.174 + * bytes are read and <code>0</code> is returned.
63.175 + * @param b the buffer into which the data is read
63.176 + * @param off the start offset in the destination array <code>b</code>
63.177 + * @param len the maximum number of bytes read
63.178 + * @return the actual number of bytes read, or -1 if the end of the
63.179 + * entry is reached
63.180 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
63.181 + * @exception IndexOutOfBoundsException if <code>off</code> is negative,
63.182 + * <code>len</code> is negative, or <code>len</code> is greater than
63.183 + * <code>b.length - off</code>
63.184 + * @exception ZipException if a ZIP file error has occurred
63.185 + * @exception IOException if an I/O error has occurred
63.186 + */
63.187 + public int read(byte[] b, int off, int len) throws IOException {
63.188 + ensureOpen();
63.189 + if (off < 0 || len < 0 || off > b.length - len) {
63.190 + throw new IndexOutOfBoundsException();
63.191 + } else if (len == 0) {
63.192 + return 0;
63.193 + }
63.194 +
63.195 + if (entry == null) {
63.196 + return -1;
63.197 + }
63.198 + switch (entry.getMethod()) {
63.199 + case DEFLATED:
63.200 + len = super.read(b, off, len);
63.201 + if (len == -1) {
63.202 + readEnd(entry);
63.203 + entryEOF = true;
63.204 + entry = null;
63.205 + } else {
63.206 + crc.update(b, off, len);
63.207 + }
63.208 + return len;
63.209 + case STORED:
63.210 + if (remaining <= 0) {
63.211 + entryEOF = true;
63.212 + entry = null;
63.213 + return -1;
63.214 + }
63.215 + if (len > remaining) {
63.216 + len = (int)remaining;
63.217 + }
63.218 + len = in.read(b, off, len);
63.219 + if (len == -1) {
63.220 + throw new ZipException("unexpected EOF");
63.221 + }
63.222 + crc.update(b, off, len);
63.223 + remaining -= len;
63.224 + if (remaining == 0 && entry.getCrc() != crc.getValue()) {
63.225 + throw new ZipException(
63.226 + "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
63.227 + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
63.228 + }
63.229 + return len;
63.230 + default:
63.231 + throw new ZipException("invalid compression method");
63.232 + }
63.233 + }
63.234 +
63.235 + /**
63.236 + * Skips specified number of bytes in the current ZIP entry.
63.237 + * @param n the number of bytes to skip
63.238 + * @return the actual number of bytes skipped
63.239 + * @exception ZipException if a ZIP file error has occurred
63.240 + * @exception IOException if an I/O error has occurred
63.241 + * @exception IllegalArgumentException if n < 0
63.242 + */
63.243 + public long skip(long n) throws IOException {
63.244 + if (n < 0) {
63.245 + throw new IllegalArgumentException("negative skip length");
63.246 + }
63.247 + ensureOpen();
63.248 + int max = (int)Math.min(n, Integer.MAX_VALUE);
63.249 + int total = 0;
63.250 + while (total < max) {
63.251 + int len = max - total;
63.252 + if (len > tmpbuf.length) {
63.253 + len = tmpbuf.length;
63.254 + }
63.255 + len = read(tmpbuf, 0, len);
63.256 + if (len == -1) {
63.257 + entryEOF = true;
63.258 + break;
63.259 + }
63.260 + total += len;
63.261 + }
63.262 + return total;
63.263 + }
63.264 +
63.265 + /**
63.266 + * Closes this input stream and releases any system resources associated
63.267 + * with the stream.
63.268 + * @exception IOException if an I/O error has occurred
63.269 + */
63.270 + public void close() throws IOException {
63.271 + if (!closed) {
63.272 + super.close();
63.273 + closed = true;
63.274 + }
63.275 + }
63.276 +
63.277 + private byte[] b = new byte[256];
63.278 +
63.279 + /*
63.280 + * Reads local file (LOC) header for next entry.
63.281 + */
63.282 + private ZipEntry readLOC() throws IOException {
63.283 + try {
63.284 + readFully(tmpbuf, 0, LOCHDR);
63.285 + } catch (EOFException e) {
63.286 + return null;
63.287 + }
63.288 + if (get32(tmpbuf, 0) != LOCSIG) {
63.289 + return null;
63.290 + }
63.291 + // get flag first, we need check EFS.
63.292 + flag = get16(tmpbuf, LOCFLG);
63.293 + // get the entry name and create the ZipEntry first
63.294 + int len = get16(tmpbuf, LOCNAM);
63.295 + int blen = b.length;
63.296 + if (len > blen) {
63.297 + do
63.298 + blen = blen * 2;
63.299 + while (len > blen);
63.300 + b = new byte[blen];
63.301 + }
63.302 + readFully(b, 0, len);
63.303 + // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
63.304 + ZipEntry e = createZipEntry(((flag & EFS) != 0)
63.305 + ? toStringUTF8(b, len)
63.306 + : toString(b, len));
63.307 + // now get the remaining fields for the entry
63.308 + if ((flag & 1) == 1) {
63.309 + throw new ZipException("encrypted ZIP entry not supported");
63.310 + }
63.311 + e.setMethod(get16(tmpbuf, LOCHOW));
63.312 + e.setTime(get32(tmpbuf, LOCTIM));
63.313 + if ((flag & 8) == 8) {
63.314 + /* "Data Descriptor" present */
63.315 + if (e.getMethod() != DEFLATED) {
63.316 + throw new ZipException(
63.317 + "only DEFLATED entries can have EXT descriptor");
63.318 + }
63.319 + } else {
63.320 + e.setCrc(get32(tmpbuf, LOCCRC));
63.321 + e.setCompressedSize(get32(tmpbuf, LOCSIZ));
63.322 + e.setSize(get32(tmpbuf, LOCLEN));
63.323 + }
63.324 + len = get16(tmpbuf, LOCEXT);
63.325 + if (len > 0) {
63.326 + byte[] bb = new byte[len];
63.327 + readFully(bb, 0, len);
63.328 + e.setExtra(bb);
63.329 + // extra fields are in "HeaderID(2)DataSize(2)Data... format
63.330 + if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
63.331 + int off = 0;
63.332 + while (off + 4 < len) {
63.333 + int sz = get16(bb, off + 2);
63.334 + if (get16(bb, off) == ZIP64_EXTID) {
63.335 + off += 4;
63.336 + // LOC extra zip64 entry MUST include BOTH original and
63.337 + // compressed file size fields
63.338 + if (sz < 16 || (off + sz) > len ) {
63.339 + // Invalid zip64 extra fields, simply skip. Even it's
63.340 + // rare, it's possible the entry size happens to be
63.341 + // the magic value and it "accidnetly" has some bytes
63.342 + // in extra match the id.
63.343 + return e;
63.344 + }
63.345 + e.setSize(get64(bb, off));
63.346 + e.setCompressedSize(get64(bb, off + 8));
63.347 + break;
63.348 + }
63.349 + off += (sz + 4);
63.350 + }
63.351 + }
63.352 + }
63.353 + return e;
63.354 + }
63.355 +
63.356 + /**
63.357 + * Creates a new <code>ZipEntry</code> object for the specified
63.358 + * entry name.
63.359 + *
63.360 + * @param name the ZIP file entry name
63.361 + * @return the ZipEntry just created
63.362 + */
63.363 + protected ZipEntry createZipEntry(String name) {
63.364 + return new ZipEntry(name);
63.365 + }
63.366 +
63.367 + /*
63.368 + * Reads end of deflated entry as well as EXT descriptor if present.
63.369 + */
63.370 + private void readEnd(ZipEntry e) throws IOException {
63.371 + int n = inf.getRemaining();
63.372 + if (n > 0) {
63.373 + ((PushbackInputStream)in).unread(buf, len - n, n);
63.374 + }
63.375 + if ((flag & 8) == 8) {
63.376 + /* "Data Descriptor" present */
63.377 + if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
63.378 + inf.getBytesRead() > ZIP64_MAGICVAL) {
63.379 + // ZIP64 format
63.380 + readFully(tmpbuf, 0, ZIP64_EXTHDR);
63.381 + long sig = get32(tmpbuf, 0);
63.382 + if (sig != EXTSIG) { // no EXTSIG present
63.383 + e.setCrc(sig);
63.384 + e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
63.385 + e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
63.386 + ((PushbackInputStream)in).unread(
63.387 + tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
63.388 + } else {
63.389 + e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
63.390 + e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
63.391 + e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
63.392 + }
63.393 + } else {
63.394 + readFully(tmpbuf, 0, EXTHDR);
63.395 + long sig = get32(tmpbuf, 0);
63.396 + if (sig != EXTSIG) { // no EXTSIG present
63.397 + e.setCrc(sig);
63.398 + e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
63.399 + e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
63.400 + ((PushbackInputStream)in).unread(
63.401 + tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
63.402 + } else {
63.403 + e.setCrc(get32(tmpbuf, EXTCRC));
63.404 + e.setCompressedSize(get32(tmpbuf, EXTSIZ));
63.405 + e.setSize(get32(tmpbuf, EXTLEN));
63.406 + }
63.407 + }
63.408 + }
63.409 + if (e.getSize() != inf.getBytesWritten()) {
63.410 + throw new ZipException(
63.411 + "invalid entry size (expected " + e.getSize() +
63.412 + " but got " + inf.getBytesWritten() + " bytes)");
63.413 + }
63.414 + if (e.getCompressedSize() != inf.getBytesRead()) {
63.415 + throw new ZipException(
63.416 + "invalid entry compressed size (expected " + e.getCompressedSize() +
63.417 + " but got " + inf.getBytesRead() + " bytes)");
63.418 + }
63.419 + if (e.getCrc() != crc.getValue()) {
63.420 + throw new ZipException(
63.421 + "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
63.422 + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
63.423 + }
63.424 + }
63.425 +
63.426 + /*
63.427 + * Reads bytes, blocking until all bytes are read.
63.428 + */
63.429 + private void readFully(byte[] b, int off, int len) throws IOException {
63.430 + while (len > 0) {
63.431 + int n = in.read(b, off, len);
63.432 + if (n == -1) {
63.433 + throw new EOFException();
63.434 + }
63.435 + off += n;
63.436 + len -= n;
63.437 + }
63.438 + }
63.439 +
63.440 + /*
63.441 + * Fetches unsigned 16-bit value from byte array at specified offset.
63.442 + * The bytes are assumed to be in Intel (little-endian) byte order.
63.443 + */
63.444 + private static final int get16(byte b[], int off) {
63.445 + return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
63.446 + }
63.447 +
63.448 + /*
63.449 + * Fetches unsigned 32-bit value from byte array at specified offset.
63.450 + * The bytes are assumed to be in Intel (little-endian) byte order.
63.451 + */
63.452 + private static final long get32(byte b[], int off) {
63.453 + return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
63.454 + }
63.455 +
63.456 + /*
63.457 + * Fetches signed 64-bit value from byte array at specified offset.
63.458 + * The bytes are assumed to be in Intel (little-endian) byte order.
63.459 + */
63.460 + private static final long get64(byte b[], int off) {
63.461 + return get32(b, off) | (get32(b, off+4) << 32);
63.462 + }
63.463 +
63.464 + private static String toStringUTF8(byte[] arr, int len) {
63.465 + return new String(arr, 0, len);
63.466 + }
63.467 +
63.468 + private static String toString(byte[] b, int len) {
63.469 + return new String(b, 0, len);
63.470 + }
63.471 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
64.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/CRC32Test.java Wed May 07 16:47:24 2014 +0200
64.3 @@ -0,0 +1,41 @@
64.4 +/**
64.5 + * Back 2 Browser Bytecode Translator
64.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
64.7 + *
64.8 + * This program is free software: you can redistribute it and/or modify
64.9 + * it under the terms of the GNU General Public License as published by
64.10 + * the Free Software Foundation, version 2 of the License.
64.11 + *
64.12 + * This program is distributed in the hope that it will be useful,
64.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
64.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64.15 + * GNU General Public License for more details.
64.16 + *
64.17 + * You should have received a copy of the GNU General Public License
64.18 + * along with this program. Look for COPYING file in the top folder.
64.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
64.20 + */
64.21 +package org.apidesign.bck2brwsr.emul.zip;
64.22 +
64.23 +import java.io.UnsupportedEncodingException;
64.24 +import java.util.zip.CRC32;
64.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
64.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
64.27 +import org.testng.annotations.Factory;
64.28 +
64.29 +/**
64.30 + *
64.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
64.32 + */
64.33 +public class CRC32Test {
64.34 +
64.35 + @Compare public long crc1() throws UnsupportedEncodingException {
64.36 + CRC32 crc = new CRC32();
64.37 + crc.update("Hello World!".getBytes("UTF-8"));
64.38 + return crc.getValue();
64.39 + }
64.40 +
64.41 + @Factory public static Object[] create() {
64.42 + return VMTest.create(CRC32Test.class);
64.43 + }
64.44 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
65.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipArchive.java Wed May 07 16:47:24 2014 +0200
65.3 @@ -0,0 +1,154 @@
65.4 +/**
65.5 + * Back 2 Browser Bytecode Translator
65.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
65.7 + *
65.8 + * This program is free software: you can redistribute it and/or modify
65.9 + * it under the terms of the GNU General Public License as published by
65.10 + * the Free Software Foundation, version 2 of the License.
65.11 + *
65.12 + * This program is distributed in the hope that it will be useful,
65.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
65.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65.15 + * GNU General Public License for more details.
65.16 + *
65.17 + * You should have received a copy of the GNU General Public License
65.18 + * along with this program. Look for COPYING file in the top folder.
65.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
65.20 + */
65.21 +package org.apidesign.bck2brwsr.emul.zip;
65.22 +
65.23 +import java.io.ByteArrayOutputStream;
65.24 +import java.io.IOException;
65.25 +import java.io.InputStream;
65.26 +import java.util.Arrays;
65.27 +import java.util.LinkedHashMap;
65.28 +import java.util.Map;
65.29 +import java.util.Objects;
65.30 +import java.util.zip.ZipEntry;
65.31 +import org.apidesign.bck2brwsr.emul.zip.ZipInputStream;
65.32 +
65.33 +/**
65.34 + *
65.35 + * @author Jaroslav Tulach <jtulach@netbeans.org>
65.36 + */
65.37 +final class ZipArchive {
65.38 + private final Map<String, byte[]> entries = new LinkedHashMap<>();
65.39 +
65.40 + public static ZipArchive createZip(InputStream is) throws IOException {
65.41 + ZipArchive a = new ZipArchive();
65.42 + readZip(is, a);
65.43 + return a;
65.44 + }
65.45 +
65.46 + public static ZipArchive createReal(InputStream is) throws IOException {
65.47 + ZipArchive a = new ZipArchive();
65.48 + realZip(is, a);
65.49 + return a;
65.50 + }
65.51 +
65.52 + /**
65.53 + * Registers entry name and data
65.54 + */
65.55 + final void register(String entry, InputStream is) throws IOException {
65.56 + ByteArrayOutputStream os = new ByteArrayOutputStream();
65.57 + for (;;) {
65.58 + int ch = is.read();
65.59 + if (ch == -1) {
65.60 + break;
65.61 + }
65.62 + os.write(ch);
65.63 + }
65.64 + os.close();
65.65 + entries.put(entry, os.toByteArray());
65.66 + }
65.67 +
65.68 + @Override
65.69 + public int hashCode() {
65.70 + return entries.hashCode();
65.71 + }
65.72 +
65.73 + @Override
65.74 + public boolean equals(Object obj) {
65.75 + if (obj == null) {
65.76 + return false;
65.77 + }
65.78 + if (getClass() != obj.getClass()) {
65.79 + return false;
65.80 + }
65.81 + final ZipArchive other = (ZipArchive) obj;
65.82 + if (!Objects.deepEquals(this.entries, other.entries)) {
65.83 + return false;
65.84 + }
65.85 + return true;
65.86 + }
65.87 +
65.88 + @Override
65.89 + public String toString() {
65.90 + StringBuilder sb = new StringBuilder();
65.91 + for (Map.Entry<String, byte[]> en : entries.entrySet()) {
65.92 + String string = en.getKey();
65.93 + byte[] bs = en.getValue();
65.94 + sb.append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
65.95 + }
65.96 + return sb.toString();
65.97 + }
65.98 +
65.99 + public void assertEquals(ZipArchive zip, String msg) {
65.100 + boolean ok = true;
65.101 + StringBuilder sb = new StringBuilder();
65.102 + sb.append(msg);
65.103 + for (Map.Entry<String, byte[]> en : entries.entrySet()) {
65.104 + String string = en.getKey();
65.105 + byte[] bs = en.getValue();
65.106 + byte[] other = zip.entries.get(string);
65.107 + sb.append("\n");
65.108 + if (other == null) {
65.109 + sb.append("EXTRA ").append(string).append(" = ").append(Arrays.toString(bs));
65.110 + ok = false;
65.111 + continue;
65.112 + }
65.113 + if (Arrays.equals(bs, other)) {
65.114 + sb.append("OK ").append(string);
65.115 + continue;
65.116 + } else {
65.117 + sb.append("DIFF ").append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
65.118 + sb.append(" TO").append(string).append(" = ").append(Arrays.toString(other)).append("\n");
65.119 + ok = false;
65.120 + continue;
65.121 + }
65.122 + }
65.123 + for (Map.Entry<String, byte[]> entry : zip.entries.entrySet()) {
65.124 + String string = entry.getKey();
65.125 + if (entries.get(string) == null) {
65.126 + sb.append("MISS ").append(string).append(" = ").append(Arrays.toString(entry.getValue()));
65.127 + ok = false;
65.128 + }
65.129 + }
65.130 + if (!ok) {
65.131 + assert false : sb.toString();
65.132 + }
65.133 + }
65.134 +
65.135 + public static void readZip(InputStream is, ZipArchive data) throws IOException {
65.136 + ZipInputStream zip = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(is);
65.137 + for (;;) {
65.138 + ZipEntry en = zip.getNextEntry();
65.139 + if (en == null) {
65.140 + return;
65.141 + }
65.142 + data.register(en.getName(), zip);
65.143 + }
65.144 + }
65.145 +
65.146 + public static void realZip(InputStream is, ZipArchive data) throws IOException {
65.147 + java.util.zip.ZipInputStream zip = new java.util.zip.ZipInputStream(is);
65.148 + for (;;) {
65.149 + ZipEntry en = zip.getNextEntry();
65.150 + if (en == null) {
65.151 + return;
65.152 + }
65.153 + data.register(en.getName(), zip);
65.154 + }
65.155 + }
65.156 +
65.157 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipCompatibilityTest.java Wed May 07 16:47:24 2014 +0200
66.3 @@ -0,0 +1,43 @@
66.4 +/**
66.5 + * Back 2 Browser Bytecode Translator
66.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
66.7 + *
66.8 + * This program is free software: you can redistribute it and/or modify
66.9 + * it under the terms of the GNU General Public License as published by
66.10 + * the Free Software Foundation, version 2 of the License.
66.11 + *
66.12 + * This program is distributed in the hope that it will be useful,
66.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
66.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66.15 + * GNU General Public License for more details.
66.16 + *
66.17 + * You should have received a copy of the GNU General Public License
66.18 + * along with this program. Look for COPYING file in the top folder.
66.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
66.20 + */
66.21 +package org.apidesign.bck2brwsr.emul.zip;
66.22 +
66.23 +import java.io.IOException;
66.24 +import java.io.InputStream;
66.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
66.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
66.27 +import org.testng.annotations.Factory;
66.28 +
66.29 +/**
66.30 + *
66.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
66.32 + */
66.33 +public class ZipCompatibilityTest {
66.34 + @Compare
66.35 + public String testDemoStaticCalculator() throws IOException {
66.36 + InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
66.37 + ZipArchive zip = ZipArchive.createZip(is);
66.38 + final String ts = zip.toString();
66.39 + return ts.substring(0, 4096) + ts.hashCode();
66.40 + }
66.41 +
66.42 + @Factory
66.43 + public static Object[] create() {
66.44 + return VMTest.create(ZipCompatibilityTest.class);
66.45 + }
66.46 +}
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
67.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipEntryTest.java Wed May 07 16:47:24 2014 +0200
67.3 @@ -0,0 +1,67 @@
67.4 +/**
67.5 + * Back 2 Browser Bytecode Translator
67.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
67.7 + *
67.8 + * This program is free software: you can redistribute it and/or modify
67.9 + * it under the terms of the GNU General Public License as published by
67.10 + * the Free Software Foundation, version 2 of the License.
67.11 + *
67.12 + * This program is distributed in the hope that it will be useful,
67.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
67.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67.15 + * GNU General Public License for more details.
67.16 + *
67.17 + * You should have received a copy of the GNU General Public License
67.18 + * along with this program. Look for COPYING file in the top folder.
67.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
67.20 + */
67.21 +package org.apidesign.bck2brwsr.vmtest.impl;
67.22 +
67.23 +import java.io.ByteArrayInputStream;
67.24 +import java.io.IOException;
67.25 +import java.io.InputStream;
67.26 +import org.apidesign.bck2brwsr.emul.zip.FastJar;
67.27 +import org.testng.annotations.Test;
67.28 +import static org.testng.Assert.*;
67.29 +
67.30 +/**
67.31 + *
67.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
67.33 + */
67.34 +@GenerateZip(name = "five.zip", contents = {
67.35 + "1.txt", "one",
67.36 + "2.txt", "duo",
67.37 + "3.txt", "three",
67.38 + "4.txt", "four",
67.39 + "5.txt", "five"
67.40 +})
67.41 +public class ZipEntryTest {
67.42 + @Test
67.43 + public void readEntriesEffectively() throws IOException {
67.44 + InputStream is = ZipEntryTest.class.getResourceAsStream("five.zip");
67.45 + byte[] arr = new byte[is.available()];
67.46 + int len = is.read(arr);
67.47 + assertEquals(len, arr.length, "Read fully");
67.48 +
67.49 + FastJar fj = new FastJar(arr);
67.50 + FastJar.Entry[] entrs = fj.list();
67.51 +
67.52 + assertEquals(5, entrs.length, "Five entries");
67.53 +
67.54 + for (int i = 1; i <= 5; i++) {
67.55 + FastJar.Entry en = entrs[i - 1];
67.56 + assertEquals(en.name, i + ".txt");
67.57 +// assertEquals(cis.cnt, 0, "Content of the file should be skipped, not read");
67.58 + }
67.59 +
67.60 + assertContent("three", fj.getInputStream(entrs[3 - 1]), "read OK");
67.61 + assertContent("five", fj.getInputStream(entrs[5 - 1]), "read OK");
67.62 + }
67.63 +
67.64 + private static void assertContent(String exp, InputStream is, String msg) throws IOException {
67.65 + byte[] arr = new byte[512];
67.66 + int len = is.read(arr);
67.67 + String s = new String(arr, 0, len);
67.68 + assertEquals(exp, s, msg);
67.69 + }
67.70 +}
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
68.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipFileTest.java Wed May 07 16:47:24 2014 +0200
68.3 @@ -0,0 +1,108 @@
68.4 +/**
68.5 + * Back 2 Browser Bytecode Translator
68.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
68.7 + *
68.8 + * This program is free software: you can redistribute it and/or modify
68.9 + * it under the terms of the GNU General Public License as published by
68.10 + * the Free Software Foundation, version 2 of the License.
68.11 + *
68.12 + * This program is distributed in the hope that it will be useful,
68.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
68.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68.15 + * GNU General Public License for more details.
68.16 + *
68.17 + * You should have received a copy of the GNU General Public License
68.18 + * along with this program. Look for COPYING file in the top folder.
68.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
68.20 + */
68.21 +package org.apidesign.bck2brwsr.vmtest.impl;
68.22 +
68.23 +import java.io.IOException;
68.24 +import java.io.InputStream;
68.25 +import java.util.Objects;
68.26 +import java.util.zip.ZipEntry;
68.27 +import java.util.zip.ZipInputStream;
68.28 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
68.29 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
68.30 +import org.apidesign.bck2brwsr.vmtest.Compare;
68.31 +import org.apidesign.bck2brwsr.vmtest.Http;
68.32 +import org.apidesign.bck2brwsr.vmtest.VMTest;
68.33 +import org.testng.annotations.Factory;
68.34 +
68.35 +/**
68.36 + *
68.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
68.38 + */
68.39 +@GenerateZip(name = "readAnEntry.zip", contents = {
68.40 + "my/main/file.txt", "Hello World!"
68.41 +})
68.42 +public class ZipFileTest {
68.43 +
68.44 + @Compare public String readAnEntry() throws IOException {
68.45 + InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip");
68.46 + ZipInputStream zip = new ZipInputStream(is);
68.47 + ZipEntry entry = zip.getNextEntry();
68.48 + assertEquals(entry.getName(), "my/main/file.txt", "Correct entry");
68.49 +
68.50 + byte[] arr = new byte[4096];
68.51 + int len = zip.read(arr);
68.52 +
68.53 + assertEquals(zip.getNextEntry(), null, "No next entry");
68.54 +
68.55 + final String ret = new String(arr, 0, len, "UTF-8");
68.56 + return ret;
68.57 + }
68.58 +
68.59 + @JavaScriptBody(args = { "res", "path" }, body =
68.60 + "var myvm = bck2brwsr.apply(null, path);\n"
68.61 + + "var cls = myvm.loadClass('java.lang.String');\n"
68.62 + + "return cls.getClass__Ljava_lang_Class_2().getResourceAsStream__Ljava_io_InputStream_2Ljava_lang_String_2(res);\n"
68.63 + )
68.64 + private static native Object loadVMResource(String res, String...path);
68.65 +
68.66 + @Http({
68.67 + @Http.Resource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip")
68.68 + })
68.69 + @BrwsrTest public void canVmLoadResourceFromZip() throws IOException {
68.70 + Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar");
68.71 + assert res instanceof InputStream : "Got array of bytes: " + res;
68.72 + InputStream is = (InputStream)res;
68.73 +
68.74 + byte[] arr = new byte[4096];
68.75 + int len = is.read(arr);
68.76 +
68.77 + final String ret = new String(arr, 0, len, "UTF-8");
68.78 +
68.79 + assertEquals(ret, "Hello World!", "Can read the bytes");
68.80 + }
68.81 +
68.82 + @GenerateZip(name = "cpattr.zip", contents = {
68.83 + "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n"
68.84 + + "Created-By: hand\n"
68.85 + + "Class-Path: realJar.jar\n\n\n"
68.86 + })
68.87 + @Http({
68.88 + @Http.Resource(path = "/readComplexEntry.jar", mimeType = "x-application/zip", content = "", resource="cpattr.zip"),
68.89 + @Http.Resource(path = "/realJar.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip"),
68.90 + })
68.91 + @BrwsrTest public void understandsClassPathAttr() throws IOException {
68.92 + Object res = loadVMResource("/my/main/file.txt", "/readComplexEntry.jar");
68.93 + assert res instanceof InputStream : "Got array of bytes: " + res;
68.94 + InputStream is = (InputStream)res;
68.95 +
68.96 + byte[] arr = new byte[4096];
68.97 + int len = is.read(arr);
68.98 +
68.99 + final String ret = new String(arr, 0, len, "UTF-8");
68.100 +
68.101 + assertEquals(ret, "Hello World!", "Can read the bytes from secondary JAR");
68.102 + }
68.103 +
68.104 + private static void assertEquals(Object real, Object exp, String msg) {
68.105 + assert Objects.equals(exp, real) : msg + " exp: " + exp + " real: " + real;
68.106 + }
68.107 +
68.108 + @Factory public static Object[] create() {
68.109 + return VMTest.create(ZipFileTest.class);
68.110 + }
68.111 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
69.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipVsJzLibTest.java Wed May 07 16:47:24 2014 +0200
69.3 @@ -0,0 +1,39 @@
69.4 +/**
69.5 + * Back 2 Browser Bytecode Translator
69.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
69.7 + *
69.8 + * This program is free software: you can redistribute it and/or modify
69.9 + * it under the terms of the GNU General Public License as published by
69.10 + * the Free Software Foundation, version 2 of the License.
69.11 + *
69.12 + * This program is distributed in the hope that it will be useful,
69.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
69.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69.15 + * GNU General Public License for more details.
69.16 + *
69.17 + * You should have received a copy of the GNU General Public License
69.18 + * along with this program. Look for COPYING file in the top folder.
69.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
69.20 + */
69.21 +package org.apidesign.bck2brwsr.emul.zip;
69.22 +
69.23 +import java.io.IOException;
69.24 +import java.io.InputStream;
69.25 +import org.testng.annotations.Test;
69.26 +
69.27 +/**
69.28 + *
69.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
69.30 + */
69.31 +public class ZipVsJzLibTest {
69.32 + @Test public void r() throws IOException {
69.33 + InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
69.34 + ZipArchive zip = ZipArchive.createZip(is);
69.35 +
69.36 + is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
69.37 + ZipArchive real = ZipArchive.createReal(is);
69.38 +
69.39 + real.assertEquals(zip, "Are they the same?");
69.40 + }
69.41 +
69.42 +}