1.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Tue May 06 17:46:47 2014 +0200
1.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Sun May 11 14:01:18 2014 +0200
1.3 @@ -144,9 +144,6 @@
1.4 while (en.hasMoreElements()) {
1.5 JarEntry e = en.nextElement();
1.6 final String n = e.getName();
1.7 - if (n.contains("package-info")) {
1.8 - continue;
1.9 - }
1.10 if (n.endsWith("/")) {
1.11 continue;
1.12 }
1.13 @@ -192,9 +189,6 @@
1.14 private static void listDir(File f, String pref, List<String> classes, List<String> resources) throws IOException {
1.15 File[] arr = f.listFiles();
1.16 if (arr == null) {
1.17 - if (f.getName().equals("package-info.class")) {
1.18 - return;
1.19 - }
1.20 if (f.getName().endsWith(".class")) {
1.21 classes.add(pref + f.getName().substring(0, f.getName().length() - 6));
1.22 } else {
1.23 @@ -209,12 +203,19 @@
1.24 }
1.25
1.26 static void compileVM(StringBuilder sb, final Res r) throws IOException {
1.27 - URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0);
1.28 - JarURLConnection juc = (JarURLConnection)u.openConnection();
1.29 -
1.30 List<String> arr = new ArrayList<>();
1.31 List<String> classes = new ArrayList<>();
1.32 - listJAR(juc.getJarFile(), classes, arr, null, null);
1.33 +
1.34 + {
1.35 + URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0);
1.36 + JarURLConnection juc = (JarURLConnection)u.openConnection();
1.37 + listJAR(juc.getJarFile(), classes, arr, null, null);
1.38 + }
1.39 + {
1.40 + URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0);
1.41 + JarURLConnection juc = (JarURLConnection)u.openConnection();
1.42 + listJAR(juc.getJarFile(), classes, arr, null, null);
1.43 + }
1.44
1.45 Bck2Brwsr.newCompiler().addRootClasses(classes.toArray(new String[0]))
1.46 .resources(new Bck2Brwsr.Resources() {
2.1 --- a/pom.xml Tue May 06 17:46:47 2014 +0200
2.2 +++ b/pom.xml Sun May 11 14:01:18 2014 +0200
2.3 @@ -87,6 +87,7 @@
2.4 <exclude>.*/**</exclude>
2.5 <exclude>rt/emul/mini/src/main/**</exclude>
2.6 <exclude>rt/emul/compact/src/main/**</exclude>
2.7 + <exclude>rt/emul/zip/src/main/**</exclude>
2.8 <exclude>rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java</exclude>
2.9 <exclude>rt/archetype/src/main/resources/archetype-resources/**</exclude>
2.10 <exclude>rt/emul/*/src/test/resources/**</exclude>
3.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipArchive.java Tue May 06 17:46:47 2014 +0200
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,154 +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.ByteArrayOutputStream;
3.24 -import java.io.IOException;
3.25 -import java.io.InputStream;
3.26 -import java.util.Arrays;
3.27 -import java.util.LinkedHashMap;
3.28 -import java.util.Map;
3.29 -import java.util.Objects;
3.30 -import java.util.zip.ZipEntry;
3.31 -import org.apidesign.bck2brwsr.emul.zip.ZipInputStream;
3.32 -
3.33 -/**
3.34 - *
3.35 - * @author Jaroslav Tulach <jtulach@netbeans.org>
3.36 - */
3.37 -final class ZipArchive {
3.38 - private final Map<String, byte[]> entries = new LinkedHashMap<>();
3.39 -
3.40 - public static ZipArchive createZip(InputStream is) throws IOException {
3.41 - ZipArchive a = new ZipArchive();
3.42 - readZip(is, a);
3.43 - return a;
3.44 - }
3.45 -
3.46 - public static ZipArchive createReal(InputStream is) throws IOException {
3.47 - ZipArchive a = new ZipArchive();
3.48 - realZip(is, a);
3.49 - return a;
3.50 - }
3.51 -
3.52 - /**
3.53 - * Registers entry name and data
3.54 - */
3.55 - final void register(String entry, InputStream is) throws IOException {
3.56 - ByteArrayOutputStream os = new ByteArrayOutputStream();
3.57 - for (;;) {
3.58 - int ch = is.read();
3.59 - if (ch == -1) {
3.60 - break;
3.61 - }
3.62 - os.write(ch);
3.63 - }
3.64 - os.close();
3.65 - entries.put(entry, os.toByteArray());
3.66 - }
3.67 -
3.68 - @Override
3.69 - public int hashCode() {
3.70 - return entries.hashCode();
3.71 - }
3.72 -
3.73 - @Override
3.74 - public boolean equals(Object obj) {
3.75 - if (obj == null) {
3.76 - return false;
3.77 - }
3.78 - if (getClass() != obj.getClass()) {
3.79 - return false;
3.80 - }
3.81 - final ZipArchive other = (ZipArchive) obj;
3.82 - if (!Objects.deepEquals(this.entries, other.entries)) {
3.83 - return false;
3.84 - }
3.85 - return true;
3.86 - }
3.87 -
3.88 - @Override
3.89 - public String toString() {
3.90 - StringBuilder sb = new StringBuilder();
3.91 - for (Map.Entry<String, byte[]> en : entries.entrySet()) {
3.92 - String string = en.getKey();
3.93 - byte[] bs = en.getValue();
3.94 - sb.append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
3.95 - }
3.96 - return sb.toString();
3.97 - }
3.98 -
3.99 - public void assertEquals(ZipArchive zip, String msg) {
3.100 - boolean ok = true;
3.101 - StringBuilder sb = new StringBuilder();
3.102 - sb.append(msg);
3.103 - for (Map.Entry<String, byte[]> en : entries.entrySet()) {
3.104 - String string = en.getKey();
3.105 - byte[] bs = en.getValue();
3.106 - byte[] other = zip.entries.get(string);
3.107 - sb.append("\n");
3.108 - if (other == null) {
3.109 - sb.append("EXTRA ").append(string).append(" = ").append(Arrays.toString(bs));
3.110 - ok = false;
3.111 - continue;
3.112 - }
3.113 - if (Arrays.equals(bs, other)) {
3.114 - sb.append("OK ").append(string);
3.115 - continue;
3.116 - } else {
3.117 - sb.append("DIFF ").append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
3.118 - sb.append(" TO").append(string).append(" = ").append(Arrays.toString(other)).append("\n");
3.119 - ok = false;
3.120 - continue;
3.121 - }
3.122 - }
3.123 - for (Map.Entry<String, byte[]> entry : zip.entries.entrySet()) {
3.124 - String string = entry.getKey();
3.125 - if (entries.get(string) == null) {
3.126 - sb.append("MISS ").append(string).append(" = ").append(Arrays.toString(entry.getValue()));
3.127 - ok = false;
3.128 - }
3.129 - }
3.130 - if (!ok) {
3.131 - assert false : sb.toString();
3.132 - }
3.133 - }
3.134 -
3.135 - public static void readZip(InputStream is, ZipArchive data) throws IOException {
3.136 - ZipInputStream zip = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(is);
3.137 - for (;;) {
3.138 - ZipEntry en = zip.getNextEntry();
3.139 - if (en == null) {
3.140 - return;
3.141 - }
3.142 - data.register(en.getName(), zip);
3.143 - }
3.144 - }
3.145 -
3.146 - public static void realZip(InputStream is, ZipArchive data) throws IOException {
3.147 - java.util.zip.ZipInputStream zip = new java.util.zip.ZipInputStream(is);
3.148 - for (;;) {
3.149 - ZipEntry en = zip.getNextEntry();
3.150 - if (en == null) {
3.151 - return;
3.152 - }
3.153 - data.register(en.getName(), zip);
3.154 - }
3.155 - }
3.156 -
3.157 -}
4.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java Tue May 06 17:46:47 2014 +0200
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,43 +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.apidesign.bck2brwsr.vmtest.Compare;
4.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
4.27 -import org.testng.annotations.Factory;
4.28 -
4.29 -/**
4.30 - *
4.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
4.32 - */
4.33 -public class ZipCompatibilityTest {
4.34 - @Compare
4.35 - public String testDemoStaticCalculator() throws IOException {
4.36 - InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
4.37 - ZipArchive zip = ZipArchive.createZip(is);
4.38 - final String ts = zip.toString();
4.39 - return ts.substring(0, 4096) + ts.hashCode();
4.40 - }
4.41 -
4.42 - @Factory
4.43 - public static Object[] create() {
4.44 - return VMTest.create(ZipCompatibilityTest.class);
4.45 - }
4.46 -}
5.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipVsJzLibTest.java Tue May 06 17:46:47 2014 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,39 +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.compact.tck;
5.22 -
5.23 -import java.io.IOException;
5.24 -import java.io.InputStream;
5.25 -import org.testng.annotations.Test;
5.26 -
5.27 -/**
5.28 - *
5.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
5.30 - */
5.31 -public class ZipVsJzLibTest {
5.32 - @Test public void r() throws IOException {
5.33 - InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
5.34 - ZipArchive zip = ZipArchive.createZip(is);
5.35 -
5.36 - is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
5.37 - ZipArchive real = ZipArchive.createReal(is);
5.38 -
5.39 - real.assertEquals(zip, "Are they the same?");
5.40 - }
5.41 -
5.42 -}
6.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/CRC32Test.java Tue May 06 17:46:47 2014 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,41 +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.UnsupportedEncodingException;
6.24 -import java.util.zip.CRC32;
6.25 -import org.apidesign.bck2brwsr.vmtest.Compare;
6.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
6.27 -import org.testng.annotations.Factory;
6.28 -
6.29 -/**
6.30 - *
6.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
6.32 - */
6.33 -public class CRC32Test {
6.34 -
6.35 - @Compare public long crc1() throws UnsupportedEncodingException {
6.36 - CRC32 crc = new CRC32();
6.37 - crc.update("Hello World!".getBytes("UTF-8"));
6.38 - return crc.getValue();
6.39 - }
6.40 -
6.41 - @Factory public static Object[] create() {
6.42 - return VMTest.create(CRC32Test.class);
6.43 - }
6.44 -}
7.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipEntryTest.java Tue May 06 17:46:47 2014 +0200
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,67 +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.ByteArrayInputStream;
7.24 -import java.io.IOException;
7.25 -import java.io.InputStream;
7.26 -import org.apidesign.bck2brwsr.emul.zip.FastJar;
7.27 -import org.testng.annotations.Test;
7.28 -import static org.testng.Assert.*;
7.29 -
7.30 -/**
7.31 - *
7.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
7.33 - */
7.34 -@GenerateZip(name = "five.zip", contents = {
7.35 - "1.txt", "one",
7.36 - "2.txt", "duo",
7.37 - "3.txt", "three",
7.38 - "4.txt", "four",
7.39 - "5.txt", "five"
7.40 -})
7.41 -public class ZipEntryTest {
7.42 - @Test
7.43 - public void readEntriesEffectively() throws IOException {
7.44 - InputStream is = ZipEntryTest.class.getResourceAsStream("five.zip");
7.45 - byte[] arr = new byte[is.available()];
7.46 - int len = is.read(arr);
7.47 - assertEquals(len, arr.length, "Read fully");
7.48 -
7.49 - FastJar fj = new FastJar(arr);
7.50 - FastJar.Entry[] entrs = fj.list();
7.51 -
7.52 - assertEquals(5, entrs.length, "Five entries");
7.53 -
7.54 - for (int i = 1; i <= 5; i++) {
7.55 - FastJar.Entry en = entrs[i - 1];
7.56 - assertEquals(en.name, i + ".txt");
7.57 -// assertEquals(cis.cnt, 0, "Content of the file should be skipped, not read");
7.58 - }
7.59 -
7.60 - assertContent("three", fj.getInputStream(entrs[3 - 1]), "read OK");
7.61 - assertContent("five", fj.getInputStream(entrs[5 - 1]), "read OK");
7.62 - }
7.63 -
7.64 - private static void assertContent(String exp, InputStream is, String msg) throws IOException {
7.65 - byte[] arr = new byte[512];
7.66 - int len = is.read(arr);
7.67 - String s = new String(arr, 0, len);
7.68 - assertEquals(exp, s, msg);
7.69 - }
7.70 -}
8.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Tue May 06 17:46:47 2014 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,108 +0,0 @@
8.4 -/**
8.5 - * Back 2 Browser Bytecode Translator
8.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
8.7 - *
8.8 - * This program is free software: you can redistribute it and/or modify
8.9 - * it under the terms of the GNU General Public License as published by
8.10 - * the Free Software Foundation, version 2 of the License.
8.11 - *
8.12 - * This program is distributed in the hope that it will be useful,
8.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.15 - * GNU General Public License for more details.
8.16 - *
8.17 - * You should have received a copy of the GNU General Public License
8.18 - * along with this program. Look for COPYING file in the top folder.
8.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
8.20 - */
8.21 -package org.apidesign.bck2brwsr.vmtest.impl;
8.22 -
8.23 -import java.io.IOException;
8.24 -import java.io.InputStream;
8.25 -import java.util.Objects;
8.26 -import java.util.zip.ZipEntry;
8.27 -import java.util.zip.ZipInputStream;
8.28 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
8.29 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
8.30 -import org.apidesign.bck2brwsr.vmtest.Compare;
8.31 -import org.apidesign.bck2brwsr.vmtest.Http;
8.32 -import org.apidesign.bck2brwsr.vmtest.VMTest;
8.33 -import org.testng.annotations.Factory;
8.34 -
8.35 -/**
8.36 - *
8.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
8.38 - */
8.39 -@GenerateZip(name = "readAnEntry.zip", contents = {
8.40 - "my/main/file.txt", "Hello World!"
8.41 -})
8.42 -public class ZipFileTest {
8.43 -
8.44 - @Compare public String readAnEntry() throws IOException {
8.45 - InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip");
8.46 - ZipInputStream zip = new ZipInputStream(is);
8.47 - ZipEntry entry = zip.getNextEntry();
8.48 - assertEquals(entry.getName(), "my/main/file.txt", "Correct entry");
8.49 -
8.50 - byte[] arr = new byte[4096];
8.51 - int len = zip.read(arr);
8.52 -
8.53 - assertEquals(zip.getNextEntry(), null, "No next entry");
8.54 -
8.55 - final String ret = new String(arr, 0, len, "UTF-8");
8.56 - return ret;
8.57 - }
8.58 -
8.59 - @JavaScriptBody(args = { "res", "path" }, body =
8.60 - "var myvm = bck2brwsr.apply(null, path);\n"
8.61 - + "var cls = myvm.loadClass('java.lang.String');\n"
8.62 - + "return cls.getClass__Ljava_lang_Class_2().getResourceAsStream__Ljava_io_InputStream_2Ljava_lang_String_2(res);\n"
8.63 - )
8.64 - private static native Object loadVMResource(String res, String...path);
8.65 -
8.66 - @Http({
8.67 - @Http.Resource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip")
8.68 - })
8.69 - @BrwsrTest public void canVmLoadResourceFromZip() throws IOException {
8.70 - Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar");
8.71 - assert res instanceof InputStream : "Got array of bytes: " + res;
8.72 - InputStream is = (InputStream)res;
8.73 -
8.74 - byte[] arr = new byte[4096];
8.75 - int len = is.read(arr);
8.76 -
8.77 - final String ret = new String(arr, 0, len, "UTF-8");
8.78 -
8.79 - assertEquals(ret, "Hello World!", "Can read the bytes");
8.80 - }
8.81 -
8.82 - @GenerateZip(name = "cpattr.zip", contents = {
8.83 - "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n"
8.84 - + "Created-By: hand\n"
8.85 - + "Class-Path: realJar.jar\n\n\n"
8.86 - })
8.87 - @Http({
8.88 - @Http.Resource(path = "/readComplexEntry.jar", mimeType = "x-application/zip", content = "", resource="cpattr.zip"),
8.89 - @Http.Resource(path = "/realJar.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip"),
8.90 - })
8.91 - @BrwsrTest public void understandsClassPathAttr() throws IOException {
8.92 - Object res = loadVMResource("/my/main/file.txt", "/readComplexEntry.jar");
8.93 - assert res instanceof InputStream : "Got array of bytes: " + res;
8.94 - InputStream is = (InputStream)res;
8.95 -
8.96 - byte[] arr = new byte[4096];
8.97 - int len = is.read(arr);
8.98 -
8.99 - final String ret = new String(arr, 0, len, "UTF-8");
8.100 -
8.101 - assertEquals(ret, "Hello World!", "Can read the bytes from secondary JAR");
8.102 - }
8.103 -
8.104 - private static void assertEquals(Object real, Object exp, String msg) {
8.105 - assert Objects.equals(exp, real) : msg + " exp: " + exp + " real: " + real;
8.106 - }
8.107 -
8.108 - @Factory public static Object[] create() {
8.109 - return VMTest.create(ZipFileTest.class);
8.110 - }
8.111 -}
9.1 Binary file rt/emul/compact/src/test/resources/org/apidesign/bck2brwsr/compact/tck/demo.static.calculator-TEST.jar has changed
10.1 --- a/rt/emul/mini/src/main/java/java/lang/String.java Tue May 06 17:46:47 2014 +0200
10.2 +++ b/rt/emul/mini/src/main/java/java/lang/String.java Sun May 11 14:01:18 2014 +0200
10.3 @@ -794,9 +794,7 @@
10.4 " arr[to++] = s[i];\n" +
10.5 "}"
10.6 )
10.7 - void getChars(char dst[], int dstBegin) {
10.8 - System.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
10.9 - }
10.10 + native void getChars(char dst[], int dstBegin);
10.11
10.12 /**
10.13 * Copies characters from this string into the destination character
10.14 @@ -834,19 +832,7 @@
10.15 " arr[dst++] = s.charCodeAt(beg++);\n" +
10.16 "}\n"
10.17 )
10.18 - public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
10.19 - if (srcBegin < 0) {
10.20 - throw new StringIndexOutOfBoundsException(srcBegin);
10.21 - }
10.22 - if (srcEnd > length()) {
10.23 - throw new StringIndexOutOfBoundsException(srcEnd);
10.24 - }
10.25 - if (srcBegin > srcEnd) {
10.26 - throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
10.27 - }
10.28 - System.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
10.29 - srcEnd - srcBegin);
10.30 - }
10.31 + public native void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin);
10.32
10.33 /**
10.34 * Copies characters from this string into the destination byte array. Each
10.35 @@ -905,10 +891,9 @@
10.36 int j = dstBegin;
10.37 int n = offset() + srcEnd;
10.38 int i = offset() + srcBegin;
10.39 - char[] val = toCharArray(); /* avoid getfield opcode */
10.40
10.41 while (i < n) {
10.42 - dst[j++] = (byte)val[i++];
10.43 + dst[j++] = (byte)charAt(i++);
10.44 }
10.45 }
10.46
10.47 @@ -1016,30 +1001,10 @@
10.48 * @see #equalsIgnoreCase(String)
10.49 */
10.50 @JavaScriptBody(args = { "obj" }, body =
10.51 - "return obj != null && obj['$instOf_java_lang_String'] && "
10.52 + "return obj !== null && obj['$instOf_java_lang_String'] && "
10.53 + "this.toString() === obj.toString();"
10.54 )
10.55 - public boolean equals(Object anObject) {
10.56 - if (this == anObject) {
10.57 - return true;
10.58 - }
10.59 - if (anObject instanceof String) {
10.60 - String anotherString = (String)anObject;
10.61 - int n = length();
10.62 - if (n == anotherString.length()) {
10.63 - char v1[] = toCharArray();
10.64 - char v2[] = anotherString.toCharArray();
10.65 - int i = offset();
10.66 - int j = anotherString.offset();
10.67 - while (n-- != 0) {
10.68 - if (v1[i++] != v2[j++])
10.69 - return false;
10.70 - }
10.71 - return true;
10.72 - }
10.73 - }
10.74 - return false;
10.75 - }
10.76 + public native boolean equals(Object anObject);
10.77
10.78 /**
10.79 * Compares this string to the specified {@code StringBuffer}. The result
10.80 @@ -1080,13 +1045,12 @@
10.81 return false;
10.82 // Argument is a StringBuffer, StringBuilder
10.83 if (cs instanceof AbstractStringBuilder) {
10.84 - char v1[] = toCharArray();
10.85 char v2[] = ((AbstractStringBuilder)cs).getValue();
10.86 int i = offset();
10.87 int j = 0;
10.88 int n = length();
10.89 while (n-- != 0) {
10.90 - if (v1[i++] != v2[j++])
10.91 + if (this.charAt(i++) != v2[j++])
10.92 return false;
10.93 }
10.94 return true;
10.95 @@ -1095,12 +1059,11 @@
10.96 if (cs.equals(this))
10.97 return true;
10.98 // Argument is a generic CharSequence
10.99 - char v1[] = toCharArray();
10.100 int i = offset();
10.101 int j = 0;
10.102 int n = length();
10.103 while (n-- != 0) {
10.104 - if (v1[i++] != cs.charAt(j++))
10.105 + if (this.charAt(i++) != cs.charAt(j++))
10.106 return false;
10.107 }
10.108 return true;
10.109 @@ -1185,8 +1148,6 @@
10.110 int len1 = length();
10.111 int len2 = anotherString.length();
10.112 int n = Math.min(len1, len2);
10.113 - char v1[] = toCharArray();
10.114 - char v2[] = anotherString.toCharArray();
10.115 int i = offset();
10.116 int j = anotherString.offset();
10.117
10.118 @@ -1194,8 +1155,8 @@
10.119 int k = i;
10.120 int lim = n + i;
10.121 while (k < lim) {
10.122 - char c1 = v1[k];
10.123 - char c2 = v2[k];
10.124 + char c1 = this.charAt(k);
10.125 + char c2 = anotherString.charAt(k);
10.126 if (c1 != c2) {
10.127 return c1 - c2;
10.128 }
10.129 @@ -1203,8 +1164,8 @@
10.130 }
10.131 } else {
10.132 while (n-- != 0) {
10.133 - char c1 = v1[i++];
10.134 - char c2 = v2[j++];
10.135 + char c1 = this.charAt(i++);
10.136 + char c2 = anotherString.charAt(j++);
10.137 if (c1 != c2) {
10.138 return c1 - c2;
10.139 }
10.140 @@ -1446,23 +1407,7 @@
10.141 "find = find.toString();\n" +
10.142 "return this.toString().substring(from, from + find.length) === find;\n"
10.143 )
10.144 - public boolean startsWith(String prefix, int toffset) {
10.145 - char ta[] = toCharArray();
10.146 - int to = offset() + toffset;
10.147 - char pa[] = prefix.toCharArray();
10.148 - int po = prefix.offset();
10.149 - int pc = prefix.length();
10.150 - // Note: toffset might be near -1>>>1.
10.151 - if ((toffset < 0) || (toffset > length() - pc)) {
10.152 - return false;
10.153 - }
10.154 - while (--pc >= 0) {
10.155 - if (ta[to++] != pa[po++]) {
10.156 - return false;
10.157 - }
10.158 - }
10.159 - return true;
10.160 - }
10.161 + public native boolean startsWith(String prefix, int toffset);
10.162
10.163 /**
10.164 * Tests if this string starts with the specified prefix.
10.165 @@ -1596,49 +1541,7 @@
10.166 "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
10.167 "return this.toString().indexOf(ch, from);\n"
10.168 )
10.169 - public int indexOf(int ch, int fromIndex) {
10.170 - if (fromIndex < 0) {
10.171 - fromIndex = 0;
10.172 - } else if (fromIndex >= length()) {
10.173 - // Note: fromIndex might be near -1>>>1.
10.174 - return -1;
10.175 - }
10.176 -
10.177 - if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
10.178 - // handle most cases here (ch is a BMP code point or a
10.179 - // negative value (invalid code point))
10.180 - final char[] value = this.toCharArray();
10.181 - final int offset = this.offset();
10.182 - final int max = offset + length();
10.183 - for (int i = offset + fromIndex; i < max ; i++) {
10.184 - if (value[i] == ch) {
10.185 - return i - offset;
10.186 - }
10.187 - }
10.188 - return -1;
10.189 - } else {
10.190 - return indexOfSupplementary(ch, fromIndex);
10.191 - }
10.192 - }
10.193 -
10.194 - /**
10.195 - * Handles (rare) calls of indexOf with a supplementary character.
10.196 - */
10.197 - private int indexOfSupplementary(int ch, int fromIndex) {
10.198 - if (Character.isValidCodePoint(ch)) {
10.199 - final char[] value = this.toCharArray();
10.200 - final int offset = this.offset();
10.201 - final char hi = Character.highSurrogate(ch);
10.202 - final char lo = Character.lowSurrogate(ch);
10.203 - final int max = offset + length() - 1;
10.204 - for (int i = offset + fromIndex; i < max; i++) {
10.205 - if (value[i] == hi && value[i+1] == lo) {
10.206 - return i - offset;
10.207 - }
10.208 - }
10.209 - }
10.210 - return -1;
10.211 - }
10.212 + public native int indexOf(int ch, int fromIndex);
10.213
10.214 /**
10.215 * Returns the index within this string of the last occurrence of
10.216 @@ -1705,42 +1608,7 @@
10.217 "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
10.218 "return this.toString().lastIndexOf(ch, from);"
10.219 )
10.220 - public int lastIndexOf(int ch, int fromIndex) {
10.221 - if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
10.222 - // handle most cases here (ch is a BMP code point or a
10.223 - // negative value (invalid code point))
10.224 - final char[] value = this.toCharArray();
10.225 - final int offset = this.offset();
10.226 - int i = offset + Math.min(fromIndex, length() - 1);
10.227 - for (; i >= offset ; i--) {
10.228 - if (value[i] == ch) {
10.229 - return i - offset;
10.230 - }
10.231 - }
10.232 - return -1;
10.233 - } else {
10.234 - return lastIndexOfSupplementary(ch, fromIndex);
10.235 - }
10.236 - }
10.237 -
10.238 - /**
10.239 - * Handles (rare) calls of lastIndexOf with a supplementary character.
10.240 - */
10.241 - private int lastIndexOfSupplementary(int ch, int fromIndex) {
10.242 - if (Character.isValidCodePoint(ch)) {
10.243 - final char[] value = this.toCharArray();
10.244 - final int offset = this.offset();
10.245 - char hi = Character.highSurrogate(ch);
10.246 - char lo = Character.lowSurrogate(ch);
10.247 - int i = offset + Math.min(fromIndex, length() - 2);
10.248 - for (; i >= offset; i--) {
10.249 - if (value[i] == hi && value[i+1] == lo) {
10.250 - return i - offset;
10.251 - }
10.252 - }
10.253 - }
10.254 - return -1;
10.255 - }
10.256 + public native int lastIndexOf(int ch, int fromIndex);
10.257
10.258 /**
10.259 * Returns the index within this string of the first occurrence of the
10.260 @@ -1819,9 +1687,7 @@
10.261 @JavaScriptBody(args = { "s", "from" }, body =
10.262 "return this.toString().lastIndexOf(s.toString(), from);"
10.263 )
10.264 - public int lastIndexOf(String str, int fromIndex) {
10.265 - return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
10.266 - }
10.267 + public native int lastIndexOf(String str, int fromIndex);
10.268
10.269 /**
10.270 * Code shared by String and StringBuffer to do searches. The
10.271 @@ -1928,19 +1794,7 @@
10.272 @JavaScriptBody(args = { "beginIndex", "endIndex" }, body =
10.273 "return this.toString().substring(beginIndex, endIndex);"
10.274 )
10.275 - public String substring(int beginIndex, int endIndex) {
10.276 - if (beginIndex < 0) {
10.277 - throw new StringIndexOutOfBoundsException(beginIndex);
10.278 - }
10.279 - if (endIndex > length()) {
10.280 - throw new StringIndexOutOfBoundsException(endIndex);
10.281 - }
10.282 - if (beginIndex > endIndex) {
10.283 - throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
10.284 - }
10.285 - return ((beginIndex == 0) && (endIndex == length())) ? this :
10.286 - new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
10.287 - }
10.288 + public native String substring(int beginIndex, int endIndex);
10.289
10.290 /**
10.291 * Returns a new character sequence that is a subsequence of this sequence.
10.292 @@ -2046,33 +1900,7 @@
10.293 " s = ret;\n" +
10.294 "}"
10.295 )
10.296 - public String replace(char oldChar, char newChar) {
10.297 - if (oldChar != newChar) {
10.298 - int len = length();
10.299 - int i = -1;
10.300 - char[] val = toCharArray(); /* avoid getfield opcode */
10.301 - int off = offset(); /* avoid getfield opcode */
10.302 -
10.303 - while (++i < len) {
10.304 - if (val[off + i] == oldChar) {
10.305 - break;
10.306 - }
10.307 - }
10.308 - if (i < len) {
10.309 - char buf[] = new char[len];
10.310 - for (int j = 0 ; j < i ; j++) {
10.311 - buf[j] = val[off+j];
10.312 - }
10.313 - while (i < len) {
10.314 - char c = val[off + i];
10.315 - buf[i] = (c == oldChar) ? newChar : c;
10.316 - i++;
10.317 - }
10.318 - return new String(buf, 0, len);
10.319 - }
10.320 - }
10.321 - return this;
10.322 - }
10.323 + public native String replace(char oldChar, char newChar);
10.324
10.325 /**
10.326 * Tells whether or not this string matches the given <a
10.327 @@ -2800,12 +2628,11 @@
10.328 int len = length();
10.329 int st = 0;
10.330 int off = offset(); /* avoid getfield opcode */
10.331 - char[] val = toCharArray(); /* avoid getfield opcode */
10.332
10.333 - while ((st < len) && (val[off + st] <= ' ')) {
10.334 + while ((st < len) && (this.charAt(off + st) <= ' ')) {
10.335 st++;
10.336 }
10.337 - while ((st < len) && (val[off + len - 1] <= ' ')) {
10.338 + while ((st < len) && (this.charAt(off + len - 1) <= ' ')) {
10.339 len--;
10.340 }
10.341 return ((st > 0) || (len < length())) ? substring(st, len) : this;
11.1 --- a/rt/emul/mini/src/main/java/java/lang/reflect/Array.java Tue May 06 17:46:47 2014 +0200
11.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Array.java Sun May 11 14:01:18 2014 +0200
11.3 @@ -75,40 +75,10 @@
11.4 if (length < 0) {
11.5 throw new NegativeArraySizeException();
11.6 }
11.7 - String sig = findSignature(componentType);
11.8 + String sig = Method.findArraySignature(componentType);
11.9 return newArray(componentType.isPrimitive(), sig, null, length);
11.10 }
11.11
11.12 - private static String findSignature(Class<?> type) {
11.13 - if (type == Integer.TYPE) {
11.14 - return "[I";
11.15 - }
11.16 - if (type == Long.TYPE) {
11.17 - return "[J";
11.18 - }
11.19 - if (type == Double.TYPE) {
11.20 - return "[D";
11.21 - }
11.22 - if (type == Float.TYPE) {
11.23 - return "[F";
11.24 - }
11.25 - if (type == Byte.TYPE) {
11.26 - return "[B";
11.27 - }
11.28 - if (type == Boolean.TYPE) {
11.29 - return "[Z";
11.30 - }
11.31 - if (type == Short.TYPE) {
11.32 - return "[S";
11.33 - }
11.34 - if (type == Character.TYPE) {
11.35 - return "[C";
11.36 - }
11.37 - if (type.getName().equals("void")) {
11.38 - throw new IllegalStateException("Can't create array for " + type);
11.39 - }
11.40 - return "[L" + type.getName().replace('.', '/') + ";";
11.41 - }
11.42 /**
11.43 * Creates a new array
11.44 * with the specified component type and dimensions.
11.45 @@ -148,7 +118,7 @@
11.46 for (int i = 1; i < dimensions.length; i++) {
11.47 sig.append('[');
11.48 }
11.49 - sig.append(findSignature(componentType));
11.50 + sig.append(Method.findArraySignature(componentType));
11.51 return multiNewArray(sig.toString(), dimensions, 0);
11.52 }
11.53
11.54 @@ -234,7 +204,7 @@
11.55 */
11.56 public static byte getByte(Object array, int index)
11.57 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.58 - if (array.getClass().getComponentType() != Byte.TYPE) {
11.59 + if (!Method.samePrimitive(array.getClass().getComponentType(), Byte.TYPE)) {
11.60 throw new IllegalArgumentException();
11.61 }
11.62 byte[] arr = (byte[]) array;
11.63 @@ -279,7 +249,7 @@
11.64 public static short getShort(Object array, int index)
11.65 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.66 final Class<?> t = array.getClass().getComponentType();
11.67 - if (t == Short.TYPE) {
11.68 + if (Method.samePrimitive(t, Short.TYPE)) {
11.69 short[] arr = (short[]) array;
11.70 return arr[index];
11.71 }
11.72 @@ -305,7 +275,7 @@
11.73 public static int getInt(Object array, int index)
11.74 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.75 final Class<?> t = array.getClass().getComponentType();
11.76 - if (t == Integer.TYPE) {
11.77 + if (Method.samePrimitive(t, Integer.TYPE)) {
11.78 int[] arr = (int[]) array;
11.79 return arr[index];
11.80 }
11.81 @@ -331,7 +301,7 @@
11.82 public static long getLong(Object array, int index)
11.83 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.84 final Class<?> t = array.getClass().getComponentType();
11.85 - if (t == Long.TYPE) {
11.86 + if (Method.samePrimitive(t, Long.TYPE)) {
11.87 long[] arr = (long[]) array;
11.88 return arr[index];
11.89 }
11.90 @@ -357,7 +327,7 @@
11.91 public static float getFloat(Object array, int index)
11.92 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.93 final Class<?> t = array.getClass().getComponentType();
11.94 - if (t == Float.TYPE) {
11.95 + if (Method.samePrimitive(t, Float.TYPE)) {
11.96 float[] arr = (float[]) array;
11.97 return arr[index];
11.98 }
11.99 @@ -383,7 +353,7 @@
11.100 public static double getDouble(Object array, int index)
11.101 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.102 final Class<?> t = array.getClass().getComponentType();
11.103 - if (t == Double.TYPE) {
11.104 + if (Method.samePrimitive(t, Double.TYPE)) {
11.105 double[] arr = (double[]) array;
11.106 return arr[index];
11.107 }
11.108 @@ -457,7 +427,7 @@
11.109 public static void setByte(Object array, int index, byte b)
11.110 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.111 Class<?> t = array.getClass().getComponentType();
11.112 - if (t == Byte.TYPE) {
11.113 + if (Method.samePrimitive(t, Byte.TYPE)) {
11.114 byte[] arr = (byte[]) array;
11.115 arr[index] = b;
11.116 } else {
11.117 @@ -505,7 +475,7 @@
11.118 public static void setShort(Object array, int index, short s)
11.119 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.120 Class<?> t = array.getClass().getComponentType();
11.121 - if (t == Short.TYPE) {
11.122 + if (Method.samePrimitive(t, Short.TYPE)) {
11.123 short[] arr = (short[]) array;
11.124 arr[index] = s;
11.125 } else {
11.126 @@ -534,7 +504,7 @@
11.127 public static void setInt(Object array, int index, int i)
11.128 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.129 Class<?> t = array.getClass().getComponentType();
11.130 - if (t == Integer.TYPE) {
11.131 + if (Method.samePrimitive(t, Integer.TYPE)) {
11.132 int[] arr = (int[]) array;
11.133 arr[index] = i;
11.134 } else {
11.135 @@ -562,7 +532,7 @@
11.136 public static void setLong(Object array, int index, long l)
11.137 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.138 Class<?> t = array.getClass().getComponentType();
11.139 - if (t == Long.TYPE) {
11.140 + if (Method.samePrimitive(t, Long.TYPE)) {
11.141 long[] arr = (long[]) array;
11.142 arr[index] = l;
11.143 } else {
11.144 @@ -590,7 +560,7 @@
11.145 public static void setFloat(Object array, int index, float f)
11.146 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.147 Class<?> t = array.getClass().getComponentType();
11.148 - if (t == Float.TYPE) {
11.149 + if (Method.samePrimitive(t, Float.TYPE)) {
11.150 float[] arr = (float[])array;
11.151 arr[index] = f;
11.152 } else {
11.153 @@ -618,7 +588,7 @@
11.154 public static void setDouble(Object array, int index, double d)
11.155 throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
11.156 Class<?> t = array.getClass().getComponentType();
11.157 - if (t == Double.TYPE) {
11.158 + if (Method.samePrimitive(t, Double.TYPE)) {
11.159 double[] arr = (double[])array;
11.160 arr[index] = d;
11.161 } else {
12.1 --- a/rt/emul/mini/src/main/java/java/lang/reflect/Method.java Tue May 06 17:46:47 2014 +0200
12.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Method.java Sun May 11 14:01:18 2014 +0200
12.3 @@ -552,28 +552,28 @@
12.4 }
12.5
12.6 static Object fromPrimitive(Class<?> type, Object o) {
12.7 - if (type == Integer.TYPE) {
12.8 + if (samePrimitive(type, Integer.TYPE)) {
12.9 return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
12.10 }
12.11 - if (type == Long.TYPE) {
12.12 + if (samePrimitive(type, Long.TYPE)) {
12.13 return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
12.14 }
12.15 - if (type == Double.TYPE) {
12.16 + if (samePrimitive(type, Double.TYPE)) {
12.17 return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
12.18 }
12.19 - if (type == Float.TYPE) {
12.20 + if (samePrimitive(type, Float.TYPE)) {
12.21 return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
12.22 }
12.23 - if (type == Byte.TYPE) {
12.24 + if (samePrimitive(type, Byte.TYPE)) {
12.25 return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
12.26 }
12.27 - if (type == Boolean.TYPE) {
12.28 + if (samePrimitive(type, Boolean.TYPE)) {
12.29 return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
12.30 }
12.31 - if (type == Short.TYPE) {
12.32 + if (samePrimitive(type, Short.TYPE)) {
12.33 return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
12.34 }
12.35 - if (type == Character.TYPE) {
12.36 + if (samePrimitive(type, Character.TYPE)) {
12.37 return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
12.38 }
12.39 if (type.getName().equals("void")) {
12.40 @@ -581,6 +581,46 @@
12.41 }
12.42 throw new IllegalStateException("Can't convert " + o);
12.43 }
12.44 + static boolean samePrimitive(Class<?> c1, Class<?> c2) {
12.45 + if (c1 == c2) {
12.46 + return true;
12.47 + }
12.48 + if (c1.isPrimitive()) {
12.49 + return c1.getName().equals(c2.getName());
12.50 + }
12.51 + return false;
12.52 + }
12.53 +
12.54 + static String findArraySignature(Class<?> type) {
12.55 + if (!type.isPrimitive()) {
12.56 + return "[L" + type.getName().replace('.', '/') + ";";
12.57 + }
12.58 + if (samePrimitive(type, Integer.TYPE)) {
12.59 + return "[I";
12.60 + }
12.61 + if (samePrimitive(type, Long.TYPE)) {
12.62 + return "[J";
12.63 + }
12.64 + if (samePrimitive(type, Double.TYPE)) {
12.65 + return "[D";
12.66 + }
12.67 + if (samePrimitive(type, Float.TYPE)) {
12.68 + return "[F";
12.69 + }
12.70 + if (samePrimitive(type, Byte.TYPE)) {
12.71 + return "[B";
12.72 + }
12.73 + if (samePrimitive(type, Boolean.TYPE)) {
12.74 + return "[Z";
12.75 + }
12.76 + if (samePrimitive(type, Short.TYPE)) {
12.77 + return "[S";
12.78 + }
12.79 + if (samePrimitive(type, Character.TYPE)) {
12.80 + return "[C";
12.81 + }
12.82 + throw new IllegalStateException("Can't create array for " + type);
12.83 + }
12.84
12.85 @JavaScriptBody(args = { "cls", "m", "o" },
12.86 body = "return cls.cnstr(false)[m](o);"
13.1 --- a/rt/emul/mini/src/main/java/java/util/zip/Adler32.java Tue May 06 17:46:47 2014 +0200
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,205 +0,0 @@
13.4 -/* Adler32.java - Computes Adler32 data checksum of a data stream
13.5 - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
13.6 -
13.7 -This file is part of GNU Classpath.
13.8 -
13.9 -GNU Classpath is free software; you can redistribute it and/or modify
13.10 -it under the terms of the GNU General Public License as published by
13.11 -the Free Software Foundation; either version 2, or (at your option)
13.12 -any later version.
13.13 -
13.14 -GNU Classpath is distributed in the hope that it will be useful, but
13.15 -WITHOUT ANY WARRANTY; without even the implied warranty of
13.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13.17 -General Public License for more details.
13.18 -
13.19 -You should have received a copy of the GNU General Public License
13.20 -along with GNU Classpath; see the file COPYING. If not, write to the
13.21 -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
13.22 -02111-1307 USA.
13.23 -
13.24 -Linking this library statically or dynamically with other modules is
13.25 -making a combined work based on this library. Thus, the terms and
13.26 -conditions of the GNU General Public License cover the whole
13.27 -combination.
13.28 -
13.29 -As a special exception, the copyright holders of this library give you
13.30 -permission to link this library with independent modules to produce an
13.31 -executable, regardless of the license terms of these independent
13.32 -modules, and to copy and distribute the resulting executable under
13.33 -terms of your choice, provided that you also meet, for each linked
13.34 -independent module, the terms and conditions of the license of that
13.35 -module. An independent module is a module which is not derived from
13.36 -or based on this library. If you modify this library, you may extend
13.37 -this exception to your version of the library, but you are not
13.38 -obligated to do so. If you do not wish to do so, delete this
13.39 -exception statement from your version. */
13.40 -
13.41 -package java.util.zip;
13.42 -
13.43 -/*
13.44 - * Written using on-line Java Platform 1.2 API Specification, as well
13.45 - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
13.46 - * The actual Adler32 algorithm is taken from RFC 1950.
13.47 - * Status: Believed complete and correct.
13.48 - */
13.49 -
13.50 -/**
13.51 - * Computes Adler32 checksum for a stream of data. An Adler32
13.52 - * checksum is not as reliable as a CRC32 checksum, but a lot faster to
13.53 - * compute.
13.54 - *<p>
13.55 - * The specification for Adler32 may be found in RFC 1950.
13.56 - * (ZLIB Compressed Data Format Specification version 3.3)
13.57 - *<p>
13.58 - *<p>
13.59 - * From that document:
13.60 - *<p>
13.61 - * "ADLER32 (Adler-32 checksum)
13.62 - * This contains a checksum value of the uncompressed data
13.63 - * (excluding any dictionary data) computed according to Adler-32
13.64 - * algorithm. This algorithm is a 32-bit extension and improvement
13.65 - * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
13.66 - * standard.
13.67 - *<p>
13.68 - * Adler-32 is composed of two sums accumulated per byte: s1 is
13.69 - * the sum of all bytes, s2 is the sum of all s1 values. Both sums
13.70 - * are done modulo 65521. s1 is initialized to 1, s2 to zero. The
13.71 - * Adler-32 checksum is stored as s2*65536 + s1 in most-
13.72 - * significant-byte first (network) order."
13.73 - *<p>
13.74 - * "8.2. The Adler-32 algorithm
13.75 - *<p>
13.76 - * The Adler-32 algorithm is much faster than the CRC32 algorithm yet
13.77 - * still provides an extremely low probability of undetected errors.
13.78 - *<p>
13.79 - * The modulo on unsigned long accumulators can be delayed for 5552
13.80 - * bytes, so the modulo operation time is negligible. If the bytes
13.81 - * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
13.82 - * and order sensitive, unlike the first sum, which is just a
13.83 - * checksum. That 65521 is prime is important to avoid a possible
13.84 - * large class of two-byte errors that leave the check unchanged.
13.85 - * (The Fletcher checksum uses 255, which is not prime and which also
13.86 - * makes the Fletcher check insensitive to single byte changes 0 <->
13.87 - * 255.)
13.88 - *<p>
13.89 - * The sum s1 is initialized to 1 instead of zero to make the length
13.90 - * of the sequence part of s2, so that the length does not have to be
13.91 - * checked separately. (Any sequence of zeroes has a Fletcher
13.92 - * checksum of zero.)"
13.93 - *
13.94 - * @author John Leuner, Per Bothner
13.95 - * @since JDK 1.1
13.96 - *
13.97 - * @see InflaterInputStream
13.98 - * @see DeflaterOutputStream
13.99 - */
13.100 -public class Adler32 implements Checksum
13.101 -{
13.102 -
13.103 - /** largest prime smaller than 65536 */
13.104 - private static final int BASE = 65521;
13.105 -
13.106 - private int checksum; //we do all in int.
13.107 -
13.108 - //Note that java doesn't have unsigned integers,
13.109 - //so we have to be careful with what arithmetic
13.110 - //we do. We return the checksum as a long to
13.111 - //avoid sign confusion.
13.112 -
13.113 - /**
13.114 - * Creates a new instance of the <code>Adler32</code> class.
13.115 - * The checksum starts off with a value of 1.
13.116 - */
13.117 - public Adler32 ()
13.118 - {
13.119 - reset();
13.120 - }
13.121 -
13.122 - /**
13.123 - * Resets the Adler32 checksum to the initial value.
13.124 - */
13.125 - public void reset ()
13.126 - {
13.127 - checksum = 1; //Initialize to 1
13.128 - }
13.129 -
13.130 - /**
13.131 - * Updates the checksum with the byte b.
13.132 - *
13.133 - * @param bval the data value to add. The high byte of the int is ignored.
13.134 - */
13.135 - public void update (int bval)
13.136 - {
13.137 - //We could make a length 1 byte array and call update again, but I
13.138 - //would rather not have that overhead
13.139 - int s1 = checksum & 0xffff;
13.140 - int s2 = checksum >>> 16;
13.141 -
13.142 - s1 = (s1 + (bval & 0xFF)) % BASE;
13.143 - s2 = (s1 + s2) % BASE;
13.144 -
13.145 - checksum = (s2 << 16) + s1;
13.146 - }
13.147 -
13.148 - /**
13.149 - * Updates the checksum with the bytes taken from the array.
13.150 - *
13.151 - * @param buffer an array of bytes
13.152 - */
13.153 - public void update (byte[] buffer)
13.154 - {
13.155 - update(buffer, 0, buffer.length);
13.156 - }
13.157 -
13.158 - /**
13.159 - * Updates the checksum with the bytes taken from the array.
13.160 - *
13.161 - * @param buf an array of bytes
13.162 - * @param off the start of the data used for this update
13.163 - * @param len the number of bytes to use for this update
13.164 - */
13.165 - public void update (byte[] buf, int off, int len)
13.166 - {
13.167 - //(By Per Bothner)
13.168 - int s1 = checksum & 0xffff;
13.169 - int s2 = checksum >>> 16;
13.170 -
13.171 - while (len > 0)
13.172 - {
13.173 - // We can defer the modulo operation:
13.174 - // s1 maximally grows from 65521 to 65521 + 255 * 3800
13.175 - // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
13.176 - int n = 3800;
13.177 - if (n > len)
13.178 - n = len;
13.179 - len -= n;
13.180 - while (--n >= 0)
13.181 - {
13.182 - s1 = s1 + (buf[off++] & 0xFF);
13.183 - s2 = s2 + s1;
13.184 - }
13.185 - s1 %= BASE;
13.186 - s2 %= BASE;
13.187 - }
13.188 -
13.189 - /*Old implementation, borrowed from somewhere:
13.190 - int n;
13.191 -
13.192 - while (len-- > 0) {
13.193 -
13.194 - s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
13.195 - s2 = (s2 + s1) % BASE;
13.196 - }*/
13.197 -
13.198 - checksum = (s2 << 16) | s1;
13.199 - }
13.200 -
13.201 - /**
13.202 - * Returns the Adler32 data checksum computed so far.
13.203 - */
13.204 - public long getValue()
13.205 - {
13.206 - return (long) checksum & 0xffffffffL;
13.207 - }
13.208 -}
14.1 --- a/rt/emul/mini/src/main/java/java/util/zip/CRC32.java Tue May 06 17:46:47 2014 +0200
14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
14.3 @@ -1,132 +0,0 @@
14.4 -/* CRC32.java - Computes CRC32 data checksum of a data stream
14.5 - Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
14.6 -
14.7 -This file is part of GNU Classpath.
14.8 -
14.9 -GNU Classpath is free software; you can redistribute it and/or modify
14.10 -it under the terms of the GNU General Public License as published by
14.11 -the Free Software Foundation; either version 2, or (at your option)
14.12 -any later version.
14.13 -
14.14 -GNU Classpath is distributed in the hope that it will be useful, but
14.15 -WITHOUT ANY WARRANTY; without even the implied warranty of
14.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14.17 -General Public License for more details.
14.18 -
14.19 -You should have received a copy of the GNU General Public License
14.20 -along with GNU Classpath; see the file COPYING. If not, write to the
14.21 -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
14.22 -02111-1307 USA.
14.23 -
14.24 -Linking this library statically or dynamically with other modules is
14.25 -making a combined work based on this library. Thus, the terms and
14.26 -conditions of the GNU General Public License cover the whole
14.27 -combination.
14.28 -
14.29 -As a special exception, the copyright holders of this library give you
14.30 -permission to link this library with independent modules to produce an
14.31 -executable, regardless of the license terms of these independent
14.32 -modules, and to copy and distribute the resulting executable under
14.33 -terms of your choice, provided that you also meet, for each linked
14.34 -independent module, the terms and conditions of the license of that
14.35 -module. An independent module is a module which is not derived from
14.36 -or based on this library. If you modify this library, you may extend
14.37 -this exception to your version of the library, but you are not
14.38 -obligated to do so. If you do not wish to do so, delete this
14.39 -exception statement from your version. */
14.40 -
14.41 -package java.util.zip;
14.42 -
14.43 -/*
14.44 - * Written using on-line Java Platform 1.2 API Specification, as well
14.45 - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
14.46 - * The actual CRC32 algorithm is taken from RFC 1952.
14.47 - * Status: Believed complete and correct.
14.48 - */
14.49 -
14.50 -/**
14.51 - * Computes CRC32 data checksum of a data stream.
14.52 - * The actual CRC32 algorithm is described in RFC 1952
14.53 - * (GZIP file format specification version 4.3).
14.54 - * Can be used to get the CRC32 over a stream if used with checked input/output
14.55 - * streams.
14.56 - *
14.57 - * @see InflaterInputStream
14.58 - * @see DeflaterOutputStream
14.59 - *
14.60 - * @author Per Bothner
14.61 - * @date April 1, 1999.
14.62 - */
14.63 -public class CRC32 implements Checksum
14.64 -{
14.65 - /** The crc data checksum so far. */
14.66 - private int crc = 0;
14.67 -
14.68 - /** The fast CRC table. Computed once when the CRC32 class is loaded. */
14.69 - private static int[] crc_table = make_crc_table();
14.70 -
14.71 - /** Make the table for a fast CRC. */
14.72 - private static int[] make_crc_table ()
14.73 - {
14.74 - int[] crc_table = new int[256];
14.75 - for (int n = 0; n < 256; n++)
14.76 - {
14.77 - int c = n;
14.78 - for (int k = 8; --k >= 0; )
14.79 - {
14.80 - if ((c & 1) != 0)
14.81 - c = 0xedb88320 ^ (c >>> 1);
14.82 - else
14.83 - c = c >>> 1;
14.84 - }
14.85 - crc_table[n] = c;
14.86 - }
14.87 - return crc_table;
14.88 - }
14.89 -
14.90 - /**
14.91 - * Returns the CRC32 data checksum computed so far.
14.92 - */
14.93 - public long getValue ()
14.94 - {
14.95 - return (long) crc & 0xffffffffL;
14.96 - }
14.97 -
14.98 - /**
14.99 - * Resets the CRC32 data checksum as if no update was ever called.
14.100 - */
14.101 - public void reset () { crc = 0; }
14.102 -
14.103 - /**
14.104 - * Updates the checksum with the int bval.
14.105 - *
14.106 - * @param bval (the byte is taken as the lower 8 bits of bval)
14.107 - */
14.108 -
14.109 - public void update (int bval)
14.110 - {
14.111 - int c = ~crc;
14.112 - c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
14.113 - crc = ~c;
14.114 - }
14.115 -
14.116 - /**
14.117 - * Adds the byte array to the data checksum.
14.118 - *
14.119 - * @param buf the buffer which contains the data
14.120 - * @param off the offset in the buffer where the data starts
14.121 - * @param len the length of the data
14.122 - */
14.123 - public void update (byte[] buf, int off, int len)
14.124 - {
14.125 - int c = ~crc;
14.126 - while (--len >= 0)
14.127 - c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
14.128 - crc = ~c;
14.129 - }
14.130 -
14.131 - /**
14.132 - * Adds the complete byte array to the data checksum.
14.133 - */
14.134 - public void update (byte[] buf) { update(buf, 0, buf.length); }
14.135 -}
15.1 --- a/rt/emul/mini/src/main/java/java/util/zip/Checksum.java Tue May 06 17:46:47 2014 +0200
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,60 +0,0 @@
15.4 -/*
15.5 - * Copyright (c) 1996, 1999, 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 - * An interface representing a data checksum.
15.33 - *
15.34 - * @author David Connelly
15.35 - */
15.36 -public
15.37 -interface Checksum {
15.38 - /**
15.39 - * Updates the current checksum with the specified byte.
15.40 - *
15.41 - * @param b the byte to update the checksum with
15.42 - */
15.43 - public void update(int b);
15.44 -
15.45 - /**
15.46 - * Updates the current checksum with the specified array of bytes.
15.47 - * @param b the byte array to update the checksum with
15.48 - * @param off the start offset of the data
15.49 - * @param len the number of bytes to use for the update
15.50 - */
15.51 - public void update(byte[] b, int off, int len);
15.52 -
15.53 - /**
15.54 - * Returns the current checksum value.
15.55 - * @return the current checksum value
15.56 - */
15.57 - public long getValue();
15.58 -
15.59 - /**
15.60 - * Resets the checksum to its initial value.
15.61 - */
15.62 - public void reset();
15.63 -}
16.1 --- a/rt/emul/mini/src/main/java/java/util/zip/DataFormatException.java Tue May 06 17:46:47 2014 +0200
16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
16.3 @@ -1,52 +0,0 @@
16.4 -/*
16.5 - * Copyright (c) 1996, 2008, 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 - * Signals that a data format error has occurred.
16.33 - *
16.34 - * @author David Connelly
16.35 - */
16.36 -public
16.37 -class DataFormatException extends Exception {
16.38 - private static final long serialVersionUID = 2219632870893641452L;
16.39 -
16.40 - /**
16.41 - * Constructs a DataFormatException with no detail message.
16.42 - */
16.43 - public DataFormatException() {
16.44 - super();
16.45 - }
16.46 -
16.47 - /**
16.48 - * Constructs a DataFormatException with the specified detail message.
16.49 - * A detail message is a String that describes this particular exception.
16.50 - * @param s the String containing a detail message
16.51 - */
16.52 - public DataFormatException(String s) {
16.53 - super(s);
16.54 - }
16.55 -}
17.1 --- a/rt/emul/mini/src/main/java/java/util/zip/Inflater.java Tue May 06 17:46:47 2014 +0200
17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
17.3 @@ -1,310 +0,0 @@
17.4 -/*
17.5 - * Copyright (c) 1996, 2011, 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 -/**
17.32 - * This class provides support for general purpose decompression using the
17.33 - * popular ZLIB compression library. The ZLIB compression library was
17.34 - * initially developed as part of the PNG graphics standard and is not
17.35 - * protected by patents. It is fully described in the specifications at
17.36 - * the <a href="package-summary.html#package_description">java.util.zip
17.37 - * package description</a>.
17.38 - *
17.39 - * <p>The following code fragment demonstrates a trivial compression
17.40 - * and decompression of a string using <tt>Deflater</tt> and
17.41 - * <tt>Inflater</tt>.
17.42 - *
17.43 - * <blockquote><pre>
17.44 - * try {
17.45 - * // Encode a String into bytes
17.46 - * String inputString = "blahblahblah\u20AC\u20AC";
17.47 - * byte[] input = inputString.getBytes("UTF-8");
17.48 - *
17.49 - * // Compress the bytes
17.50 - * byte[] output = new byte[100];
17.51 - * Deflater compresser = new Deflater();
17.52 - * compresser.setInput(input);
17.53 - * compresser.finish();
17.54 - * int compressedDataLength = compresser.deflate(output);
17.55 - *
17.56 - * // Decompress the bytes
17.57 - * Inflater decompresser = new Inflater();
17.58 - * decompresser.setInput(output, 0, compressedDataLength);
17.59 - * byte[] result = new byte[100];
17.60 - * int resultLength = decompresser.inflate(result);
17.61 - * decompresser.end();
17.62 - *
17.63 - * // Decode the bytes into a String
17.64 - * String outputString = new String(result, 0, resultLength, "UTF-8");
17.65 - * } catch(java.io.UnsupportedEncodingException ex) {
17.66 - * // handle
17.67 - * } catch (java.util.zip.DataFormatException ex) {
17.68 - * // handle
17.69 - * }
17.70 - * </pre></blockquote>
17.71 - *
17.72 - * @see Deflater
17.73 - * @author David Connelly
17.74 - *
17.75 - */
17.76 -public
17.77 -class Inflater {
17.78 - private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
17.79 -
17.80 - /**
17.81 - * Creates a new decompressor. If the parameter 'nowrap' is true then
17.82 - * the ZLIB header and checksum fields will not be used. This provides
17.83 - * compatibility with the compression format used by both GZIP and PKZIP.
17.84 - * <p>
17.85 - * Note: When using the 'nowrap' option it is also necessary to provide
17.86 - * an extra "dummy" byte as input. This is required by the ZLIB native
17.87 - * library in order to support certain optimizations.
17.88 - *
17.89 - * @param nowrap if true then support GZIP compatible compression
17.90 - */
17.91 - public Inflater(boolean nowrap) {
17.92 - if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
17.93 - impl = null;
17.94 - } else {
17.95 - impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
17.96 - }
17.97 - }
17.98 -
17.99 - /**
17.100 - * Creates a new decompressor.
17.101 - */
17.102 - public Inflater() {
17.103 - this(false);
17.104 - }
17.105 -
17.106 - /**
17.107 - * Sets input data for decompression. Should be called whenever
17.108 - * needsInput() returns true indicating that more input data is
17.109 - * required.
17.110 - * @param b the input data bytes
17.111 - * @param off the start offset of the input data
17.112 - * @param len the length of the input data
17.113 - * @see Inflater#needsInput
17.114 - */
17.115 - public void setInput(byte[] b, int off, int len) {
17.116 - impl.setInput(b, off, len);
17.117 - }
17.118 -
17.119 - /**
17.120 - * Sets input data for decompression. Should be called whenever
17.121 - * needsInput() returns true indicating that more input data is
17.122 - * required.
17.123 - * @param b the input data bytes
17.124 - * @see Inflater#needsInput
17.125 - */
17.126 - public void setInput(byte[] b) {
17.127 - impl.setInput(b);
17.128 - }
17.129 -
17.130 - /**
17.131 - * Sets the preset dictionary to the given array of bytes. Should be
17.132 - * called when inflate() returns 0 and needsDictionary() returns true
17.133 - * indicating that a preset dictionary is required. The method getAdler()
17.134 - * can be used to get the Adler-32 value of the dictionary needed.
17.135 - * @param b the dictionary data bytes
17.136 - * @param off the start offset of the data
17.137 - * @param len the length of the data
17.138 - * @see Inflater#needsDictionary
17.139 - * @see Inflater#getAdler
17.140 - */
17.141 - public void setDictionary(byte[] b, int off, int len) {
17.142 - impl.setDictionary(b, off, len);
17.143 - }
17.144 -
17.145 - /**
17.146 - * Sets the preset dictionary to the given array of bytes. Should be
17.147 - * called when inflate() returns 0 and needsDictionary() returns true
17.148 - * indicating that a preset dictionary is required. The method getAdler()
17.149 - * can be used to get the Adler-32 value of the dictionary needed.
17.150 - * @param b the dictionary data bytes
17.151 - * @see Inflater#needsDictionary
17.152 - * @see Inflater#getAdler
17.153 - */
17.154 - public void setDictionary(byte[] b) {
17.155 - impl.setDictionary(b);
17.156 - }
17.157 -
17.158 - /**
17.159 - * Returns the total number of bytes remaining in the input buffer.
17.160 - * This can be used to find out what bytes still remain in the input
17.161 - * buffer after decompression has finished.
17.162 - * @return the total number of bytes remaining in the input buffer
17.163 - */
17.164 - public int getRemaining() {
17.165 - return impl.getRemaining();
17.166 - }
17.167 -
17.168 - /**
17.169 - * Returns true if no data remains in the input buffer. This can
17.170 - * be used to determine if #setInput should be called in order
17.171 - * to provide more input.
17.172 - * @return true if no data remains in the input buffer
17.173 - */
17.174 - public boolean needsInput() {
17.175 - return impl.needsInput();
17.176 - }
17.177 -
17.178 - /**
17.179 - * Returns true if a preset dictionary is needed for decompression.
17.180 - * @return true if a preset dictionary is needed for decompression
17.181 - * @see Inflater#setDictionary
17.182 - */
17.183 - public boolean needsDictionary() {
17.184 - return impl.needsDictionary();
17.185 - }
17.186 -
17.187 - /**
17.188 - * Returns true if the end of the compressed data stream has been
17.189 - * reached.
17.190 - * @return true if the end of the compressed data stream has been
17.191 - * reached
17.192 - */
17.193 - public boolean finished() {
17.194 - return impl.finished();
17.195 - }
17.196 -
17.197 - /**
17.198 - * Uncompresses bytes into specified buffer. Returns actual number
17.199 - * of bytes uncompressed. A return value of 0 indicates that
17.200 - * needsInput() or needsDictionary() should be called in order to
17.201 - * determine if more input data or a preset dictionary is required.
17.202 - * In the latter case, getAdler() can be used to get the Adler-32
17.203 - * value of the dictionary required.
17.204 - * @param b the buffer for the uncompressed data
17.205 - * @param off the start offset of the data
17.206 - * @param len the maximum number of uncompressed bytes
17.207 - * @return the actual number of uncompressed bytes
17.208 - * @exception DataFormatException if the compressed data format is invalid
17.209 - * @see Inflater#needsInput
17.210 - * @see Inflater#needsDictionary
17.211 - */
17.212 - public int inflate(byte[] b, int off, int len)
17.213 - throws DataFormatException
17.214 - {
17.215 - return impl.inflate(b, off, len);
17.216 - }
17.217 -
17.218 - /**
17.219 - * Uncompresses bytes into specified buffer. Returns actual number
17.220 - * of bytes uncompressed. A return value of 0 indicates that
17.221 - * needsInput() or needsDictionary() should be called in order to
17.222 - * determine if more input data or a preset dictionary is required.
17.223 - * In the latter case, getAdler() can be used to get the Adler-32
17.224 - * value of the dictionary required.
17.225 - * @param b the buffer for the uncompressed data
17.226 - * @return the actual number of uncompressed bytes
17.227 - * @exception DataFormatException if the compressed data format is invalid
17.228 - * @see Inflater#needsInput
17.229 - * @see Inflater#needsDictionary
17.230 - */
17.231 - public int inflate(byte[] b) throws DataFormatException {
17.232 - return impl.inflate(b);
17.233 - }
17.234 -
17.235 - /**
17.236 - * Returns the ADLER-32 value of the uncompressed data.
17.237 - * @return the ADLER-32 value of the uncompressed data
17.238 - */
17.239 - public int getAdler() {
17.240 - return impl.getAdler();
17.241 - }
17.242 -
17.243 - /**
17.244 - * Returns the total number of compressed bytes input so far.
17.245 - *
17.246 - * <p>Since the number of bytes may be greater than
17.247 - * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
17.248 - * the preferred means of obtaining this information.</p>
17.249 - *
17.250 - * @return the total number of compressed bytes input so far
17.251 - */
17.252 - public int getTotalIn() {
17.253 - return impl.getTotalIn();
17.254 - }
17.255 -
17.256 - /**
17.257 - * Returns the total number of compressed bytes input so far.</p>
17.258 - *
17.259 - * @return the total (non-negative) number of compressed bytes input so far
17.260 - * @since 1.5
17.261 - */
17.262 - public long getBytesRead() {
17.263 - return impl.getBytesRead();
17.264 - }
17.265 -
17.266 - /**
17.267 - * Returns the total number of uncompressed bytes output so far.
17.268 - *
17.269 - * <p>Since the number of bytes may be greater than
17.270 - * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
17.271 - * the preferred means of obtaining this information.</p>
17.272 - *
17.273 - * @return the total number of uncompressed bytes output so far
17.274 - */
17.275 - public int getTotalOut() {
17.276 - return impl.getTotalOut();
17.277 - }
17.278 -
17.279 - /**
17.280 - * Returns the total number of uncompressed bytes output so far.</p>
17.281 - *
17.282 - * @return the total (non-negative) number of uncompressed bytes output so far
17.283 - * @since 1.5
17.284 - */
17.285 - public long getBytesWritten() {
17.286 - return impl.getBytesWritten();
17.287 - }
17.288 -
17.289 - /**
17.290 - * Resets inflater so that a new set of input data can be processed.
17.291 - */
17.292 - public void reset() {
17.293 - impl.reset();
17.294 - }
17.295 -
17.296 - /**
17.297 - * Closes the decompressor and discards any unprocessed input.
17.298 - * This method should be called when the decompressor is no longer
17.299 - * being used, but will also be called automatically by the finalize()
17.300 - * method. Once this method is called, the behavior of the Inflater
17.301 - * object is undefined.
17.302 - */
17.303 - public void end() {
17.304 - impl.end();
17.305 - }
17.306 -
17.307 - /**
17.308 - * Closes the decompressor when garbage is collected.
17.309 - */
17.310 - protected void finalize() {
17.311 - end();
17.312 - }
17.313 -}
18.1 --- a/rt/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java Tue May 06 17:46:47 2014 +0200
18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
18.3 @@ -1,288 +0,0 @@
18.4 -/*
18.5 - * Copyright (c) 1996, 2006, 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.FilterInputStream;
18.32 -import java.io.InputStream;
18.33 -import java.io.IOException;
18.34 -import java.io.EOFException;
18.35 -
18.36 -/**
18.37 - * This class implements a stream filter for uncompressing data in the
18.38 - * "deflate" compression format. It is also used as the basis for other
18.39 - * decompression filters, such as GZIPInputStream.
18.40 - *
18.41 - * @see Inflater
18.42 - * @author David Connelly
18.43 - */
18.44 -public
18.45 -class InflaterInputStream extends FilterInputStream {
18.46 - /**
18.47 - * Decompressor for this stream.
18.48 - */
18.49 - protected Inflater inf;
18.50 -
18.51 - /**
18.52 - * Input buffer for decompression.
18.53 - */
18.54 - protected byte[] buf;
18.55 -
18.56 - /**
18.57 - * Length of input buffer.
18.58 - */
18.59 - protected int len;
18.60 -
18.61 - private boolean closed = false;
18.62 - // this flag is set to true after EOF has reached
18.63 - private boolean reachEOF = false;
18.64 -
18.65 - /**
18.66 - * Check to make sure that this stream has not been closed
18.67 - */
18.68 - private void ensureOpen() throws IOException {
18.69 - if (closed) {
18.70 - throw new IOException("Stream closed");
18.71 - }
18.72 - }
18.73 -
18.74 -
18.75 - /**
18.76 - * Creates a new input stream with the specified decompressor and
18.77 - * buffer size.
18.78 - * @param in the input stream
18.79 - * @param inf the decompressor ("inflater")
18.80 - * @param size the input buffer size
18.81 - * @exception IllegalArgumentException if size is <= 0
18.82 - */
18.83 - public InflaterInputStream(InputStream in, Inflater inf, int size) {
18.84 - super(in);
18.85 - if (in == null || inf == null) {
18.86 - throw new NullPointerException();
18.87 - } else if (size <= 0) {
18.88 - throw new IllegalArgumentException("buffer size <= 0");
18.89 - }
18.90 - this.inf = inf;
18.91 - buf = new byte[size];
18.92 - }
18.93 -
18.94 - /**
18.95 - * Creates a new input stream with the specified decompressor and a
18.96 - * default buffer size.
18.97 - * @param in the input stream
18.98 - * @param inf the decompressor ("inflater")
18.99 - */
18.100 - public InflaterInputStream(InputStream in, Inflater inf) {
18.101 - this(in, inf, 512);
18.102 - }
18.103 -
18.104 - boolean usesDefaultInflater = false;
18.105 -
18.106 - /**
18.107 - * Creates a new input stream with a default decompressor and buffer size.
18.108 - * @param in the input stream
18.109 - */
18.110 - public InflaterInputStream(InputStream in) {
18.111 - this(in, new Inflater());
18.112 - usesDefaultInflater = true;
18.113 - }
18.114 -
18.115 - private byte[] singleByteBuf = new byte[1];
18.116 -
18.117 - /**
18.118 - * Reads a byte of uncompressed data. This method will block until
18.119 - * enough input is available for decompression.
18.120 - * @return the byte read, or -1 if end of compressed input is reached
18.121 - * @exception IOException if an I/O error has occurred
18.122 - */
18.123 - public int read() throws IOException {
18.124 - ensureOpen();
18.125 - return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
18.126 - }
18.127 -
18.128 - /**
18.129 - * Reads uncompressed data into an array of bytes. If <code>len</code> is not
18.130 - * zero, the method will block until some input can be decompressed; otherwise,
18.131 - * no bytes are read and <code>0</code> is returned.
18.132 - * @param b the buffer into which the data is read
18.133 - * @param off the start offset in the destination array <code>b</code>
18.134 - * @param len the maximum number of bytes read
18.135 - * @return the actual number of bytes read, or -1 if the end of the
18.136 - * compressed input is reached or a preset dictionary is needed
18.137 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
18.138 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
18.139 - * <code>len</code> is negative, or <code>len</code> is greater than
18.140 - * <code>b.length - off</code>
18.141 - * @exception ZipException if a ZIP format error has occurred
18.142 - * @exception IOException if an I/O error has occurred
18.143 - */
18.144 - public int read(byte[] b, int off, int len) throws IOException {
18.145 - ensureOpen();
18.146 - if (b == null) {
18.147 - throw new NullPointerException();
18.148 - } else if (off < 0 || len < 0 || len > b.length - off) {
18.149 - throw new IndexOutOfBoundsException();
18.150 - } else if (len == 0) {
18.151 - return 0;
18.152 - }
18.153 - try {
18.154 - int n;
18.155 - while ((n = inf.inflate(b, off, len)) == 0) {
18.156 - if (inf.finished() || inf.needsDictionary()) {
18.157 - reachEOF = true;
18.158 - return -1;
18.159 - }
18.160 - if (inf.needsInput()) {
18.161 - fill();
18.162 - }
18.163 - }
18.164 - return n;
18.165 - } catch (DataFormatException e) {
18.166 - String s = e.getMessage();
18.167 - throw new ZipException(s != null ? s : "Invalid ZLIB data format");
18.168 - }
18.169 - }
18.170 -
18.171 - /**
18.172 - * Returns 0 after EOF has been reached, otherwise always return 1.
18.173 - * <p>
18.174 - * Programs should not count on this method to return the actual number
18.175 - * of bytes that could be read without blocking.
18.176 - *
18.177 - * @return 1 before EOF and 0 after EOF.
18.178 - * @exception IOException if an I/O error occurs.
18.179 - *
18.180 - */
18.181 - public int available() throws IOException {
18.182 - ensureOpen();
18.183 - if (reachEOF) {
18.184 - return 0;
18.185 - } else {
18.186 - return 1;
18.187 - }
18.188 - }
18.189 -
18.190 - private byte[] b = new byte[512];
18.191 -
18.192 - /**
18.193 - * Skips specified number of bytes of uncompressed data.
18.194 - * @param n the number of bytes to skip
18.195 - * @return the actual number of bytes skipped.
18.196 - * @exception IOException if an I/O error has occurred
18.197 - * @exception IllegalArgumentException if n < 0
18.198 - */
18.199 - public long skip(long n) throws IOException {
18.200 - if (n < 0) {
18.201 - throw new IllegalArgumentException("negative skip length");
18.202 - }
18.203 - ensureOpen();
18.204 - int max = (int)Math.min(n, Integer.MAX_VALUE);
18.205 - int total = 0;
18.206 - while (total < max) {
18.207 - int len = max - total;
18.208 - if (len > b.length) {
18.209 - len = b.length;
18.210 - }
18.211 - len = read(b, 0, len);
18.212 - if (len == -1) {
18.213 - reachEOF = true;
18.214 - break;
18.215 - }
18.216 - total += len;
18.217 - }
18.218 - return total;
18.219 - }
18.220 -
18.221 - /**
18.222 - * Closes this input stream and releases any system resources associated
18.223 - * with the stream.
18.224 - * @exception IOException if an I/O error has occurred
18.225 - */
18.226 - public void close() throws IOException {
18.227 - if (!closed) {
18.228 - if (usesDefaultInflater)
18.229 - inf.end();
18.230 - in.close();
18.231 - closed = true;
18.232 - }
18.233 - }
18.234 -
18.235 - /**
18.236 - * Fills input buffer with more data to decompress.
18.237 - * @exception IOException if an I/O error has occurred
18.238 - */
18.239 - protected void fill() throws IOException {
18.240 - ensureOpen();
18.241 - len = in.read(buf, 0, buf.length);
18.242 - if (len == -1) {
18.243 - throw new EOFException("Unexpected end of ZLIB input stream");
18.244 - }
18.245 - inf.setInput(buf, 0, len);
18.246 - }
18.247 -
18.248 - /**
18.249 - * Tests if this input stream supports the <code>mark</code> and
18.250 - * <code>reset</code> methods. The <code>markSupported</code>
18.251 - * method of <code>InflaterInputStream</code> returns
18.252 - * <code>false</code>.
18.253 - *
18.254 - * @return a <code>boolean</code> indicating if this stream type supports
18.255 - * the <code>mark</code> and <code>reset</code> methods.
18.256 - * @see java.io.InputStream#mark(int)
18.257 - * @see java.io.InputStream#reset()
18.258 - */
18.259 - public boolean markSupported() {
18.260 - return false;
18.261 - }
18.262 -
18.263 - /**
18.264 - * Marks the current position in this input stream.
18.265 - *
18.266 - * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
18.267 - * does nothing.
18.268 - *
18.269 - * @param readlimit the maximum limit of bytes that can be read before
18.270 - * the mark position becomes invalid.
18.271 - * @see java.io.InputStream#reset()
18.272 - */
18.273 - public synchronized void mark(int readlimit) {
18.274 - }
18.275 -
18.276 - /**
18.277 - * Repositions this stream to the position at the time the
18.278 - * <code>mark</code> method was last called on this input stream.
18.279 - *
18.280 - * <p> The method <code>reset</code> for class
18.281 - * <code>InflaterInputStream</code> does nothing except throw an
18.282 - * <code>IOException</code>.
18.283 - *
18.284 - * @exception IOException if this method is invoked.
18.285 - * @see java.io.InputStream#mark(int)
18.286 - * @see java.io.IOException
18.287 - */
18.288 - public synchronized void reset() throws IOException {
18.289 - throw new IOException("mark/reset not supported");
18.290 - }
18.291 -}
19.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZStreamRef.java Tue May 06 17:46:47 2014 +0200
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,46 +0,0 @@
19.4 -/*
19.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
19.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19.7 - *
19.8 - * This code is free software; you can redistribute it and/or modify it
19.9 - * under the terms of the GNU General Public License version 2 only, as
19.10 - * published by the Free Software Foundation. Oracle designates this
19.11 - * particular file as subject to the "Classpath" exception as provided
19.12 - * by Oracle in the LICENSE file that accompanied this code.
19.13 - *
19.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
19.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19.17 - * version 2 for more details (a copy is included in the LICENSE file that
19.18 - * accompanied this code).
19.19 - *
19.20 - * You should have received a copy of the GNU General Public License version
19.21 - * 2 along with this work; if not, write to the Free Software Foundation,
19.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.23 - *
19.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19.25 - * or visit www.oracle.com if you need additional information or have any
19.26 - * questions.
19.27 - */
19.28 -
19.29 -package java.util.zip;
19.30 -
19.31 -/**
19.32 - * A reference to the native zlib's z_stream structure.
19.33 - */
19.34 -
19.35 -class ZStreamRef {
19.36 -
19.37 - private long address;
19.38 - ZStreamRef (long address) {
19.39 - this.address = address;
19.40 - }
19.41 -
19.42 - long address() {
19.43 - return address;
19.44 - }
19.45 -
19.46 - void clear() {
19.47 - address = 0;
19.48 - }
19.49 -}
20.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipConstants.java Tue May 06 17:46:47 2014 +0200
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,98 +0,0 @@
20.4 -/*
20.5 - * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
20.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.7 - *
20.8 - * This code is free software; you can redistribute it and/or modify it
20.9 - * under the terms of the GNU General Public License version 2 only, as
20.10 - * published by the Free Software Foundation. Oracle designates this
20.11 - * particular file as subject to the "Classpath" exception as provided
20.12 - * by Oracle in the LICENSE file that accompanied this code.
20.13 - *
20.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
20.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.17 - * version 2 for more details (a copy is included in the LICENSE file that
20.18 - * accompanied this code).
20.19 - *
20.20 - * You should have received a copy of the GNU General Public License version
20.21 - * 2 along with this work; if not, write to the Free Software Foundation,
20.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.23 - *
20.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20.25 - * or visit www.oracle.com if you need additional information or have any
20.26 - * questions.
20.27 - */
20.28 -
20.29 -package java.util.zip;
20.30 -
20.31 -/*
20.32 - * This interface defines the constants that are used by the classes
20.33 - * which manipulate ZIP files.
20.34 - *
20.35 - * @author David Connelly
20.36 - */
20.37 -interface ZipConstants {
20.38 - /*
20.39 - * Header signatures
20.40 - */
20.41 - static long LOCSIG = 0x04034b50L; // "PK\003\004"
20.42 - static long EXTSIG = 0x08074b50L; // "PK\007\008"
20.43 - static long CENSIG = 0x02014b50L; // "PK\001\002"
20.44 - static long ENDSIG = 0x06054b50L; // "PK\005\006"
20.45 -
20.46 - /*
20.47 - * Header sizes in bytes (including signatures)
20.48 - */
20.49 - static final int LOCHDR = 30; // LOC header size
20.50 - static final int EXTHDR = 16; // EXT header size
20.51 - static final int CENHDR = 46; // CEN header size
20.52 - static final int ENDHDR = 22; // END header size
20.53 -
20.54 - /*
20.55 - * Local file (LOC) header field offsets
20.56 - */
20.57 - static final int LOCVER = 4; // version needed to extract
20.58 - static final int LOCFLG = 6; // general purpose bit flag
20.59 - static final int LOCHOW = 8; // compression method
20.60 - static final int LOCTIM = 10; // modification time
20.61 - static final int LOCCRC = 14; // uncompressed file crc-32 value
20.62 - static final int LOCSIZ = 18; // compressed size
20.63 - static final int LOCLEN = 22; // uncompressed size
20.64 - static final int LOCNAM = 26; // filename length
20.65 - static final int LOCEXT = 28; // extra field length
20.66 -
20.67 - /*
20.68 - * Extra local (EXT) header field offsets
20.69 - */
20.70 - static final int EXTCRC = 4; // uncompressed file crc-32 value
20.71 - static final int EXTSIZ = 8; // compressed size
20.72 - static final int EXTLEN = 12; // uncompressed size
20.73 -
20.74 - /*
20.75 - * Central directory (CEN) header field offsets
20.76 - */
20.77 - static final int CENVEM = 4; // version made by
20.78 - static final int CENVER = 6; // version needed to extract
20.79 - static final int CENFLG = 8; // encrypt, decrypt flags
20.80 - static final int CENHOW = 10; // compression method
20.81 - static final int CENTIM = 12; // modification time
20.82 - static final int CENCRC = 16; // uncompressed file crc-32 value
20.83 - static final int CENSIZ = 20; // compressed size
20.84 - static final int CENLEN = 24; // uncompressed size
20.85 - static final int CENNAM = 28; // filename length
20.86 - static final int CENEXT = 30; // extra field length
20.87 - static final int CENCOM = 32; // comment length
20.88 - static final int CENDSK = 34; // disk number start
20.89 - static final int CENATT = 36; // internal file attributes
20.90 - static final int CENATX = 38; // external file attributes
20.91 - static final int CENOFF = 42; // LOC header offset
20.92 -
20.93 - /*
20.94 - * End of central directory (END) header field offsets
20.95 - */
20.96 - static final int ENDSUB = 8; // number of entries on this disk
20.97 - static final int ENDTOT = 10; // total number of entries
20.98 - static final int ENDSIZ = 12; // central directory size in bytes
20.99 - static final int ENDOFF = 16; // offset of first CEN header
20.100 - static final int ENDCOM = 20; // zip file comment length
20.101 -}
21.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipEntry.java Tue May 06 17:46:47 2014 +0200
21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
21.3 @@ -1,331 +0,0 @@
21.4 -/*
21.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
21.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21.7 - *
21.8 - * This code is free software; you can redistribute it and/or modify it
21.9 - * under the terms of the GNU General Public License version 2 only, as
21.10 - * published by the Free Software Foundation. Oracle designates this
21.11 - * particular file as subject to the "Classpath" exception as provided
21.12 - * by Oracle in the LICENSE file that accompanied this code.
21.13 - *
21.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
21.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21.17 - * version 2 for more details (a copy is included in the LICENSE file that
21.18 - * accompanied this code).
21.19 - *
21.20 - * You should have received a copy of the GNU General Public License version
21.21 - * 2 along with this work; if not, write to the Free Software Foundation,
21.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21.23 - *
21.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21.25 - * or visit www.oracle.com if you need additional information or have any
21.26 - * questions.
21.27 - */
21.28 -
21.29 -package java.util.zip;
21.30 -
21.31 -/**
21.32 - * This class is used to represent a ZIP file entry.
21.33 - *
21.34 - * @author David Connelly
21.35 - */
21.36 -public
21.37 -class ZipEntry implements ZipConstants, Cloneable {
21.38 - String name; // entry name
21.39 - long time = -1; // modification time (in DOS time)
21.40 - long crc = -1; // crc-32 of entry data
21.41 - long size = -1; // uncompressed size of entry data
21.42 - long csize = -1; // compressed size of entry data
21.43 - int method = -1; // compression method
21.44 - int flag = 0; // general purpose flag
21.45 - byte[] extra; // optional extra field data for entry
21.46 - String comment; // optional comment string for entry
21.47 -
21.48 - /**
21.49 - * Compression method for uncompressed entries.
21.50 - */
21.51 - public static final int STORED = 0;
21.52 -
21.53 - /**
21.54 - * Compression method for compressed (deflated) entries.
21.55 - */
21.56 - public static final int DEFLATED = 8;
21.57 -
21.58 - /**
21.59 - * Creates a new zip entry with the specified name.
21.60 - *
21.61 - * @param name the entry name
21.62 - * @exception NullPointerException if the entry name is null
21.63 - * @exception IllegalArgumentException if the entry name is longer than
21.64 - * 0xFFFF bytes
21.65 - */
21.66 - public ZipEntry(String name) {
21.67 - if (name == null) {
21.68 - throw new NullPointerException();
21.69 - }
21.70 - if (name.length() > 0xFFFF) {
21.71 - throw new IllegalArgumentException("entry name too long");
21.72 - }
21.73 - this.name = name;
21.74 - }
21.75 -
21.76 - /**
21.77 - * Creates a new zip entry with fields taken from the specified
21.78 - * zip entry.
21.79 - * @param e a zip Entry object
21.80 - */
21.81 - public ZipEntry(ZipEntry e) {
21.82 - name = e.name;
21.83 - time = e.time;
21.84 - crc = e.crc;
21.85 - size = e.size;
21.86 - csize = e.csize;
21.87 - method = e.method;
21.88 - flag = e.flag;
21.89 - extra = e.extra;
21.90 - comment = e.comment;
21.91 - }
21.92 -
21.93 - /*
21.94 - * Creates a new un-initialized zip entry
21.95 - */
21.96 - ZipEntry() {}
21.97 -
21.98 - /**
21.99 - * Returns the name of the entry.
21.100 - * @return the name of the entry
21.101 - */
21.102 - public String getName() {
21.103 - return name;
21.104 - }
21.105 -
21.106 - /**
21.107 - * Sets the modification time of the entry.
21.108 - * @param time the entry modification time in number of milliseconds
21.109 - * since the epoch
21.110 - * @see #getTime()
21.111 - */
21.112 - public void setTime(long time) {
21.113 - this.time = javaToDosTime(time);
21.114 - }
21.115 -
21.116 - /**
21.117 - * Returns the modification time of the entry, or -1 if not specified.
21.118 - * @return the modification time of the entry, or -1 if not specified
21.119 - * @see #setTime(long)
21.120 - */
21.121 - public long getTime() {
21.122 - return time != -1 ? dosToJavaTime(time) : -1;
21.123 - }
21.124 -
21.125 - /**
21.126 - * Sets the uncompressed size of the entry data.
21.127 - * @param size the uncompressed size in bytes
21.128 - * @exception IllegalArgumentException if the specified size is less
21.129 - * than 0, is greater than 0xFFFFFFFF when
21.130 - * <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
21.131 - * or is less than 0 when ZIP64 is supported
21.132 - * @see #getSize()
21.133 - */
21.134 - public void setSize(long size) {
21.135 - if (size < 0) {
21.136 - throw new IllegalArgumentException("invalid entry size");
21.137 - }
21.138 - this.size = size;
21.139 - }
21.140 -
21.141 - /**
21.142 - * Returns the uncompressed size of the entry data, or -1 if not known.
21.143 - * @return the uncompressed size of the entry data, or -1 if not known
21.144 - * @see #setSize(long)
21.145 - */
21.146 - public long getSize() {
21.147 - return size;
21.148 - }
21.149 -
21.150 - /**
21.151 - * Returns the size of the compressed entry data, or -1 if not known.
21.152 - * In the case of a stored entry, the compressed size will be the same
21.153 - * as the uncompressed size of the entry.
21.154 - * @return the size of the compressed entry data, or -1 if not known
21.155 - * @see #setCompressedSize(long)
21.156 - */
21.157 - public long getCompressedSize() {
21.158 - return csize;
21.159 - }
21.160 -
21.161 - /**
21.162 - * Sets the size of the compressed entry data.
21.163 - * @param csize the compressed size to set to
21.164 - * @see #getCompressedSize()
21.165 - */
21.166 - public void setCompressedSize(long csize) {
21.167 - this.csize = csize;
21.168 - }
21.169 -
21.170 - /**
21.171 - * Sets the CRC-32 checksum of the uncompressed entry data.
21.172 - * @param crc the CRC-32 value
21.173 - * @exception IllegalArgumentException if the specified CRC-32 value is
21.174 - * less than 0 or greater than 0xFFFFFFFF
21.175 - * @see #getCrc()
21.176 - */
21.177 - public void setCrc(long crc) {
21.178 - if (crc < 0 || crc > 0xFFFFFFFFL) {
21.179 - throw new IllegalArgumentException("invalid entry crc-32");
21.180 - }
21.181 - this.crc = crc;
21.182 - }
21.183 -
21.184 - /**
21.185 - * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
21.186 - * not known.
21.187 - * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
21.188 - * not known
21.189 - * @see #setCrc(long)
21.190 - */
21.191 - public long getCrc() {
21.192 - return crc;
21.193 - }
21.194 -
21.195 - /**
21.196 - * Sets the compression method for the entry.
21.197 - * @param method the compression method, either STORED or DEFLATED
21.198 - * @exception IllegalArgumentException if the specified compression
21.199 - * method is invalid
21.200 - * @see #getMethod()
21.201 - */
21.202 - public void setMethod(int method) {
21.203 - if (method != STORED && method != DEFLATED) {
21.204 - throw new IllegalArgumentException("invalid compression method");
21.205 - }
21.206 - this.method = method;
21.207 - }
21.208 -
21.209 - /**
21.210 - * Returns the compression method of the entry, or -1 if not specified.
21.211 - * @return the compression method of the entry, or -1 if not specified
21.212 - * @see #setMethod(int)
21.213 - */
21.214 - public int getMethod() {
21.215 - return method;
21.216 - }
21.217 -
21.218 - /**
21.219 - * Sets the optional extra field data for the entry.
21.220 - * @param extra the extra field data bytes
21.221 - * @exception IllegalArgumentException if the length of the specified
21.222 - * extra field data is greater than 0xFFFF bytes
21.223 - * @see #getExtra()
21.224 - */
21.225 - public void setExtra(byte[] extra) {
21.226 - if (extra != null && extra.length > 0xFFFF) {
21.227 - throw new IllegalArgumentException("invalid extra field length");
21.228 - }
21.229 - this.extra = extra;
21.230 - }
21.231 -
21.232 - /**
21.233 - * Returns the extra field data for the entry, or null if none.
21.234 - * @return the extra field data for the entry, or null if none
21.235 - * @see #setExtra(byte[])
21.236 - */
21.237 - public byte[] getExtra() {
21.238 - return extra;
21.239 - }
21.240 -
21.241 - /**
21.242 - * Sets the optional comment string for the entry.
21.243 - *
21.244 - * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
21.245 - * specified comment string is greater than 0xFFFF bytes after encoding, only
21.246 - * the first 0xFFFF bytes are output to the ZIP file entry.
21.247 - *
21.248 - * @param comment the comment string
21.249 - *
21.250 - * @see #getComment()
21.251 - */
21.252 - public void setComment(String comment) {
21.253 - this.comment = comment;
21.254 - }
21.255 -
21.256 - /**
21.257 - * Returns the comment string for the entry, or null if none.
21.258 - * @return the comment string for the entry, or null if none
21.259 - * @see #setComment(String)
21.260 - */
21.261 - public String getComment() {
21.262 - return comment;
21.263 - }
21.264 -
21.265 - /**
21.266 - * Returns true if this is a directory entry. A directory entry is
21.267 - * defined to be one whose name ends with a '/'.
21.268 - * @return true if this is a directory entry
21.269 - */
21.270 - public boolean isDirectory() {
21.271 - return name.endsWith("/");
21.272 - }
21.273 -
21.274 - /**
21.275 - * Returns a string representation of the ZIP entry.
21.276 - */
21.277 - public String toString() {
21.278 - return getName();
21.279 - }
21.280 -
21.281 - /*
21.282 - * Converts DOS time to Java time (number of milliseconds since epoch).
21.283 - */
21.284 - private static long dosToJavaTime(long dtime) {
21.285 - return dtime;
21.286 - /* XXX:
21.287 - Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
21.288 - (int)(((dtime >> 21) & 0x0f) - 1),
21.289 - (int)((dtime >> 16) & 0x1f),
21.290 - (int)((dtime >> 11) & 0x1f),
21.291 - (int)((dtime >> 5) & 0x3f),
21.292 - (int)((dtime << 1) & 0x3e));
21.293 - return d.getTime();
21.294 - */
21.295 - }
21.296 -
21.297 - /*
21.298 - * Converts Java time to DOS time.
21.299 - */
21.300 - private static long javaToDosTime(long time) {
21.301 - return time;
21.302 - /* XXX:
21.303 - Date d = new Date(time);
21.304 - int year = d.getYear() + 1900;
21.305 - if (year < 1980) {
21.306 - return (1 << 21) | (1 << 16);
21.307 - }
21.308 - return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
21.309 - d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
21.310 - d.getSeconds() >> 1;
21.311 - */
21.312 - }
21.313 -
21.314 - /**
21.315 - * Returns the hash code value for this entry.
21.316 - */
21.317 - public int hashCode() {
21.318 - return name.hashCode();
21.319 - }
21.320 -
21.321 - /**
21.322 - * Returns a copy of this entry.
21.323 - */
21.324 - public Object clone() {
21.325 - try {
21.326 - ZipEntry e = (ZipEntry)super.clone();
21.327 - e.extra = (extra == null) ? null : extra.clone();
21.328 - return e;
21.329 - } catch (CloneNotSupportedException e) {
21.330 - // This should never happen, since we are Cloneable
21.331 - throw new IllegalStateException();
21.332 - }
21.333 - }
21.334 -}
22.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipException.java Tue May 06 17:46:47 2014 +0200
22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
22.3 @@ -1,60 +0,0 @@
22.4 -/*
22.5 - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
22.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22.7 - *
22.8 - * This code is free software; you can redistribute it and/or modify it
22.9 - * under the terms of the GNU General Public License version 2 only, as
22.10 - * published by the Free Software Foundation. Oracle designates this
22.11 - * particular file as subject to the "Classpath" exception as provided
22.12 - * by Oracle in the LICENSE file that accompanied this code.
22.13 - *
22.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
22.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22.17 - * version 2 for more details (a copy is included in the LICENSE file that
22.18 - * accompanied this code).
22.19 - *
22.20 - * You should have received a copy of the GNU General Public License version
22.21 - * 2 along with this work; if not, write to the Free Software Foundation,
22.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22.23 - *
22.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22.25 - * or visit www.oracle.com if you need additional information or have any
22.26 - * questions.
22.27 - */
22.28 -
22.29 -package java.util.zip;
22.30 -
22.31 -import java.io.IOException;
22.32 -
22.33 -/**
22.34 - * Signals that a Zip exception of some sort has occurred.
22.35 - *
22.36 - * @author unascribed
22.37 - * @see java.io.IOException
22.38 - * @since JDK1.0
22.39 - */
22.40 -
22.41 -public
22.42 -class ZipException extends IOException {
22.43 - private static final long serialVersionUID = 8000196834066748623L;
22.44 -
22.45 - /**
22.46 - * Constructs a <code>ZipException</code> with <code>null</code>
22.47 - * as its error detail message.
22.48 - */
22.49 - public ZipException() {
22.50 - super();
22.51 - }
22.52 -
22.53 - /**
22.54 - * Constructs a <code>ZipException</code> with the specified detail
22.55 - * message.
22.56 - *
22.57 - * @param s the detail message.
22.58 - */
22.59 -
22.60 - public ZipException(String s) {
22.61 - super(s);
22.62 - }
22.63 -}
23.1 --- a/rt/emul/mini/src/main/java/java/util/zip/ZipInputStream.java Tue May 06 17:46:47 2014 +0200
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,194 +0,0 @@
23.4 -/*
23.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
23.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23.7 - *
23.8 - * This code is free software; you can redistribute it and/or modify it
23.9 - * under the terms of the GNU General Public License version 2 only, as
23.10 - * published by the Free Software Foundation. Oracle designates this
23.11 - * particular file as subject to the "Classpath" exception as provided
23.12 - * by Oracle in the LICENSE file that accompanied this code.
23.13 - *
23.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
23.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23.17 - * version 2 for more details (a copy is included in the LICENSE file that
23.18 - * accompanied this code).
23.19 - *
23.20 - * You should have received a copy of the GNU General Public License version
23.21 - * 2 along with this work; if not, write to the Free Software Foundation,
23.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23.23 - *
23.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23.25 - * or visit www.oracle.com if you need additional information or have any
23.26 - * questions.
23.27 - */
23.28 -
23.29 -package java.util.zip;
23.30 -
23.31 -import java.io.InputStream;
23.32 -import java.io.IOException;
23.33 -
23.34 -/**
23.35 - * This class implements an input stream filter for reading files in the
23.36 - * ZIP file format. Includes support for both compressed and uncompressed
23.37 - * entries.
23.38 - *
23.39 - * @author David Connelly
23.40 - */
23.41 -public
23.42 -class ZipInputStream extends InflaterInputStream implements ZipConstants {
23.43 - private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
23.44 -
23.45 - /**
23.46 - * Creates a new ZIP input stream.
23.47 - *
23.48 - * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
23.49 - * decode the entry names.
23.50 - *
23.51 - * @param in the actual input stream
23.52 - */
23.53 - public ZipInputStream(InputStream in) {
23.54 - super(in);
23.55 - impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
23.56 - }
23.57 -
23.58 - /**
23.59 - * Creates a new ZIP input stream.
23.60 - *
23.61 - * @param in the actual input stream
23.62 - *
23.63 - * @param charset
23.64 - * The {@linkplain java.nio.charset.Charset charset} to be
23.65 - * used to decode the ZIP entry name (ignored if the
23.66 - * <a href="package-summary.html#lang_encoding"> language
23.67 - * encoding bit</a> of the ZIP entry's general purpose bit
23.68 - * flag is set).
23.69 - *
23.70 - * @since 1.7
23.71 - *
23.72 - public ZipInputStream(InputStream in, Charset charset) {
23.73 - super(new PushbackInputStream(in, 512), new Inflater(true), 512);
23.74 - usesDefaultInflater = true;
23.75 - if(in == null) {
23.76 - throw new NullPointerException("in is null");
23.77 - }
23.78 - if (charset == null)
23.79 - throw new NullPointerException("charset is null");
23.80 - this.zc = ZipCoder.get(charset);
23.81 - }
23.82 - */
23.83 -
23.84 - /**
23.85 - * Reads the next ZIP file entry and positions the stream at the
23.86 - * beginning of the entry data.
23.87 - * @return the next ZIP file entry, or null if there are no more entries
23.88 - * @exception ZipException if a ZIP file error has occurred
23.89 - * @exception IOException if an I/O error has occurred
23.90 - */
23.91 - public ZipEntry getNextEntry() throws IOException {
23.92 - return impl.getNextEntry();
23.93 - }
23.94 -
23.95 - /**
23.96 - * Closes the current ZIP entry and positions the stream for reading the
23.97 - * next entry.
23.98 - * @exception ZipException if a ZIP file error has occurred
23.99 - * @exception IOException if an I/O error has occurred
23.100 - */
23.101 - public void closeEntry() throws IOException {
23.102 - impl.closeEntry();
23.103 - }
23.104 -
23.105 - /**
23.106 - * Returns 0 after EOF has reached for the current entry data,
23.107 - * otherwise always return 1.
23.108 - * <p>
23.109 - * Programs should not count on this method to return the actual number
23.110 - * of bytes that could be read without blocking.
23.111 - *
23.112 - * @return 1 before EOF and 0 after EOF has reached for current entry.
23.113 - * @exception IOException if an I/O error occurs.
23.114 - *
23.115 - */
23.116 - public int available() throws IOException {
23.117 - return impl.available();
23.118 - }
23.119 -
23.120 - /**
23.121 - * Reads from the current ZIP entry into an array of bytes.
23.122 - * If <code>len</code> is not zero, the method
23.123 - * blocks until some input is available; otherwise, no
23.124 - * bytes are read and <code>0</code> is returned.
23.125 - * @param b the buffer into which the data is read
23.126 - * @param off the start offset in the destination array <code>b</code>
23.127 - * @param len the maximum number of bytes read
23.128 - * @return the actual number of bytes read, or -1 if the end of the
23.129 - * entry is reached
23.130 - * @exception NullPointerException if <code>b</code> is <code>null</code>.
23.131 - * @exception IndexOutOfBoundsException if <code>off</code> is negative,
23.132 - * <code>len</code> is negative, or <code>len</code> is greater than
23.133 - * <code>b.length - off</code>
23.134 - * @exception ZipException if a ZIP file error has occurred
23.135 - * @exception IOException if an I/O error has occurred
23.136 - */
23.137 - public int read(byte[] b, int off, int len) throws IOException {
23.138 - return impl.read(b, off, len);
23.139 - }
23.140 -
23.141 - /**
23.142 - * Skips specified number of bytes in the current ZIP entry.
23.143 - * @param n the number of bytes to skip
23.144 - * @return the actual number of bytes skipped
23.145 - * @exception ZipException if a ZIP file error has occurred
23.146 - * @exception IOException if an I/O error has occurred
23.147 - * @exception IllegalArgumentException if n < 0
23.148 - */
23.149 - public long skip(long n) throws IOException {
23.150 - return impl.skip(n);
23.151 - }
23.152 -
23.153 - /**
23.154 - * Closes this input stream and releases any system resources associated
23.155 - * with the stream.
23.156 - * @exception IOException if an I/O error has occurred
23.157 - */
23.158 - public void close() throws IOException {
23.159 - impl.close();
23.160 - }
23.161 -
23.162 - /**
23.163 - * Creates a new <code>ZipEntry</code> object for the specified
23.164 - * entry name.
23.165 - *
23.166 - * @param name the ZIP file entry name
23.167 - * @return the ZipEntry just created
23.168 - */
23.169 - protected ZipEntry createZipEntry(String name) {
23.170 - return new ZipEntry(name);
23.171 - }
23.172 -
23.173 - @Override
23.174 - public int read() throws IOException {
23.175 - return impl.read();
23.176 - }
23.177 -
23.178 - @Override
23.179 - public boolean markSupported() {
23.180 - return impl.markSupported();
23.181 - }
23.182 -
23.183 - @Override
23.184 - public void mark(int readlimit) {
23.185 - impl.mark(readlimit);
23.186 - }
23.187 -
23.188 - @Override
23.189 - public void reset() throws IOException {
23.190 - impl.reset();
23.191 - }
23.192 -
23.193 - @Override
23.194 - public int read(byte[] b) throws IOException {
23.195 - return impl.read(b);
23.196 - }
23.197 -}
24.1 --- a/rt/emul/mini/src/main/java/java/util/zip/package-info.java Tue May 06 17:46:47 2014 +0200
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,21 +0,0 @@
24.4 -/**
24.5 - * Back 2 Browser Bytecode Translator
24.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
24.7 - *
24.8 - * This program is free software: you can redistribute it and/or modify
24.9 - * it under the terms of the GNU General Public License as published by
24.10 - * the Free Software Foundation, version 2 of the License.
24.11 - *
24.12 - * This program is distributed in the hope that it will be useful,
24.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
24.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24.15 - * GNU General Public License for more details.
24.16 - *
24.17 - * You should have received a copy of the GNU General Public License
24.18 - * along with this program. Look for COPYING file in the top folder.
24.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
24.20 - */
24.21 -@Exported
24.22 -package java.util.zip;
24.23 -
24.24 -import org.apidesign.bck2brwsr.core.Exported;
25.1 --- a/rt/emul/mini/src/main/java/java/util/zip/package.html Tue May 06 17:46:47 2014 +0200
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,98 +0,0 @@
25.4 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
25.5 -<html>
25.6 -<head>
25.7 -<!--
25.8 -Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
25.9 -DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25.10 -
25.11 -This code is free software; you can redistribute it and/or modify it
25.12 -under the terms of the GNU General Public License version 2 only, as
25.13 -published by the Free Software Foundation. Oracle designates this
25.14 -particular file as subject to the "Classpath" exception as provided
25.15 -by Oracle in the LICENSE file that accompanied this code.
25.16 -
25.17 -This code is distributed in the hope that it will be useful, but WITHOUT
25.18 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25.19 -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25.20 -version 2 for more details (a copy is included in the LICENSE file that
25.21 -accompanied this code).
25.22 -
25.23 -You should have received a copy of the GNU General Public License version
25.24 -2 along with this work; if not, write to the Free Software Foundation,
25.25 -Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25.26 -
25.27 -Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25.28 -or visit www.oracle.com if you need additional information or have any
25.29 -questions.
25.30 --->
25.31 -
25.32 -</head>
25.33 -<body bgcolor="white">
25.34 -
25.35 -Provides classes for reading and writing the standard ZIP and GZIP
25.36 -file formats. Also includes classes for compressing and decompressing
25.37 -data using the DEFLATE compression algorithm, which is used by the
25.38 -ZIP and GZIP file formats. Additionally, there are utility classes
25.39 -for computing the CRC-32 and Adler-32 checksums of arbitrary
25.40 -input streams.
25.41 -
25.42 -
25.43 -<h2>Package Specification</h2>
25.44 -
25.45 -</a>
25.46 -<ul>
25.47 - <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
25.48 - Info-ZIP Application Note 970311
25.49 - </a> - a detailed description of the Info-ZIP format upon which
25.50 - the <code>java.util.zip</code> classes are based.
25.51 -<p>
25.52 - <a name="zip64">
25.53 - <li>An implementation may optionally support the ZIP64(tm) format extensions
25.54 - defined by the
25.55 - <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
25.56 - PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
25.57 - are used to overcome the size limitations of the original ZIP format.
25.58 -<p>
25.59 - <a name="lang_encoding">
25.60 - <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
25.61 - PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
25.62 - encode ZIP entry filename and comment fields using UTF-8.
25.63 -<p>
25.64 - <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
25.65 - ZLIB Compressed Data Format Specification version 3.3</a>
25.66 -
25.67 - <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
25.68 - (RFC 1950)
25.69 -<p>
25.70 - <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
25.71 - DEFLATE Compressed Data Format Specification version 1.3</a>
25.72 -
25.73 - <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
25.74 - (RFC 1951)
25.75 -<p>
25.76 - <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
25.77 - GZIP file format specification version 4.3</a>
25.78 -
25.79 - <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
25.80 - (RFC 1952)
25.81 -<p>
25.82 - <li>CRC-32 checksum is described in RFC 1952 (above)
25.83 -<p>
25.84 - <li>Adler-32 checksum is described in RFC 1950 (above)
25.85 -</ul>
25.86 -
25.87 -
25.88 -<!--
25.89 -<h2>Related Documentation</h2>
25.90 -
25.91 -For overviews, tutorials, examples, guides, and tool documentation, please see:
25.92 -<ul>
25.93 - <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
25.94 -</ul>
25.95 --->
25.96 -
25.97 -@since JDK1.1
25.98 -</body>
25.99 -</html>
25.100 -
25.101 -
26.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java Tue May 06 17:46:47 2014 +0200
26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
26.3 @@ -1,139 +0,0 @@
26.4 -/* -*-mode:java; c-basic-offset:2; -*- */
26.5 -/*
26.6 -Copyright (c) 2000-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 -final class Adler32 implements Checksum {
26.41 -
26.42 - // largest prime smaller than 65536
26.43 - static final private int BASE=65521;
26.44 - // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
26.45 - static final private int NMAX=5552;
26.46 -
26.47 - private long s1=1L;
26.48 - private long s2=0L;
26.49 -
26.50 - public void reset(long init){
26.51 - s1=init&0xffff;
26.52 - s2=(init>>16)&0xffff;
26.53 - }
26.54 -
26.55 - public void reset(){
26.56 - s1=1L;
26.57 - s2=0L;
26.58 - }
26.59 -
26.60 - public long getValue(){
26.61 - return ((s2<<16)|s1);
26.62 - }
26.63 -
26.64 - public void update(byte[] buf, int index, int len){
26.65 -
26.66 - if(len==1){
26.67 - s1+=buf[index++]&0xff; s2+=s1;
26.68 - s1%=BASE;
26.69 - s2%=BASE;
26.70 - return;
26.71 - }
26.72 -
26.73 - int len1 = len/NMAX;
26.74 - int len2 = len%NMAX;
26.75 - while(len1-->0) {
26.76 - int k=NMAX;
26.77 - len-=k;
26.78 - while(k-->0){
26.79 - s1+=buf[index++]&0xff; s2+=s1;
26.80 - }
26.81 - s1%=BASE;
26.82 - s2%=BASE;
26.83 - }
26.84 -
26.85 - int k=len2;
26.86 - len-=k;
26.87 - while(k-->0){
26.88 - s1+=buf[index++]&0xff; s2+=s1;
26.89 - }
26.90 - s1%=BASE;
26.91 - s2%=BASE;
26.92 - }
26.93 -
26.94 - public Adler32 copy(){
26.95 - Adler32 foo = new Adler32();
26.96 - foo.s1 = this.s1;
26.97 - foo.s2 = this.s2;
26.98 - return foo;
26.99 - }
26.100 -
26.101 - // The following logic has come from zlib.1.2.
26.102 - static long combine(long adler1, long adler2, long len2){
26.103 - long BASEL = (long)BASE;
26.104 - long sum1;
26.105 - long sum2;
26.106 - long rem; // unsigned int
26.107 -
26.108 - rem = len2 % BASEL;
26.109 - sum1 = adler1 & 0xffffL;
26.110 - sum2 = rem * sum1;
26.111 - sum2 %= BASEL; // MOD(sum2);
26.112 - sum1 += (adler2 & 0xffffL) + BASEL - 1;
26.113 - sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
26.114 - if (sum1 >= BASEL) sum1 -= BASEL;
26.115 - if (sum1 >= BASEL) sum1 -= BASEL;
26.116 - if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
26.117 - if (sum2 >= BASEL) sum2 -= BASEL;
26.118 - return sum1 | (sum2 << 16);
26.119 - }
26.120 -
26.121 -/*
26.122 - private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
26.123 - public void update(byte[] buf, int index, int len){
26.124 - if(buf==null) {adler.reset();}
26.125 - else{adler.update(buf, index, len);}
26.126 - }
26.127 - public void reset(){
26.128 - adler.reset();
26.129 - }
26.130 - public void reset(long init){
26.131 - if(init==1L){
26.132 - adler.reset();
26.133 - }
26.134 - else{
26.135 - System.err.println("unsupported operation");
26.136 - }
26.137 - }
26.138 - public long getValue(){
26.139 - return adler.getValue();
26.140 - }
26.141 -*/
26.142 -}
27.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Tue May 06 17:46:47 2014 +0200
27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
27.3 @@ -1,181 +0,0 @@
27.4 -/* -*-mode:java; c-basic-offset:2; -*- */
27.5 -/*
27.6 -Copyright (c) 2011 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 CRC32 implements Checksum {
27.43 -
27.44 - /*
27.45 - * The following logic has come from RFC1952.
27.46 - */
27.47 - private int v = 0;
27.48 - private static int[] crc_table = null;
27.49 - static {
27.50 - crc_table = new int[256];
27.51 - for (int n = 0; n < 256; n++) {
27.52 - int c = n;
27.53 - for (int k = 8; --k >= 0; ) {
27.54 - if ((c & 1) != 0)
27.55 - c = 0xedb88320 ^ (c >>> 1);
27.56 - else
27.57 - c = c >>> 1;
27.58 - }
27.59 - crc_table[n] = c;
27.60 - }
27.61 - }
27.62 -
27.63 - public void update (byte[] buf, int index, int len) {
27.64 - int c = ~v;
27.65 - while (--len >= 0)
27.66 - c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
27.67 - v = ~c;
27.68 - }
27.69 -
27.70 - public void reset(){
27.71 - v = 0;
27.72 - }
27.73 -
27.74 - public void reset(long vv){
27.75 - v = (int)(vv&0xffffffffL);
27.76 - }
27.77 -
27.78 - public long getValue(){
27.79 - return (long)(v&0xffffffffL);
27.80 - }
27.81 -
27.82 - // The following logic has come from zlib.1.2.
27.83 - private static final int GF2_DIM = 32;
27.84 - static long combine(long crc1, long crc2, long len2){
27.85 - long row;
27.86 - long[] even = new long[GF2_DIM];
27.87 - long[] odd = new long[GF2_DIM];
27.88 -
27.89 - // degenerate case (also disallow negative lengths)
27.90 - if (len2 <= 0)
27.91 - return crc1;
27.92 -
27.93 - // put operator for one zero bit in odd
27.94 - odd[0] = 0xedb88320L; // CRC-32 polynomial
27.95 - row = 1;
27.96 - for (int n = 1; n < GF2_DIM; n++) {
27.97 - odd[n] = row;
27.98 - row <<= 1;
27.99 - }
27.100 -
27.101 - // put operator for two zero bits in even
27.102 - gf2_matrix_square(even, odd);
27.103 -
27.104 - // put operator for four zero bits in odd
27.105 - gf2_matrix_square(odd, even);
27.106 -
27.107 - // apply len2 zeros to crc1 (first square will put the operator for one
27.108 - // zero byte, eight zero bits, in even)
27.109 - do {
27.110 - // apply zeros operator for this bit of len2
27.111 - gf2_matrix_square(even, odd);
27.112 - if ((len2 & 1)!=0)
27.113 - crc1 = gf2_matrix_times(even, crc1);
27.114 - len2 >>= 1;
27.115 -
27.116 - // if no more bits set, then done
27.117 - if (len2 == 0)
27.118 - break;
27.119 -
27.120 - // another iteration of the loop with odd and even swapped
27.121 - gf2_matrix_square(odd, even);
27.122 - if ((len2 & 1)!=0)
27.123 - crc1 = gf2_matrix_times(odd, crc1);
27.124 - len2 >>= 1;
27.125 -
27.126 - // if no more bits set, then done
27.127 - } while (len2 != 0);
27.128 -
27.129 - /* return combined crc */
27.130 - crc1 ^= crc2;
27.131 - return crc1;
27.132 - }
27.133 -
27.134 - private static long gf2_matrix_times(long[] mat, long vec){
27.135 - long sum = 0;
27.136 - int index = 0;
27.137 - while (vec!=0) {
27.138 - if ((vec & 1)!=0)
27.139 - sum ^= mat[index];
27.140 - vec >>= 1;
27.141 - index++;
27.142 - }
27.143 - return sum;
27.144 - }
27.145 -
27.146 - static final void gf2_matrix_square(long[] square, long[] mat) {
27.147 - for (int n = 0; n < GF2_DIM; n++)
27.148 - square[n] = gf2_matrix_times(mat, mat[n]);
27.149 - }
27.150 -
27.151 - /*
27.152 - private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
27.153 -
27.154 - public void update(byte[] buf, int index, int len){
27.155 - if(buf==null) {crc32.reset();}
27.156 - else{crc32.update(buf, index, len);}
27.157 - }
27.158 - public void reset(){
27.159 - crc32.reset();
27.160 - }
27.161 - public void reset(long init){
27.162 - if(init==0L){
27.163 - crc32.reset();
27.164 - }
27.165 - else{
27.166 - System.err.println("unsupported operation");
27.167 - }
27.168 - }
27.169 - public long getValue(){
27.170 - return crc32.getValue();
27.171 - }
27.172 -*/
27.173 - public CRC32 copy(){
27.174 - CRC32 foo = new CRC32();
27.175 - foo.v = this.v;
27.176 - return foo;
27.177 - }
27.178 -
27.179 - public static int[] getCRC32Table(){
27.180 - int[] tmp = new int[crc_table.length];
27.181 - System.arraycopy(crc_table, 0, tmp, 0, tmp.length);
27.182 - return tmp;
27.183 - }
27.184 -}
28.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java Tue May 06 17:46:47 2014 +0200
28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
28.3 @@ -1,43 +0,0 @@
28.4 -/* -*-mode:java; c-basic-offset:2; -*- */
28.5 -/*
28.6 -Copyright (c) 2011 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 -interface Checksum {
28.41 - void update(byte[] buf, int index, int len);
28.42 - void reset();
28.43 - void reset(long init);
28.44 - long getValue();
28.45 - Checksum copy();
28.46 -}
29.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Tue May 06 17:46:47 2014 +0200
29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
29.3 @@ -1,175 +0,0 @@
29.4 -/*
29.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
29.6 - *
29.7 - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
29.8 - *
29.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
29.10 - * Other names may be trademarks of their respective owners.
29.11 - *
29.12 - * The contents of this file are subject to the terms of either the GNU
29.13 - * General Public License Version 2 only ("GPL") or the Common
29.14 - * Development and Distribution License("CDDL") (collectively, the
29.15 - * "License"). You may not use this file except in compliance with the
29.16 - * License. You can obtain a copy of the License at
29.17 - * http://www.netbeans.org/cddl-gplv2.html
29.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
29.19 - * specific language governing permissions and limitations under the
29.20 - * License. When distributing the software, include this License Header
29.21 - * Notice in each file and include the License file at
29.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
29.23 - * particular file as subject to the "Classpath" exception as provided
29.24 - * by Oracle in the GPL Version 2 section of the License file that
29.25 - * accompanied this code. If applicable, add the following below the
29.26 - * License Header, with the fields enclosed by brackets [] replaced by
29.27 - * your own identifying information:
29.28 - * "Portions Copyrighted [year] [name of copyright owner]"
29.29 - *
29.30 - * Contributor(s):
29.31 - *
29.32 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
29.33 - */
29.34 -package org.apidesign.bck2brwsr.emul.zip;
29.35 -
29.36 -import java.io.ByteArrayInputStream;
29.37 -import java.io.IOException;
29.38 -import java.io.InputStream;
29.39 -import java.util.zip.ZipEntry;
29.40 -import java.util.zip.ZipInputStream;
29.41 -
29.42 -/**
29.43 - *
29.44 - * @author Tomas Zezula
29.45 - */
29.46 -public final class FastJar {
29.47 - private final byte[] arr;
29.48 -
29.49 - public FastJar(byte[] arr) {
29.50 - this.arr = arr;
29.51 - }
29.52 -
29.53 -
29.54 - private static final int GIVE_UP = 1<<16;
29.55 -
29.56 - public static final class Entry {
29.57 -
29.58 - public final String name;
29.59 - final long offset;
29.60 - private final long dosTime;
29.61 -
29.62 - Entry (String name, long offset, long time) {
29.63 - assert name != null;
29.64 - this.name = name;
29.65 - this.offset = offset;
29.66 - this.dosTime = time;
29.67 - }
29.68 -/*
29.69 - public long getTime () {
29.70 - Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
29.71 - (int)(((dosTime >> 21) & 0x0f) - 1),
29.72 - (int)((dosTime >> 16) & 0x1f),
29.73 - (int)((dosTime >> 11) & 0x1f),
29.74 - (int)((dosTime >> 5) & 0x3f),
29.75 - (int)((dosTime << 1) & 0x3e));
29.76 - return d.getTime();
29.77 - }
29.78 - */
29.79 - }
29.80 -
29.81 - public InputStream getInputStream (final Entry e) throws IOException {
29.82 - return getInputStream(arr, e.offset);
29.83 - }
29.84 -
29.85 - private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
29.86 - ByteArrayInputStream is = new ByteArrayInputStream(arr);
29.87 - is.skip(offset);
29.88 - ZipInputStream in = new ZipInputStream (is);
29.89 - ZipEntry e = in.getNextEntry();
29.90 - if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
29.91 - int cp = arr.length - is.available();
29.92 - return new ByteArrayInputStream(arr, cp, (int)e.getSize());
29.93 - }
29.94 - return in;
29.95 - }
29.96 -
29.97 - public Entry[] list() throws IOException {
29.98 - final int size = arr.length;
29.99 -
29.100 - int at = size - ZipInputStream.ENDHDR;
29.101 -
29.102 - byte[] data = new byte[ZipInputStream.ENDHDR];
29.103 - int giveup = 0;
29.104 -
29.105 - do {
29.106 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
29.107 - at--;
29.108 - giveup++;
29.109 - if (giveup > GIVE_UP) {
29.110 - throw new IOException ();
29.111 - }
29.112 - } while (getsig(data) != ZipInputStream.ENDSIG);
29.113 -
29.114 -
29.115 - final long censize = endsiz(data);
29.116 - final long cenoff = endoff(data);
29.117 - at = (int) cenoff;
29.118 -
29.119 - Entry[] result = new Entry[0];
29.120 - int cenread = 0;
29.121 - data = new byte[ZipInputStream.CENHDR];
29.122 - while (cenread < censize) {
29.123 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
29.124 - at += data.length;
29.125 - if (getsig(data) != ZipInputStream.CENSIG) {
29.126 - throw new IOException("No central table"); //NOI18N
29.127 - }
29.128 - int cennam = cennam(data);
29.129 - int cenext = cenext(data);
29.130 - int cencom = cencom(data);
29.131 - long lhoff = cenoff(data);
29.132 - long centim = centim(data);
29.133 - String name = new String(arr, at, cennam, "UTF-8");
29.134 - at += cennam;
29.135 - int seekby = cenext+cencom;
29.136 - int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
29.137 - cenread+=cendatalen;
29.138 - result = addEntry(result, new Entry(name,lhoff, centim));
29.139 - at += seekby;
29.140 - }
29.141 - return result;
29.142 - }
29.143 -
29.144 - private Entry[] addEntry(Entry[] result, Entry entry) {
29.145 - Entry[] e = new Entry[result.length + 1];
29.146 - e[result.length] = entry;
29.147 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(result, 0, e, 0, result.length);
29.148 - return e;
29.149 - }
29.150 -
29.151 - private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
29.152 - private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
29.153 - private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
29.154 - private static final long cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
29.155 - private static final long censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
29.156 - private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
29.157 - private static final int cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
29.158 - private static final int cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
29.159 - private static final int cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
29.160 - private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
29.161 - private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
29.162 - private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
29.163 - private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
29.164 - private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
29.165 -
29.166 - private static final int get16(final byte[] b, int off) throws IOException {
29.167 - final int b1 = b[off];
29.168 - final int b2 = b[off+1];
29.169 - return (b1 & 0xff) | ((b2 & 0xff) << 8);
29.170 - }
29.171 -
29.172 - private static final long get32(final byte[] b, int off) throws IOException {
29.173 - final int s1 = get16(b, off);
29.174 - final int s2 = get16(b, off+2);
29.175 - return s1 | ((long)s2 << 16);
29.176 - }
29.177 -
29.178 -}
30.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Tue May 06 17:46:47 2014 +0200
30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
30.3 @@ -1,215 +0,0 @@
30.4 -/* -*-mode:java; c-basic-offset:2; -*- */
30.5 -/*
30.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
30.7 -
30.8 -Redistribution and use in source and binary forms, with or without
30.9 -modification, are permitted provided that the following conditions are met:
30.10 -
30.11 - 1. Redistributions of source code must retain the above copyright notice,
30.12 - this list of conditions and the following disclaimer.
30.13 -
30.14 - 2. Redistributions in binary form must reproduce the above copyright
30.15 - notice, this list of conditions and the following disclaimer in
30.16 - the documentation and/or other materials provided with the distribution.
30.17 -
30.18 - 3. The names of the authors may not be used to endorse or promote products
30.19 - derived from this software without specific prior written permission.
30.20 -
30.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
30.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
30.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
30.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
30.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30.31 - */
30.32 -/*
30.33 - * This program is based on zlib-1.1.3, so all credit should go authors
30.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
30.35 - * and contributors of zlib.
30.36 - */
30.37 -
30.38 -package org.apidesign.bck2brwsr.emul.zip;
30.39 -
30.40 -import org.apidesign.bck2brwsr.emul.lang.System;
30.41 -import java.io.UnsupportedEncodingException;
30.42 -
30.43 -/**
30.44 - * @see "http://www.ietf.org/rfc/rfc1952.txt"
30.45 - */
30.46 -final class GZIPHeader implements Cloneable {
30.47 -
30.48 - public static final byte OS_MSDOS = (byte) 0x00;
30.49 - public static final byte OS_AMIGA = (byte) 0x01;
30.50 - public static final byte OS_VMS = (byte) 0x02;
30.51 - public static final byte OS_UNIX = (byte) 0x03;
30.52 - public static final byte OS_ATARI = (byte) 0x05;
30.53 - public static final byte OS_OS2 = (byte) 0x06;
30.54 - public static final byte OS_MACOS = (byte) 0x07;
30.55 - public static final byte OS_TOPS20 = (byte) 0x0a;
30.56 - public static final byte OS_WIN32 = (byte) 0x0b;
30.57 - public static final byte OS_VMCMS = (byte) 0x04;
30.58 - public static final byte OS_ZSYSTEM = (byte) 0x08;
30.59 - public static final byte OS_CPM = (byte) 0x09;
30.60 - public static final byte OS_QDOS = (byte) 0x0c;
30.61 - public static final byte OS_RISCOS = (byte) 0x0d;
30.62 - public static final byte OS_UNKNOWN = (byte) 0xff;
30.63 -
30.64 - boolean text = false;
30.65 - private boolean fhcrc = false;
30.66 - long time;
30.67 - int xflags;
30.68 - int os = 255;
30.69 - byte[] extra;
30.70 - byte[] name;
30.71 - byte[] comment;
30.72 - int hcrc;
30.73 - long crc;
30.74 - boolean done = false;
30.75 - long mtime = 0;
30.76 -
30.77 - public void setModifiedTime(long mtime) {
30.78 - this.mtime = mtime;
30.79 - }
30.80 -
30.81 - public long getModifiedTime() {
30.82 - return mtime;
30.83 - }
30.84 -
30.85 - public void setOS(int os) {
30.86 - if((0<=os && os <=13) || os==255)
30.87 - this.os=os;
30.88 - else
30.89 - throw new IllegalArgumentException("os: "+os);
30.90 - }
30.91 -
30.92 - public int getOS(){
30.93 - return os;
30.94 - }
30.95 -
30.96 - public void setName(String name) {
30.97 - try{
30.98 - this.name=name.getBytes("ISO-8859-1");
30.99 - }
30.100 - catch(UnsupportedEncodingException e){
30.101 - throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
30.102 - }
30.103 - }
30.104 -
30.105 - public String getName(){
30.106 - if(name==null) return "";
30.107 - try {
30.108 - return new String(name, "ISO-8859-1");
30.109 - }
30.110 - catch (UnsupportedEncodingException e) {
30.111 - throw new IllegalArgumentException(e.toString());
30.112 - }
30.113 - }
30.114 -
30.115 - public void setComment(String comment) {
30.116 - try{
30.117 - this.comment=comment.getBytes("ISO-8859-1");
30.118 - }
30.119 - catch(UnsupportedEncodingException e){
30.120 - throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
30.121 - }
30.122 - }
30.123 -
30.124 - public String getComment(){
30.125 - if(comment==null) return "";
30.126 - try {
30.127 - return new String(comment, "ISO-8859-1");
30.128 - }
30.129 - catch (UnsupportedEncodingException e) {
30.130 - throw new IllegalArgumentException(e.toString());
30.131 - }
30.132 - }
30.133 -
30.134 - public void setCRC(long crc){
30.135 - this.crc = crc;
30.136 - }
30.137 -
30.138 - public long getCRC(){
30.139 - return crc;
30.140 - }
30.141 -/*
30.142 - void put(Deflate d){
30.143 - int flag = 0;
30.144 - if(text){
30.145 - flag |= 1; // FTEXT
30.146 - }
30.147 - if(fhcrc){
30.148 - flag |= 2; // FHCRC
30.149 - }
30.150 - if(extra!=null){
30.151 - flag |= 4; // FEXTRA
30.152 - }
30.153 - if(name!=null){
30.154 - flag |= 8; // FNAME
30.155 - }
30.156 - if(comment!=null){
30.157 - flag |= 16; // FCOMMENT
30.158 - }
30.159 - int xfl = 0;
30.160 - if(d.level == JZlib.Z_BEST_SPEED){
30.161 - xfl |= 4;
30.162 - }
30.163 - else if (d.level == JZlib.Z_BEST_COMPRESSION){
30.164 - xfl |= 2;
30.165 - }
30.166 -
30.167 - d.put_short((short)0x8b1f); // ID1 ID2
30.168 - d.put_byte((byte)8); // CM(Compression Method)
30.169 - d.put_byte((byte)flag);
30.170 - d.put_byte((byte)mtime);
30.171 - d.put_byte((byte)(mtime>>8));
30.172 - d.put_byte((byte)(mtime>>16));
30.173 - d.put_byte((byte)(mtime>>24));
30.174 - d.put_byte((byte)xfl);
30.175 - d.put_byte((byte)os);
30.176 -
30.177 - if(extra!=null){
30.178 - d.put_byte((byte)extra.length);
30.179 - d.put_byte((byte)(extra.length>>8));
30.180 - d.put_byte(extra, 0, extra.length);
30.181 - }
30.182 -
30.183 - if(name!=null){
30.184 - d.put_byte(name, 0, name.length);
30.185 - d.put_byte((byte)0);
30.186 - }
30.187 -
30.188 - if(comment!=null){
30.189 - d.put_byte(comment, 0, comment.length);
30.190 - d.put_byte((byte)0);
30.191 - }
30.192 - }
30.193 -*/
30.194 - @Override
30.195 - public Object clone() throws CloneNotSupportedException {
30.196 - GZIPHeader gheader = (GZIPHeader)super.clone();
30.197 - byte[] tmp;
30.198 - if(gheader.extra!=null){
30.199 - tmp=new byte[gheader.extra.length];
30.200 - System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
30.201 - gheader.extra = tmp;
30.202 - }
30.203 -
30.204 - if(gheader.name!=null){
30.205 - tmp=new byte[gheader.name.length];
30.206 - System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
30.207 - gheader.name = tmp;
30.208 - }
30.209 -
30.210 - if(gheader.comment!=null){
30.211 - tmp=new byte[gheader.comment.length];
30.212 - System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
30.213 - gheader.comment = tmp;
30.214 - }
30.215 -
30.216 - return gheader;
30.217 - }
30.218 -}
31.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Tue May 06 17:46:47 2014 +0200
31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
31.3 @@ -1,616 +0,0 @@
31.4 -/* -*-mode:java; c-basic-offset:2; -*- */
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 -import org.apidesign.bck2brwsr.emul.lang.System;
31.41 -
31.42 -final class InfBlocks{
31.43 - static final private int MANY=1440;
31.44 -
31.45 - // And'ing with mask[n] masks the lower n bits
31.46 - static final private int[] inflate_mask = {
31.47 - 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
31.48 - 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
31.49 - 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
31.50 - 0x00007fff, 0x0000ffff
31.51 - };
31.52 -
31.53 - // Table for deflate from PKZIP's appnote.txt.
31.54 - static final int[] border = { // Order of the bit length code lengths
31.55 - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
31.56 - };
31.57 -
31.58 - static final private int Z_OK=0;
31.59 - static final private int Z_STREAM_END=1;
31.60 - static final private int Z_NEED_DICT=2;
31.61 - static final private int Z_ERRNO=-1;
31.62 - static final private int Z_STREAM_ERROR=-2;
31.63 - static final private int Z_DATA_ERROR=-3;
31.64 - static final private int Z_MEM_ERROR=-4;
31.65 - static final private int Z_BUF_ERROR=-5;
31.66 - static final private int Z_VERSION_ERROR=-6;
31.67 -
31.68 - static final private int TYPE=0; // get type bits (3, including end bit)
31.69 - static final private int LENS=1; // get lengths for stored
31.70 - static final private int STORED=2;// processing stored block
31.71 - static final private int TABLE=3; // get table lengths
31.72 - static final private int BTREE=4; // get bit lengths tree for a dynamic block
31.73 - static final private int DTREE=5; // get length, distance trees for a dynamic block
31.74 - static final private int CODES=6; // processing fixed or dynamic block
31.75 - static final private int DRY=7; // output remaining window bytes
31.76 - static final private int DONE=8; // finished last block, done
31.77 - static final private int BAD=9; // ot a data error--stuck here
31.78 -
31.79 - int mode; // current inflate_block mode
31.80 -
31.81 - int left; // if STORED, bytes left to copy
31.82 -
31.83 - int table; // table lengths (14 bits)
31.84 - int index; // index into blens (or border)
31.85 - int[] blens; // bit lengths of codes
31.86 - int[] bb=new int[1]; // bit length tree depth
31.87 - int[] tb=new int[1]; // bit length decoding tree
31.88 -
31.89 - int[] bl=new int[1];
31.90 - int[] bd=new int[1];
31.91 -
31.92 - int[][] tl=new int[1][];
31.93 - int[][] td=new int[1][];
31.94 - int[] tli=new int[1]; // tl_index
31.95 - int[] tdi=new int[1]; // td_index
31.96 -
31.97 - private final InfCodes codes; // if CODES, current state
31.98 -
31.99 - int last; // true if this block is the last block
31.100 -
31.101 - // mode independent information
31.102 - int bitk; // bits in bit buffer
31.103 - int bitb; // bit buffer
31.104 - int[] hufts; // single malloc for tree space
31.105 - byte[] window; // sliding window
31.106 - int end; // one byte after sliding window
31.107 - int read; // window read pointer
31.108 - int write; // window write pointer
31.109 - private boolean check;
31.110 -
31.111 - private final InfTree inftree=new InfTree();
31.112 -
31.113 - private final ZStream z;
31.114 -
31.115 - InfBlocks(ZStream z, int w){
31.116 - this.z=z;
31.117 - this.codes=new InfCodes(this.z, this);
31.118 - hufts=new int[MANY*3];
31.119 - window=new byte[w];
31.120 - end=w;
31.121 - this.check = (z.istate.wrap==0) ? false : true;
31.122 - mode = TYPE;
31.123 - reset();
31.124 - }
31.125 -
31.126 - void reset(){
31.127 - if(mode==BTREE || mode==DTREE){
31.128 - }
31.129 - if(mode==CODES){
31.130 - codes.free(z);
31.131 - }
31.132 - mode=TYPE;
31.133 - bitk=0;
31.134 - bitb=0;
31.135 - read=write=0;
31.136 - if(check){
31.137 - z.adler.reset();
31.138 - }
31.139 - }
31.140 -
31.141 - int proc(int r){
31.142 - int t; // temporary storage
31.143 - int b; // bit buffer
31.144 - int k; // bits in bit buffer
31.145 - int p; // input data pointer
31.146 - int n; // bytes available there
31.147 - int q; // output window write pointer
31.148 - int m; // bytes to end of window or read pointer
31.149 -
31.150 - // copy input/output information to locals (UPDATE macro restores)
31.151 - {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
31.152 - {q=write;m=(int)(q<read?read-q-1:end-q);}
31.153 -
31.154 - // process input based on current state
31.155 - while(true){
31.156 - switch (mode){
31.157 - case TYPE:
31.158 -
31.159 - while(k<(3)){
31.160 - if(n!=0){
31.161 - r=Z_OK;
31.162 - }
31.163 - else{
31.164 - bitb=b; bitk=k;
31.165 - z.avail_in=n;
31.166 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.167 - write=q;
31.168 - return inflate_flush(r);
31.169 - };
31.170 - n--;
31.171 - b|=(z.next_in[p++]&0xff)<<k;
31.172 - k+=8;
31.173 - }
31.174 - t = (int)(b & 7);
31.175 - last = t & 1;
31.176 -
31.177 - switch (t >>> 1){
31.178 - case 0: // stored
31.179 - {b>>>=(3);k-=(3);}
31.180 - t = k & 7; // go to byte boundary
31.181 -
31.182 - {b>>>=(t);k-=(t);}
31.183 - mode = LENS; // get length of stored block
31.184 - break;
31.185 - case 1: // fixed
31.186 - InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
31.187 - codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
31.188 -
31.189 - {b>>>=(3);k-=(3);}
31.190 -
31.191 - mode = CODES;
31.192 - break;
31.193 - case 2: // dynamic
31.194 -
31.195 - {b>>>=(3);k-=(3);}
31.196 -
31.197 - mode = TABLE;
31.198 - break;
31.199 - case 3: // illegal
31.200 -
31.201 - {b>>>=(3);k-=(3);}
31.202 - mode = BAD;
31.203 - z.msg = "invalid block type";
31.204 - r = Z_DATA_ERROR;
31.205 -
31.206 - bitb=b; bitk=k;
31.207 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.208 - write=q;
31.209 - return inflate_flush(r);
31.210 - }
31.211 - break;
31.212 - case LENS:
31.213 -
31.214 - while(k<(32)){
31.215 - if(n!=0){
31.216 - r=Z_OK;
31.217 - }
31.218 - else{
31.219 - bitb=b; bitk=k;
31.220 - z.avail_in=n;
31.221 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.222 - write=q;
31.223 - return inflate_flush(r);
31.224 - };
31.225 - n--;
31.226 - b|=(z.next_in[p++]&0xff)<<k;
31.227 - k+=8;
31.228 - }
31.229 -
31.230 - if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)){
31.231 - mode = BAD;
31.232 - z.msg = "invalid stored block lengths";
31.233 - r = Z_DATA_ERROR;
31.234 -
31.235 - bitb=b; bitk=k;
31.236 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.237 - write=q;
31.238 - return inflate_flush(r);
31.239 - }
31.240 - left = (b & 0xffff);
31.241 - b = k = 0; // dump bits
31.242 - mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
31.243 - break;
31.244 - case STORED:
31.245 - if (n == 0){
31.246 - bitb=b; bitk=k;
31.247 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.248 - write=q;
31.249 - return inflate_flush(r);
31.250 - }
31.251 -
31.252 - if(m==0){
31.253 - if(q==end&&read!=0){
31.254 - q=0; m=(int)(q<read?read-q-1:end-q);
31.255 - }
31.256 - if(m==0){
31.257 - write=q;
31.258 - r=inflate_flush(r);
31.259 - q=write;m=(int)(q<read?read-q-1:end-q);
31.260 - if(q==end&&read!=0){
31.261 - q=0; m=(int)(q<read?read-q-1:end-q);
31.262 - }
31.263 - if(m==0){
31.264 - bitb=b; bitk=k;
31.265 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.266 - write=q;
31.267 - return inflate_flush(r);
31.268 - }
31.269 - }
31.270 - }
31.271 - r=Z_OK;
31.272 -
31.273 - t = left;
31.274 - if(t>n) t = n;
31.275 - if(t>m) t = m;
31.276 - System.arraycopy(z.next_in, p, window, q, t);
31.277 - p += t; n -= t;
31.278 - q += t; m -= t;
31.279 - if ((left -= t) != 0)
31.280 - break;
31.281 - mode = last!=0 ? DRY : TYPE;
31.282 - break;
31.283 - case TABLE:
31.284 -
31.285 - while(k<(14)){
31.286 - if(n!=0){
31.287 - r=Z_OK;
31.288 - }
31.289 - else{
31.290 - bitb=b; bitk=k;
31.291 - z.avail_in=n;
31.292 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.293 - write=q;
31.294 - return inflate_flush(r);
31.295 - };
31.296 - n--;
31.297 - b|=(z.next_in[p++]&0xff)<<k;
31.298 - k+=8;
31.299 - }
31.300 -
31.301 - table = t = (b & 0x3fff);
31.302 - if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
31.303 - {
31.304 - mode = BAD;
31.305 - z.msg = "too many length or distance symbols";
31.306 - r = Z_DATA_ERROR;
31.307 -
31.308 - bitb=b; bitk=k;
31.309 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.310 - write=q;
31.311 - return inflate_flush(r);
31.312 - }
31.313 - t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
31.314 - if(blens==null || blens.length<t){
31.315 - blens=new int[t];
31.316 - }
31.317 - else{
31.318 - for(int i=0; i<t; i++){blens[i]=0;}
31.319 - }
31.320 -
31.321 - {b>>>=(14);k-=(14);}
31.322 -
31.323 - index = 0;
31.324 - mode = BTREE;
31.325 - case BTREE:
31.326 - while (index < 4 + (table >>> 10)){
31.327 - while(k<(3)){
31.328 - if(n!=0){
31.329 - r=Z_OK;
31.330 - }
31.331 - else{
31.332 - bitb=b; bitk=k;
31.333 - z.avail_in=n;
31.334 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.335 - write=q;
31.336 - return inflate_flush(r);
31.337 - };
31.338 - n--;
31.339 - b|=(z.next_in[p++]&0xff)<<k;
31.340 - k+=8;
31.341 - }
31.342 -
31.343 - blens[border[index++]] = b&7;
31.344 -
31.345 - {b>>>=(3);k-=(3);}
31.346 - }
31.347 -
31.348 - while(index < 19){
31.349 - blens[border[index++]] = 0;
31.350 - }
31.351 -
31.352 - bb[0] = 7;
31.353 - t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
31.354 - if (t != Z_OK){
31.355 - r = t;
31.356 - if (r == Z_DATA_ERROR){
31.357 - blens=null;
31.358 - mode = BAD;
31.359 - }
31.360 -
31.361 - bitb=b; bitk=k;
31.362 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.363 - write=q;
31.364 - return inflate_flush(r);
31.365 - }
31.366 -
31.367 - index = 0;
31.368 - mode = DTREE;
31.369 - case DTREE:
31.370 - while (true){
31.371 - t = table;
31.372 - if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
31.373 - break;
31.374 - }
31.375 -
31.376 - int[] h;
31.377 - int i, j, c;
31.378 -
31.379 - t = bb[0];
31.380 -
31.381 - while(k<(t)){
31.382 - if(n!=0){
31.383 - r=Z_OK;
31.384 - }
31.385 - else{
31.386 - bitb=b; bitk=k;
31.387 - z.avail_in=n;
31.388 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.389 - write=q;
31.390 - return inflate_flush(r);
31.391 - };
31.392 - n--;
31.393 - b|=(z.next_in[p++]&0xff)<<k;
31.394 - k+=8;
31.395 - }
31.396 -
31.397 - if(tb[0]==-1){
31.398 - //System.err.println("null...");
31.399 - }
31.400 -
31.401 - t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
31.402 - c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
31.403 -
31.404 - if (c < 16){
31.405 - b>>>=(t);k-=(t);
31.406 - blens[index++] = c;
31.407 - }
31.408 - else { // c == 16..18
31.409 - i = c == 18 ? 7 : c - 14;
31.410 - j = c == 18 ? 11 : 3;
31.411 -
31.412 - while(k<(t+i)){
31.413 - if(n!=0){
31.414 - r=Z_OK;
31.415 - }
31.416 - else{
31.417 - bitb=b; bitk=k;
31.418 - z.avail_in=n;
31.419 - z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.420 - write=q;
31.421 - return inflate_flush(r);
31.422 - };
31.423 - n--;
31.424 - b|=(z.next_in[p++]&0xff)<<k;
31.425 - k+=8;
31.426 - }
31.427 -
31.428 - b>>>=(t);k-=(t);
31.429 -
31.430 - j += (b & inflate_mask[i]);
31.431 -
31.432 - b>>>=(i);k-=(i);
31.433 -
31.434 - i = index;
31.435 - t = table;
31.436 - if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
31.437 - (c == 16 && i < 1)){
31.438 - blens=null;
31.439 - mode = BAD;
31.440 - z.msg = "invalid bit length repeat";
31.441 - r = Z_DATA_ERROR;
31.442 -
31.443 - bitb=b; bitk=k;
31.444 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.445 - write=q;
31.446 - return inflate_flush(r);
31.447 - }
31.448 -
31.449 - c = c == 16 ? blens[i-1] : 0;
31.450 - do{
31.451 - blens[i++] = c;
31.452 - }
31.453 - while (--j!=0);
31.454 - index = i;
31.455 - }
31.456 - }
31.457 -
31.458 - tb[0]=-1;
31.459 - {
31.460 - bl[0] = 9; // must be <= 9 for lookahead assumptions
31.461 - bd[0] = 6; // must be <= 9 for lookahead assumptions
31.462 - t = table;
31.463 - t = inftree.inflate_trees_dynamic(257 + (t & 0x1f),
31.464 - 1 + ((t >> 5) & 0x1f),
31.465 - blens, bl, bd, tli, tdi, hufts, z);
31.466 -
31.467 - if (t != Z_OK){
31.468 - if (t == Z_DATA_ERROR){
31.469 - blens=null;
31.470 - mode = BAD;
31.471 - }
31.472 - r = t;
31.473 -
31.474 - bitb=b; bitk=k;
31.475 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.476 - write=q;
31.477 - return inflate_flush(r);
31.478 - }
31.479 - codes.init(bl[0], bd[0], hufts, tli[0], hufts, tdi[0]);
31.480 - }
31.481 - mode = CODES;
31.482 - case CODES:
31.483 - bitb=b; bitk=k;
31.484 - z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.485 - write=q;
31.486 -
31.487 - if ((r = codes.proc(r)) != Z_STREAM_END){
31.488 - return inflate_flush(r);
31.489 - }
31.490 - r = Z_OK;
31.491 - codes.free(z);
31.492 -
31.493 - p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
31.494 - q=write;m=(int)(q<read?read-q-1:end-q);
31.495 -
31.496 - if (last==0){
31.497 - mode = TYPE;
31.498 - break;
31.499 - }
31.500 - mode = DRY;
31.501 - case DRY:
31.502 - write=q;
31.503 - r=inflate_flush(r);
31.504 - q=write; m=(int)(q<read?read-q-1:end-q);
31.505 - if (read != write){
31.506 - bitb=b; bitk=k;
31.507 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.508 - write=q;
31.509 - return inflate_flush(r);
31.510 - }
31.511 - mode = DONE;
31.512 - case DONE:
31.513 - r = Z_STREAM_END;
31.514 -
31.515 - bitb=b; bitk=k;
31.516 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.517 - write=q;
31.518 - return inflate_flush(r);
31.519 - case BAD:
31.520 - r = Z_DATA_ERROR;
31.521 -
31.522 - bitb=b; bitk=k;
31.523 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.524 - write=q;
31.525 - return inflate_flush(r);
31.526 -
31.527 - default:
31.528 - r = Z_STREAM_ERROR;
31.529 -
31.530 - bitb=b; bitk=k;
31.531 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
31.532 - write=q;
31.533 - return inflate_flush(r);
31.534 - }
31.535 - }
31.536 - }
31.537 -
31.538 - void free(){
31.539 - reset();
31.540 - window=null;
31.541 - hufts=null;
31.542 - //ZFREE(z, s);
31.543 - }
31.544 -
31.545 - void set_dictionary(byte[] d, int start, int n){
31.546 - System.arraycopy(d, start, window, 0, n);
31.547 - read = write = n;
31.548 - }
31.549 -
31.550 - // Returns true if inflate is currently at the end of a block generated
31.551 - // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
31.552 - int sync_point(){
31.553 - return mode == LENS ? 1 : 0;
31.554 - }
31.555 -
31.556 - // copy as much as possible from the sliding window to the output area
31.557 - int inflate_flush(int r){
31.558 - int n;
31.559 - int p;
31.560 - int q;
31.561 -
31.562 - // local copies of source and destination pointers
31.563 - p = z.next_out_index;
31.564 - q = read;
31.565 -
31.566 - // compute number of bytes to copy as far as end of window
31.567 - n = (int)((q <= write ? write : end) - q);
31.568 - if(n > z.avail_out) n = z.avail_out;
31.569 - if(n!=0 && r == Z_BUF_ERROR) r = Z_OK;
31.570 -
31.571 - // update counters
31.572 - z.avail_out -= n;
31.573 - z.total_out += n;
31.574 -
31.575 - // update check information
31.576 - if(check && n>0){
31.577 - z.adler.update(window, q, n);
31.578 - }
31.579 -
31.580 - // copy as far as end of window
31.581 - System.arraycopy(window, q, z.next_out, p, n);
31.582 - p += n;
31.583 - q += n;
31.584 -
31.585 - // see if more to copy at beginning of window
31.586 - if (q == end){
31.587 - // wrap pointers
31.588 - q = 0;
31.589 - if (write == end)
31.590 - write = 0;
31.591 -
31.592 - // compute bytes to copy
31.593 - n = write - q;
31.594 - if (n > z.avail_out) n = z.avail_out;
31.595 - if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
31.596 -
31.597 - // update counters
31.598 - z.avail_out -= n;
31.599 - z.total_out += n;
31.600 -
31.601 - // update check information
31.602 - if(check && n>0){
31.603 - z.adler.update(window, q, n);
31.604 - }
31.605 -
31.606 - // copy
31.607 - System.arraycopy(window, q, z.next_out, p, n);
31.608 - p += n;
31.609 - q += n;
31.610 - }
31.611 -
31.612 - // update pointers
31.613 - z.next_out_index = p;
31.614 - read = q;
31.615 -
31.616 - // done
31.617 - return r;
31.618 - }
31.619 -}
32.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java Tue May 06 17:46:47 2014 +0200
32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
32.3 @@ -1,612 +0,0 @@
32.4 -/* -*-mode:java; c-basic-offset:2; -*- */
32.5 -/*
32.6 -Copyright (c) 2000,2001,2002,2003 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 -final class InfCodes{
32.43 -
32.44 - static final private int[] inflate_mask = {
32.45 - 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
32.46 - 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
32.47 - 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
32.48 - 0x00007fff, 0x0000ffff
32.49 - };
32.50 -
32.51 - static final private int Z_OK=0;
32.52 - static final private int Z_STREAM_END=1;
32.53 - static final private int Z_NEED_DICT=2;
32.54 - static final private int Z_ERRNO=-1;
32.55 - static final private int Z_STREAM_ERROR=-2;
32.56 - static final private int Z_DATA_ERROR=-3;
32.57 - static final private int Z_MEM_ERROR=-4;
32.58 - static final private int Z_BUF_ERROR=-5;
32.59 - static final private int Z_VERSION_ERROR=-6;
32.60 -
32.61 - // waiting for "i:"=input,
32.62 - // "o:"=output,
32.63 - // "x:"=nothing
32.64 - static final private int START=0; // x: set up for LEN
32.65 - static final private int LEN=1; // i: get length/literal/eob next
32.66 - static final private int LENEXT=2; // i: getting length extra (have base)
32.67 - static final private int DIST=3; // i: get distance next
32.68 - static final private int DISTEXT=4;// i: getting distance extra
32.69 - static final private int COPY=5; // o: copying bytes in window, waiting for space
32.70 - static final private int LIT=6; // o: got literal, waiting for output space
32.71 - static final private int WASH=7; // o: got eob, possibly still output waiting
32.72 - static final private int END=8; // x: got eob and all data flushed
32.73 - static final private int BADCODE=9;// x: got error
32.74 -
32.75 - int mode; // current inflate_codes mode
32.76 -
32.77 - // mode dependent information
32.78 - int len;
32.79 -
32.80 - int[] tree; // pointer into tree
32.81 - int tree_index=0;
32.82 - int need; // bits needed
32.83 -
32.84 - int lit;
32.85 -
32.86 - // if EXT or COPY, where and how much
32.87 - int get; // bits to get for extra
32.88 - int dist; // distance back to copy from
32.89 -
32.90 - byte lbits; // ltree bits decoded per branch
32.91 - byte dbits; // dtree bits decoder per branch
32.92 - int[] ltree; // literal/length/eob tree
32.93 - int ltree_index; // literal/length/eob tree
32.94 - int[] dtree; // distance tree
32.95 - int dtree_index; // distance tree
32.96 -
32.97 - private final ZStream z;
32.98 - private final InfBlocks s;
32.99 - InfCodes(ZStream z, InfBlocks s){
32.100 - this.z=z;
32.101 - this.s=s;
32.102 - }
32.103 -
32.104 - void init(int bl, int bd,
32.105 - int[] tl, int tl_index,
32.106 - int[] td, int td_index){
32.107 - mode=START;
32.108 - lbits=(byte)bl;
32.109 - dbits=(byte)bd;
32.110 - ltree=tl;
32.111 - ltree_index=tl_index;
32.112 - dtree = td;
32.113 - dtree_index=td_index;
32.114 - tree=null;
32.115 - }
32.116 -
32.117 - int proc(int r){
32.118 - int j; // temporary storage
32.119 - int[] t; // temporary pointer
32.120 - int tindex; // temporary pointer
32.121 - int e; // extra bits or operation
32.122 - int b=0; // bit buffer
32.123 - int k=0; // bits in bit buffer
32.124 - int p=0; // input data pointer
32.125 - int n; // bytes available there
32.126 - int q; // output window write pointer
32.127 - int m; // bytes to end of window or read pointer
32.128 - int f; // pointer to copy strings from
32.129 -
32.130 - // copy input/output information to locals (UPDATE macro restores)
32.131 - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
32.132 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
32.133 -
32.134 - // process input and output based on current state
32.135 - while (true){
32.136 - switch (mode){
32.137 - // waiting for "i:"=input, "o:"=output, "x:"=nothing
32.138 - case START: // x: set up for LEN
32.139 - if (m >= 258 && n >= 10){
32.140 -
32.141 - s.bitb=b;s.bitk=k;
32.142 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.143 - s.write=q;
32.144 - r = inflate_fast(lbits, dbits,
32.145 - ltree, ltree_index,
32.146 - dtree, dtree_index,
32.147 - s, z);
32.148 -
32.149 - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
32.150 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
32.151 -
32.152 - if (r != Z_OK){
32.153 - mode = r == Z_STREAM_END ? WASH : BADCODE;
32.154 - break;
32.155 - }
32.156 - }
32.157 - need = lbits;
32.158 - tree = ltree;
32.159 - tree_index=ltree_index;
32.160 -
32.161 - mode = LEN;
32.162 - case LEN: // i: get length/literal/eob next
32.163 - j = need;
32.164 -
32.165 - while(k<(j)){
32.166 - if(n!=0)r=Z_OK;
32.167 - else{
32.168 -
32.169 - s.bitb=b;s.bitk=k;
32.170 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.171 - s.write=q;
32.172 - return s.inflate_flush(r);
32.173 - }
32.174 - n--;
32.175 - b|=(z.next_in[p++]&0xff)<<k;
32.176 - k+=8;
32.177 - }
32.178 -
32.179 - tindex=(tree_index+(b&inflate_mask[j]))*3;
32.180 -
32.181 - b>>>=(tree[tindex+1]);
32.182 - k-=(tree[tindex+1]);
32.183 -
32.184 - e=tree[tindex];
32.185 -
32.186 - if(e == 0){ // literal
32.187 - lit = tree[tindex+2];
32.188 - mode = LIT;
32.189 - break;
32.190 - }
32.191 - if((e & 16)!=0 ){ // length
32.192 - get = e & 15;
32.193 - len = tree[tindex+2];
32.194 - mode = LENEXT;
32.195 - break;
32.196 - }
32.197 - if ((e & 64) == 0){ // next table
32.198 - need = e;
32.199 - tree_index = tindex/3+tree[tindex+2];
32.200 - break;
32.201 - }
32.202 - if ((e & 32)!=0){ // end of block
32.203 - mode = WASH;
32.204 - break;
32.205 - }
32.206 - mode = BADCODE; // invalid code
32.207 - z.msg = "invalid literal/length code";
32.208 - r = Z_DATA_ERROR;
32.209 -
32.210 - s.bitb=b;s.bitk=k;
32.211 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.212 - s.write=q;
32.213 - return s.inflate_flush(r);
32.214 -
32.215 - case LENEXT: // i: getting length extra (have base)
32.216 - j = get;
32.217 -
32.218 - while(k<(j)){
32.219 - if(n!=0)r=Z_OK;
32.220 - else{
32.221 -
32.222 - s.bitb=b;s.bitk=k;
32.223 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.224 - s.write=q;
32.225 - return s.inflate_flush(r);
32.226 - }
32.227 - n--; b|=(z.next_in[p++]&0xff)<<k;
32.228 - k+=8;
32.229 - }
32.230 -
32.231 - len += (b & inflate_mask[j]);
32.232 -
32.233 - b>>=j;
32.234 - k-=j;
32.235 -
32.236 - need = dbits;
32.237 - tree = dtree;
32.238 - tree_index=dtree_index;
32.239 - mode = DIST;
32.240 - case DIST: // i: get distance next
32.241 - j = need;
32.242 -
32.243 - while(k<(j)){
32.244 - if(n!=0)r=Z_OK;
32.245 - else{
32.246 -
32.247 - s.bitb=b;s.bitk=k;
32.248 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.249 - s.write=q;
32.250 - return s.inflate_flush(r);
32.251 - }
32.252 - n--; b|=(z.next_in[p++]&0xff)<<k;
32.253 - k+=8;
32.254 - }
32.255 -
32.256 - tindex=(tree_index+(b & inflate_mask[j]))*3;
32.257 -
32.258 - b>>=tree[tindex+1];
32.259 - k-=tree[tindex+1];
32.260 -
32.261 - e = (tree[tindex]);
32.262 - if((e & 16)!=0){ // distance
32.263 - get = e & 15;
32.264 - dist = tree[tindex+2];
32.265 - mode = DISTEXT;
32.266 - break;
32.267 - }
32.268 - if ((e & 64) == 0){ // next table
32.269 - need = e;
32.270 - tree_index = tindex/3 + tree[tindex+2];
32.271 - break;
32.272 - }
32.273 - mode = BADCODE; // invalid code
32.274 - z.msg = "invalid distance code";
32.275 - r = Z_DATA_ERROR;
32.276 -
32.277 - s.bitb=b;s.bitk=k;
32.278 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.279 - s.write=q;
32.280 - return s.inflate_flush(r);
32.281 -
32.282 - case DISTEXT: // i: getting distance extra
32.283 - j = get;
32.284 -
32.285 - while(k<(j)){
32.286 - if(n!=0)r=Z_OK;
32.287 - else{
32.288 -
32.289 - s.bitb=b;s.bitk=k;
32.290 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.291 - s.write=q;
32.292 - return s.inflate_flush(r);
32.293 - }
32.294 - n--; b|=(z.next_in[p++]&0xff)<<k;
32.295 - k+=8;
32.296 - }
32.297 -
32.298 - dist += (b & inflate_mask[j]);
32.299 -
32.300 - b>>=j;
32.301 - k-=j;
32.302 -
32.303 - mode = COPY;
32.304 - case COPY: // o: copying bytes in window, waiting for space
32.305 - f = q - dist;
32.306 - while(f < 0){ // modulo window size-"while" instead
32.307 - f += s.end; // of "if" handles invalid distances
32.308 - }
32.309 - while (len!=0){
32.310 -
32.311 - if(m==0){
32.312 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
32.313 - if(m==0){
32.314 - s.write=q; r=s.inflate_flush(r);
32.315 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
32.316 -
32.317 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
32.318 -
32.319 - if(m==0){
32.320 - s.bitb=b;s.bitk=k;
32.321 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.322 - s.write=q;
32.323 - return s.inflate_flush(r);
32.324 - }
32.325 - }
32.326 - }
32.327 -
32.328 - s.window[q++]=s.window[f++]; m--;
32.329 -
32.330 - if (f == s.end)
32.331 - f = 0;
32.332 - len--;
32.333 - }
32.334 - mode = START;
32.335 - break;
32.336 - case LIT: // o: got literal, waiting for output space
32.337 - if(m==0){
32.338 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
32.339 - if(m==0){
32.340 - s.write=q; r=s.inflate_flush(r);
32.341 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
32.342 -
32.343 - if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
32.344 - if(m==0){
32.345 - s.bitb=b;s.bitk=k;
32.346 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.347 - s.write=q;
32.348 - return s.inflate_flush(r);
32.349 - }
32.350 - }
32.351 - }
32.352 - r=Z_OK;
32.353 -
32.354 - s.window[q++]=(byte)lit; m--;
32.355 -
32.356 - mode = START;
32.357 - break;
32.358 - case WASH: // o: got eob, possibly more output
32.359 - if (k > 7){ // return unused byte, if any
32.360 - k -= 8;
32.361 - n++;
32.362 - p--; // can always return one
32.363 - }
32.364 -
32.365 - s.write=q; r=s.inflate_flush(r);
32.366 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
32.367 -
32.368 - if (s.read != s.write){
32.369 - s.bitb=b;s.bitk=k;
32.370 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.371 - s.write=q;
32.372 - return s.inflate_flush(r);
32.373 - }
32.374 - mode = END;
32.375 - case END:
32.376 - r = Z_STREAM_END;
32.377 - s.bitb=b;s.bitk=k;
32.378 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.379 - s.write=q;
32.380 - return s.inflate_flush(r);
32.381 -
32.382 - case BADCODE: // x: got error
32.383 -
32.384 - r = Z_DATA_ERROR;
32.385 -
32.386 - s.bitb=b;s.bitk=k;
32.387 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.388 - s.write=q;
32.389 - return s.inflate_flush(r);
32.390 -
32.391 - default:
32.392 - r = Z_STREAM_ERROR;
32.393 -
32.394 - s.bitb=b;s.bitk=k;
32.395 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.396 - s.write=q;
32.397 - return s.inflate_flush(r);
32.398 - }
32.399 - }
32.400 - }
32.401 -
32.402 - void free(ZStream z){
32.403 - // ZFREE(z, c);
32.404 - }
32.405 -
32.406 - // Called with number of bytes left to write in window at least 258
32.407 - // (the maximum string length) and number of input bytes available
32.408 - // at least ten. The ten bytes are six bytes for the longest length/
32.409 - // distance pair plus four bytes for overloading the bit buffer.
32.410 -
32.411 - int inflate_fast(int bl, int bd,
32.412 - int[] tl, int tl_index,
32.413 - int[] td, int td_index,
32.414 - InfBlocks s, ZStream z){
32.415 - int t; // temporary pointer
32.416 - int[] tp; // temporary pointer
32.417 - int tp_index; // temporary pointer
32.418 - int e; // extra bits or operation
32.419 - int b; // bit buffer
32.420 - int k; // bits in bit buffer
32.421 - int p; // input data pointer
32.422 - int n; // bytes available there
32.423 - int q; // output window write pointer
32.424 - int m; // bytes to end of window or read pointer
32.425 - int ml; // mask for literal/length tree
32.426 - int md; // mask for distance tree
32.427 - int c; // bytes to copy
32.428 - int d; // distance back to copy from
32.429 - int r; // copy source pointer
32.430 -
32.431 - int tp_index_t_3; // (tp_index+t)*3
32.432 -
32.433 - // load input, output, bit values
32.434 - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
32.435 - q=s.write;m=q<s.read?s.read-q-1:s.end-q;
32.436 -
32.437 - // initialize masks
32.438 - ml = inflate_mask[bl];
32.439 - md = inflate_mask[bd];
32.440 -
32.441 - // do until not enough input or output space for fast loop
32.442 - do { // assume called with m >= 258 && n >= 10
32.443 - // get literal/length code
32.444 - while(k<(20)){ // max bits for literal/length code
32.445 - n--;
32.446 - b|=(z.next_in[p++]&0xff)<<k;k+=8;
32.447 - }
32.448 -
32.449 - t= b&ml;
32.450 - tp=tl;
32.451 - tp_index=tl_index;
32.452 - tp_index_t_3=(tp_index+t)*3;
32.453 - if ((e = tp[tp_index_t_3]) == 0){
32.454 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
32.455 -
32.456 - s.window[q++] = (byte)tp[tp_index_t_3+2];
32.457 - m--;
32.458 - continue;
32.459 - }
32.460 - do {
32.461 -
32.462 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
32.463 -
32.464 - if((e&16)!=0){
32.465 - e &= 15;
32.466 - c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
32.467 -
32.468 - b>>=e; k-=e;
32.469 -
32.470 - // decode distance base of block to copy
32.471 - while(k<(15)){ // max bits for distance code
32.472 - n--;
32.473 - b|=(z.next_in[p++]&0xff)<<k;k+=8;
32.474 - }
32.475 -
32.476 - t= b&md;
32.477 - tp=td;
32.478 - tp_index=td_index;
32.479 - tp_index_t_3=(tp_index+t)*3;
32.480 - e = tp[tp_index_t_3];
32.481 -
32.482 - do {
32.483 -
32.484 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
32.485 -
32.486 - if((e&16)!=0){
32.487 - // get extra bits to add to distance base
32.488 - e &= 15;
32.489 - while(k<(e)){ // get extra bits (up to 13)
32.490 - n--;
32.491 - b|=(z.next_in[p++]&0xff)<<k;k+=8;
32.492 - }
32.493 -
32.494 - d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
32.495 -
32.496 - b>>=(e); k-=(e);
32.497 -
32.498 - // do the copy
32.499 - m -= c;
32.500 - if (q >= d){ // offset before dest
32.501 - // just copy
32.502 - r=q-d;
32.503 - if(q-r>0 && 2>(q-r)){
32.504 - s.window[q++]=s.window[r++]; // minimum count is three,
32.505 - s.window[q++]=s.window[r++]; // so unroll loop a little
32.506 - c-=2;
32.507 - }
32.508 - else{
32.509 - System.arraycopy(s.window, r, s.window, q, 2);
32.510 - q+=2; r+=2; c-=2;
32.511 - }
32.512 - }
32.513 - else{ // else offset after destination
32.514 - r=q-d;
32.515 - do{
32.516 - r+=s.end; // force pointer in window
32.517 - }while(r<0); // covers invalid distances
32.518 - e=s.end-r;
32.519 - if(c>e){ // if source crosses,
32.520 - c-=e; // wrapped copy
32.521 - if(q-r>0 && e>(q-r)){
32.522 - do{s.window[q++] = s.window[r++];}
32.523 - while(--e!=0);
32.524 - }
32.525 - else{
32.526 - System.arraycopy(s.window, r, s.window, q, e);
32.527 - q+=e; r+=e; e=0;
32.528 - }
32.529 - r = 0; // copy rest from start of window
32.530 - }
32.531 -
32.532 - }
32.533 -
32.534 - // copy all or what's left
32.535 - if(q-r>0 && c>(q-r)){
32.536 - do{s.window[q++] = s.window[r++];}
32.537 - while(--c!=0);
32.538 - }
32.539 - else{
32.540 - System.arraycopy(s.window, r, s.window, q, c);
32.541 - q+=c; r+=c; c=0;
32.542 - }
32.543 - break;
32.544 - }
32.545 - else if((e&64)==0){
32.546 - t+=tp[tp_index_t_3+2];
32.547 - t+=(b&inflate_mask[e]);
32.548 - tp_index_t_3=(tp_index+t)*3;
32.549 - e=tp[tp_index_t_3];
32.550 - }
32.551 - else{
32.552 - z.msg = "invalid distance code";
32.553 -
32.554 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
32.555 -
32.556 - s.bitb=b;s.bitk=k;
32.557 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.558 - s.write=q;
32.559 -
32.560 - return Z_DATA_ERROR;
32.561 - }
32.562 - }
32.563 - while(true);
32.564 - break;
32.565 - }
32.566 -
32.567 - if((e&64)==0){
32.568 - t+=tp[tp_index_t_3+2];
32.569 - t+=(b&inflate_mask[e]);
32.570 - tp_index_t_3=(tp_index+t)*3;
32.571 - if((e=tp[tp_index_t_3])==0){
32.572 -
32.573 - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
32.574 -
32.575 - s.window[q++]=(byte)tp[tp_index_t_3+2];
32.576 - m--;
32.577 - break;
32.578 - }
32.579 - }
32.580 - else if((e&32)!=0){
32.581 -
32.582 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
32.583 -
32.584 - s.bitb=b;s.bitk=k;
32.585 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.586 - s.write=q;
32.587 -
32.588 - return Z_STREAM_END;
32.589 - }
32.590 - else{
32.591 - z.msg="invalid literal/length code";
32.592 -
32.593 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
32.594 -
32.595 - s.bitb=b;s.bitk=k;
32.596 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.597 - s.write=q;
32.598 -
32.599 - return Z_DATA_ERROR;
32.600 - }
32.601 - }
32.602 - while(true);
32.603 - }
32.604 - while(m>=258 && n>= 10);
32.605 -
32.606 - // not enough input or output--restore pointers and return
32.607 - c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
32.608 -
32.609 - s.bitb=b;s.bitk=k;
32.610 - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
32.611 - s.write=q;
32.612 -
32.613 - return Z_OK;
32.614 - }
32.615 -}
33.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java Tue May 06 17:46:47 2014 +0200
33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
33.3 @@ -1,520 +0,0 @@
33.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
33.5 -/*
33.6 -Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
33.7 -
33.8 -Redistribution and use in source and binary forms, with or without
33.9 -modification, are permitted provided that the following conditions are met:
33.10 -
33.11 - 1. Redistributions of source code must retain the above copyright notice,
33.12 - this list of conditions and the following disclaimer.
33.13 -
33.14 - 2. Redistributions in binary form must reproduce the above copyright
33.15 - notice, this list of conditions and the following disclaimer in
33.16 - the documentation and/or other materials provided with the distribution.
33.17 -
33.18 - 3. The names of the authors may not be used to endorse or promote products
33.19 - derived from this software without specific prior written permission.
33.20 -
33.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
33.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
33.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
33.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
33.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33.31 - */
33.32 -/*
33.33 - * This program is based on zlib-1.1.3, so all credit should go authors
33.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
33.35 - * and contributors of zlib.
33.36 - */
33.37 -
33.38 -package org.apidesign.bck2brwsr.emul.zip;
33.39 -
33.40 -import org.apidesign.bck2brwsr.emul.lang.System;
33.41 -
33.42 -final class InfTree{
33.43 -
33.44 - static final private int MANY=1440;
33.45 -
33.46 - static final private int Z_OK=0;
33.47 - static final private int Z_STREAM_END=1;
33.48 - static final private int Z_NEED_DICT=2;
33.49 - static final private int Z_ERRNO=-1;
33.50 - static final private int Z_STREAM_ERROR=-2;
33.51 - static final private int Z_DATA_ERROR=-3;
33.52 - static final private int Z_MEM_ERROR=-4;
33.53 - static final private int Z_BUF_ERROR=-5;
33.54 - static final private int Z_VERSION_ERROR=-6;
33.55 -
33.56 - static final int fixed_bl = 9;
33.57 - static final int fixed_bd = 5;
33.58 -
33.59 - static final int[] fixed_tl = {
33.60 - 96,7,256, 0,8,80, 0,8,16, 84,8,115,
33.61 - 82,7,31, 0,8,112, 0,8,48, 0,9,192,
33.62 - 80,7,10, 0,8,96, 0,8,32, 0,9,160,
33.63 - 0,8,0, 0,8,128, 0,8,64, 0,9,224,
33.64 - 80,7,6, 0,8,88, 0,8,24, 0,9,144,
33.65 - 83,7,59, 0,8,120, 0,8,56, 0,9,208,
33.66 - 81,7,17, 0,8,104, 0,8,40, 0,9,176,
33.67 - 0,8,8, 0,8,136, 0,8,72, 0,9,240,
33.68 - 80,7,4, 0,8,84, 0,8,20, 85,8,227,
33.69 - 83,7,43, 0,8,116, 0,8,52, 0,9,200,
33.70 - 81,7,13, 0,8,100, 0,8,36, 0,9,168,
33.71 - 0,8,4, 0,8,132, 0,8,68, 0,9,232,
33.72 - 80,7,8, 0,8,92, 0,8,28, 0,9,152,
33.73 - 84,7,83, 0,8,124, 0,8,60, 0,9,216,
33.74 - 82,7,23, 0,8,108, 0,8,44, 0,9,184,
33.75 - 0,8,12, 0,8,140, 0,8,76, 0,9,248,
33.76 - 80,7,3, 0,8,82, 0,8,18, 85,8,163,
33.77 - 83,7,35, 0,8,114, 0,8,50, 0,9,196,
33.78 - 81,7,11, 0,8,98, 0,8,34, 0,9,164,
33.79 - 0,8,2, 0,8,130, 0,8,66, 0,9,228,
33.80 - 80,7,7, 0,8,90, 0,8,26, 0,9,148,
33.81 - 84,7,67, 0,8,122, 0,8,58, 0,9,212,
33.82 - 82,7,19, 0,8,106, 0,8,42, 0,9,180,
33.83 - 0,8,10, 0,8,138, 0,8,74, 0,9,244,
33.84 - 80,7,5, 0,8,86, 0,8,22, 192,8,0,
33.85 - 83,7,51, 0,8,118, 0,8,54, 0,9,204,
33.86 - 81,7,15, 0,8,102, 0,8,38, 0,9,172,
33.87 - 0,8,6, 0,8,134, 0,8,70, 0,9,236,
33.88 - 80,7,9, 0,8,94, 0,8,30, 0,9,156,
33.89 - 84,7,99, 0,8,126, 0,8,62, 0,9,220,
33.90 - 82,7,27, 0,8,110, 0,8,46, 0,9,188,
33.91 - 0,8,14, 0,8,142, 0,8,78, 0,9,252,
33.92 - 96,7,256, 0,8,81, 0,8,17, 85,8,131,
33.93 - 82,7,31, 0,8,113, 0,8,49, 0,9,194,
33.94 - 80,7,10, 0,8,97, 0,8,33, 0,9,162,
33.95 - 0,8,1, 0,8,129, 0,8,65, 0,9,226,
33.96 - 80,7,6, 0,8,89, 0,8,25, 0,9,146,
33.97 - 83,7,59, 0,8,121, 0,8,57, 0,9,210,
33.98 - 81,7,17, 0,8,105, 0,8,41, 0,9,178,
33.99 - 0,8,9, 0,8,137, 0,8,73, 0,9,242,
33.100 - 80,7,4, 0,8,85, 0,8,21, 80,8,258,
33.101 - 83,7,43, 0,8,117, 0,8,53, 0,9,202,
33.102 - 81,7,13, 0,8,101, 0,8,37, 0,9,170,
33.103 - 0,8,5, 0,8,133, 0,8,69, 0,9,234,
33.104 - 80,7,8, 0,8,93, 0,8,29, 0,9,154,
33.105 - 84,7,83, 0,8,125, 0,8,61, 0,9,218,
33.106 - 82,7,23, 0,8,109, 0,8,45, 0,9,186,
33.107 - 0,8,13, 0,8,141, 0,8,77, 0,9,250,
33.108 - 80,7,3, 0,8,83, 0,8,19, 85,8,195,
33.109 - 83,7,35, 0,8,115, 0,8,51, 0,9,198,
33.110 - 81,7,11, 0,8,99, 0,8,35, 0,9,166,
33.111 - 0,8,3, 0,8,131, 0,8,67, 0,9,230,
33.112 - 80,7,7, 0,8,91, 0,8,27, 0,9,150,
33.113 - 84,7,67, 0,8,123, 0,8,59, 0,9,214,
33.114 - 82,7,19, 0,8,107, 0,8,43, 0,9,182,
33.115 - 0,8,11, 0,8,139, 0,8,75, 0,9,246,
33.116 - 80,7,5, 0,8,87, 0,8,23, 192,8,0,
33.117 - 83,7,51, 0,8,119, 0,8,55, 0,9,206,
33.118 - 81,7,15, 0,8,103, 0,8,39, 0,9,174,
33.119 - 0,8,7, 0,8,135, 0,8,71, 0,9,238,
33.120 - 80,7,9, 0,8,95, 0,8,31, 0,9,158,
33.121 - 84,7,99, 0,8,127, 0,8,63, 0,9,222,
33.122 - 82,7,27, 0,8,111, 0,8,47, 0,9,190,
33.123 - 0,8,15, 0,8,143, 0,8,79, 0,9,254,
33.124 - 96,7,256, 0,8,80, 0,8,16, 84,8,115,
33.125 - 82,7,31, 0,8,112, 0,8,48, 0,9,193,
33.126 -
33.127 - 80,7,10, 0,8,96, 0,8,32, 0,9,161,
33.128 - 0,8,0, 0,8,128, 0,8,64, 0,9,225,
33.129 - 80,7,6, 0,8,88, 0,8,24, 0,9,145,
33.130 - 83,7,59, 0,8,120, 0,8,56, 0,9,209,
33.131 - 81,7,17, 0,8,104, 0,8,40, 0,9,177,
33.132 - 0,8,8, 0,8,136, 0,8,72, 0,9,241,
33.133 - 80,7,4, 0,8,84, 0,8,20, 85,8,227,
33.134 - 83,7,43, 0,8,116, 0,8,52, 0,9,201,
33.135 - 81,7,13, 0,8,100, 0,8,36, 0,9,169,
33.136 - 0,8,4, 0,8,132, 0,8,68, 0,9,233,
33.137 - 80,7,8, 0,8,92, 0,8,28, 0,9,153,
33.138 - 84,7,83, 0,8,124, 0,8,60, 0,9,217,
33.139 - 82,7,23, 0,8,108, 0,8,44, 0,9,185,
33.140 - 0,8,12, 0,8,140, 0,8,76, 0,9,249,
33.141 - 80,7,3, 0,8,82, 0,8,18, 85,8,163,
33.142 - 83,7,35, 0,8,114, 0,8,50, 0,9,197,
33.143 - 81,7,11, 0,8,98, 0,8,34, 0,9,165,
33.144 - 0,8,2, 0,8,130, 0,8,66, 0,9,229,
33.145 - 80,7,7, 0,8,90, 0,8,26, 0,9,149,
33.146 - 84,7,67, 0,8,122, 0,8,58, 0,9,213,
33.147 - 82,7,19, 0,8,106, 0,8,42, 0,9,181,
33.148 - 0,8,10, 0,8,138, 0,8,74, 0,9,245,
33.149 - 80,7,5, 0,8,86, 0,8,22, 192,8,0,
33.150 - 83,7,51, 0,8,118, 0,8,54, 0,9,205,
33.151 - 81,7,15, 0,8,102, 0,8,38, 0,9,173,
33.152 - 0,8,6, 0,8,134, 0,8,70, 0,9,237,
33.153 - 80,7,9, 0,8,94, 0,8,30, 0,9,157,
33.154 - 84,7,99, 0,8,126, 0,8,62, 0,9,221,
33.155 - 82,7,27, 0,8,110, 0,8,46, 0,9,189,
33.156 - 0,8,14, 0,8,142, 0,8,78, 0,9,253,
33.157 - 96,7,256, 0,8,81, 0,8,17, 85,8,131,
33.158 - 82,7,31, 0,8,113, 0,8,49, 0,9,195,
33.159 - 80,7,10, 0,8,97, 0,8,33, 0,9,163,
33.160 - 0,8,1, 0,8,129, 0,8,65, 0,9,227,
33.161 - 80,7,6, 0,8,89, 0,8,25, 0,9,147,
33.162 - 83,7,59, 0,8,121, 0,8,57, 0,9,211,
33.163 - 81,7,17, 0,8,105, 0,8,41, 0,9,179,
33.164 - 0,8,9, 0,8,137, 0,8,73, 0,9,243,
33.165 - 80,7,4, 0,8,85, 0,8,21, 80,8,258,
33.166 - 83,7,43, 0,8,117, 0,8,53, 0,9,203,
33.167 - 81,7,13, 0,8,101, 0,8,37, 0,9,171,
33.168 - 0,8,5, 0,8,133, 0,8,69, 0,9,235,
33.169 - 80,7,8, 0,8,93, 0,8,29, 0,9,155,
33.170 - 84,7,83, 0,8,125, 0,8,61, 0,9,219,
33.171 - 82,7,23, 0,8,109, 0,8,45, 0,9,187,
33.172 - 0,8,13, 0,8,141, 0,8,77, 0,9,251,
33.173 - 80,7,3, 0,8,83, 0,8,19, 85,8,195,
33.174 - 83,7,35, 0,8,115, 0,8,51, 0,9,199,
33.175 - 81,7,11, 0,8,99, 0,8,35, 0,9,167,
33.176 - 0,8,3, 0,8,131, 0,8,67, 0,9,231,
33.177 - 80,7,7, 0,8,91, 0,8,27, 0,9,151,
33.178 - 84,7,67, 0,8,123, 0,8,59, 0,9,215,
33.179 - 82,7,19, 0,8,107, 0,8,43, 0,9,183,
33.180 - 0,8,11, 0,8,139, 0,8,75, 0,9,247,
33.181 - 80,7,5, 0,8,87, 0,8,23, 192,8,0,
33.182 - 83,7,51, 0,8,119, 0,8,55, 0,9,207,
33.183 - 81,7,15, 0,8,103, 0,8,39, 0,9,175,
33.184 - 0,8,7, 0,8,135, 0,8,71, 0,9,239,
33.185 - 80,7,9, 0,8,95, 0,8,31, 0,9,159,
33.186 - 84,7,99, 0,8,127, 0,8,63, 0,9,223,
33.187 - 82,7,27, 0,8,111, 0,8,47, 0,9,191,
33.188 - 0,8,15, 0,8,143, 0,8,79, 0,9,255
33.189 - };
33.190 - static final int[] fixed_td = {
33.191 - 80,5,1, 87,5,257, 83,5,17, 91,5,4097,
33.192 - 81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
33.193 - 80,5,3, 88,5,513, 84,5,33, 92,5,8193,
33.194 - 82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
33.195 - 80,5,2, 87,5,385, 83,5,25, 91,5,6145,
33.196 - 81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
33.197 - 80,5,4, 88,5,769, 84,5,49, 92,5,12289,
33.198 - 82,5,13, 90,5,3073, 86,5,193, 192,5,24577
33.199 - };
33.200 -
33.201 - // Tables for deflate from PKZIP's appnote.txt.
33.202 - static final int[] cplens = { // Copy lengths for literal codes 257..285
33.203 - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
33.204 - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
33.205 - };
33.206 -
33.207 - // see note #13 above about 258
33.208 - static final int[] cplext = { // Extra bits for literal codes 257..285
33.209 - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
33.210 - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
33.211 - };
33.212 -
33.213 - static final int[] cpdist = { // Copy offsets for distance codes 0..29
33.214 - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
33.215 - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
33.216 - 8193, 12289, 16385, 24577
33.217 - };
33.218 -
33.219 - static final int[] cpdext = { // Extra bits for distance codes
33.220 - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
33.221 - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
33.222 - 12, 12, 13, 13};
33.223 -
33.224 - // If BMAX needs to be larger than 16, then h and x[] should be uLong.
33.225 - static final int BMAX=15; // maximum bit length of any code
33.226 -
33.227 - int[] hn = null; // hufts used in space
33.228 - int[] v = null; // work area for huft_build
33.229 - int[] c = null; // bit length count table
33.230 - int[] r = null; // table entry for structure assignment
33.231 - int[] u = null; // table stack
33.232 - int[] x = null; // bit offsets, then code stack
33.233 -
33.234 - private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
33.235 - int bindex,
33.236 - int n, // number of codes (assumed <= 288)
33.237 - int s, // number of simple-valued codes (0..s-1)
33.238 - int[] d, // list of base values for non-simple codes
33.239 - int[] e, // list of extra bits for non-simple codes
33.240 - int[] t, // result: starting table
33.241 - int[] m, // maximum lookup bits, returns actual
33.242 - int[] hp,// space for trees
33.243 - int[] hn,// hufts used in space
33.244 - int[] v // working area: values in order of bit length
33.245 - ){
33.246 - // Given a list of code lengths and a maximum table size, make a set of
33.247 - // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
33.248 - // if the given code set is incomplete (the tables are still built in this
33.249 - // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
33.250 - // lengths), or Z_MEM_ERROR if not enough memory.
33.251 -
33.252 - int a; // counter for codes of length k
33.253 - int f; // i repeats in table every f entries
33.254 - int g; // maximum code length
33.255 - int h; // table level
33.256 - int i; // counter, current code
33.257 - int j; // counter
33.258 - int k; // number of bits in current code
33.259 - int l; // bits per table (returned in m)
33.260 - int mask; // (1 << w) - 1, to avoid cc -O bug on HP
33.261 - int p; // pointer into c[], b[], or v[]
33.262 - int q; // points to current table
33.263 - int w; // bits before this table == (l * h)
33.264 - int xp; // pointer into x
33.265 - int y; // number of dummy codes added
33.266 - int z; // number of entries in current table
33.267 -
33.268 - // Generate counts for each bit length
33.269 -
33.270 - p = 0; i = n;
33.271 - do {
33.272 - c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX
33.273 - }while(i!=0);
33.274 -
33.275 - if(c[0] == n){ // null input--all zero length codes
33.276 - t[0] = -1;
33.277 - m[0] = 0;
33.278 - return Z_OK;
33.279 - }
33.280 -
33.281 - // Find minimum and maximum length, bound *m by those
33.282 - l = m[0];
33.283 - for (j = 1; j <= BMAX; j++)
33.284 - if(c[j]!=0) break;
33.285 - k = j; // minimum code length
33.286 - if(l < j){
33.287 - l = j;
33.288 - }
33.289 - for (i = BMAX; i!=0; i--){
33.290 - if(c[i]!=0) break;
33.291 - }
33.292 - g = i; // maximum code length
33.293 - if(l > i){
33.294 - l = i;
33.295 - }
33.296 - m[0] = l;
33.297 -
33.298 - // Adjust last length count to fill out codes, if needed
33.299 - for (y = 1 << j; j < i; j++, y <<= 1){
33.300 - if ((y -= c[j]) < 0){
33.301 - return Z_DATA_ERROR;
33.302 - }
33.303 - }
33.304 - if ((y -= c[i]) < 0){
33.305 - return Z_DATA_ERROR;
33.306 - }
33.307 - c[i] += y;
33.308 -
33.309 - // Generate starting offsets into the value table for each length
33.310 - x[1] = j = 0;
33.311 - p = 1; xp = 2;
33.312 - while (--i!=0) { // note that i == g from above
33.313 - x[xp] = (j += c[p]);
33.314 - xp++;
33.315 - p++;
33.316 - }
33.317 -
33.318 - // Make a table of values in order of bit lengths
33.319 - i = 0; p = 0;
33.320 - do {
33.321 - if ((j = b[bindex+p]) != 0){
33.322 - v[x[j]++] = i;
33.323 - }
33.324 - p++;
33.325 - }
33.326 - while (++i < n);
33.327 - n = x[g]; // set n to length of v
33.328 -
33.329 - // Generate the Huffman codes and for each, make the table entries
33.330 - x[0] = i = 0; // first Huffman code is zero
33.331 - p = 0; // grab values in bit order
33.332 - h = -1; // no tables yet--level -1
33.333 - w = -l; // bits decoded == (l * h)
33.334 - u[0] = 0; // just to keep compilers happy
33.335 - q = 0; // ditto
33.336 - z = 0; // ditto
33.337 -
33.338 - // go through the bit lengths (k already is bits in shortest code)
33.339 - for (; k <= g; k++){
33.340 - a = c[k];
33.341 - while (a--!=0){
33.342 - // here i is the Huffman code of length k bits for value *p
33.343 - // make tables up to required level
33.344 - while (k > w + l){
33.345 - h++;
33.346 - w += l; // previous table always l bits
33.347 - // compute minimum size table less than or equal to l bits
33.348 - z = g - w;
33.349 - z = (z > l) ? l : z; // table size upper limit
33.350 - if((f=1<<(j=k-w))>a+1){ // try a k-w bit table
33.351 - // too few codes for k-w bit table
33.352 - f -= a + 1; // deduct codes from patterns left
33.353 - xp = k;
33.354 - if(j < z){
33.355 - while (++j < z){ // try smaller tables up to z bits
33.356 - if((f <<= 1) <= c[++xp])
33.357 - break; // enough codes to use up j bits
33.358 - f -= c[xp]; // else deduct codes from patterns
33.359 - }
33.360 - }
33.361 - }
33.362 - z = 1 << j; // table entries for j-bit table
33.363 -
33.364 - // allocate new table
33.365 - if (hn[0] + z > MANY){ // (note: doesn't matter for fixed)
33.366 - return Z_DATA_ERROR; // overflow of MANY
33.367 - }
33.368 - u[h] = q = /*hp+*/ hn[0]; // DEBUG
33.369 - hn[0] += z;
33.370 -
33.371 - // connect to last table, if there is one
33.372 - if(h!=0){
33.373 - x[h]=i; // save pattern for backing up
33.374 - r[0]=(byte)j; // bits in this table
33.375 - r[1]=(byte)l; // bits to dump before this table
33.376 - j=i>>>(w - l);
33.377 - r[2] = (int)(q - u[h-1] - j); // offset to this table
33.378 - System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
33.379 - }
33.380 - else{
33.381 - t[0] = q; // first table is returned result
33.382 - }
33.383 - }
33.384 -
33.385 - // set up table entry in r
33.386 - r[1] = (byte)(k - w);
33.387 - if (p >= n){
33.388 - r[0] = 128 + 64; // out of values--invalid code
33.389 - }
33.390 - else if (v[p] < s){
33.391 - r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
33.392 - r[2] = v[p++]; // simple code is just the value
33.393 - }
33.394 - else{
33.395 - r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
33.396 - r[2]=d[v[p++] - s];
33.397 - }
33.398 -
33.399 - // fill code-like entries with r
33.400 - f=1<<(k-w);
33.401 - for (j=i>>>w;j<z;j+=f){
33.402 - System.arraycopy(r, 0, hp, (q+j)*3, 3);
33.403 - }
33.404 -
33.405 - // backwards increment the k-bit code i
33.406 - for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
33.407 - i ^= j;
33.408 - }
33.409 - i ^= j;
33.410 -
33.411 - // backup over finished tables
33.412 - mask = (1 << w) - 1; // needed on HP, cc -O bug
33.413 - while ((i & mask) != x[h]){
33.414 - h--; // don't need to update q
33.415 - w -= l;
33.416 - mask = (1 << w) - 1;
33.417 - }
33.418 - }
33.419 - }
33.420 - // Return Z_BUF_ERROR if we were given an incomplete table
33.421 - return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
33.422 - }
33.423 -
33.424 - int inflate_trees_bits(int[] c, // 19 code lengths
33.425 - int[] bb, // bits tree desired/actual depth
33.426 - int[] tb, // bits tree result
33.427 - int[] hp, // space for trees
33.428 - ZStream z // for messages
33.429 - ){
33.430 - int result;
33.431 - initWorkArea(19);
33.432 - hn[0]=0;
33.433 - result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
33.434 -
33.435 - if(result == Z_DATA_ERROR){
33.436 - z.msg = "oversubscribed dynamic bit lengths tree";
33.437 - }
33.438 - else if(result == Z_BUF_ERROR || bb[0] == 0){
33.439 - z.msg = "incomplete dynamic bit lengths tree";
33.440 - result = Z_DATA_ERROR;
33.441 - }
33.442 - return result;
33.443 - }
33.444 -
33.445 - int inflate_trees_dynamic(int nl, // number of literal/length codes
33.446 - int nd, // number of distance codes
33.447 - int[] c, // that many (total) code lengths
33.448 - int[] bl, // literal desired/actual bit depth
33.449 - int[] bd, // distance desired/actual bit depth
33.450 - int[] tl, // literal/length tree result
33.451 - int[] td, // distance tree result
33.452 - int[] hp, // space for trees
33.453 - ZStream z // for messages
33.454 - ){
33.455 - int result;
33.456 -
33.457 - // build literal/length tree
33.458 - initWorkArea(288);
33.459 - hn[0]=0;
33.460 - result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
33.461 - if (result != Z_OK || bl[0] == 0){
33.462 - if(result == Z_DATA_ERROR){
33.463 - z.msg = "oversubscribed literal/length tree";
33.464 - }
33.465 - else if (result != Z_MEM_ERROR){
33.466 - z.msg = "incomplete literal/length tree";
33.467 - result = Z_DATA_ERROR;
33.468 - }
33.469 - return result;
33.470 - }
33.471 -
33.472 - // build distance tree
33.473 - initWorkArea(288);
33.474 - result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
33.475 -
33.476 - if (result != Z_OK || (bd[0] == 0 && nl > 257)){
33.477 - if (result == Z_DATA_ERROR){
33.478 - z.msg = "oversubscribed distance tree";
33.479 - }
33.480 - else if (result == Z_BUF_ERROR) {
33.481 - z.msg = "incomplete distance tree";
33.482 - result = Z_DATA_ERROR;
33.483 - }
33.484 - else if (result != Z_MEM_ERROR){
33.485 - z.msg = "empty distance tree with lengths";
33.486 - result = Z_DATA_ERROR;
33.487 - }
33.488 - return result;
33.489 - }
33.490 -
33.491 - return Z_OK;
33.492 - }
33.493 -
33.494 - static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
33.495 - int[] bd, //distance desired/actual bit depth
33.496 - int[][] tl,//literal/length tree result
33.497 - int[][] td,//distance tree result
33.498 - ZStream z //for memory allocation
33.499 - ){
33.500 - bl[0]=fixed_bl;
33.501 - bd[0]=fixed_bd;
33.502 - tl[0]=fixed_tl;
33.503 - td[0]=fixed_td;
33.504 - return Z_OK;
33.505 - }
33.506 -
33.507 - private void initWorkArea(int vsize){
33.508 - if(hn==null){
33.509 - hn=new int[1];
33.510 - v=new int[vsize];
33.511 - c=new int[BMAX+1];
33.512 - r=new int[3];
33.513 - u=new int[BMAX];
33.514 - x=new int[BMAX+1];
33.515 - }
33.516 - if(v.length<vsize){ v=new int[vsize]; }
33.517 - for(int i=0; i<vsize; i++){v[i]=0;}
33.518 - for(int i=0; i<BMAX+1; i++){c[i]=0;}
33.519 - for(int i=0; i<3; i++){r[i]=0;}
33.520 - System.arraycopy(c, 0, u, 0, BMAX);
33.521 - System.arraycopy(c, 0, x, 0, BMAX+1);
33.522 - }
33.523 -}
34.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflate.java Tue May 06 17:46:47 2014 +0200
34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
34.3 @@ -1,727 +0,0 @@
34.4 -/* -*-mode:java; c-basic-offset:2; -*- */
34.5 -/*
34.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
34.7 -
34.8 -Redistribution and use in source and binary forms, with or without
34.9 -modification, are permitted provided that the following conditions are met:
34.10 -
34.11 - 1. Redistributions of source code must retain the above copyright notice,
34.12 - this list of conditions and the following disclaimer.
34.13 -
34.14 - 2. Redistributions in binary form must reproduce the above copyright
34.15 - notice, this list of conditions and the following disclaimer in
34.16 - the documentation and/or other materials provided with the distribution.
34.17 -
34.18 - 3. The names of the authors may not be used to endorse or promote products
34.19 - derived from this software without specific prior written permission.
34.20 -
34.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
34.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
34.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
34.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
34.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34.31 - */
34.32 -/*
34.33 - * This program is based on zlib-1.1.3, so all credit should go authors
34.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
34.35 - * and contributors of zlib.
34.36 - */
34.37 -
34.38 -package org.apidesign.bck2brwsr.emul.zip;
34.39 -
34.40 -import org.apidesign.bck2brwsr.emul.lang.System;
34.41 -
34.42 -final class Inflate{
34.43 -
34.44 - static final private int MAX_WBITS=15; // 32K LZ77 window
34.45 -
34.46 - // preset dictionary flag in zlib header
34.47 - static final private int PRESET_DICT=0x20;
34.48 -
34.49 - static final int Z_NO_FLUSH=0;
34.50 - static final int Z_PARTIAL_FLUSH=1;
34.51 - static final int Z_SYNC_FLUSH=2;
34.52 - static final int Z_FULL_FLUSH=3;
34.53 - static final int Z_FINISH=4;
34.54 -
34.55 - static final private int Z_DEFLATED=8;
34.56 -
34.57 - static final private int Z_OK=0;
34.58 - static final private int Z_STREAM_END=1;
34.59 - static final private int Z_NEED_DICT=2;
34.60 - static final private int Z_ERRNO=-1;
34.61 - static final private int Z_STREAM_ERROR=-2;
34.62 - static final private int Z_DATA_ERROR=-3;
34.63 - static final private int Z_MEM_ERROR=-4;
34.64 - static final private int Z_BUF_ERROR=-5;
34.65 - static final private int Z_VERSION_ERROR=-6;
34.66 -
34.67 - static final private int METHOD=0; // waiting for method byte
34.68 - static final private int FLAG=1; // waiting for flag byte
34.69 - static final private int DICT4=2; // four dictionary check bytes to go
34.70 - static final private int DICT3=3; // three dictionary check bytes to go
34.71 - static final private int DICT2=4; // two dictionary check bytes to go
34.72 - static final private int DICT1=5; // one dictionary check byte to go
34.73 - static final int DICT0=6; // waiting for inflateSetDictionary
34.74 - static final private int BLOCKS=7; // decompressing blocks
34.75 - static final private int CHECK4=8; // four check bytes to go
34.76 - static final private int CHECK3=9; // three check bytes to go
34.77 - static final private int CHECK2=10; // two check bytes to go
34.78 - static final private int CHECK1=11; // one check byte to go
34.79 - static final private int DONE=12; // finished check, done
34.80 - static final private int BAD=13; // got an error--stay here
34.81 -
34.82 - static final private int HEAD=14;
34.83 - static final private int LENGTH=15;
34.84 - static final private int TIME=16;
34.85 - static final private int OS=17;
34.86 - static final private int EXLEN=18;
34.87 - static final private int EXTRA=19;
34.88 - static final private int NAME=20;
34.89 - static final private int COMMENT=21;
34.90 - static final private int HCRC=22;
34.91 - static final private int FLAGS=23;
34.92 -
34.93 - int mode; // current inflate mode
34.94 -
34.95 - // mode dependent information
34.96 - int method; // if FLAGS, method byte
34.97 -
34.98 - // if CHECK, check values to compare
34.99 - long was = -1; // computed check value
34.100 - long need; // stream check value
34.101 -
34.102 - // if BAD, inflateSync's marker bytes count
34.103 - int marker;
34.104 -
34.105 - // mode independent information
34.106 - int wrap; // flag for no wrapper
34.107 - int wbits; // log2(window size) (8..15, defaults to 15)
34.108 -
34.109 - InfBlocks blocks; // current inflate_blocks state
34.110 -
34.111 - private final ZStream z;
34.112 -
34.113 - private int flags;
34.114 -
34.115 - private int need_bytes = -1;
34.116 - private byte[] crcbuf=new byte[4];
34.117 -
34.118 - GZIPHeader gheader = null;
34.119 -
34.120 - int inflateReset(){
34.121 - if(z == null) return Z_STREAM_ERROR;
34.122 -
34.123 - z.total_in = z.total_out = 0;
34.124 - z.msg = null;
34.125 - this.mode = HEAD;
34.126 - this.need_bytes = -1;
34.127 - this.blocks.reset();
34.128 - return Z_OK;
34.129 - }
34.130 -
34.131 - int inflateEnd(){
34.132 - if(blocks != null){
34.133 - blocks.free();
34.134 - }
34.135 - return Z_OK;
34.136 - }
34.137 -
34.138 - Inflate(ZStream z){
34.139 - this.z=z;
34.140 - }
34.141 -
34.142 - int inflateInit(int w){
34.143 - z.msg = null;
34.144 - blocks = null;
34.145 -
34.146 - // handle undocumented wrap option (no zlib header or check)
34.147 - wrap = 0;
34.148 - if(w < 0){
34.149 - w = - w;
34.150 - }
34.151 - else {
34.152 - wrap = (w >> 4) + 1;
34.153 - if(w < 48)
34.154 - w &= 15;
34.155 - }
34.156 -
34.157 - if(w<8 ||w>15){
34.158 - inflateEnd();
34.159 - return Z_STREAM_ERROR;
34.160 - }
34.161 - if(blocks != null && wbits != w){
34.162 - blocks.free();
34.163 - blocks=null;
34.164 - }
34.165 -
34.166 - // set window size
34.167 - wbits=w;
34.168 -
34.169 - this.blocks=new InfBlocks(z, 1<<w);
34.170 -
34.171 - // reset state
34.172 - inflateReset();
34.173 -
34.174 - return Z_OK;
34.175 - }
34.176 -
34.177 - int inflate(int f){
34.178 - int hold = 0;
34.179 -
34.180 - int r;
34.181 - int b;
34.182 -
34.183 - if(z == null || z.next_in == null){
34.184 - if(f == Z_FINISH && this.mode==HEAD)
34.185 - return Z_OK;
34.186 - return Z_STREAM_ERROR;
34.187 - }
34.188 -
34.189 - f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
34.190 - r = Z_BUF_ERROR;
34.191 - while (true){
34.192 -
34.193 - switch (this.mode){
34.194 - case HEAD:
34.195 - if(wrap==0){
34.196 - this.mode = BLOCKS;
34.197 - break;
34.198 - }
34.199 -
34.200 - try { r=readBytes(2, r, f); }
34.201 - catch(Return e){ return e.r; }
34.202 -
34.203 - if((wrap&2)!=0 && this.need == 0x8b1fL) { // gzip header
34.204 - z.adler=new CRC32();
34.205 - checksum(2, this.need);
34.206 -
34.207 - if(gheader==null)
34.208 - gheader=new GZIPHeader();
34.209 -
34.210 - this.mode = FLAGS;
34.211 - break;
34.212 - }
34.213 -
34.214 - flags = 0;
34.215 -
34.216 - this.method = ((int)this.need)&0xff;
34.217 - b=((int)(this.need>>8))&0xff;
34.218 -
34.219 - if((wrap&1)==0 || // check if zlib header allowed
34.220 - (((this.method << 8)+b) % 31)!=0){
34.221 - this.mode = BAD;
34.222 - z.msg = "incorrect header check";
34.223 - // since zlib 1.2, it is allowted to inflateSync for this case.
34.224 - /*
34.225 - this.marker = 5; // can't try inflateSync
34.226 - */
34.227 - break;
34.228 - }
34.229 -
34.230 - if((this.method&0xf)!=Z_DEFLATED){
34.231 - this.mode = BAD;
34.232 - z.msg="unknown compression method";
34.233 - // since zlib 1.2, it is allowted to inflateSync for this case.
34.234 - /*
34.235 - this.marker = 5; // can't try inflateSync
34.236 - */
34.237 - break;
34.238 - }
34.239 -
34.240 - if((this.method>>4)+8>this.wbits){
34.241 - this.mode = BAD;
34.242 - z.msg="invalid window size";
34.243 - // since zlib 1.2, it is allowted to inflateSync for this case.
34.244 - /*
34.245 - this.marker = 5; // can't try inflateSync
34.246 - */
34.247 - break;
34.248 - }
34.249 -
34.250 - z.adler=new Adler32();
34.251 -
34.252 - if((b&PRESET_DICT)==0){
34.253 - this.mode = BLOCKS;
34.254 - break;
34.255 - }
34.256 - this.mode = DICT4;
34.257 - case DICT4:
34.258 -
34.259 - if(z.avail_in==0)return r;r=f;
34.260 -
34.261 - z.avail_in--; z.total_in++;
34.262 - this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
34.263 - this.mode=DICT3;
34.264 - case DICT3:
34.265 -
34.266 - if(z.avail_in==0)return r;r=f;
34.267 -
34.268 - z.avail_in--; z.total_in++;
34.269 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
34.270 - this.mode=DICT2;
34.271 - case DICT2:
34.272 -
34.273 - if(z.avail_in==0)return r;r=f;
34.274 -
34.275 - z.avail_in--; z.total_in++;
34.276 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
34.277 - this.mode=DICT1;
34.278 - case DICT1:
34.279 -
34.280 - if(z.avail_in==0)return r;r=f;
34.281 -
34.282 - z.avail_in--; z.total_in++;
34.283 - this.need += (z.next_in[z.next_in_index++]&0xffL);
34.284 - z.adler.reset(this.need);
34.285 - this.mode = DICT0;
34.286 - return Z_NEED_DICT;
34.287 - case DICT0:
34.288 - this.mode = BAD;
34.289 - z.msg = "need dictionary";
34.290 - this.marker = 0; // can try inflateSync
34.291 - return Z_STREAM_ERROR;
34.292 - case BLOCKS:
34.293 - r = this.blocks.proc(r);
34.294 - if(r == Z_DATA_ERROR){
34.295 - this.mode = BAD;
34.296 - this.marker = 0; // can try inflateSync
34.297 - break;
34.298 - }
34.299 - if(r == Z_OK){
34.300 - r = f;
34.301 - }
34.302 - if(r != Z_STREAM_END){
34.303 - return r;
34.304 - }
34.305 - r = f;
34.306 - this.was=z.adler.getValue();
34.307 - this.blocks.reset();
34.308 - if(this.wrap==0){
34.309 - this.mode=DONE;
34.310 - break;
34.311 - }
34.312 - this.mode=CHECK4;
34.313 - case CHECK4:
34.314 -
34.315 - if(z.avail_in==0)return r;r=f;
34.316 -
34.317 - z.avail_in--; z.total_in++;
34.318 - this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
34.319 - this.mode=CHECK3;
34.320 - case CHECK3:
34.321 -
34.322 - if(z.avail_in==0)return r;r=f;
34.323 -
34.324 - z.avail_in--; z.total_in++;
34.325 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
34.326 - this.mode = CHECK2;
34.327 - case CHECK2:
34.328 -
34.329 - if(z.avail_in==0)return r;r=f;
34.330 -
34.331 - z.avail_in--; z.total_in++;
34.332 - this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
34.333 - this.mode = CHECK1;
34.334 - case CHECK1:
34.335 -
34.336 - if(z.avail_in==0)return r;r=f;
34.337 -
34.338 - z.avail_in--; z.total_in++;
34.339 - this.need+=(z.next_in[z.next_in_index++]&0xffL);
34.340 -
34.341 - if(flags!=0){ // gzip
34.342 - this.need = ((this.need&0xff000000)>>24 |
34.343 - (this.need&0x00ff0000)>>8 |
34.344 - (this.need&0x0000ff00)<<8 |
34.345 - (this.need&0x0000ffff)<<24)&0xffffffffL;
34.346 - }
34.347 -
34.348 - if(((int)(this.was)) != ((int)(this.need))){
34.349 - z.msg = "incorrect data check";
34.350 - // chack is delayed
34.351 - /*
34.352 - this.mode = BAD;
34.353 - this.marker = 5; // can't try inflateSync
34.354 - break;
34.355 - */
34.356 - }
34.357 - else if(flags!=0 && gheader!=null){
34.358 - gheader.crc = this.need;
34.359 - }
34.360 -
34.361 - this.mode = LENGTH;
34.362 - case LENGTH:
34.363 - if (wrap!=0 && flags!=0) {
34.364 -
34.365 - try { r=readBytes(4, r, f); }
34.366 - catch(Return e){ return e.r; }
34.367 -
34.368 - if(z.msg!=null && z.msg.equals("incorrect data check")){
34.369 - this.mode = BAD;
34.370 - this.marker = 5; // can't try inflateSync
34.371 - break;
34.372 - }
34.373 -
34.374 - if (this.need != (z.total_out & 0xffffffffL)) {
34.375 - z.msg = "incorrect length check";
34.376 - this.mode = BAD;
34.377 - break;
34.378 - }
34.379 - z.msg = null;
34.380 - }
34.381 - else {
34.382 - if(z.msg!=null && z.msg.equals("incorrect data check")){
34.383 - this.mode = BAD;
34.384 - this.marker = 5; // can't try inflateSync
34.385 - break;
34.386 - }
34.387 - }
34.388 -
34.389 - this.mode = DONE;
34.390 - case DONE:
34.391 - return Z_STREAM_END;
34.392 - case BAD:
34.393 - return Z_DATA_ERROR;
34.394 -
34.395 - case FLAGS:
34.396 -
34.397 - try { r=readBytes(2, r, f); }
34.398 - catch(Return e){ return e.r; }
34.399 -
34.400 - flags = ((int)this.need)&0xffff;
34.401 -
34.402 - if ((flags & 0xff) != Z_DEFLATED) {
34.403 - z.msg = "unknown compression method";
34.404 - this.mode = BAD;
34.405 - break;
34.406 - }
34.407 - if ((flags & 0xe000)!=0) {
34.408 - z.msg = "unknown header flags set";
34.409 - this.mode = BAD;
34.410 - break;
34.411 - }
34.412 -
34.413 - if ((flags & 0x0200)!=0){
34.414 - checksum(2, this.need);
34.415 - }
34.416 -
34.417 - this.mode = TIME;
34.418 -
34.419 - case TIME:
34.420 - try { r=readBytes(4, r, f); }
34.421 - catch(Return e){ return e.r; }
34.422 - if(gheader!=null)
34.423 - gheader.time = this.need;
34.424 - if ((flags & 0x0200)!=0){
34.425 - checksum(4, this.need);
34.426 - }
34.427 - this.mode = OS;
34.428 - case OS:
34.429 - try { r=readBytes(2, r, f); }
34.430 - catch(Return e){ return e.r; }
34.431 - if(gheader!=null){
34.432 - gheader.xflags = ((int)this.need)&0xff;
34.433 - gheader.os = (((int)this.need)>>8)&0xff;
34.434 - }
34.435 - if ((flags & 0x0200)!=0){
34.436 - checksum(2, this.need);
34.437 - }
34.438 - this.mode = EXLEN;
34.439 - case EXLEN:
34.440 - if ((flags & 0x0400)!=0) {
34.441 - try { r=readBytes(2, r, f); }
34.442 - catch(Return e){ return e.r; }
34.443 - if(gheader!=null){
34.444 - gheader.extra = new byte[((int)this.need)&0xffff];
34.445 - }
34.446 - if ((flags & 0x0200)!=0){
34.447 - checksum(2, this.need);
34.448 - }
34.449 - }
34.450 - else if(gheader!=null){
34.451 - gheader.extra=null;
34.452 - }
34.453 - this.mode = EXTRA;
34.454 -
34.455 - case EXTRA:
34.456 - if ((flags & 0x0400)!=0) {
34.457 - try {
34.458 - r=readBytes(r, f);
34.459 - if(gheader!=null){
34.460 - byte[] foo = tmp_array;
34.461 - tmp_array=null;
34.462 - if(foo.length == gheader.extra.length){
34.463 - System.arraycopy(foo, 0, gheader.extra, 0, foo.length);
34.464 - }
34.465 - else{
34.466 - z.msg = "bad extra field length";
34.467 - this.mode = BAD;
34.468 - break;
34.469 - }
34.470 - }
34.471 - }
34.472 - catch(Return e){ return e.r; }
34.473 - }
34.474 - else if(gheader!=null){
34.475 - gheader.extra=null;
34.476 - }
34.477 - this.mode = NAME;
34.478 - case NAME:
34.479 - if ((flags & 0x0800)!=0) {
34.480 - try {
34.481 - r=readString(r, f);
34.482 - if(gheader!=null){
34.483 - gheader.name=tmp_array;
34.484 - }
34.485 - tmp_array=null;
34.486 - }
34.487 - catch(Return e){ return e.r; }
34.488 - }
34.489 - else if(gheader!=null){
34.490 - gheader.name=null;
34.491 - }
34.492 - this.mode = COMMENT;
34.493 - case COMMENT:
34.494 - if ((flags & 0x1000)!=0) {
34.495 - try {
34.496 - r=readString(r, f);
34.497 - if(gheader!=null){
34.498 - gheader.comment=tmp_array;
34.499 - }
34.500 - tmp_array=null;
34.501 - }
34.502 - catch(Return e){ return e.r; }
34.503 - }
34.504 - else if(gheader!=null){
34.505 - gheader.comment=null;
34.506 - }
34.507 - this.mode = HCRC;
34.508 - case HCRC:
34.509 - if ((flags & 0x0200)!=0) {
34.510 - try { r=readBytes(2, r, f); }
34.511 - catch(Return e){ return e.r; }
34.512 - if(gheader!=null){
34.513 - gheader.hcrc=(int)(this.need&0xffff);
34.514 - }
34.515 - if(this.need != (z.adler.getValue()&0xffffL)){
34.516 - this.mode = BAD;
34.517 - z.msg = "header crc mismatch";
34.518 - this.marker = 5; // can't try inflateSync
34.519 - break;
34.520 - }
34.521 - }
34.522 - z.adler = new CRC32();
34.523 -
34.524 - this.mode = BLOCKS;
34.525 - break;
34.526 - default:
34.527 - return Z_STREAM_ERROR;
34.528 - }
34.529 - }
34.530 - }
34.531 -
34.532 - int inflateSetDictionary(byte[] dictionary, int dictLength){
34.533 - if(z==null || (this.mode != DICT0 && this.wrap != 0)){
34.534 - return Z_STREAM_ERROR;
34.535 - }
34.536 -
34.537 - int index=0;
34.538 - int length = dictLength;
34.539 -
34.540 - if(this.mode==DICT0){
34.541 - long adler_need=z.adler.getValue();
34.542 - z.adler.reset();
34.543 - z.adler.update(dictionary, 0, dictLength);
34.544 - if(z.adler.getValue()!=adler_need){
34.545 - return Z_DATA_ERROR;
34.546 - }
34.547 - }
34.548 -
34.549 - z.adler.reset();
34.550 -
34.551 - if(length >= (1<<this.wbits)){
34.552 - length = (1<<this.wbits)-1;
34.553 - index=dictLength - length;
34.554 - }
34.555 - this.blocks.set_dictionary(dictionary, index, length);
34.556 - this.mode = BLOCKS;
34.557 - return Z_OK;
34.558 - }
34.559 -
34.560 - static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
34.561 -
34.562 - int inflateSync(){
34.563 - int n; // number of bytes to look at
34.564 - int p; // pointer to bytes
34.565 - int m; // number of marker bytes found in a row
34.566 - long r, w; // temporaries to save total_in and total_out
34.567 -
34.568 - // set up
34.569 - if(z == null)
34.570 - return Z_STREAM_ERROR;
34.571 - if(this.mode != BAD){
34.572 - this.mode = BAD;
34.573 - this.marker = 0;
34.574 - }
34.575 - if((n=z.avail_in)==0)
34.576 - return Z_BUF_ERROR;
34.577 -
34.578 - p=z.next_in_index;
34.579 - m=this.marker;
34.580 - // search
34.581 - while (n!=0 && m < 4){
34.582 - if(z.next_in[p] == mark[m]){
34.583 - m++;
34.584 - }
34.585 - else if(z.next_in[p]!=0){
34.586 - m = 0;
34.587 - }
34.588 - else{
34.589 - m = 4 - m;
34.590 - }
34.591 - p++; n--;
34.592 - }
34.593 -
34.594 - // restore
34.595 - z.total_in += p-z.next_in_index;
34.596 - z.next_in_index = p;
34.597 - z.avail_in = n;
34.598 - this.marker = m;
34.599 -
34.600 - // return no joy or set up to restart on a new block
34.601 - if(m != 4){
34.602 - return Z_DATA_ERROR;
34.603 - }
34.604 - r=z.total_in; w=z.total_out;
34.605 - inflateReset();
34.606 - z.total_in=r; z.total_out = w;
34.607 - this.mode = BLOCKS;
34.608 -
34.609 - return Z_OK;
34.610 - }
34.611 -
34.612 - // Returns true if inflate is currently at the end of a block generated
34.613 - // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
34.614 - // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
34.615 - // but removes the length bytes of the resulting empty stored block. When
34.616 - // decompressing, PPP checks that at the end of input packet, inflate is
34.617 - // waiting for these length bytes.
34.618 - int inflateSyncPoint(){
34.619 - if(z == null || this.blocks == null)
34.620 - return Z_STREAM_ERROR;
34.621 - return this.blocks.sync_point();
34.622 - }
34.623 -
34.624 - private int readBytes(int n, int r, int f) throws Return{
34.625 - if(need_bytes == -1){
34.626 - need_bytes=n;
34.627 - this.need=0;
34.628 - }
34.629 - while(need_bytes>0){
34.630 - if(z.avail_in==0){ throw new Return(r); }; r=f;
34.631 - z.avail_in--; z.total_in++;
34.632 - this.need = this.need |
34.633 - ((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8));
34.634 - need_bytes--;
34.635 - }
34.636 - if(n==2){
34.637 - this.need&=0xffffL;
34.638 - }
34.639 - else if(n==4) {
34.640 - this.need&=0xffffffffL;
34.641 - }
34.642 - need_bytes=-1;
34.643 - return r;
34.644 - }
34.645 - class Return extends Exception{
34.646 - int r;
34.647 - Return(int r){this.r=r; }
34.648 - }
34.649 -
34.650 - private byte[] tmp_array;
34.651 - private int readString(int r, int f) throws Return{
34.652 - int b=0;
34.653 - byte[] arr = new byte[4092];
34.654 - int at = 0;
34.655 - do {
34.656 - if(z.avail_in==0){ throw new Return(r); }; r=f;
34.657 - z.avail_in--; z.total_in++;
34.658 - b = z.next_in[z.next_in_index];
34.659 - if(b!=0) arr = append(arr, z.next_in[z.next_in_index], at++);
34.660 - z.adler.update(z.next_in, z.next_in_index, 1);
34.661 - z.next_in_index++;
34.662 - }while(b!=0);
34.663 -
34.664 - tmp_array = copy(arr, at);
34.665 -
34.666 - return r;
34.667 - }
34.668 -
34.669 - private int readBytes(int r, int f) throws Return{
34.670 - int b=0;
34.671 - byte[] arr = new byte[4092];
34.672 - int at = 0;
34.673 - while(this.need>0){
34.674 - if(z.avail_in==0){ throw new Return(r); }; r=f;
34.675 - z.avail_in--; z.total_in++;
34.676 - b = z.next_in[z.next_in_index];
34.677 - arr = append(arr, z.next_in[z.next_in_index], at++);
34.678 - z.adler.update(z.next_in, z.next_in_index, 1);
34.679 - z.next_in_index++;
34.680 - this.need--;
34.681 - }
34.682 -
34.683 - tmp_array = copy(arr, at);
34.684 -
34.685 - return r;
34.686 - }
34.687 -
34.688 - private static byte[] copy(byte[] arr, int len) {
34.689 - byte[] ret = new byte[len];
34.690 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, 0, ret, 0, len);
34.691 - return ret;
34.692 - }
34.693 - private static byte[] append(byte[] arr, byte b, int index) {
34.694 - arr[index] = b;
34.695 - return arr;
34.696 - }
34.697 -
34.698 - private void checksum(int n, long v){
34.699 - for(int i=0; i<n; i++){
34.700 - crcbuf[i]=(byte)(v&0xff);
34.701 - v>>=8;
34.702 - }
34.703 - z.adler.update(crcbuf, 0, n);
34.704 - }
34.705 -
34.706 - public GZIPHeader getGZIPHeader(){
34.707 - return gheader;
34.708 - }
34.709 -
34.710 - boolean inParsingHeader(){
34.711 - switch(mode){
34.712 - case HEAD:
34.713 - case DICT4:
34.714 - case DICT3:
34.715 - case DICT2:
34.716 - case DICT1:
34.717 - case FLAGS:
34.718 - case TIME:
34.719 - case OS:
34.720 - case EXLEN:
34.721 - case EXTRA:
34.722 - case NAME:
34.723 - case COMMENT:
34.724 - case HCRC:
34.725 - return true;
34.726 - default:
34.727 - return false;
34.728 - }
34.729 - }
34.730 -}
35.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java Tue May 06 17:46:47 2014 +0200
35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
35.3 @@ -1,338 +0,0 @@
35.4 -/*
35.5 - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
35.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35.7 - *
35.8 - * This code is free software; you can redistribute it and/or modify it
35.9 - * under the terms of the GNU General Public License version 2 only, as
35.10 - * published by the Free Software Foundation. Oracle designates this
35.11 - * particular file as subject to the "Classpath" exception as provided
35.12 - * by Oracle in the LICENSE file that accompanied this code.
35.13 - *
35.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
35.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
35.17 - * version 2 for more details (a copy is included in the LICENSE file that
35.18 - * accompanied this code).
35.19 - *
35.20 - * You should have received a copy of the GNU General Public License version
35.21 - * 2 along with this work; if not, write to the Free Software Foundation,
35.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35.23 - *
35.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35.25 - * or visit www.oracle.com if you need additional information or have any
35.26 - * questions.
35.27 - */
35.28 -
35.29 -package org.apidesign.bck2brwsr.emul.zip;
35.30 -
35.31 -import java.util.zip.*;
35.32 -import java.io.IOException;
35.33 -
35.34 -/**
35.35 - * This class provides support for general purpose decompression using the
35.36 - * popular ZLIB compression library. The ZLIB compression library was
35.37 - * initially developed as part of the PNG graphics standard and is not
35.38 - * protected by patents. It is fully described in the specifications at
35.39 - * the <a href="package-summary.html#package_description">java.util.zip
35.40 - * package description</a>.
35.41 - *
35.42 - * <p>The following code fragment demonstrates a trivial compression
35.43 - * and decompression of a string using <tt>Deflater</tt> and
35.44 - * <tt>Inflater</tt>.
35.45 - *
35.46 - * <blockquote><pre>
35.47 - * try {
35.48 - * // Encode a String into bytes
35.49 - * String inputString = "blahblahblah\u20AC\u20AC";
35.50 - * byte[] input = inputString.getBytes("UTF-8");
35.51 - *
35.52 - * // Compress the bytes
35.53 - * byte[] output = new byte[100];
35.54 - * Deflater compresser = new Deflater();
35.55 - * compresser.setInput(input);
35.56 - * compresser.finish();
35.57 - * int compressedDataLength = compresser.deflate(output);
35.58 - *
35.59 - * // Decompress the bytes
35.60 - * Inflater decompresser = new Inflater();
35.61 - * decompresser.setInput(output, 0, compressedDataLength);
35.62 - * byte[] result = new byte[100];
35.63 - * int resultLength = decompresser.inflate(result);
35.64 - * decompresser.end();
35.65 - *
35.66 - * // Decode the bytes into a String
35.67 - * String outputString = new String(result, 0, resultLength, "UTF-8");
35.68 - * } catch(java.io.UnsupportedEncodingException ex) {
35.69 - * // handle
35.70 - * } catch (java.util.zip.DataFormatException ex) {
35.71 - * // handle
35.72 - * }
35.73 - * </pre></blockquote>
35.74 - *
35.75 - * @see Deflater
35.76 - * @author David Connelly
35.77 - *
35.78 - */
35.79 -public
35.80 -class Inflater extends java.util.zip.Inflater {
35.81 - private final boolean nowrap;
35.82 - private JzLibInflater impl;
35.83 -
35.84 - /**
35.85 - * Creates a new decompressor. If the parameter 'nowrap' is true then
35.86 - * the ZLIB header and checksum fields will not be used. This provides
35.87 - * compatibility with the compression format used by both GZIP and PKZIP.
35.88 - * <p>
35.89 - * Note: When using the 'nowrap' option it is also necessary to provide
35.90 - * an extra "dummy" byte as input. This is required by the ZLIB native
35.91 - * library in order to support certain optimizations.
35.92 - *
35.93 - * @param nowrap if true then support GZIP compatible compression
35.94 - */
35.95 - public Inflater(boolean nowrap) {
35.96 - this.nowrap = nowrap;
35.97 - reset();
35.98 - }
35.99 -
35.100 - /**
35.101 - * Creates a new decompressor.
35.102 - */
35.103 - public Inflater() {
35.104 - this(false);
35.105 - }
35.106 -
35.107 - /**
35.108 - * Sets input data for decompression. Should be called whenever
35.109 - * needsInput() returns true indicating that more input data is
35.110 - * required.
35.111 - * @param b the input data bytes
35.112 - * @param off the start offset of the input data
35.113 - * @param len the length of the input data
35.114 - * @see Inflater#needsInput
35.115 - */
35.116 - public void setInput(byte[] b, int off, int len) {
35.117 - if (b == null) {
35.118 - throw new NullPointerException();
35.119 - }
35.120 - if (off < 0 || len < 0 || off > b.length - len) {
35.121 - throw new ArrayIndexOutOfBoundsException();
35.122 - }
35.123 - impl.setInput(b, off, len, false);
35.124 - }
35.125 -
35.126 - /**
35.127 - * Sets input data for decompression. Should be called whenever
35.128 - * needsInput() returns true indicating that more input data is
35.129 - * required.
35.130 - * @param b the input data bytes
35.131 - * @see Inflater#needsInput
35.132 - */
35.133 - public void setInput(byte[] b) {
35.134 - setInput(b, 0, b.length);
35.135 - }
35.136 -
35.137 - /**
35.138 - * Sets the preset dictionary to the given array of bytes. Should be
35.139 - * called when inflate() returns 0 and needsDictionary() returns true
35.140 - * indicating that a preset dictionary is required. The method getAdler()
35.141 - * can be used to get the Adler-32 value of the dictionary needed.
35.142 - * @param b the dictionary data bytes
35.143 - * @param off the start offset of the data
35.144 - * @param len the length of the data
35.145 - * @see Inflater#needsDictionary
35.146 - * @see Inflater#getAdler
35.147 - */
35.148 - public void setDictionary(byte[] b, int off, int len) {
35.149 - if (b == null) {
35.150 - throw new NullPointerException();
35.151 - }
35.152 - if (off < 0 || len < 0 || off > b.length - len) {
35.153 - throw new ArrayIndexOutOfBoundsException();
35.154 - }
35.155 - byte[] arr;
35.156 - if (off == 0) {
35.157 - arr = b;
35.158 - } else {
35.159 - arr = new byte[len];
35.160 - org.apidesign.bck2brwsr.emul.lang.System.arraycopy(b, off, arr, 0, len);
35.161 - }
35.162 - impl.setDictionary(arr, len);
35.163 - }
35.164 -
35.165 - /**
35.166 - * Sets the preset dictionary to the given array of bytes. Should be
35.167 - * called when inflate() returns 0 and needsDictionary() returns true
35.168 - * indicating that a preset dictionary is required. The method getAdler()
35.169 - * can be used to get the Adler-32 value of the dictionary needed.
35.170 - * @param b the dictionary data bytes
35.171 - * @see Inflater#needsDictionary
35.172 - * @see Inflater#getAdler
35.173 - */
35.174 - public void setDictionary(byte[] b) {
35.175 - impl.setDictionary(b, b.length);
35.176 - }
35.177 -
35.178 - /**
35.179 - * Returns the total number of bytes remaining in the input buffer.
35.180 - * This can be used to find out what bytes still remain in the input
35.181 - * buffer after decompression has finished.
35.182 - * @return the total number of bytes remaining in the input buffer
35.183 - */
35.184 - public int getRemaining() {
35.185 - return impl.getAvailIn();
35.186 - }
35.187 -
35.188 - /**
35.189 - * Returns true if no data remains in the input buffer. This can
35.190 - * be used to determine if #setInput should be called in order
35.191 - * to provide more input.
35.192 - * @return true if no data remains in the input buffer
35.193 - */
35.194 - public boolean needsInput() {
35.195 - return getRemaining() <= 0;
35.196 - }
35.197 -
35.198 - /**
35.199 - * Returns true if a preset dictionary is needed for decompression.
35.200 - * @return true if a preset dictionary is needed for decompression
35.201 - * @see Inflater#setDictionary
35.202 - */
35.203 - public boolean needsDictionary() {
35.204 - return impl.needDict();
35.205 - }
35.206 -
35.207 - /**
35.208 - * Returns true if the end of the compressed data stream has been
35.209 - * reached.
35.210 - * @return true if the end of the compressed data stream has been
35.211 - * reached
35.212 - */
35.213 - public boolean finished() {
35.214 - return impl.finished();
35.215 - }
35.216 -
35.217 - /**
35.218 - * Uncompresses bytes into specified buffer. Returns actual number
35.219 - * of bytes uncompressed. A return value of 0 indicates that
35.220 - * needsInput() or needsDictionary() should be called in order to
35.221 - * determine if more input data or a preset dictionary is required.
35.222 - * In the latter case, getAdler() can be used to get the Adler-32
35.223 - * value of the dictionary required.
35.224 - * @param b the buffer for the uncompressed data
35.225 - * @param off the start offset of the data
35.226 - * @param len the maximum number of uncompressed bytes
35.227 - * @return the actual number of uncompressed bytes
35.228 - * @exception DataFormatException if the compressed data format is invalid
35.229 - * @see Inflater#needsInput
35.230 - * @see Inflater#needsDictionary
35.231 - */
35.232 - public int inflate(byte[] b, int off, int len)
35.233 - throws DataFormatException
35.234 - {
35.235 - if (b == null) {
35.236 - throw new NullPointerException();
35.237 - }
35.238 - if (off < 0 || len < 0 || off > b.length - len) {
35.239 - throw new ArrayIndexOutOfBoundsException();
35.240 - }
35.241 - impl.setOutput(b, off, len);
35.242 - int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
35.243 - return impl.next_out_index - off;
35.244 - }
35.245 -
35.246 - /**
35.247 - * Uncompresses bytes into specified buffer. Returns actual number
35.248 - * of bytes uncompressed. A return value of 0 indicates that
35.249 - * needsInput() or needsDictionary() should be called in order to
35.250 - * determine if more input data or a preset dictionary is required.
35.251 - * In the latter case, getAdler() can be used to get the Adler-32
35.252 - * value of the dictionary required.
35.253 - * @param b the buffer for the uncompressed data
35.254 - * @return the actual number of uncompressed bytes
35.255 - * @exception DataFormatException if the compressed data format is invalid
35.256 - * @see Inflater#needsInput
35.257 - * @see Inflater#needsDictionary
35.258 - */
35.259 - public int inflate(byte[] b) throws DataFormatException {
35.260 - return inflate(b, 0, b.length);
35.261 - }
35.262 -
35.263 - /**
35.264 - * Returns the ADLER-32 value of the uncompressed data.
35.265 - * @return the ADLER-32 value of the uncompressed data
35.266 - */
35.267 - public int getAdler() {
35.268 - return (int) impl.getAdler();
35.269 - }
35.270 -
35.271 - /**
35.272 - * Returns the total number of compressed bytes input so far.
35.273 - *
35.274 - * <p>Since the number of bytes may be greater than
35.275 - * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
35.276 - * the preferred means of obtaining this information.</p>
35.277 - *
35.278 - * @return the total number of compressed bytes input so far
35.279 - */
35.280 - public int getTotalIn() {
35.281 - return (int) getBytesRead();
35.282 - }
35.283 -
35.284 - /**
35.285 - * Returns the total number of compressed bytes input so far.</p>
35.286 - *
35.287 - * @return the total (non-negative) number of compressed bytes input so far
35.288 - * @since 1.5
35.289 - */
35.290 - public long getBytesRead() {
35.291 - return impl.total_in;
35.292 - }
35.293 -
35.294 - /**
35.295 - * Returns the total number of uncompressed bytes output so far.
35.296 - *
35.297 - * <p>Since the number of bytes may be greater than
35.298 - * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
35.299 - * the preferred means of obtaining this information.</p>
35.300 - *
35.301 - * @return the total number of uncompressed bytes output so far
35.302 - */
35.303 - public int getTotalOut() {
35.304 - return (int) getBytesWritten();
35.305 - }
35.306 -
35.307 - /**
35.308 - * Returns the total number of uncompressed bytes output so far.</p>
35.309 - *
35.310 - * @return the total (non-negative) number of uncompressed bytes output so far
35.311 - * @since 1.5
35.312 - */
35.313 - public long getBytesWritten() {
35.314 - return impl.total_out;
35.315 - }
35.316 -
35.317 - /**
35.318 - * Resets inflater so that a new set of input data can be processed.
35.319 - */
35.320 - public void reset() {
35.321 - impl = new JzLibInflater(15, nowrap);
35.322 - }
35.323 -
35.324 - /**
35.325 - * Closes the decompressor and discards any unprocessed input.
35.326 - * This method should be called when the decompressor is no longer
35.327 - * being used, but will also be called automatically by the finalize()
35.328 - * method. Once this method is called, the behavior of the Inflater
35.329 - * object is undefined.
35.330 - */
35.331 - public void end() {
35.332 - impl.end();
35.333 - }
35.334 -
35.335 - /**
35.336 - * Closes the decompressor when garbage is collected.
35.337 - */
35.338 - protected void finalize() {
35.339 - end();
35.340 - }
35.341 -}
36.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java Tue May 06 17:46:47 2014 +0200
36.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
36.3 @@ -1,137 +0,0 @@
36.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
36.5 -/*
36.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
36.7 -
36.8 -Redistribution and use in source and binary forms, with or without
36.9 -modification, are permitted provided that the following conditions are met:
36.10 -
36.11 - 1. Redistributions of source code must retain the above copyright notice,
36.12 - this list of conditions and the following disclaimer.
36.13 -
36.14 - 2. Redistributions in binary form must reproduce the above copyright
36.15 - notice, this list of conditions and the following disclaimer in
36.16 - the documentation and/or other materials provided with the distribution.
36.17 -
36.18 - 3. The names of the authors may not be used to endorse or promote products
36.19 - derived from this software without specific prior written permission.
36.20 -
36.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
36.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
36.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
36.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
36.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36.31 - */
36.32 -/*
36.33 - * This program is based on zlib-1.1.3, so all credit should go authors
36.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
36.35 - * and contributors of zlib.
36.36 - */
36.37 -
36.38 -package org.apidesign.bck2brwsr.emul.zip;
36.39 -
36.40 -final class JzLibInflater extends ZStream{
36.41 -
36.42 - static final private int MAX_WBITS=15; // 32K LZ77 window
36.43 - static final private int DEF_WBITS=MAX_WBITS;
36.44 -
36.45 - public static final int Z_NO_FLUSH=0;
36.46 - static final private int Z_PARTIAL_FLUSH=1;
36.47 - static final private int Z_SYNC_FLUSH=2;
36.48 - static final private int Z_FULL_FLUSH=3;
36.49 - static final private int Z_FINISH=4;
36.50 -
36.51 - static final private int MAX_MEM_LEVEL=9;
36.52 -
36.53 - static final private int Z_OK=0;
36.54 - static final private int Z_STREAM_END=1;
36.55 - static final private int Z_NEED_DICT=2;
36.56 - static final private int Z_ERRNO=-1;
36.57 - static final private int Z_STREAM_ERROR=-2;
36.58 - static final private int Z_DATA_ERROR=-3;
36.59 - static final private int Z_MEM_ERROR=-4;
36.60 - static final private int Z_BUF_ERROR=-5;
36.61 - static final private int Z_VERSION_ERROR=-6;
36.62 -
36.63 - public JzLibInflater() {
36.64 - super();
36.65 - init();
36.66 - }
36.67 -
36.68 - public JzLibInflater(int w) {
36.69 - this(w, false);
36.70 - }
36.71 -
36.72 - public JzLibInflater(int w, boolean nowrap) {
36.73 - super();
36.74 - int ret = init(w, nowrap);
36.75 - if(ret!=Z_OK)
36.76 - throw new IllegalStateException(ret+": "+msg);
36.77 - }
36.78 -
36.79 - private boolean finished = false;
36.80 -
36.81 - public int init(){
36.82 - return init(DEF_WBITS);
36.83 - }
36.84 -
36.85 - public int init(boolean nowrap){
36.86 - return init(DEF_WBITS, nowrap);
36.87 - }
36.88 -
36.89 - public int init(int w){
36.90 - return init(w, false);
36.91 - }
36.92 -
36.93 - public int init(int w, boolean nowrap){
36.94 - finished = false;
36.95 - istate=new Inflate(this);
36.96 - return istate.inflateInit(nowrap?-w:w);
36.97 - }
36.98 -
36.99 - public int inflate(int f){
36.100 - if(istate==null) return Z_STREAM_ERROR;
36.101 - int ret = istate.inflate(f);
36.102 - if(ret == Z_STREAM_END)
36.103 - finished = true;
36.104 - return ret;
36.105 - }
36.106 -
36.107 - public int end(){
36.108 - finished = true;
36.109 - if(istate==null) return Z_STREAM_ERROR;
36.110 - int ret=istate.inflateEnd();
36.111 -// istate = null;
36.112 - return ret;
36.113 - }
36.114 -
36.115 - public int sync(){
36.116 - if(istate == null)
36.117 - return Z_STREAM_ERROR;
36.118 - return istate.inflateSync();
36.119 - }
36.120 -
36.121 - public int syncPoint(){
36.122 - if(istate == null)
36.123 - return Z_STREAM_ERROR;
36.124 - return istate.inflateSyncPoint();
36.125 - }
36.126 -
36.127 - public int setDictionary(byte[] dictionary, int dictLength){
36.128 - if(istate == null)
36.129 - return Z_STREAM_ERROR;
36.130 - return istate.inflateSetDictionary(dictionary, dictLength);
36.131 - }
36.132 -
36.133 - public boolean finished(){
36.134 - return istate.mode==12 /*DONE*/;
36.135 - }
36.136 -
36.137 - public boolean needDict() {
36.138 - return istate == null ? false : istate.mode == Inflate.DICT0;
36.139 - }
36.140 -}
37.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java Tue May 06 17:46:47 2014 +0200
37.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
37.3 @@ -1,253 +0,0 @@
37.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
37.5 -/*
37.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
37.7 -
37.8 -Redistribution and use in source and binary forms, with or without
37.9 -modification, are permitted provided that the following conditions are met:
37.10 -
37.11 - 1. Redistributions of source code must retain the above copyright notice,
37.12 - this list of conditions and the following disclaimer.
37.13 -
37.14 - 2. Redistributions in binary form must reproduce the above copyright
37.15 - notice, this list of conditions and the following disclaimer in
37.16 - the documentation and/or other materials provided with the distribution.
37.17 -
37.18 - 3. The names of the authors may not be used to endorse or promote products
37.19 - derived from this software without specific prior written permission.
37.20 -
37.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
37.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
37.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
37.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
37.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
37.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37.31 - */
37.32 -/*
37.33 - * This program is based on zlib-1.1.3, so all credit should go authors
37.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
37.35 - * and contributors of zlib.
37.36 - */
37.37 -
37.38 -package org.apidesign.bck2brwsr.emul.zip;
37.39 -
37.40 -import org.apidesign.bck2brwsr.emul.lang.System;
37.41 -
37.42 -/**
37.43 - * ZStream
37.44 - *
37.45 - * @deprecated Not for public use in the future.
37.46 - */
37.47 -@Deprecated
37.48 -class ZStream{
37.49 -
37.50 - static final private int MAX_WBITS=15; // 32K LZ77 window
37.51 - static final private int DEF_WBITS=MAX_WBITS;
37.52 -
37.53 - static final private int Z_NO_FLUSH=0;
37.54 - static final private int Z_PARTIAL_FLUSH=1;
37.55 - static final private int Z_SYNC_FLUSH=2;
37.56 - static final private int Z_FULL_FLUSH=3;
37.57 - static final private int Z_FINISH=4;
37.58 -
37.59 - static final private int MAX_MEM_LEVEL=9;
37.60 -
37.61 - static final private int Z_OK=0;
37.62 - static final private int Z_STREAM_END=1;
37.63 - static final private int Z_NEED_DICT=2;
37.64 - static final private int Z_ERRNO=-1;
37.65 - static final private int Z_STREAM_ERROR=-2;
37.66 - static final private int Z_DATA_ERROR=-3;
37.67 - static final private int Z_MEM_ERROR=-4;
37.68 - static final private int Z_BUF_ERROR=-5;
37.69 - static final private int Z_VERSION_ERROR=-6;
37.70 -
37.71 - public byte[] next_in; // next input byte
37.72 - public int next_in_index;
37.73 - public int avail_in; // number of bytes available at next_in
37.74 - public long total_in; // total nb of input bytes read so far
37.75 -
37.76 - public byte[] next_out; // next output byte should be put there
37.77 - public int next_out_index;
37.78 - public int avail_out; // remaining free space at next_out
37.79 - public long total_out; // total nb of bytes output so far
37.80 -
37.81 - public String msg;
37.82 -
37.83 - Inflate istate;
37.84 -
37.85 - int data_type; // best guess about the data type: ascii or binary
37.86 -
37.87 - Checksum adler;
37.88 -
37.89 - public ZStream(){
37.90 - this(new Adler32());
37.91 - }
37.92 -
37.93 - public ZStream(Checksum adler){
37.94 - this.adler=adler;
37.95 - }
37.96 -
37.97 - public int inflateInit(){
37.98 - return inflateInit(DEF_WBITS);
37.99 - }
37.100 - public int inflateInit(boolean nowrap){
37.101 - return inflateInit(DEF_WBITS, nowrap);
37.102 - }
37.103 - public int inflateInit(int w){
37.104 - return inflateInit(w, false);
37.105 - }
37.106 -
37.107 - public int inflateInit(int w, boolean nowrap){
37.108 - istate=new Inflate(this);
37.109 - return istate.inflateInit(nowrap?-w:w);
37.110 - }
37.111 -
37.112 - public int inflate(int f){
37.113 - if(istate==null) return Z_STREAM_ERROR;
37.114 - return istate.inflate(f);
37.115 - }
37.116 - public int inflateEnd(){
37.117 - if(istate==null) return Z_STREAM_ERROR;
37.118 - int ret=istate.inflateEnd();
37.119 -// istate = null;
37.120 - return ret;
37.121 - }
37.122 -
37.123 - public int inflateSync(){
37.124 - if(istate == null)
37.125 - return Z_STREAM_ERROR;
37.126 - return istate.inflateSync();
37.127 - }
37.128 - public int inflateSyncPoint(){
37.129 - if(istate == null)
37.130 - return Z_STREAM_ERROR;
37.131 - return istate.inflateSyncPoint();
37.132 - }
37.133 - public int inflateSetDictionary(byte[] dictionary, int dictLength){
37.134 - if(istate == null)
37.135 - return Z_STREAM_ERROR;
37.136 - return istate.inflateSetDictionary(dictionary, dictLength);
37.137 - }
37.138 - public boolean inflateFinished(){
37.139 - return istate.mode==12 /*DONE*/;
37.140 - }
37.141 -
37.142 -
37.143 - public long getAdler(){
37.144 - return adler.getValue();
37.145 - }
37.146 -
37.147 - public void free(){
37.148 - next_in=null;
37.149 - next_out=null;
37.150 - msg=null;
37.151 - }
37.152 -
37.153 - public void setOutput(byte[] buf){
37.154 - setOutput(buf, 0, buf.length);
37.155 - }
37.156 -
37.157 - public void setOutput(byte[] buf, int off, int len){
37.158 - next_out = buf;
37.159 - next_out_index = off;
37.160 - avail_out = len;
37.161 - }
37.162 -
37.163 - public void setInput(byte[] buf){
37.164 - setInput(buf, 0, buf.length, false);
37.165 - }
37.166 -
37.167 - public void setInput(byte[] buf, boolean append){
37.168 - setInput(buf, 0, buf.length, append);
37.169 - }
37.170 -
37.171 - public void setInput(byte[] buf, int off, int len, boolean append){
37.172 - if(len<=0 && append && next_in!=null) return;
37.173 -
37.174 - if(avail_in>0 && append){
37.175 - byte[] tmp = new byte[avail_in+len];
37.176 - System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
37.177 - System.arraycopy(buf, off, tmp, avail_in, len);
37.178 - next_in=tmp;
37.179 - next_in_index=0;
37.180 - avail_in+=len;
37.181 - }
37.182 - else{
37.183 - next_in=buf;
37.184 - next_in_index=off;
37.185 - avail_in=len;
37.186 - }
37.187 - }
37.188 -
37.189 - public byte[] getNextIn(){
37.190 - return next_in;
37.191 - }
37.192 -
37.193 - public void setNextIn(byte[] next_in){
37.194 - this.next_in = next_in;
37.195 - }
37.196 -
37.197 - public int getNextInIndex(){
37.198 - return next_in_index;
37.199 - }
37.200 -
37.201 - public void setNextInIndex(int next_in_index){
37.202 - this.next_in_index = next_in_index;
37.203 - }
37.204 -
37.205 - public int getAvailIn(){
37.206 - return avail_in;
37.207 - }
37.208 -
37.209 - public void setAvailIn(int avail_in){
37.210 - this.avail_in = avail_in;
37.211 - }
37.212 -
37.213 - public byte[] getNextOut(){
37.214 - return next_out;
37.215 - }
37.216 -
37.217 - public void setNextOut(byte[] next_out){
37.218 - this.next_out = next_out;
37.219 - }
37.220 -
37.221 - public int getNextOutIndex(){
37.222 - return next_out_index;
37.223 - }
37.224 -
37.225 - public void setNextOutIndex(int next_out_index){
37.226 - this.next_out_index = next_out_index;
37.227 - }
37.228 -
37.229 - public int getAvailOut(){
37.230 - return avail_out;
37.231 -
37.232 - }
37.233 -
37.234 - public void setAvailOut(int avail_out){
37.235 - this.avail_out = avail_out;
37.236 - }
37.237 -
37.238 - public long getTotalOut(){
37.239 - return total_out;
37.240 - }
37.241 -
37.242 - public long getTotalIn(){
37.243 - return total_in;
37.244 - }
37.245 -
37.246 - public String getMessage(){
37.247 - return msg;
37.248 - }
37.249 -
37.250 - /**
37.251 - * Those methods are expected to be override by Inflater and Deflater.
37.252 - * In the future, they will become abstract methods.
37.253 - */
37.254 - public int end(){ return Z_OK; }
37.255 - public boolean finished(){ return false; }
37.256 -}
38.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java Tue May 06 17:46:47 2014 +0200
38.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
38.3 @@ -1,84 +0,0 @@
38.4 -/*
38.5 - * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
38.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38.7 - *
38.8 - * This code is free software; you can redistribute it and/or modify it
38.9 - * under the terms of the GNU General Public License version 2 only, as
38.10 - * published by the Free Software Foundation. Oracle designates this
38.11 - * particular file as subject to the "Classpath" exception as provided
38.12 - * by Oracle in the LICENSE file that accompanied this code.
38.13 - *
38.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
38.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
38.17 - * version 2 for more details (a copy is included in the LICENSE file that
38.18 - * accompanied this code).
38.19 - *
38.20 - * You should have received a copy of the GNU General Public License version
38.21 - * 2 along with this work; if not, write to the Free Software Foundation,
38.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38.23 - *
38.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
38.25 - * or visit www.oracle.com if you need additional information or have any
38.26 - * questions.
38.27 - */
38.28 -
38.29 -package org.apidesign.bck2brwsr.emul.zip;
38.30 -
38.31 -/*
38.32 - * This class defines the constants that are used by the classes
38.33 - * which manipulate Zip64 files.
38.34 - */
38.35 -
38.36 -public class ZipConstants64 {
38.37 -
38.38 - /*
38.39 - * ZIP64 constants
38.40 - */
38.41 - static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006"
38.42 - static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007"
38.43 - static final int ZIP64_ENDHDR = 56; // ZIP64 end header size
38.44 - static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size
38.45 - static final int ZIP64_EXTHDR = 24; // EXT header size
38.46 - static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID
38.47 -
38.48 - static final int ZIP64_MAGICCOUNT = 0xFFFF;
38.49 - static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
38.50 -
38.51 - /*
38.52 - * Zip64 End of central directory (END) header field offsets
38.53 - */
38.54 - static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir
38.55 - static final int ZIP64_ENDVEM = 12; // version made by
38.56 - static final int ZIP64_ENDVER = 14; // version needed to extract
38.57 - static final int ZIP64_ENDNMD = 16; // number of this disk
38.58 - static final int ZIP64_ENDDSK = 20; // disk number of start
38.59 - static final int ZIP64_ENDTOD = 24; // total number of entries on this disk
38.60 - static final int ZIP64_ENDTOT = 32; // total number of entries
38.61 - static final int ZIP64_ENDSIZ = 40; // central directory size in bytes
38.62 - static final int ZIP64_ENDOFF = 48; // offset of first CEN header
38.63 - static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector
38.64 -
38.65 - /*
38.66 - * Zip64 End of central directory locator field offsets
38.67 - */
38.68 - static final int ZIP64_LOCDSK = 4; // disk number start
38.69 - static final int ZIP64_LOCOFF = 8; // offset of zip64 end
38.70 - static final int ZIP64_LOCTOT = 16; // total number of disks
38.71 -
38.72 - /*
38.73 - * Zip64 Extra local (EXT) header field offsets
38.74 - */
38.75 - static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value
38.76 - static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte
38.77 - static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte
38.78 -
38.79 - /*
38.80 - * Language encoding flag EFS
38.81 - */
38.82 - static final int EFS = 0x800; // If this bit is set the filename and
38.83 - // comment fields for this file must be
38.84 - // encoded using UTF-8.
38.85 -
38.86 - private ZipConstants64() {}
38.87 -}
39.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java Tue May 06 17:46:47 2014 +0200
39.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
39.3 @@ -1,468 +0,0 @@
39.4 -/*
39.5 - * Copyright (c) 1996, 2009, 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 org.apidesign.bck2brwsr.emul.zip;
39.30 -
39.31 -import java.util.zip.*;
39.32 -import java.io.InputStream;
39.33 -import java.io.IOException;
39.34 -import java.io.EOFException;
39.35 -import java.io.PushbackInputStream;
39.36 -import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*;
39.37 -import static java.util.zip.ZipInputStream.*;
39.38 -
39.39 -/**
39.40 - * This class implements an input stream filter for reading files in the
39.41 - * ZIP file format. Includes support for both compressed and uncompressed
39.42 - * entries.
39.43 - *
39.44 - * @author David Connelly
39.45 - */
39.46 -public
39.47 -class ZipInputStream extends InflaterInputStream {
39.48 - private ZipEntry entry;
39.49 - private int flag;
39.50 - private CRC32 crc = new CRC32();
39.51 - private long remaining;
39.52 - private byte[] tmpbuf = new byte[512];
39.53 -
39.54 - private static final int STORED = ZipEntry.STORED;
39.55 - private static final int DEFLATED = ZipEntry.DEFLATED;
39.56 -
39.57 - private boolean closed = false;
39.58 - // this flag is set to true after EOF has reached for
39.59 - // one entry
39.60 - private boolean entryEOF = false;
39.61 -
39.62 - /**
39.63 - * Check to make sure that this stream has not been closed
39.64 - */
39.65 - private void ensureOpen() throws IOException {
39.66 - if (closed) {
39.67 - throw new IOException("Stream closed");
39.68 - }
39.69 - }
39.70 -
39.71 - /**
39.72 - * Creates a new ZIP input stream.
39.73 - *
39.74 - * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
39.75 - * decode the entry names.
39.76 - *
39.77 - * @param in the actual input stream
39.78 - */
39.79 - public ZipInputStream(InputStream in) {
39.80 -// this(in, "UTF-8");
39.81 - super(new PushbackInputStream(in, 512), new Inflater(true), 512);
39.82 - //usesDefaultInflater = true;
39.83 - if(in == null) {
39.84 - throw new NullPointerException("in is null");
39.85 - }
39.86 - }
39.87 -
39.88 - /**
39.89 - * Creates a new ZIP input stream.
39.90 - *
39.91 - * @param in the actual input stream
39.92 - *
39.93 - * @param charset
39.94 - * The {@linkplain java.nio.charset.Charset charset} to be
39.95 - * used to decode the ZIP entry name (ignored if the
39.96 - * <a href="package-summary.html#lang_encoding"> language
39.97 - * encoding bit</a> of the ZIP entry's general purpose bit
39.98 - * flag is set).
39.99 - *
39.100 - * @since 1.7
39.101 - *
39.102 - public ZipInputStream(InputStream in, Charset charset) {
39.103 - super(new PushbackInputStream(in, 512), new Inflater(true), 512);
39.104 - usesDefaultInflater = true;
39.105 - if(in == null) {
39.106 - throw new NullPointerException("in is null");
39.107 - }
39.108 - if (charset == null)
39.109 - throw new NullPointerException("charset is null");
39.110 - this.zc = ZipCoder.get(charset);
39.111 - }
39.112 - */
39.113 -
39.114 - /**
39.115 - * Reads the next ZIP file entry and positions the stream at the
39.116 - * beginning of the entry data.
39.117 - * @return the next ZIP file entry, or null if there are no more entries
39.118 - * @exception ZipException if a ZIP file error has occurred
39.119 - * @exception IOException if an I/O error has occurred
39.120 - */
39.121 - public ZipEntry getNextEntry() throws IOException {
39.122 - ensureOpen();
39.123 - if (entry != null) {
39.124 - closeEntry();
39.125 - }
39.126 - crc.reset();
39.127 - inf.reset();
39.128 - if ((entry = readLOC()) == null) {
39.129 - return null;
39.130 - }
39.131 - if (entry.getMethod() == STORED) {
39.132 - remaining = entry.getSize();
39.133 - }
39.134 - entryEOF = false;
39.135 - return entry;
39.136 - }
39.137 -
39.138 - /**
39.139 - * Closes the current ZIP entry and positions the stream for reading the
39.140 - * next entry.
39.141 - * @exception ZipException if a ZIP file error has occurred
39.142 - * @exception IOException if an I/O error has occurred
39.143 - */
39.144 - public void closeEntry() throws IOException {
39.145 - ensureOpen();
39.146 - while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
39.147 - entryEOF = true;
39.148 - }
39.149 -
39.150 - /**
39.151 - * Returns 0 after EOF has reached for the current entry data,
39.152 - * otherwise always return 1.
39.153 - * <p>
39.154 - * Programs should not count on this method to return the actual number
39.155 - * of bytes that could be read without blocking.
39.156 - *
39.157 - * @return 1 before EOF and 0 after EOF has reached for current entry.
39.158 - * @exception IOException if an I/O error occurs.
39.159 - *
39.160 - */
39.161 - public int available() throws IOException {
39.162 - ensureOpen();
39.163 - if (entryEOF) {
39.164 - return 0;
39.165 - } else {
39.166 - return 1;
39.167 - }
39.168 - }
39.169 -
39.170 - /**
39.171 - * Reads from the current ZIP entry into an array of bytes.
39.172 - * If <code>len</code> is not zero, the method
39.173 - * blocks until some input is available; otherwise, no
39.174 - * bytes are read and <code>0</code> is returned.
39.175 - * @param b the buffer into which the data is read
39.176 - * @param off the start offset in the destination array <code>b</code>
39.177 - * @param len the maximum number of bytes read
39.178 - * @return the actual number of bytes read, or -1 if the end of the
39.179 - * entry is reached
39.180 - * @exception NullPointerException if <code>b</code> is <code>null</code>.
39.181 - * @exception IndexOutOfBoundsException if <code>off</code> is negative,
39.182 - * <code>len</code> is negative, or <code>len</code> is greater than
39.183 - * <code>b.length - off</code>
39.184 - * @exception ZipException if a ZIP file error has occurred
39.185 - * @exception IOException if an I/O error has occurred
39.186 - */
39.187 - public int read(byte[] b, int off, int len) throws IOException {
39.188 - ensureOpen();
39.189 - if (off < 0 || len < 0 || off > b.length - len) {
39.190 - throw new IndexOutOfBoundsException();
39.191 - } else if (len == 0) {
39.192 - return 0;
39.193 - }
39.194 -
39.195 - if (entry == null) {
39.196 - return -1;
39.197 - }
39.198 - switch (entry.getMethod()) {
39.199 - case DEFLATED:
39.200 - len = super.read(b, off, len);
39.201 - if (len == -1) {
39.202 - readEnd(entry);
39.203 - entryEOF = true;
39.204 - entry = null;
39.205 - } else {
39.206 - crc.update(b, off, len);
39.207 - }
39.208 - return len;
39.209 - case STORED:
39.210 - if (remaining <= 0) {
39.211 - entryEOF = true;
39.212 - entry = null;
39.213 - return -1;
39.214 - }
39.215 - if (len > remaining) {
39.216 - len = (int)remaining;
39.217 - }
39.218 - len = in.read(b, off, len);
39.219 - if (len == -1) {
39.220 - throw new ZipException("unexpected EOF");
39.221 - }
39.222 - crc.update(b, off, len);
39.223 - remaining -= len;
39.224 - if (remaining == 0 && entry.getCrc() != crc.getValue()) {
39.225 - throw new ZipException(
39.226 - "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
39.227 - " but got 0x" + Long.toHexString(crc.getValue()) + ")");
39.228 - }
39.229 - return len;
39.230 - default:
39.231 - throw new ZipException("invalid compression method");
39.232 - }
39.233 - }
39.234 -
39.235 - /**
39.236 - * Skips specified number of bytes in the current ZIP entry.
39.237 - * @param n the number of bytes to skip
39.238 - * @return the actual number of bytes skipped
39.239 - * @exception ZipException if a ZIP file error has occurred
39.240 - * @exception IOException if an I/O error has occurred
39.241 - * @exception IllegalArgumentException if n < 0
39.242 - */
39.243 - public long skip(long n) throws IOException {
39.244 - if (n < 0) {
39.245 - throw new IllegalArgumentException("negative skip length");
39.246 - }
39.247 - ensureOpen();
39.248 - int max = (int)Math.min(n, Integer.MAX_VALUE);
39.249 - int total = 0;
39.250 - while (total < max) {
39.251 - int len = max - total;
39.252 - if (len > tmpbuf.length) {
39.253 - len = tmpbuf.length;
39.254 - }
39.255 - len = read(tmpbuf, 0, len);
39.256 - if (len == -1) {
39.257 - entryEOF = true;
39.258 - break;
39.259 - }
39.260 - total += len;
39.261 - }
39.262 - return total;
39.263 - }
39.264 -
39.265 - /**
39.266 - * Closes this input stream and releases any system resources associated
39.267 - * with the stream.
39.268 - * @exception IOException if an I/O error has occurred
39.269 - */
39.270 - public void close() throws IOException {
39.271 - if (!closed) {
39.272 - super.close();
39.273 - closed = true;
39.274 - }
39.275 - }
39.276 -
39.277 - private byte[] b = new byte[256];
39.278 -
39.279 - /*
39.280 - * Reads local file (LOC) header for next entry.
39.281 - */
39.282 - private ZipEntry readLOC() throws IOException {
39.283 - try {
39.284 - readFully(tmpbuf, 0, LOCHDR);
39.285 - } catch (EOFException e) {
39.286 - return null;
39.287 - }
39.288 - if (get32(tmpbuf, 0) != LOCSIG) {
39.289 - return null;
39.290 - }
39.291 - // get flag first, we need check EFS.
39.292 - flag = get16(tmpbuf, LOCFLG);
39.293 - // get the entry name and create the ZipEntry first
39.294 - int len = get16(tmpbuf, LOCNAM);
39.295 - int blen = b.length;
39.296 - if (len > blen) {
39.297 - do
39.298 - blen = blen * 2;
39.299 - while (len > blen);
39.300 - b = new byte[blen];
39.301 - }
39.302 - readFully(b, 0, len);
39.303 - // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
39.304 - ZipEntry e = createZipEntry(((flag & EFS) != 0)
39.305 - ? toStringUTF8(b, len)
39.306 - : toString(b, len));
39.307 - // now get the remaining fields for the entry
39.308 - if ((flag & 1) == 1) {
39.309 - throw new ZipException("encrypted ZIP entry not supported");
39.310 - }
39.311 - e.setMethod(get16(tmpbuf, LOCHOW));
39.312 - e.setTime(get32(tmpbuf, LOCTIM));
39.313 - if ((flag & 8) == 8) {
39.314 - /* "Data Descriptor" present */
39.315 - if (e.getMethod() != DEFLATED) {
39.316 - throw new ZipException(
39.317 - "only DEFLATED entries can have EXT descriptor");
39.318 - }
39.319 - } else {
39.320 - e.setCrc(get32(tmpbuf, LOCCRC));
39.321 - e.setCompressedSize(get32(tmpbuf, LOCSIZ));
39.322 - e.setSize(get32(tmpbuf, LOCLEN));
39.323 - }
39.324 - len = get16(tmpbuf, LOCEXT);
39.325 - if (len > 0) {
39.326 - byte[] bb = new byte[len];
39.327 - readFully(bb, 0, len);
39.328 - e.setExtra(bb);
39.329 - // extra fields are in "HeaderID(2)DataSize(2)Data... format
39.330 - if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
39.331 - int off = 0;
39.332 - while (off + 4 < len) {
39.333 - int sz = get16(bb, off + 2);
39.334 - if (get16(bb, off) == ZIP64_EXTID) {
39.335 - off += 4;
39.336 - // LOC extra zip64 entry MUST include BOTH original and
39.337 - // compressed file size fields
39.338 - if (sz < 16 || (off + sz) > len ) {
39.339 - // Invalid zip64 extra fields, simply skip. Even it's
39.340 - // rare, it's possible the entry size happens to be
39.341 - // the magic value and it "accidnetly" has some bytes
39.342 - // in extra match the id.
39.343 - return e;
39.344 - }
39.345 - e.setSize(get64(bb, off));
39.346 - e.setCompressedSize(get64(bb, off + 8));
39.347 - break;
39.348 - }
39.349 - off += (sz + 4);
39.350 - }
39.351 - }
39.352 - }
39.353 - return e;
39.354 - }
39.355 -
39.356 - /**
39.357 - * Creates a new <code>ZipEntry</code> object for the specified
39.358 - * entry name.
39.359 - *
39.360 - * @param name the ZIP file entry name
39.361 - * @return the ZipEntry just created
39.362 - */
39.363 - protected ZipEntry createZipEntry(String name) {
39.364 - return new ZipEntry(name);
39.365 - }
39.366 -
39.367 - /*
39.368 - * Reads end of deflated entry as well as EXT descriptor if present.
39.369 - */
39.370 - private void readEnd(ZipEntry e) throws IOException {
39.371 - int n = inf.getRemaining();
39.372 - if (n > 0) {
39.373 - ((PushbackInputStream)in).unread(buf, len - n, n);
39.374 - }
39.375 - if ((flag & 8) == 8) {
39.376 - /* "Data Descriptor" present */
39.377 - if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
39.378 - inf.getBytesRead() > ZIP64_MAGICVAL) {
39.379 - // ZIP64 format
39.380 - readFully(tmpbuf, 0, ZIP64_EXTHDR);
39.381 - long sig = get32(tmpbuf, 0);
39.382 - if (sig != EXTSIG) { // no EXTSIG present
39.383 - e.setCrc(sig);
39.384 - e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
39.385 - e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
39.386 - ((PushbackInputStream)in).unread(
39.387 - tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
39.388 - } else {
39.389 - e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
39.390 - e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
39.391 - e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
39.392 - }
39.393 - } else {
39.394 - readFully(tmpbuf, 0, EXTHDR);
39.395 - long sig = get32(tmpbuf, 0);
39.396 - if (sig != EXTSIG) { // no EXTSIG present
39.397 - e.setCrc(sig);
39.398 - e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
39.399 - e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
39.400 - ((PushbackInputStream)in).unread(
39.401 - tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
39.402 - } else {
39.403 - e.setCrc(get32(tmpbuf, EXTCRC));
39.404 - e.setCompressedSize(get32(tmpbuf, EXTSIZ));
39.405 - e.setSize(get32(tmpbuf, EXTLEN));
39.406 - }
39.407 - }
39.408 - }
39.409 - if (e.getSize() != inf.getBytesWritten()) {
39.410 - throw new ZipException(
39.411 - "invalid entry size (expected " + e.getSize() +
39.412 - " but got " + inf.getBytesWritten() + " bytes)");
39.413 - }
39.414 - if (e.getCompressedSize() != inf.getBytesRead()) {
39.415 - throw new ZipException(
39.416 - "invalid entry compressed size (expected " + e.getCompressedSize() +
39.417 - " but got " + inf.getBytesRead() + " bytes)");
39.418 - }
39.419 - if (e.getCrc() != crc.getValue()) {
39.420 - throw new ZipException(
39.421 - "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
39.422 - " but got 0x" + Long.toHexString(crc.getValue()) + ")");
39.423 - }
39.424 - }
39.425 -
39.426 - /*
39.427 - * Reads bytes, blocking until all bytes are read.
39.428 - */
39.429 - private void readFully(byte[] b, int off, int len) throws IOException {
39.430 - while (len > 0) {
39.431 - int n = in.read(b, off, len);
39.432 - if (n == -1) {
39.433 - throw new EOFException();
39.434 - }
39.435 - off += n;
39.436 - len -= n;
39.437 - }
39.438 - }
39.439 -
39.440 - /*
39.441 - * Fetches unsigned 16-bit value from byte array at specified offset.
39.442 - * The bytes are assumed to be in Intel (little-endian) byte order.
39.443 - */
39.444 - private static final int get16(byte b[], int off) {
39.445 - return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
39.446 - }
39.447 -
39.448 - /*
39.449 - * Fetches unsigned 32-bit value from byte array at specified offset.
39.450 - * The bytes are assumed to be in Intel (little-endian) byte order.
39.451 - */
39.452 - private static final long get32(byte b[], int off) {
39.453 - return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
39.454 - }
39.455 -
39.456 - /*
39.457 - * Fetches signed 64-bit value from byte array at specified offset.
39.458 - * The bytes are assumed to be in Intel (little-endian) byte order.
39.459 - */
39.460 - private static final long get64(byte b[], int off) {
39.461 - return get32(b, off) | (get32(b, off+4) << 32);
39.462 - }
39.463 -
39.464 - private static String toStringUTF8(byte[] arr, int len) {
39.465 - return new String(arr, 0, len);
39.466 - }
39.467 -
39.468 - private static String toString(byte[] b, int len) {
39.469 - return new String(b, 0, len);
39.470 - }
39.471 -}
40.1 --- a/rt/emul/pom.xml Tue May 06 17:46:47 2014 +0200
40.2 +++ b/rt/emul/pom.xml Sun May 11 14:01:18 2014 +0200
40.3 @@ -16,5 +16,6 @@
40.4 <module>compact</module>
40.5 <module>brwsrtest</module>
40.6 <module>fake</module>
40.7 + <module>zip</module>
40.8 </modules>
40.9 </project>
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
41.2 +++ b/rt/emul/zip/pom.xml Sun May 11 14:01:18 2014 +0200
41.3 @@ -0,0 +1,70 @@
41.4 +<?xml version="1.0" encoding="UTF-8"?>
41.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">
41.6 + <modelVersion>4.0.0</modelVersion>
41.7 + <parent>
41.8 + <groupId>org.apidesign.bck2brwsr</groupId>
41.9 + <artifactId>emul.pom</artifactId>
41.10 + <version>0.9-SNAPSHOT</version>
41.11 + </parent>
41.12 + <artifactId>emul.zip</artifactId>
41.13 + <name>Unzip by JCraft for Bck2Brwsr</name>
41.14 + <description>>
41.15 + 100% pure Java re-implementation of Zlib
41.16 + that allows usage of JAR files with Bck2Brwsr
41.17 + virtual machine.
41.18 + </description>
41.19 + <packaging>jar</packaging>
41.20 + <build>
41.21 + <plugins>
41.22 + <plugin>
41.23 + <groupId>org.apache.maven.plugins</groupId>
41.24 + <artifactId>maven-surefire-plugin</artifactId>
41.25 + <configuration>
41.26 + <systemProperties>
41.27 + <vmtest.js>brwsr</vmtest.js>
41.28 + </systemProperties>
41.29 + </configuration>
41.30 + </plugin>
41.31 + </plugins>
41.32 + </build>
41.33 + <dependencies>
41.34 + <dependency>
41.35 + <groupId>org.apidesign.bck2brwsr</groupId>
41.36 + <artifactId>core</artifactId>
41.37 + <version>${project.version}</version>
41.38 + <type>jar</type>
41.39 + </dependency>
41.40 + <dependency>
41.41 + <groupId>org.testng</groupId>
41.42 + <artifactId>testng</artifactId>
41.43 + <scope>test</scope>
41.44 + </dependency>
41.45 + <dependency>
41.46 + <groupId>org.apidesign.bck2brwsr</groupId>
41.47 + <artifactId>emul.mini</artifactId>
41.48 + <version>${project.version}</version>
41.49 + <scope>compile</scope>
41.50 + <type>jar</type>
41.51 + </dependency>
41.52 + <dependency>
41.53 + <groupId>org.apidesign.bck2brwsr</groupId>
41.54 + <artifactId>vmtest</artifactId>
41.55 + <version>${project.version}</version>
41.56 + <scope>test</scope>
41.57 + <type>jar</type>
41.58 + </dependency>
41.59 + <dependency>
41.60 + <groupId>org.apidesign.bck2brwsr</groupId>
41.61 + <artifactId>launcher.http</artifactId>
41.62 + <version>${project.version}</version>
41.63 + <scope>test</scope>
41.64 + <type>jar</type>
41.65 + </dependency>
41.66 + <dependency>
41.67 + <groupId>org.apidesign.bck2brwsr</groupId>
41.68 + <artifactId>vm4brwsr</artifactId>
41.69 + <version>${project.version}</version>
41.70 + <type>jar</type>
41.71 + </dependency>
41.72 + </dependencies>
41.73 +</project>
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
42.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/Adler32.java Sun May 11 14:01:18 2014 +0200
42.3 @@ -0,0 +1,205 @@
42.4 +/* Adler32.java - Computes Adler32 data checksum of a data stream
42.5 + Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
42.6 +
42.7 +This file is part of GNU Classpath.
42.8 +
42.9 +GNU Classpath is free software; you can redistribute it and/or modify
42.10 +it under the terms of the GNU General Public License as published by
42.11 +the Free Software Foundation; either version 2, or (at your option)
42.12 +any later version.
42.13 +
42.14 +GNU Classpath is distributed in the hope that it will be useful, but
42.15 +WITHOUT ANY WARRANTY; without even the implied warranty of
42.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42.17 +General Public License for more details.
42.18 +
42.19 +You should have received a copy of the GNU General Public License
42.20 +along with GNU Classpath; see the file COPYING. If not, write to the
42.21 +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
42.22 +02111-1307 USA.
42.23 +
42.24 +Linking this library statically or dynamically with other modules is
42.25 +making a combined work based on this library. Thus, the terms and
42.26 +conditions of the GNU General Public License cover the whole
42.27 +combination.
42.28 +
42.29 +As a special exception, the copyright holders of this library give you
42.30 +permission to link this library with independent modules to produce an
42.31 +executable, regardless of the license terms of these independent
42.32 +modules, and to copy and distribute the resulting executable under
42.33 +terms of your choice, provided that you also meet, for each linked
42.34 +independent module, the terms and conditions of the license of that
42.35 +module. An independent module is a module which is not derived from
42.36 +or based on this library. If you modify this library, you may extend
42.37 +this exception to your version of the library, but you are not
42.38 +obligated to do so. If you do not wish to do so, delete this
42.39 +exception statement from your version. */
42.40 +
42.41 +package java.util.zip;
42.42 +
42.43 +/*
42.44 + * Written using on-line Java Platform 1.2 API Specification, as well
42.45 + * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
42.46 + * The actual Adler32 algorithm is taken from RFC 1950.
42.47 + * Status: Believed complete and correct.
42.48 + */
42.49 +
42.50 +/**
42.51 + * Computes Adler32 checksum for a stream of data. An Adler32
42.52 + * checksum is not as reliable as a CRC32 checksum, but a lot faster to
42.53 + * compute.
42.54 + *<p>
42.55 + * The specification for Adler32 may be found in RFC 1950.
42.56 + * (ZLIB Compressed Data Format Specification version 3.3)
42.57 + *<p>
42.58 + *<p>
42.59 + * From that document:
42.60 + *<p>
42.61 + * "ADLER32 (Adler-32 checksum)
42.62 + * This contains a checksum value of the uncompressed data
42.63 + * (excluding any dictionary data) computed according to Adler-32
42.64 + * algorithm. This algorithm is a 32-bit extension and improvement
42.65 + * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
42.66 + * standard.
42.67 + *<p>
42.68 + * Adler-32 is composed of two sums accumulated per byte: s1 is
42.69 + * the sum of all bytes, s2 is the sum of all s1 values. Both sums
42.70 + * are done modulo 65521. s1 is initialized to 1, s2 to zero. The
42.71 + * Adler-32 checksum is stored as s2*65536 + s1 in most-
42.72 + * significant-byte first (network) order."
42.73 + *<p>
42.74 + * "8.2. The Adler-32 algorithm
42.75 + *<p>
42.76 + * The Adler-32 algorithm is much faster than the CRC32 algorithm yet
42.77 + * still provides an extremely low probability of undetected errors.
42.78 + *<p>
42.79 + * The modulo on unsigned long accumulators can be delayed for 5552
42.80 + * bytes, so the modulo operation time is negligible. If the bytes
42.81 + * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
42.82 + * and order sensitive, unlike the first sum, which is just a
42.83 + * checksum. That 65521 is prime is important to avoid a possible
42.84 + * large class of two-byte errors that leave the check unchanged.
42.85 + * (The Fletcher checksum uses 255, which is not prime and which also
42.86 + * makes the Fletcher check insensitive to single byte changes 0 <->
42.87 + * 255.)
42.88 + *<p>
42.89 + * The sum s1 is initialized to 1 instead of zero to make the length
42.90 + * of the sequence part of s2, so that the length does not have to be
42.91 + * checked separately. (Any sequence of zeroes has a Fletcher
42.92 + * checksum of zero.)"
42.93 + *
42.94 + * @author John Leuner, Per Bothner
42.95 + * @since JDK 1.1
42.96 + *
42.97 + * @see InflaterInputStream
42.98 + * @see DeflaterOutputStream
42.99 + */
42.100 +public class Adler32 implements Checksum
42.101 +{
42.102 +
42.103 + /** largest prime smaller than 65536 */
42.104 + private static final int BASE = 65521;
42.105 +
42.106 + private int checksum; //we do all in int.
42.107 +
42.108 + //Note that java doesn't have unsigned integers,
42.109 + //so we have to be careful with what arithmetic
42.110 + //we do. We return the checksum as a long to
42.111 + //avoid sign confusion.
42.112 +
42.113 + /**
42.114 + * Creates a new instance of the <code>Adler32</code> class.
42.115 + * The checksum starts off with a value of 1.
42.116 + */
42.117 + public Adler32 ()
42.118 + {
42.119 + reset();
42.120 + }
42.121 +
42.122 + /**
42.123 + * Resets the Adler32 checksum to the initial value.
42.124 + */
42.125 + public void reset ()
42.126 + {
42.127 + checksum = 1; //Initialize to 1
42.128 + }
42.129 +
42.130 + /**
42.131 + * Updates the checksum with the byte b.
42.132 + *
42.133 + * @param bval the data value to add. The high byte of the int is ignored.
42.134 + */
42.135 + public void update (int bval)
42.136 + {
42.137 + //We could make a length 1 byte array and call update again, but I
42.138 + //would rather not have that overhead
42.139 + int s1 = checksum & 0xffff;
42.140 + int s2 = checksum >>> 16;
42.141 +
42.142 + s1 = (s1 + (bval & 0xFF)) % BASE;
42.143 + s2 = (s1 + s2) % BASE;
42.144 +
42.145 + checksum = (s2 << 16) + s1;
42.146 + }
42.147 +
42.148 + /**
42.149 + * Updates the checksum with the bytes taken from the array.
42.150 + *
42.151 + * @param buffer an array of bytes
42.152 + */
42.153 + public void update (byte[] buffer)
42.154 + {
42.155 + update(buffer, 0, buffer.length);
42.156 + }
42.157 +
42.158 + /**
42.159 + * Updates the checksum with the bytes taken from the array.
42.160 + *
42.161 + * @param buf an array of bytes
42.162 + * @param off the start of the data used for this update
42.163 + * @param len the number of bytes to use for this update
42.164 + */
42.165 + public void update (byte[] buf, int off, int len)
42.166 + {
42.167 + //(By Per Bothner)
42.168 + int s1 = checksum & 0xffff;
42.169 + int s2 = checksum >>> 16;
42.170 +
42.171 + while (len > 0)
42.172 + {
42.173 + // We can defer the modulo operation:
42.174 + // s1 maximally grows from 65521 to 65521 + 255 * 3800
42.175 + // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
42.176 + int n = 3800;
42.177 + if (n > len)
42.178 + n = len;
42.179 + len -= n;
42.180 + while (--n >= 0)
42.181 + {
42.182 + s1 = s1 + (buf[off++] & 0xFF);
42.183 + s2 = s2 + s1;
42.184 + }
42.185 + s1 %= BASE;
42.186 + s2 %= BASE;
42.187 + }
42.188 +
42.189 + /*Old implementation, borrowed from somewhere:
42.190 + int n;
42.191 +
42.192 + while (len-- > 0) {
42.193 +
42.194 + s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
42.195 + s2 = (s2 + s1) % BASE;
42.196 + }*/
42.197 +
42.198 + checksum = (s2 << 16) | s1;
42.199 + }
42.200 +
42.201 + /**
42.202 + * Returns the Adler32 data checksum computed so far.
42.203 + */
42.204 + public long getValue()
42.205 + {
42.206 + return (long) checksum & 0xffffffffL;
42.207 + }
42.208 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/CRC32.java Sun May 11 14:01:18 2014 +0200
43.3 @@ -0,0 +1,132 @@
43.4 +/* CRC32.java - Computes CRC32 data checksum of a data stream
43.5 + Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
43.6 +
43.7 +This file is part of GNU Classpath.
43.8 +
43.9 +GNU Classpath is free software; you can redistribute it and/or modify
43.10 +it under the terms of the GNU General Public License as published by
43.11 +the Free Software Foundation; either version 2, or (at your option)
43.12 +any later version.
43.13 +
43.14 +GNU Classpath is distributed in the hope that it will be useful, but
43.15 +WITHOUT ANY WARRANTY; without even the implied warranty of
43.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43.17 +General Public License for more details.
43.18 +
43.19 +You should have received a copy of the GNU General Public License
43.20 +along with GNU Classpath; see the file COPYING. If not, write to the
43.21 +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
43.22 +02111-1307 USA.
43.23 +
43.24 +Linking this library statically or dynamically with other modules is
43.25 +making a combined work based on this library. Thus, the terms and
43.26 +conditions of the GNU General Public License cover the whole
43.27 +combination.
43.28 +
43.29 +As a special exception, the copyright holders of this library give you
43.30 +permission to link this library with independent modules to produce an
43.31 +executable, regardless of the license terms of these independent
43.32 +modules, and to copy and distribute the resulting executable under
43.33 +terms of your choice, provided that you also meet, for each linked
43.34 +independent module, the terms and conditions of the license of that
43.35 +module. An independent module is a module which is not derived from
43.36 +or based on this library. If you modify this library, you may extend
43.37 +this exception to your version of the library, but you are not
43.38 +obligated to do so. If you do not wish to do so, delete this
43.39 +exception statement from your version. */
43.40 +
43.41 +package java.util.zip;
43.42 +
43.43 +/*
43.44 + * Written using on-line Java Platform 1.2 API Specification, as well
43.45 + * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
43.46 + * The actual CRC32 algorithm is taken from RFC 1952.
43.47 + * Status: Believed complete and correct.
43.48 + */
43.49 +
43.50 +/**
43.51 + * Computes CRC32 data checksum of a data stream.
43.52 + * The actual CRC32 algorithm is described in RFC 1952
43.53 + * (GZIP file format specification version 4.3).
43.54 + * Can be used to get the CRC32 over a stream if used with checked input/output
43.55 + * streams.
43.56 + *
43.57 + * @see InflaterInputStream
43.58 + * @see DeflaterOutputStream
43.59 + *
43.60 + * @author Per Bothner
43.61 + * @date April 1, 1999.
43.62 + */
43.63 +public class CRC32 implements Checksum
43.64 +{
43.65 + /** The crc data checksum so far. */
43.66 + private int crc = 0;
43.67 +
43.68 + /** The fast CRC table. Computed once when the CRC32 class is loaded. */
43.69 + private static int[] crc_table = make_crc_table();
43.70 +
43.71 + /** Make the table for a fast CRC. */
43.72 + private static int[] make_crc_table ()
43.73 + {
43.74 + int[] crc_table = new int[256];
43.75 + for (int n = 0; n < 256; n++)
43.76 + {
43.77 + int c = n;
43.78 + for (int k = 8; --k >= 0; )
43.79 + {
43.80 + if ((c & 1) != 0)
43.81 + c = 0xedb88320 ^ (c >>> 1);
43.82 + else
43.83 + c = c >>> 1;
43.84 + }
43.85 + crc_table[n] = c;
43.86 + }
43.87 + return crc_table;
43.88 + }
43.89 +
43.90 + /**
43.91 + * Returns the CRC32 data checksum computed so far.
43.92 + */
43.93 + public long getValue ()
43.94 + {
43.95 + return (long) crc & 0xffffffffL;
43.96 + }
43.97 +
43.98 + /**
43.99 + * Resets the CRC32 data checksum as if no update was ever called.
43.100 + */
43.101 + public void reset () { crc = 0; }
43.102 +
43.103 + /**
43.104 + * Updates the checksum with the int bval.
43.105 + *
43.106 + * @param bval (the byte is taken as the lower 8 bits of bval)
43.107 + */
43.108 +
43.109 + public void update (int bval)
43.110 + {
43.111 + int c = ~crc;
43.112 + c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
43.113 + crc = ~c;
43.114 + }
43.115 +
43.116 + /**
43.117 + * Adds the byte array to the data checksum.
43.118 + *
43.119 + * @param buf the buffer which contains the data
43.120 + * @param off the offset in the buffer where the data starts
43.121 + * @param len the length of the data
43.122 + */
43.123 + public void update (byte[] buf, int off, int len)
43.124 + {
43.125 + int c = ~crc;
43.126 + while (--len >= 0)
43.127 + c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
43.128 + crc = ~c;
43.129 + }
43.130 +
43.131 + /**
43.132 + * Adds the complete byte array to the data checksum.
43.133 + */
43.134 + public void update (byte[] buf) { update(buf, 0, buf.length); }
43.135 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/Checksum.java Sun May 11 14:01:18 2014 +0200
44.3 @@ -0,0 +1,60 @@
44.4 +/*
44.5 + * Copyright (c) 1996, 1999, 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 + * An interface representing a data checksum.
44.33 + *
44.34 + * @author David Connelly
44.35 + */
44.36 +public
44.37 +interface Checksum {
44.38 + /**
44.39 + * Updates the current checksum with the specified byte.
44.40 + *
44.41 + * @param b the byte to update the checksum with
44.42 + */
44.43 + public void update(int b);
44.44 +
44.45 + /**
44.46 + * Updates the current checksum with the specified array of bytes.
44.47 + * @param b the byte array to update the checksum with
44.48 + * @param off the start offset of the data
44.49 + * @param len the number of bytes to use for the update
44.50 + */
44.51 + public void update(byte[] b, int off, int len);
44.52 +
44.53 + /**
44.54 + * Returns the current checksum value.
44.55 + * @return the current checksum value
44.56 + */
44.57 + public long getValue();
44.58 +
44.59 + /**
44.60 + * Resets the checksum to its initial value.
44.61 + */
44.62 + public void reset();
44.63 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
45.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/DataFormatException.java Sun May 11 14:01:18 2014 +0200
45.3 @@ -0,0 +1,52 @@
45.4 +/*
45.5 + * Copyright (c) 1996, 2008, 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 + * Signals that a data format error has occurred.
45.33 + *
45.34 + * @author David Connelly
45.35 + */
45.36 +public
45.37 +class DataFormatException extends Exception {
45.38 + private static final long serialVersionUID = 2219632870893641452L;
45.39 +
45.40 + /**
45.41 + * Constructs a DataFormatException with no detail message.
45.42 + */
45.43 + public DataFormatException() {
45.44 + super();
45.45 + }
45.46 +
45.47 + /**
45.48 + * Constructs a DataFormatException with the specified detail message.
45.49 + * A detail message is a String that describes this particular exception.
45.50 + * @param s the String containing a detail message
45.51 + */
45.52 + public DataFormatException(String s) {
45.53 + super(s);
45.54 + }
45.55 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
46.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/Inflater.java Sun May 11 14:01:18 2014 +0200
46.3 @@ -0,0 +1,310 @@
46.4 +/*
46.5 + * Copyright (c) 1996, 2011, 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 +/**
46.32 + * This class provides support for general purpose decompression using the
46.33 + * popular ZLIB compression library. The ZLIB compression library was
46.34 + * initially developed as part of the PNG graphics standard and is not
46.35 + * protected by patents. It is fully described in the specifications at
46.36 + * the <a href="package-summary.html#package_description">java.util.zip
46.37 + * package description</a>.
46.38 + *
46.39 + * <p>The following code fragment demonstrates a trivial compression
46.40 + * and decompression of a string using <tt>Deflater</tt> and
46.41 + * <tt>Inflater</tt>.
46.42 + *
46.43 + * <blockquote><pre>
46.44 + * try {
46.45 + * // Encode a String into bytes
46.46 + * String inputString = "blahblahblah\u20AC\u20AC";
46.47 + * byte[] input = inputString.getBytes("UTF-8");
46.48 + *
46.49 + * // Compress the bytes
46.50 + * byte[] output = new byte[100];
46.51 + * Deflater compresser = new Deflater();
46.52 + * compresser.setInput(input);
46.53 + * compresser.finish();
46.54 + * int compressedDataLength = compresser.deflate(output);
46.55 + *
46.56 + * // Decompress the bytes
46.57 + * Inflater decompresser = new Inflater();
46.58 + * decompresser.setInput(output, 0, compressedDataLength);
46.59 + * byte[] result = new byte[100];
46.60 + * int resultLength = decompresser.inflate(result);
46.61 + * decompresser.end();
46.62 + *
46.63 + * // Decode the bytes into a String
46.64 + * String outputString = new String(result, 0, resultLength, "UTF-8");
46.65 + * } catch(java.io.UnsupportedEncodingException ex) {
46.66 + * // handle
46.67 + * } catch (java.util.zip.DataFormatException ex) {
46.68 + * // handle
46.69 + * }
46.70 + * </pre></blockquote>
46.71 + *
46.72 + * @see Deflater
46.73 + * @author David Connelly
46.74 + *
46.75 + */
46.76 +public
46.77 +class Inflater {
46.78 + private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
46.79 +
46.80 + /**
46.81 + * Creates a new decompressor. If the parameter 'nowrap' is true then
46.82 + * the ZLIB header and checksum fields will not be used. This provides
46.83 + * compatibility with the compression format used by both GZIP and PKZIP.
46.84 + * <p>
46.85 + * Note: When using the 'nowrap' option it is also necessary to provide
46.86 + * an extra "dummy" byte as input. This is required by the ZLIB native
46.87 + * library in order to support certain optimizations.
46.88 + *
46.89 + * @param nowrap if true then support GZIP compatible compression
46.90 + */
46.91 + public Inflater(boolean nowrap) {
46.92 + if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
46.93 + impl = null;
46.94 + } else {
46.95 + impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
46.96 + }
46.97 + }
46.98 +
46.99 + /**
46.100 + * Creates a new decompressor.
46.101 + */
46.102 + public Inflater() {
46.103 + this(false);
46.104 + }
46.105 +
46.106 + /**
46.107 + * Sets input data for decompression. Should be called whenever
46.108 + * needsInput() returns true indicating that more input data is
46.109 + * required.
46.110 + * @param b the input data bytes
46.111 + * @param off the start offset of the input data
46.112 + * @param len the length of the input data
46.113 + * @see Inflater#needsInput
46.114 + */
46.115 + public void setInput(byte[] b, int off, int len) {
46.116 + impl.setInput(b, off, len);
46.117 + }
46.118 +
46.119 + /**
46.120 + * Sets input data for decompression. Should be called whenever
46.121 + * needsInput() returns true indicating that more input data is
46.122 + * required.
46.123 + * @param b the input data bytes
46.124 + * @see Inflater#needsInput
46.125 + */
46.126 + public void setInput(byte[] b) {
46.127 + impl.setInput(b);
46.128 + }
46.129 +
46.130 + /**
46.131 + * Sets the preset dictionary to the given array of bytes. Should be
46.132 + * called when inflate() returns 0 and needsDictionary() returns true
46.133 + * indicating that a preset dictionary is required. The method getAdler()
46.134 + * can be used to get the Adler-32 value of the dictionary needed.
46.135 + * @param b the dictionary data bytes
46.136 + * @param off the start offset of the data
46.137 + * @param len the length of the data
46.138 + * @see Inflater#needsDictionary
46.139 + * @see Inflater#getAdler
46.140 + */
46.141 + public void setDictionary(byte[] b, int off, int len) {
46.142 + impl.setDictionary(b, off, len);
46.143 + }
46.144 +
46.145 + /**
46.146 + * Sets the preset dictionary to the given array of bytes. Should be
46.147 + * called when inflate() returns 0 and needsDictionary() returns true
46.148 + * indicating that a preset dictionary is required. The method getAdler()
46.149 + * can be used to get the Adler-32 value of the dictionary needed.
46.150 + * @param b the dictionary data bytes
46.151 + * @see Inflater#needsDictionary
46.152 + * @see Inflater#getAdler
46.153 + */
46.154 + public void setDictionary(byte[] b) {
46.155 + impl.setDictionary(b);
46.156 + }
46.157 +
46.158 + /**
46.159 + * Returns the total number of bytes remaining in the input buffer.
46.160 + * This can be used to find out what bytes still remain in the input
46.161 + * buffer after decompression has finished.
46.162 + * @return the total number of bytes remaining in the input buffer
46.163 + */
46.164 + public int getRemaining() {
46.165 + return impl.getRemaining();
46.166 + }
46.167 +
46.168 + /**
46.169 + * Returns true if no data remains in the input buffer. This can
46.170 + * be used to determine if #setInput should be called in order
46.171 + * to provide more input.
46.172 + * @return true if no data remains in the input buffer
46.173 + */
46.174 + public boolean needsInput() {
46.175 + return impl.needsInput();
46.176 + }
46.177 +
46.178 + /**
46.179 + * Returns true if a preset dictionary is needed for decompression.
46.180 + * @return true if a preset dictionary is needed for decompression
46.181 + * @see Inflater#setDictionary
46.182 + */
46.183 + public boolean needsDictionary() {
46.184 + return impl.needsDictionary();
46.185 + }
46.186 +
46.187 + /**
46.188 + * Returns true if the end of the compressed data stream has been
46.189 + * reached.
46.190 + * @return true if the end of the compressed data stream has been
46.191 + * reached
46.192 + */
46.193 + public boolean finished() {
46.194 + return impl.finished();
46.195 + }
46.196 +
46.197 + /**
46.198 + * Uncompresses bytes into specified buffer. Returns actual number
46.199 + * of bytes uncompressed. A return value of 0 indicates that
46.200 + * needsInput() or needsDictionary() should be called in order to
46.201 + * determine if more input data or a preset dictionary is required.
46.202 + * In the latter case, getAdler() can be used to get the Adler-32
46.203 + * value of the dictionary required.
46.204 + * @param b the buffer for the uncompressed data
46.205 + * @param off the start offset of the data
46.206 + * @param len the maximum number of uncompressed bytes
46.207 + * @return the actual number of uncompressed bytes
46.208 + * @exception DataFormatException if the compressed data format is invalid
46.209 + * @see Inflater#needsInput
46.210 + * @see Inflater#needsDictionary
46.211 + */
46.212 + public int inflate(byte[] b, int off, int len)
46.213 + throws DataFormatException
46.214 + {
46.215 + return impl.inflate(b, off, len);
46.216 + }
46.217 +
46.218 + /**
46.219 + * Uncompresses bytes into specified buffer. Returns actual number
46.220 + * of bytes uncompressed. A return value of 0 indicates that
46.221 + * needsInput() or needsDictionary() should be called in order to
46.222 + * determine if more input data or a preset dictionary is required.
46.223 + * In the latter case, getAdler() can be used to get the Adler-32
46.224 + * value of the dictionary required.
46.225 + * @param b the buffer for the uncompressed data
46.226 + * @return the actual number of uncompressed bytes
46.227 + * @exception DataFormatException if the compressed data format is invalid
46.228 + * @see Inflater#needsInput
46.229 + * @see Inflater#needsDictionary
46.230 + */
46.231 + public int inflate(byte[] b) throws DataFormatException {
46.232 + return impl.inflate(b);
46.233 + }
46.234 +
46.235 + /**
46.236 + * Returns the ADLER-32 value of the uncompressed data.
46.237 + * @return the ADLER-32 value of the uncompressed data
46.238 + */
46.239 + public int getAdler() {
46.240 + return impl.getAdler();
46.241 + }
46.242 +
46.243 + /**
46.244 + * Returns the total number of compressed bytes input so far.
46.245 + *
46.246 + * <p>Since the number of bytes may be greater than
46.247 + * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
46.248 + * the preferred means of obtaining this information.</p>
46.249 + *
46.250 + * @return the total number of compressed bytes input so far
46.251 + */
46.252 + public int getTotalIn() {
46.253 + return impl.getTotalIn();
46.254 + }
46.255 +
46.256 + /**
46.257 + * Returns the total number of compressed bytes input so far.</p>
46.258 + *
46.259 + * @return the total (non-negative) number of compressed bytes input so far
46.260 + * @since 1.5
46.261 + */
46.262 + public long getBytesRead() {
46.263 + return impl.getBytesRead();
46.264 + }
46.265 +
46.266 + /**
46.267 + * Returns the total number of uncompressed bytes output so far.
46.268 + *
46.269 + * <p>Since the number of bytes may be greater than
46.270 + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
46.271 + * the preferred means of obtaining this information.</p>
46.272 + *
46.273 + * @return the total number of uncompressed bytes output so far
46.274 + */
46.275 + public int getTotalOut() {
46.276 + return impl.getTotalOut();
46.277 + }
46.278 +
46.279 + /**
46.280 + * Returns the total number of uncompressed bytes output so far.</p>
46.281 + *
46.282 + * @return the total (non-negative) number of uncompressed bytes output so far
46.283 + * @since 1.5
46.284 + */
46.285 + public long getBytesWritten() {
46.286 + return impl.getBytesWritten();
46.287 + }
46.288 +
46.289 + /**
46.290 + * Resets inflater so that a new set of input data can be processed.
46.291 + */
46.292 + public void reset() {
46.293 + impl.reset();
46.294 + }
46.295 +
46.296 + /**
46.297 + * Closes the decompressor and discards any unprocessed input.
46.298 + * This method should be called when the decompressor is no longer
46.299 + * being used, but will also be called automatically by the finalize()
46.300 + * method. Once this method is called, the behavior of the Inflater
46.301 + * object is undefined.
46.302 + */
46.303 + public void end() {
46.304 + impl.end();
46.305 + }
46.306 +
46.307 + /**
46.308 + * Closes the decompressor when garbage is collected.
46.309 + */
46.310 + protected void finalize() {
46.311 + end();
46.312 + }
46.313 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
47.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/InflaterInputStream.java Sun May 11 14:01:18 2014 +0200
47.3 @@ -0,0 +1,288 @@
47.4 +/*
47.5 + * Copyright (c) 1996, 2006, 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.FilterInputStream;
47.32 +import java.io.InputStream;
47.33 +import java.io.IOException;
47.34 +import java.io.EOFException;
47.35 +
47.36 +/**
47.37 + * This class implements a stream filter for uncompressing data in the
47.38 + * "deflate" compression format. It is also used as the basis for other
47.39 + * decompression filters, such as GZIPInputStream.
47.40 + *
47.41 + * @see Inflater
47.42 + * @author David Connelly
47.43 + */
47.44 +public
47.45 +class InflaterInputStream extends FilterInputStream {
47.46 + /**
47.47 + * Decompressor for this stream.
47.48 + */
47.49 + protected Inflater inf;
47.50 +
47.51 + /**
47.52 + * Input buffer for decompression.
47.53 + */
47.54 + protected byte[] buf;
47.55 +
47.56 + /**
47.57 + * Length of input buffer.
47.58 + */
47.59 + protected int len;
47.60 +
47.61 + private boolean closed = false;
47.62 + // this flag is set to true after EOF has reached
47.63 + private boolean reachEOF = false;
47.64 +
47.65 + /**
47.66 + * Check to make sure that this stream has not been closed
47.67 + */
47.68 + private void ensureOpen() throws IOException {
47.69 + if (closed) {
47.70 + throw new IOException("Stream closed");
47.71 + }
47.72 + }
47.73 +
47.74 +
47.75 + /**
47.76 + * Creates a new input stream with the specified decompressor and
47.77 + * buffer size.
47.78 + * @param in the input stream
47.79 + * @param inf the decompressor ("inflater")
47.80 + * @param size the input buffer size
47.81 + * @exception IllegalArgumentException if size is <= 0
47.82 + */
47.83 + public InflaterInputStream(InputStream in, Inflater inf, int size) {
47.84 + super(in);
47.85 + if (in == null || inf == null) {
47.86 + throw new NullPointerException();
47.87 + } else if (size <= 0) {
47.88 + throw new IllegalArgumentException("buffer size <= 0");
47.89 + }
47.90 + this.inf = inf;
47.91 + buf = new byte[size];
47.92 + }
47.93 +
47.94 + /**
47.95 + * Creates a new input stream with the specified decompressor and a
47.96 + * default buffer size.
47.97 + * @param in the input stream
47.98 + * @param inf the decompressor ("inflater")
47.99 + */
47.100 + public InflaterInputStream(InputStream in, Inflater inf) {
47.101 + this(in, inf, 512);
47.102 + }
47.103 +
47.104 + boolean usesDefaultInflater = false;
47.105 +
47.106 + /**
47.107 + * Creates a new input stream with a default decompressor and buffer size.
47.108 + * @param in the input stream
47.109 + */
47.110 + public InflaterInputStream(InputStream in) {
47.111 + this(in, new Inflater());
47.112 + usesDefaultInflater = true;
47.113 + }
47.114 +
47.115 + private byte[] singleByteBuf = new byte[1];
47.116 +
47.117 + /**
47.118 + * Reads a byte of uncompressed data. This method will block until
47.119 + * enough input is available for decompression.
47.120 + * @return the byte read, or -1 if end of compressed input is reached
47.121 + * @exception IOException if an I/O error has occurred
47.122 + */
47.123 + public int read() throws IOException {
47.124 + ensureOpen();
47.125 + return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
47.126 + }
47.127 +
47.128 + /**
47.129 + * Reads uncompressed data into an array of bytes. If <code>len</code> is not
47.130 + * zero, the method will block until some input can be decompressed; otherwise,
47.131 + * no bytes are read and <code>0</code> is returned.
47.132 + * @param b the buffer into which the data is read
47.133 + * @param off the start offset in the destination array <code>b</code>
47.134 + * @param len the maximum number of bytes read
47.135 + * @return the actual number of bytes read, or -1 if the end of the
47.136 + * compressed input is reached or a preset dictionary is needed
47.137 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
47.138 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
47.139 + * <code>len</code> is negative, or <code>len</code> is greater than
47.140 + * <code>b.length - off</code>
47.141 + * @exception ZipException if a ZIP format error has occurred
47.142 + * @exception IOException if an I/O error has occurred
47.143 + */
47.144 + public int read(byte[] b, int off, int len) throws IOException {
47.145 + ensureOpen();
47.146 + if (b == null) {
47.147 + throw new NullPointerException();
47.148 + } else if (off < 0 || len < 0 || len > b.length - off) {
47.149 + throw new IndexOutOfBoundsException();
47.150 + } else if (len == 0) {
47.151 + return 0;
47.152 + }
47.153 + try {
47.154 + int n;
47.155 + while ((n = inf.inflate(b, off, len)) == 0) {
47.156 + if (inf.finished() || inf.needsDictionary()) {
47.157 + reachEOF = true;
47.158 + return -1;
47.159 + }
47.160 + if (inf.needsInput()) {
47.161 + fill();
47.162 + }
47.163 + }
47.164 + return n;
47.165 + } catch (DataFormatException e) {
47.166 + String s = e.getMessage();
47.167 + throw new ZipException(s != null ? s : "Invalid ZLIB data format");
47.168 + }
47.169 + }
47.170 +
47.171 + /**
47.172 + * Returns 0 after EOF has been reached, otherwise always return 1.
47.173 + * <p>
47.174 + * Programs should not count on this method to return the actual number
47.175 + * of bytes that could be read without blocking.
47.176 + *
47.177 + * @return 1 before EOF and 0 after EOF.
47.178 + * @exception IOException if an I/O error occurs.
47.179 + *
47.180 + */
47.181 + public int available() throws IOException {
47.182 + ensureOpen();
47.183 + if (reachEOF) {
47.184 + return 0;
47.185 + } else {
47.186 + return 1;
47.187 + }
47.188 + }
47.189 +
47.190 + private byte[] b = new byte[512];
47.191 +
47.192 + /**
47.193 + * Skips specified number of bytes of uncompressed data.
47.194 + * @param n the number of bytes to skip
47.195 + * @return the actual number of bytes skipped.
47.196 + * @exception IOException if an I/O error has occurred
47.197 + * @exception IllegalArgumentException if n < 0
47.198 + */
47.199 + public long skip(long n) throws IOException {
47.200 + if (n < 0) {
47.201 + throw new IllegalArgumentException("negative skip length");
47.202 + }
47.203 + ensureOpen();
47.204 + int max = (int)Math.min(n, Integer.MAX_VALUE);
47.205 + int total = 0;
47.206 + while (total < max) {
47.207 + int len = max - total;
47.208 + if (len > b.length) {
47.209 + len = b.length;
47.210 + }
47.211 + len = read(b, 0, len);
47.212 + if (len == -1) {
47.213 + reachEOF = true;
47.214 + break;
47.215 + }
47.216 + total += len;
47.217 + }
47.218 + return total;
47.219 + }
47.220 +
47.221 + /**
47.222 + * Closes this input stream and releases any system resources associated
47.223 + * with the stream.
47.224 + * @exception IOException if an I/O error has occurred
47.225 + */
47.226 + public void close() throws IOException {
47.227 + if (!closed) {
47.228 + if (usesDefaultInflater)
47.229 + inf.end();
47.230 + in.close();
47.231 + closed = true;
47.232 + }
47.233 + }
47.234 +
47.235 + /**
47.236 + * Fills input buffer with more data to decompress.
47.237 + * @exception IOException if an I/O error has occurred
47.238 + */
47.239 + protected void fill() throws IOException {
47.240 + ensureOpen();
47.241 + len = in.read(buf, 0, buf.length);
47.242 + if (len == -1) {
47.243 + throw new EOFException("Unexpected end of ZLIB input stream");
47.244 + }
47.245 + inf.setInput(buf, 0, len);
47.246 + }
47.247 +
47.248 + /**
47.249 + * Tests if this input stream supports the <code>mark</code> and
47.250 + * <code>reset</code> methods. The <code>markSupported</code>
47.251 + * method of <code>InflaterInputStream</code> returns
47.252 + * <code>false</code>.
47.253 + *
47.254 + * @return a <code>boolean</code> indicating if this stream type supports
47.255 + * the <code>mark</code> and <code>reset</code> methods.
47.256 + * @see java.io.InputStream#mark(int)
47.257 + * @see java.io.InputStream#reset()
47.258 + */
47.259 + public boolean markSupported() {
47.260 + return false;
47.261 + }
47.262 +
47.263 + /**
47.264 + * Marks the current position in this input stream.
47.265 + *
47.266 + * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
47.267 + * does nothing.
47.268 + *
47.269 + * @param readlimit the maximum limit of bytes that can be read before
47.270 + * the mark position becomes invalid.
47.271 + * @see java.io.InputStream#reset()
47.272 + */
47.273 + public synchronized void mark(int readlimit) {
47.274 + }
47.275 +
47.276 + /**
47.277 + * Repositions this stream to the position at the time the
47.278 + * <code>mark</code> method was last called on this input stream.
47.279 + *
47.280 + * <p> The method <code>reset</code> for class
47.281 + * <code>InflaterInputStream</code> does nothing except throw an
47.282 + * <code>IOException</code>.
47.283 + *
47.284 + * @exception IOException if this method is invoked.
47.285 + * @see java.io.InputStream#mark(int)
47.286 + * @see java.io.IOException
47.287 + */
47.288 + public synchronized void reset() throws IOException {
47.289 + throw new IOException("mark/reset not supported");
47.290 + }
47.291 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
48.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZStreamRef.java Sun May 11 14:01:18 2014 +0200
48.3 @@ -0,0 +1,46 @@
48.4 +/*
48.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48.7 + *
48.8 + * This code is free software; you can redistribute it and/or modify it
48.9 + * under the terms of the GNU General Public License version 2 only, as
48.10 + * published by the Free Software Foundation. Oracle designates this
48.11 + * particular file as subject to the "Classpath" exception as provided
48.12 + * by Oracle in the LICENSE file that accompanied this code.
48.13 + *
48.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
48.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
48.17 + * version 2 for more details (a copy is included in the LICENSE file that
48.18 + * accompanied this code).
48.19 + *
48.20 + * You should have received a copy of the GNU General Public License version
48.21 + * 2 along with this work; if not, write to the Free Software Foundation,
48.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
48.23 + *
48.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
48.25 + * or visit www.oracle.com if you need additional information or have any
48.26 + * questions.
48.27 + */
48.28 +
48.29 +package java.util.zip;
48.30 +
48.31 +/**
48.32 + * A reference to the native zlib's z_stream structure.
48.33 + */
48.34 +
48.35 +class ZStreamRef {
48.36 +
48.37 + private long address;
48.38 + ZStreamRef (long address) {
48.39 + this.address = address;
48.40 + }
48.41 +
48.42 + long address() {
48.43 + return address;
48.44 + }
48.45 +
48.46 + void clear() {
48.47 + address = 0;
48.48 + }
48.49 +}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
49.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipConstants.java Sun May 11 14:01:18 2014 +0200
49.3 @@ -0,0 +1,98 @@
49.4 +/*
49.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49.7 + *
49.8 + * This code is free software; you can redistribute it and/or modify it
49.9 + * under the terms of the GNU General Public License version 2 only, as
49.10 + * published by the Free Software Foundation. Oracle designates this
49.11 + * particular file as subject to the "Classpath" exception as provided
49.12 + * by Oracle in the LICENSE file that accompanied this code.
49.13 + *
49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
49.17 + * version 2 for more details (a copy is included in the LICENSE file that
49.18 + * accompanied this code).
49.19 + *
49.20 + * You should have received a copy of the GNU General Public License version
49.21 + * 2 along with this work; if not, write to the Free Software Foundation,
49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49.23 + *
49.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49.25 + * or visit www.oracle.com if you need additional information or have any
49.26 + * questions.
49.27 + */
49.28 +
49.29 +package java.util.zip;
49.30 +
49.31 +/*
49.32 + * This interface defines the constants that are used by the classes
49.33 + * which manipulate ZIP files.
49.34 + *
49.35 + * @author David Connelly
49.36 + */
49.37 +interface ZipConstants {
49.38 + /*
49.39 + * Header signatures
49.40 + */
49.41 + static long LOCSIG = 0x04034b50L; // "PK\003\004"
49.42 + static long EXTSIG = 0x08074b50L; // "PK\007\008"
49.43 + static long CENSIG = 0x02014b50L; // "PK\001\002"
49.44 + static long ENDSIG = 0x06054b50L; // "PK\005\006"
49.45 +
49.46 + /*
49.47 + * Header sizes in bytes (including signatures)
49.48 + */
49.49 + static final int LOCHDR = 30; // LOC header size
49.50 + static final int EXTHDR = 16; // EXT header size
49.51 + static final int CENHDR = 46; // CEN header size
49.52 + static final int ENDHDR = 22; // END header size
49.53 +
49.54 + /*
49.55 + * Local file (LOC) header field offsets
49.56 + */
49.57 + static final int LOCVER = 4; // version needed to extract
49.58 + static final int LOCFLG = 6; // general purpose bit flag
49.59 + static final int LOCHOW = 8; // compression method
49.60 + static final int LOCTIM = 10; // modification time
49.61 + static final int LOCCRC = 14; // uncompressed file crc-32 value
49.62 + static final int LOCSIZ = 18; // compressed size
49.63 + static final int LOCLEN = 22; // uncompressed size
49.64 + static final int LOCNAM = 26; // filename length
49.65 + static final int LOCEXT = 28; // extra field length
49.66 +
49.67 + /*
49.68 + * Extra local (EXT) header field offsets
49.69 + */
49.70 + static final int EXTCRC = 4; // uncompressed file crc-32 value
49.71 + static final int EXTSIZ = 8; // compressed size
49.72 + static final int EXTLEN = 12; // uncompressed size
49.73 +
49.74 + /*
49.75 + * Central directory (CEN) header field offsets
49.76 + */
49.77 + static final int CENVEM = 4; // version made by
49.78 + static final int CENVER = 6; // version needed to extract
49.79 + static final int CENFLG = 8; // encrypt, decrypt flags
49.80 + static final int CENHOW = 10; // compression method
49.81 + static final int CENTIM = 12; // modification time
49.82 + static final int CENCRC = 16; // uncompressed file crc-32 value
49.83 + static final int CENSIZ = 20; // compressed size
49.84 + static final int CENLEN = 24; // uncompressed size
49.85 + static final int CENNAM = 28; // filename length
49.86 + static final int CENEXT = 30; // extra field length
49.87 + static final int CENCOM = 32; // comment length
49.88 + static final int CENDSK = 34; // disk number start
49.89 + static final int CENATT = 36; // internal file attributes
49.90 + static final int CENATX = 38; // external file attributes
49.91 + static final int CENOFF = 42; // LOC header offset
49.92 +
49.93 + /*
49.94 + * End of central directory (END) header field offsets
49.95 + */
49.96 + static final int ENDSUB = 8; // number of entries on this disk
49.97 + static final int ENDTOT = 10; // total number of entries
49.98 + static final int ENDSIZ = 12; // central directory size in bytes
49.99 + static final int ENDOFF = 16; // offset of first CEN header
49.100 + static final int ENDCOM = 20; // zip file comment length
49.101 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
50.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipEntry.java Sun May 11 14:01:18 2014 +0200
50.3 @@ -0,0 +1,331 @@
50.4 +/*
50.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50.7 + *
50.8 + * This code is free software; you can redistribute it and/or modify it
50.9 + * under the terms of the GNU General Public License version 2 only, as
50.10 + * published by the Free Software Foundation. Oracle designates this
50.11 + * particular file as subject to the "Classpath" exception as provided
50.12 + * by Oracle in the LICENSE file that accompanied this code.
50.13 + *
50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50.17 + * version 2 for more details (a copy is included in the LICENSE file that
50.18 + * accompanied this code).
50.19 + *
50.20 + * You should have received a copy of the GNU General Public License version
50.21 + * 2 along with this work; if not, write to the Free Software Foundation,
50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50.23 + *
50.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
50.25 + * or visit www.oracle.com if you need additional information or have any
50.26 + * questions.
50.27 + */
50.28 +
50.29 +package java.util.zip;
50.30 +
50.31 +/**
50.32 + * This class is used to represent a ZIP file entry.
50.33 + *
50.34 + * @author David Connelly
50.35 + */
50.36 +public
50.37 +class ZipEntry implements ZipConstants, Cloneable {
50.38 + String name; // entry name
50.39 + long time = -1; // modification time (in DOS time)
50.40 + long crc = -1; // crc-32 of entry data
50.41 + long size = -1; // uncompressed size of entry data
50.42 + long csize = -1; // compressed size of entry data
50.43 + int method = -1; // compression method
50.44 + int flag = 0; // general purpose flag
50.45 + byte[] extra; // optional extra field data for entry
50.46 + String comment; // optional comment string for entry
50.47 +
50.48 + /**
50.49 + * Compression method for uncompressed entries.
50.50 + */
50.51 + public static final int STORED = 0;
50.52 +
50.53 + /**
50.54 + * Compression method for compressed (deflated) entries.
50.55 + */
50.56 + public static final int DEFLATED = 8;
50.57 +
50.58 + /**
50.59 + * Creates a new zip entry with the specified name.
50.60 + *
50.61 + * @param name the entry name
50.62 + * @exception NullPointerException if the entry name is null
50.63 + * @exception IllegalArgumentException if the entry name is longer than
50.64 + * 0xFFFF bytes
50.65 + */
50.66 + public ZipEntry(String name) {
50.67 + if (name == null) {
50.68 + throw new NullPointerException();
50.69 + }
50.70 + if (name.length() > 0xFFFF) {
50.71 + throw new IllegalArgumentException("entry name too long");
50.72 + }
50.73 + this.name = name;
50.74 + }
50.75 +
50.76 + /**
50.77 + * Creates a new zip entry with fields taken from the specified
50.78 + * zip entry.
50.79 + * @param e a zip Entry object
50.80 + */
50.81 + public ZipEntry(ZipEntry e) {
50.82 + name = e.name;
50.83 + time = e.time;
50.84 + crc = e.crc;
50.85 + size = e.size;
50.86 + csize = e.csize;
50.87 + method = e.method;
50.88 + flag = e.flag;
50.89 + extra = e.extra;
50.90 + comment = e.comment;
50.91 + }
50.92 +
50.93 + /*
50.94 + * Creates a new un-initialized zip entry
50.95 + */
50.96 + ZipEntry() {}
50.97 +
50.98 + /**
50.99 + * Returns the name of the entry.
50.100 + * @return the name of the entry
50.101 + */
50.102 + public String getName() {
50.103 + return name;
50.104 + }
50.105 +
50.106 + /**
50.107 + * Sets the modification time of the entry.
50.108 + * @param time the entry modification time in number of milliseconds
50.109 + * since the epoch
50.110 + * @see #getTime()
50.111 + */
50.112 + public void setTime(long time) {
50.113 + this.time = javaToDosTime(time);
50.114 + }
50.115 +
50.116 + /**
50.117 + * Returns the modification time of the entry, or -1 if not specified.
50.118 + * @return the modification time of the entry, or -1 if not specified
50.119 + * @see #setTime(long)
50.120 + */
50.121 + public long getTime() {
50.122 + return time != -1 ? dosToJavaTime(time) : -1;
50.123 + }
50.124 +
50.125 + /**
50.126 + * Sets the uncompressed size of the entry data.
50.127 + * @param size the uncompressed size in bytes
50.128 + * @exception IllegalArgumentException if the specified size is less
50.129 + * than 0, is greater than 0xFFFFFFFF when
50.130 + * <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
50.131 + * or is less than 0 when ZIP64 is supported
50.132 + * @see #getSize()
50.133 + */
50.134 + public void setSize(long size) {
50.135 + if (size < 0) {
50.136 + throw new IllegalArgumentException("invalid entry size");
50.137 + }
50.138 + this.size = size;
50.139 + }
50.140 +
50.141 + /**
50.142 + * Returns the uncompressed size of the entry data, or -1 if not known.
50.143 + * @return the uncompressed size of the entry data, or -1 if not known
50.144 + * @see #setSize(long)
50.145 + */
50.146 + public long getSize() {
50.147 + return size;
50.148 + }
50.149 +
50.150 + /**
50.151 + * Returns the size of the compressed entry data, or -1 if not known.
50.152 + * In the case of a stored entry, the compressed size will be the same
50.153 + * as the uncompressed size of the entry.
50.154 + * @return the size of the compressed entry data, or -1 if not known
50.155 + * @see #setCompressedSize(long)
50.156 + */
50.157 + public long getCompressedSize() {
50.158 + return csize;
50.159 + }
50.160 +
50.161 + /**
50.162 + * Sets the size of the compressed entry data.
50.163 + * @param csize the compressed size to set to
50.164 + * @see #getCompressedSize()
50.165 + */
50.166 + public void setCompressedSize(long csize) {
50.167 + this.csize = csize;
50.168 + }
50.169 +
50.170 + /**
50.171 + * Sets the CRC-32 checksum of the uncompressed entry data.
50.172 + * @param crc the CRC-32 value
50.173 + * @exception IllegalArgumentException if the specified CRC-32 value is
50.174 + * less than 0 or greater than 0xFFFFFFFF
50.175 + * @see #getCrc()
50.176 + */
50.177 + public void setCrc(long crc) {
50.178 + if (crc < 0 || crc > 0xFFFFFFFFL) {
50.179 + throw new IllegalArgumentException("invalid entry crc-32");
50.180 + }
50.181 + this.crc = crc;
50.182 + }
50.183 +
50.184 + /**
50.185 + * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
50.186 + * not known.
50.187 + * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
50.188 + * not known
50.189 + * @see #setCrc(long)
50.190 + */
50.191 + public long getCrc() {
50.192 + return crc;
50.193 + }
50.194 +
50.195 + /**
50.196 + * Sets the compression method for the entry.
50.197 + * @param method the compression method, either STORED or DEFLATED
50.198 + * @exception IllegalArgumentException if the specified compression
50.199 + * method is invalid
50.200 + * @see #getMethod()
50.201 + */
50.202 + public void setMethod(int method) {
50.203 + if (method != STORED && method != DEFLATED) {
50.204 + throw new IllegalArgumentException("invalid compression method");
50.205 + }
50.206 + this.method = method;
50.207 + }
50.208 +
50.209 + /**
50.210 + * Returns the compression method of the entry, or -1 if not specified.
50.211 + * @return the compression method of the entry, or -1 if not specified
50.212 + * @see #setMethod(int)
50.213 + */
50.214 + public int getMethod() {
50.215 + return method;
50.216 + }
50.217 +
50.218 + /**
50.219 + * Sets the optional extra field data for the entry.
50.220 + * @param extra the extra field data bytes
50.221 + * @exception IllegalArgumentException if the length of the specified
50.222 + * extra field data is greater than 0xFFFF bytes
50.223 + * @see #getExtra()
50.224 + */
50.225 + public void setExtra(byte[] extra) {
50.226 + if (extra != null && extra.length > 0xFFFF) {
50.227 + throw new IllegalArgumentException("invalid extra field length");
50.228 + }
50.229 + this.extra = extra;
50.230 + }
50.231 +
50.232 + /**
50.233 + * Returns the extra field data for the entry, or null if none.
50.234 + * @return the extra field data for the entry, or null if none
50.235 + * @see #setExtra(byte[])
50.236 + */
50.237 + public byte[] getExtra() {
50.238 + return extra;
50.239 + }
50.240 +
50.241 + /**
50.242 + * Sets the optional comment string for the entry.
50.243 + *
50.244 + * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
50.245 + * specified comment string is greater than 0xFFFF bytes after encoding, only
50.246 + * the first 0xFFFF bytes are output to the ZIP file entry.
50.247 + *
50.248 + * @param comment the comment string
50.249 + *
50.250 + * @see #getComment()
50.251 + */
50.252 + public void setComment(String comment) {
50.253 + this.comment = comment;
50.254 + }
50.255 +
50.256 + /**
50.257 + * Returns the comment string for the entry, or null if none.
50.258 + * @return the comment string for the entry, or null if none
50.259 + * @see #setComment(String)
50.260 + */
50.261 + public String getComment() {
50.262 + return comment;
50.263 + }
50.264 +
50.265 + /**
50.266 + * Returns true if this is a directory entry. A directory entry is
50.267 + * defined to be one whose name ends with a '/'.
50.268 + * @return true if this is a directory entry
50.269 + */
50.270 + public boolean isDirectory() {
50.271 + return name.endsWith("/");
50.272 + }
50.273 +
50.274 + /**
50.275 + * Returns a string representation of the ZIP entry.
50.276 + */
50.277 + public String toString() {
50.278 + return getName();
50.279 + }
50.280 +
50.281 + /*
50.282 + * Converts DOS time to Java time (number of milliseconds since epoch).
50.283 + */
50.284 + private static long dosToJavaTime(long dtime) {
50.285 + return dtime;
50.286 + /* XXX:
50.287 + Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
50.288 + (int)(((dtime >> 21) & 0x0f) - 1),
50.289 + (int)((dtime >> 16) & 0x1f),
50.290 + (int)((dtime >> 11) & 0x1f),
50.291 + (int)((dtime >> 5) & 0x3f),
50.292 + (int)((dtime << 1) & 0x3e));
50.293 + return d.getTime();
50.294 + */
50.295 + }
50.296 +
50.297 + /*
50.298 + * Converts Java time to DOS time.
50.299 + */
50.300 + private static long javaToDosTime(long time) {
50.301 + return time;
50.302 + /* XXX:
50.303 + Date d = new Date(time);
50.304 + int year = d.getYear() + 1900;
50.305 + if (year < 1980) {
50.306 + return (1 << 21) | (1 << 16);
50.307 + }
50.308 + return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
50.309 + d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
50.310 + d.getSeconds() >> 1;
50.311 + */
50.312 + }
50.313 +
50.314 + /**
50.315 + * Returns the hash code value for this entry.
50.316 + */
50.317 + public int hashCode() {
50.318 + return name.hashCode();
50.319 + }
50.320 +
50.321 + /**
50.322 + * Returns a copy of this entry.
50.323 + */
50.324 + public Object clone() {
50.325 + try {
50.326 + ZipEntry e = (ZipEntry)super.clone();
50.327 + e.extra = (extra == null) ? null : extra.clone();
50.328 + return e;
50.329 + } catch (CloneNotSupportedException e) {
50.330 + // This should never happen, since we are Cloneable
50.331 + throw new IllegalStateException();
50.332 + }
50.333 + }
50.334 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipException.java Sun May 11 14:01:18 2014 +0200
51.3 @@ -0,0 +1,60 @@
51.4 +/*
51.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
51.7 + *
51.8 + * This code is free software; you can redistribute it and/or modify it
51.9 + * under the terms of the GNU General Public License version 2 only, as
51.10 + * published by the Free Software Foundation. Oracle designates this
51.11 + * particular file as subject to the "Classpath" exception as provided
51.12 + * by Oracle in the LICENSE file that accompanied this code.
51.13 + *
51.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
51.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
51.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51.17 + * version 2 for more details (a copy is included in the LICENSE file that
51.18 + * accompanied this code).
51.19 + *
51.20 + * You should have received a copy of the GNU General Public License version
51.21 + * 2 along with this work; if not, write to the Free Software Foundation,
51.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
51.23 + *
51.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
51.25 + * or visit www.oracle.com if you need additional information or have any
51.26 + * questions.
51.27 + */
51.28 +
51.29 +package java.util.zip;
51.30 +
51.31 +import java.io.IOException;
51.32 +
51.33 +/**
51.34 + * Signals that a Zip exception of some sort has occurred.
51.35 + *
51.36 + * @author unascribed
51.37 + * @see java.io.IOException
51.38 + * @since JDK1.0
51.39 + */
51.40 +
51.41 +public
51.42 +class ZipException extends IOException {
51.43 + private static final long serialVersionUID = 8000196834066748623L;
51.44 +
51.45 + /**
51.46 + * Constructs a <code>ZipException</code> with <code>null</code>
51.47 + * as its error detail message.
51.48 + */
51.49 + public ZipException() {
51.50 + super();
51.51 + }
51.52 +
51.53 + /**
51.54 + * Constructs a <code>ZipException</code> with the specified detail
51.55 + * message.
51.56 + *
51.57 + * @param s the detail message.
51.58 + */
51.59 +
51.60 + public ZipException(String s) {
51.61 + super(s);
51.62 + }
51.63 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
52.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/ZipInputStream.java Sun May 11 14:01:18 2014 +0200
52.3 @@ -0,0 +1,194 @@
52.4 +/*
52.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
52.7 + *
52.8 + * This code is free software; you can redistribute it and/or modify it
52.9 + * under the terms of the GNU General Public License version 2 only, as
52.10 + * published by the Free Software Foundation. Oracle designates this
52.11 + * particular file as subject to the "Classpath" exception as provided
52.12 + * by Oracle in the LICENSE file that accompanied this code.
52.13 + *
52.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
52.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
52.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
52.17 + * version 2 for more details (a copy is included in the LICENSE file that
52.18 + * accompanied this code).
52.19 + *
52.20 + * You should have received a copy of the GNU General Public License version
52.21 + * 2 along with this work; if not, write to the Free Software Foundation,
52.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
52.23 + *
52.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
52.25 + * or visit www.oracle.com if you need additional information or have any
52.26 + * questions.
52.27 + */
52.28 +
52.29 +package java.util.zip;
52.30 +
52.31 +import java.io.InputStream;
52.32 +import java.io.IOException;
52.33 +
52.34 +/**
52.35 + * This class implements an input stream filter for reading files in the
52.36 + * ZIP file format. Includes support for both compressed and uncompressed
52.37 + * entries.
52.38 + *
52.39 + * @author David Connelly
52.40 + */
52.41 +public
52.42 +class ZipInputStream extends InflaterInputStream implements ZipConstants {
52.43 + private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
52.44 +
52.45 + /**
52.46 + * Creates a new ZIP input stream.
52.47 + *
52.48 + * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
52.49 + * decode the entry names.
52.50 + *
52.51 + * @param in the actual input stream
52.52 + */
52.53 + public ZipInputStream(InputStream in) {
52.54 + super(in);
52.55 + impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
52.56 + }
52.57 +
52.58 + /**
52.59 + * Creates a new ZIP input stream.
52.60 + *
52.61 + * @param in the actual input stream
52.62 + *
52.63 + * @param charset
52.64 + * The {@linkplain java.nio.charset.Charset charset} to be
52.65 + * used to decode the ZIP entry name (ignored if the
52.66 + * <a href="package-summary.html#lang_encoding"> language
52.67 + * encoding bit</a> of the ZIP entry's general purpose bit
52.68 + * flag is set).
52.69 + *
52.70 + * @since 1.7
52.71 + *
52.72 + public ZipInputStream(InputStream in, Charset charset) {
52.73 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
52.74 + usesDefaultInflater = true;
52.75 + if(in == null) {
52.76 + throw new NullPointerException("in is null");
52.77 + }
52.78 + if (charset == null)
52.79 + throw new NullPointerException("charset is null");
52.80 + this.zc = ZipCoder.get(charset);
52.81 + }
52.82 + */
52.83 +
52.84 + /**
52.85 + * Reads the next ZIP file entry and positions the stream at the
52.86 + * beginning of the entry data.
52.87 + * @return the next ZIP file entry, or null if there are no more entries
52.88 + * @exception ZipException if a ZIP file error has occurred
52.89 + * @exception IOException if an I/O error has occurred
52.90 + */
52.91 + public ZipEntry getNextEntry() throws IOException {
52.92 + return impl.getNextEntry();
52.93 + }
52.94 +
52.95 + /**
52.96 + * Closes the current ZIP entry and positions the stream for reading the
52.97 + * next entry.
52.98 + * @exception ZipException if a ZIP file error has occurred
52.99 + * @exception IOException if an I/O error has occurred
52.100 + */
52.101 + public void closeEntry() throws IOException {
52.102 + impl.closeEntry();
52.103 + }
52.104 +
52.105 + /**
52.106 + * Returns 0 after EOF has reached for the current entry data,
52.107 + * otherwise always return 1.
52.108 + * <p>
52.109 + * Programs should not count on this method to return the actual number
52.110 + * of bytes that could be read without blocking.
52.111 + *
52.112 + * @return 1 before EOF and 0 after EOF has reached for current entry.
52.113 + * @exception IOException if an I/O error occurs.
52.114 + *
52.115 + */
52.116 + public int available() throws IOException {
52.117 + return impl.available();
52.118 + }
52.119 +
52.120 + /**
52.121 + * Reads from the current ZIP entry into an array of bytes.
52.122 + * If <code>len</code> is not zero, the method
52.123 + * blocks until some input is available; otherwise, no
52.124 + * bytes are read and <code>0</code> is returned.
52.125 + * @param b the buffer into which the data is read
52.126 + * @param off the start offset in the destination array <code>b</code>
52.127 + * @param len the maximum number of bytes read
52.128 + * @return the actual number of bytes read, or -1 if the end of the
52.129 + * entry is reached
52.130 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
52.131 + * @exception IndexOutOfBoundsException if <code>off</code> is negative,
52.132 + * <code>len</code> is negative, or <code>len</code> is greater than
52.133 + * <code>b.length - off</code>
52.134 + * @exception ZipException if a ZIP file error has occurred
52.135 + * @exception IOException if an I/O error has occurred
52.136 + */
52.137 + public int read(byte[] b, int off, int len) throws IOException {
52.138 + return impl.read(b, off, len);
52.139 + }
52.140 +
52.141 + /**
52.142 + * Skips specified number of bytes in the current ZIP entry.
52.143 + * @param n the number of bytes to skip
52.144 + * @return the actual number of bytes skipped
52.145 + * @exception ZipException if a ZIP file error has occurred
52.146 + * @exception IOException if an I/O error has occurred
52.147 + * @exception IllegalArgumentException if n < 0
52.148 + */
52.149 + public long skip(long n) throws IOException {
52.150 + return impl.skip(n);
52.151 + }
52.152 +
52.153 + /**
52.154 + * Closes this input stream and releases any system resources associated
52.155 + * with the stream.
52.156 + * @exception IOException if an I/O error has occurred
52.157 + */
52.158 + public void close() throws IOException {
52.159 + impl.close();
52.160 + }
52.161 +
52.162 + /**
52.163 + * Creates a new <code>ZipEntry</code> object for the specified
52.164 + * entry name.
52.165 + *
52.166 + * @param name the ZIP file entry name
52.167 + * @return the ZipEntry just created
52.168 + */
52.169 + protected ZipEntry createZipEntry(String name) {
52.170 + return new ZipEntry(name);
52.171 + }
52.172 +
52.173 + @Override
52.174 + public int read() throws IOException {
52.175 + return impl.read();
52.176 + }
52.177 +
52.178 + @Override
52.179 + public boolean markSupported() {
52.180 + return impl.markSupported();
52.181 + }
52.182 +
52.183 + @Override
52.184 + public void mark(int readlimit) {
52.185 + impl.mark(readlimit);
52.186 + }
52.187 +
52.188 + @Override
52.189 + public void reset() throws IOException {
52.190 + impl.reset();
52.191 + }
52.192 +
52.193 + @Override
52.194 + public int read(byte[] b) throws IOException {
52.195 + return impl.read(b);
52.196 + }
52.197 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
53.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/package-info.java Sun May 11 14:01:18 2014 +0200
53.3 @@ -0,0 +1,22 @@
53.4 +/**
53.5 + * Back 2 Browser Bytecode Translator
53.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
53.7 + *
53.8 + * This program is free software: you can redistribute it and/or modify
53.9 + * it under the terms of the GNU General Public License as published by
53.10 + * the Free Software Foundation, version 2 of the License.
53.11 + *
53.12 + * This program is distributed in the hope that it will be useful,
53.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
53.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53.15 + * GNU General Public License for more details.
53.16 + *
53.17 + * You should have received a copy of the GNU General Public License
53.18 + * along with this program. Look for COPYING file in the top folder.
53.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
53.20 + */
53.21 +@Exported
53.22 +package java.util.zip;
53.23 +
53.24 +import org.apidesign.bck2brwsr.core.Exported;
53.25 +
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
54.2 +++ b/rt/emul/zip/src/main/java/java/util/zip/package.html Sun May 11 14:01:18 2014 +0200
54.3 @@ -0,0 +1,98 @@
54.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
54.5 +<html>
54.6 +<head>
54.7 +<!--
54.8 +Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
54.9 +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
54.10 +
54.11 +This code is free software; you can redistribute it and/or modify it
54.12 +under the terms of the GNU General Public License version 2 only, as
54.13 +published by the Free Software Foundation. Oracle designates this
54.14 +particular file as subject to the "Classpath" exception as provided
54.15 +by Oracle in the LICENSE file that accompanied this code.
54.16 +
54.17 +This code is distributed in the hope that it will be useful, but WITHOUT
54.18 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
54.19 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
54.20 +version 2 for more details (a copy is included in the LICENSE file that
54.21 +accompanied this code).
54.22 +
54.23 +You should have received a copy of the GNU General Public License version
54.24 +2 along with this work; if not, write to the Free Software Foundation,
54.25 +Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
54.26 +
54.27 +Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
54.28 +or visit www.oracle.com if you need additional information or have any
54.29 +questions.
54.30 +-->
54.31 +
54.32 +</head>
54.33 +<body bgcolor="white">
54.34 +
54.35 +Provides classes for reading and writing the standard ZIP and GZIP
54.36 +file formats. Also includes classes for compressing and decompressing
54.37 +data using the DEFLATE compression algorithm, which is used by the
54.38 +ZIP and GZIP file formats. Additionally, there are utility classes
54.39 +for computing the CRC-32 and Adler-32 checksums of arbitrary
54.40 +input streams.
54.41 +
54.42 +
54.43 +<h2>Package Specification</h2>
54.44 +
54.45 +</a>
54.46 +<ul>
54.47 + <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
54.48 + Info-ZIP Application Note 970311
54.49 + </a> - a detailed description of the Info-ZIP format upon which
54.50 + the <code>java.util.zip</code> classes are based.
54.51 +<p>
54.52 + <a name="zip64">
54.53 + <li>An implementation may optionally support the ZIP64(tm) format extensions
54.54 + defined by the
54.55 + <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
54.56 + PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
54.57 + are used to overcome the size limitations of the original ZIP format.
54.58 +<p>
54.59 + <a name="lang_encoding">
54.60 + <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
54.61 + PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
54.62 + encode ZIP entry filename and comment fields using UTF-8.
54.63 +<p>
54.64 + <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
54.65 + ZLIB Compressed Data Format Specification version 3.3</a>
54.66 +
54.67 + <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
54.68 + (RFC 1950)
54.69 +<p>
54.70 + <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
54.71 + DEFLATE Compressed Data Format Specification version 1.3</a>
54.72 +
54.73 + <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
54.74 + (RFC 1951)
54.75 +<p>
54.76 + <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
54.77 + GZIP file format specification version 4.3</a>
54.78 +
54.79 + <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
54.80 + (RFC 1952)
54.81 +<p>
54.82 + <li>CRC-32 checksum is described in RFC 1952 (above)
54.83 +<p>
54.84 + <li>Adler-32 checksum is described in RFC 1950 (above)
54.85 +</ul>
54.86 +
54.87 +
54.88 +<!--
54.89 +<h2>Related Documentation</h2>
54.90 +
54.91 +For overviews, tutorials, examples, guides, and tool documentation, please see:
54.92 +<ul>
54.93 + <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
54.94 +</ul>
54.95 +-->
54.96 +
54.97 +@since JDK1.1
54.98 +</body>
54.99 +</html>
54.100 +
54.101 +
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/Adler32.java Sun May 11 14:01:18 2014 +0200
55.3 @@ -0,0 +1,139 @@
55.4 +/* -*-mode:java; c-basic-offset:2; -*- */
55.5 +/*
55.6 +Copyright (c) 2000-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 +final class Adler32 implements Checksum {
55.41 +
55.42 + // largest prime smaller than 65536
55.43 + static final private int BASE=65521;
55.44 + // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
55.45 + static final private int NMAX=5552;
55.46 +
55.47 + private long s1=1L;
55.48 + private long s2=0L;
55.49 +
55.50 + public void reset(long init){
55.51 + s1=init&0xffff;
55.52 + s2=(init>>16)&0xffff;
55.53 + }
55.54 +
55.55 + public void reset(){
55.56 + s1=1L;
55.57 + s2=0L;
55.58 + }
55.59 +
55.60 + public long getValue(){
55.61 + return ((s2<<16)|s1);
55.62 + }
55.63 +
55.64 + public void update(byte[] buf, int index, int len){
55.65 +
55.66 + if(len==1){
55.67 + s1+=buf[index++]&0xff; s2+=s1;
55.68 + s1%=BASE;
55.69 + s2%=BASE;
55.70 + return;
55.71 + }
55.72 +
55.73 + int len1 = len/NMAX;
55.74 + int len2 = len%NMAX;
55.75 + while(len1-->0) {
55.76 + int k=NMAX;
55.77 + len-=k;
55.78 + while(k-->0){
55.79 + s1+=buf[index++]&0xff; s2+=s1;
55.80 + }
55.81 + s1%=BASE;
55.82 + s2%=BASE;
55.83 + }
55.84 +
55.85 + int k=len2;
55.86 + len-=k;
55.87 + while(k-->0){
55.88 + s1+=buf[index++]&0xff; s2+=s1;
55.89 + }
55.90 + s1%=BASE;
55.91 + s2%=BASE;
55.92 + }
55.93 +
55.94 + public Adler32 copy(){
55.95 + Adler32 foo = new Adler32();
55.96 + foo.s1 = this.s1;
55.97 + foo.s2 = this.s2;
55.98 + return foo;
55.99 + }
55.100 +
55.101 + // The following logic has come from zlib.1.2.
55.102 + static long combine(long adler1, long adler2, long len2){
55.103 + long BASEL = (long)BASE;
55.104 + long sum1;
55.105 + long sum2;
55.106 + long rem; // unsigned int
55.107 +
55.108 + rem = len2 % BASEL;
55.109 + sum1 = adler1 & 0xffffL;
55.110 + sum2 = rem * sum1;
55.111 + sum2 %= BASEL; // MOD(sum2);
55.112 + sum1 += (adler2 & 0xffffL) + BASEL - 1;
55.113 + sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
55.114 + if (sum1 >= BASEL) sum1 -= BASEL;
55.115 + if (sum1 >= BASEL) sum1 -= BASEL;
55.116 + if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
55.117 + if (sum2 >= BASEL) sum2 -= BASEL;
55.118 + return sum1 | (sum2 << 16);
55.119 + }
55.120 +
55.121 +/*
55.122 + private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
55.123 + public void update(byte[] buf, int index, int len){
55.124 + if(buf==null) {adler.reset();}
55.125 + else{adler.update(buf, index, len);}
55.126 + }
55.127 + public void reset(){
55.128 + adler.reset();
55.129 + }
55.130 + public void reset(long init){
55.131 + if(init==1L){
55.132 + adler.reset();
55.133 + }
55.134 + else{
55.135 + System.err.println("unsupported operation");
55.136 + }
55.137 + }
55.138 + public long getValue(){
55.139 + return adler.getValue();
55.140 + }
55.141 +*/
55.142 +}
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/CRC32.java Sun May 11 14:01:18 2014 +0200
56.3 @@ -0,0 +1,181 @@
56.4 +/* -*-mode:java; c-basic-offset:2; -*- */
56.5 +/*
56.6 +Copyright (c) 2011 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 CRC32 implements Checksum {
56.43 +
56.44 + /*
56.45 + * The following logic has come from RFC1952.
56.46 + */
56.47 + private int v = 0;
56.48 + private static int[] crc_table = null;
56.49 + static {
56.50 + crc_table = new int[256];
56.51 + for (int n = 0; n < 256; n++) {
56.52 + int c = n;
56.53 + for (int k = 8; --k >= 0; ) {
56.54 + if ((c & 1) != 0)
56.55 + c = 0xedb88320 ^ (c >>> 1);
56.56 + else
56.57 + c = c >>> 1;
56.58 + }
56.59 + crc_table[n] = c;
56.60 + }
56.61 + }
56.62 +
56.63 + public void update (byte[] buf, int index, int len) {
56.64 + int c = ~v;
56.65 + while (--len >= 0)
56.66 + c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
56.67 + v = ~c;
56.68 + }
56.69 +
56.70 + public void reset(){
56.71 + v = 0;
56.72 + }
56.73 +
56.74 + public void reset(long vv){
56.75 + v = (int)(vv&0xffffffffL);
56.76 + }
56.77 +
56.78 + public long getValue(){
56.79 + return (long)(v&0xffffffffL);
56.80 + }
56.81 +
56.82 + // The following logic has come from zlib.1.2.
56.83 + private static final int GF2_DIM = 32;
56.84 + static long combine(long crc1, long crc2, long len2){
56.85 + long row;
56.86 + long[] even = new long[GF2_DIM];
56.87 + long[] odd = new long[GF2_DIM];
56.88 +
56.89 + // degenerate case (also disallow negative lengths)
56.90 + if (len2 <= 0)
56.91 + return crc1;
56.92 +
56.93 + // put operator for one zero bit in odd
56.94 + odd[0] = 0xedb88320L; // CRC-32 polynomial
56.95 + row = 1;
56.96 + for (int n = 1; n < GF2_DIM; n++) {
56.97 + odd[n] = row;
56.98 + row <<= 1;
56.99 + }
56.100 +
56.101 + // put operator for two zero bits in even
56.102 + gf2_matrix_square(even, odd);
56.103 +
56.104 + // put operator for four zero bits in odd
56.105 + gf2_matrix_square(odd, even);
56.106 +
56.107 + // apply len2 zeros to crc1 (first square will put the operator for one
56.108 + // zero byte, eight zero bits, in even)
56.109 + do {
56.110 + // apply zeros operator for this bit of len2
56.111 + gf2_matrix_square(even, odd);
56.112 + if ((len2 & 1)!=0)
56.113 + crc1 = gf2_matrix_times(even, crc1);
56.114 + len2 >>= 1;
56.115 +
56.116 + // if no more bits set, then done
56.117 + if (len2 == 0)
56.118 + break;
56.119 +
56.120 + // another iteration of the loop with odd and even swapped
56.121 + gf2_matrix_square(odd, even);
56.122 + if ((len2 & 1)!=0)
56.123 + crc1 = gf2_matrix_times(odd, crc1);
56.124 + len2 >>= 1;
56.125 +
56.126 + // if no more bits set, then done
56.127 + } while (len2 != 0);
56.128 +
56.129 + /* return combined crc */
56.130 + crc1 ^= crc2;
56.131 + return crc1;
56.132 + }
56.133 +
56.134 + private static long gf2_matrix_times(long[] mat, long vec){
56.135 + long sum = 0;
56.136 + int index = 0;
56.137 + while (vec!=0) {
56.138 + if ((vec & 1)!=0)
56.139 + sum ^= mat[index];
56.140 + vec >>= 1;
56.141 + index++;
56.142 + }
56.143 + return sum;
56.144 + }
56.145 +
56.146 + static final void gf2_matrix_square(long[] square, long[] mat) {
56.147 + for (int n = 0; n < GF2_DIM; n++)
56.148 + square[n] = gf2_matrix_times(mat, mat[n]);
56.149 + }
56.150 +
56.151 + /*
56.152 + private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
56.153 +
56.154 + public void update(byte[] buf, int index, int len){
56.155 + if(buf==null) {crc32.reset();}
56.156 + else{crc32.update(buf, index, len);}
56.157 + }
56.158 + public void reset(){
56.159 + crc32.reset();
56.160 + }
56.161 + public void reset(long init){
56.162 + if(init==0L){
56.163 + crc32.reset();
56.164 + }
56.165 + else{
56.166 + System.err.println("unsupported operation");
56.167 + }
56.168 + }
56.169 + public long getValue(){
56.170 + return crc32.getValue();
56.171 + }
56.172 +*/
56.173 + public CRC32 copy(){
56.174 + CRC32 foo = new CRC32();
56.175 + foo.v = this.v;
56.176 + return foo;
56.177 + }
56.178 +
56.179 + public static int[] getCRC32Table(){
56.180 + int[] tmp = new int[crc_table.length];
56.181 + FastJar.arraycopy(crc_table, 0, tmp, 0, tmp.length);
56.182 + return tmp;
56.183 + }
56.184 +}
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/Checksum.java Sun May 11 14:01:18 2014 +0200
57.3 @@ -0,0 +1,43 @@
57.4 +/* -*-mode:java; c-basic-offset:2; -*- */
57.5 +/*
57.6 +Copyright (c) 2011 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 +interface Checksum {
57.41 + void update(byte[] buf, int index, int len);
57.42 + void reset();
57.43 + void reset(long init);
57.44 + long getValue();
57.45 + Checksum copy();
57.46 +}
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/FastJar.java Sun May 11 14:01:18 2014 +0200
58.3 @@ -0,0 +1,198 @@
58.4 +/*
58.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
58.6 + *
58.7 + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
58.8 + *
58.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
58.10 + * Other names may be trademarks of their respective owners.
58.11 + *
58.12 + * The contents of this file are subject to the terms of either the GNU
58.13 + * General Public License Version 2 only ("GPL") or the Common
58.14 + * Development and Distribution License("CDDL") (collectively, the
58.15 + * "License"). You may not use this file except in compliance with the
58.16 + * License. You can obtain a copy of the License at
58.17 + * http://www.netbeans.org/cddl-gplv2.html
58.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
58.19 + * specific language governing permissions and limitations under the
58.20 + * License. When distributing the software, include this License Header
58.21 + * Notice in each file and include the License file at
58.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
58.23 + * particular file as subject to the "Classpath" exception as provided
58.24 + * by Oracle in the GPL Version 2 section of the License file that
58.25 + * accompanied this code. If applicable, add the following below the
58.26 + * License Header, with the fields enclosed by brackets [] replaced by
58.27 + * your own identifying information:
58.28 + * "Portions Copyrighted [year] [name of copyright owner]"
58.29 + *
58.30 + * Contributor(s):
58.31 + *
58.32 + * Portions Copyrighted 2007 Sun Microsystems, Inc.
58.33 + */
58.34 +package org.apidesign.bck2brwsr.emul.zip;
58.35 +
58.36 +import java.io.ByteArrayInputStream;
58.37 +import java.io.IOException;
58.38 +import java.io.InputStream;
58.39 +import java.lang.reflect.Method;
58.40 +import java.util.zip.ZipEntry;
58.41 +import java.util.zip.ZipInputStream;
58.42 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
58.43 +
58.44 +/**
58.45 + *
58.46 + * @author Tomas Zezula
58.47 + */
58.48 +public final class FastJar {
58.49 + private final byte[] arr;
58.50 +
58.51 + public FastJar(byte[] arr) {
58.52 + this.arr = arr;
58.53 + }
58.54 +
58.55 +
58.56 + private static final int GIVE_UP = 1<<16;
58.57 +
58.58 + public static final class Entry {
58.59 +
58.60 + public final String name;
58.61 + final long offset;
58.62 + private final long dosTime;
58.63 +
58.64 + Entry (String name, long offset, long time) {
58.65 + assert name != null;
58.66 + this.name = name;
58.67 + this.offset = offset;
58.68 + this.dosTime = time;
58.69 + }
58.70 +/*
58.71 + public long getTime () {
58.72 + Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
58.73 + (int)(((dosTime >> 21) & 0x0f) - 1),
58.74 + (int)((dosTime >> 16) & 0x1f),
58.75 + (int)((dosTime >> 11) & 0x1f),
58.76 + (int)((dosTime >> 5) & 0x3f),
58.77 + (int)((dosTime << 1) & 0x3e));
58.78 + return d.getTime();
58.79 + }
58.80 + */
58.81 + }
58.82 +
58.83 + public InputStream getInputStream (final Entry e) throws IOException {
58.84 + return getInputStream(arr, e.offset);
58.85 + }
58.86 +
58.87 + private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
58.88 + ByteArrayInputStream is = new ByteArrayInputStream(arr);
58.89 + is.skip(offset);
58.90 + ZipInputStream in = new ZipInputStream (is);
58.91 + ZipEntry e = in.getNextEntry();
58.92 + if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
58.93 + int cp = arr.length - is.available();
58.94 + return new ByteArrayInputStream(arr, cp, (int)e.getSize());
58.95 + }
58.96 + return in;
58.97 + }
58.98 +
58.99 + public Entry[] list() throws IOException {
58.100 + final int size = arr.length;
58.101 +
58.102 + int at = size - ZipInputStream.ENDHDR;
58.103 +
58.104 + byte[] data = new byte[ZipInputStream.ENDHDR];
58.105 + int giveup = 0;
58.106 +
58.107 + do {
58.108 + FastJar.arraycopy(arr, at, data, 0, data.length);
58.109 + at--;
58.110 + giveup++;
58.111 + if (giveup > GIVE_UP) {
58.112 + throw new IOException ();
58.113 + }
58.114 + } while (getsig(data) != ZipInputStream.ENDSIG);
58.115 +
58.116 +
58.117 + final long censize = endsiz(data);
58.118 + final long cenoff = endoff(data);
58.119 + at = (int) cenoff;
58.120 +
58.121 + Entry[] result = new Entry[0];
58.122 + int cenread = 0;
58.123 + data = new byte[ZipInputStream.CENHDR];
58.124 + while (cenread < censize) {
58.125 + FastJar.arraycopy(arr, at, data, 0, data.length);
58.126 + at += data.length;
58.127 + if (getsig(data) != ZipInputStream.CENSIG) {
58.128 + throw new IOException("No central table"); //NOI18N
58.129 + }
58.130 + int cennam = cennam(data);
58.131 + int cenext = cenext(data);
58.132 + int cencom = cencom(data);
58.133 + long lhoff = cenoff(data);
58.134 + long centim = centim(data);
58.135 + String name = new String(arr, at, cennam, "UTF-8");
58.136 + at += cennam;
58.137 + int seekby = cenext+cencom;
58.138 + int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
58.139 + cenread+=cendatalen;
58.140 + result = addEntry(result, new Entry(name,lhoff, centim));
58.141 + at += seekby;
58.142 + }
58.143 + return result;
58.144 + }
58.145 +
58.146 + private Entry[] addEntry(Entry[] result, Entry entry) {
58.147 + Entry[] e = new Entry[result.length + 1];
58.148 + e[result.length] = entry;
58.149 + FastJar.arraycopy(result, 0, e, 0, result.length);
58.150 + return e;
58.151 + }
58.152 +
58.153 + private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
58.154 + private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
58.155 + private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
58.156 + private static final long cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
58.157 + private static final long censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
58.158 + private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
58.159 + private static final int cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
58.160 + private static final int cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
58.161 + private static final int cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
58.162 + private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
58.163 + private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
58.164 + private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
58.165 + private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
58.166 + private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
58.167 +
58.168 + private static final int get16(final byte[] b, int off) throws IOException {
58.169 + final int b1 = b[off];
58.170 + final int b2 = b[off+1];
58.171 + return (b1 & 0xff) | ((b2 & 0xff) << 8);
58.172 + }
58.173 +
58.174 + private static final long get32(final byte[] b, int off) throws IOException {
58.175 + final int s1 = get16(b, off);
58.176 + final int s2 = get16(b, off+2);
58.177 + return s1 | ((long)s2 << 16);
58.178 + }
58.179 +
58.180 + @JavaScriptBody(args = {"value", "srcBegin", "dst", "dstBegin", "count"}, body
58.181 + = "if (srcBegin < dstBegin) {\n"
58.182 + + " while (count-- > 0) {\n"
58.183 + + " dst[dstBegin + count] = value[srcBegin + count];\n"
58.184 + + " }\n"
58.185 + + "} else {\n"
58.186 + + " while (count-- > 0) {\n"
58.187 + + " dst[dstBegin++] = value[srcBegin++];\n"
58.188 + + " }\n"
58.189 + + "}"
58.190 + )
58.191 + static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) {
58.192 + try {
58.193 + Class<?> system = Class.forName("java.lang.System");
58.194 + Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class);
58.195 + m.invoke(null, src, srcBegin, dst, dstBegin, count);
58.196 + } catch (Exception ex) {
58.197 + throw new IllegalStateException(ex);
58.198 + }
58.199 + }
58.200 +
58.201 +}
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/GZIPHeader.java Sun May 11 14:01:18 2014 +0200
59.3 @@ -0,0 +1,215 @@
59.4 +/* -*-mode:java; c-basic-offset:2; -*- */
59.5 +/*
59.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
59.7 +
59.8 +Redistribution and use in source and binary forms, with or without
59.9 +modification, are permitted provided that the following conditions are met:
59.10 +
59.11 + 1. Redistributions of source code must retain the above copyright notice,
59.12 + this list of conditions and the following disclaimer.
59.13 +
59.14 + 2. Redistributions in binary form must reproduce the above copyright
59.15 + notice, this list of conditions and the following disclaimer in
59.16 + the documentation and/or other materials provided with the distribution.
59.17 +
59.18 + 3. The names of the authors may not be used to endorse or promote products
59.19 + derived from this software without specific prior written permission.
59.20 +
59.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
59.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
59.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
59.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
59.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
59.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
59.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
59.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
59.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59.31 + */
59.32 +/*
59.33 + * This program is based on zlib-1.1.3, so all credit should go authors
59.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
59.35 + * and contributors of zlib.
59.36 + */
59.37 +
59.38 +package org.apidesign.bck2brwsr.emul.zip;
59.39 +
59.40 +
59.41 +import java.io.UnsupportedEncodingException;
59.42 +
59.43 +/**
59.44 + * @see "http://www.ietf.org/rfc/rfc1952.txt"
59.45 + */
59.46 +final class GZIPHeader implements Cloneable {
59.47 +
59.48 + public static final byte OS_MSDOS = (byte) 0x00;
59.49 + public static final byte OS_AMIGA = (byte) 0x01;
59.50 + public static final byte OS_VMS = (byte) 0x02;
59.51 + public static final byte OS_UNIX = (byte) 0x03;
59.52 + public static final byte OS_ATARI = (byte) 0x05;
59.53 + public static final byte OS_OS2 = (byte) 0x06;
59.54 + public static final byte OS_MACOS = (byte) 0x07;
59.55 + public static final byte OS_TOPS20 = (byte) 0x0a;
59.56 + public static final byte OS_WIN32 = (byte) 0x0b;
59.57 + public static final byte OS_VMCMS = (byte) 0x04;
59.58 + public static final byte OS_ZSYSTEM = (byte) 0x08;
59.59 + public static final byte OS_CPM = (byte) 0x09;
59.60 + public static final byte OS_QDOS = (byte) 0x0c;
59.61 + public static final byte OS_RISCOS = (byte) 0x0d;
59.62 + public static final byte OS_UNKNOWN = (byte) 0xff;
59.63 +
59.64 + boolean text = false;
59.65 + private boolean fhcrc = false;
59.66 + long time;
59.67 + int xflags;
59.68 + int os = 255;
59.69 + byte[] extra;
59.70 + byte[] name;
59.71 + byte[] comment;
59.72 + int hcrc;
59.73 + long crc;
59.74 + boolean done = false;
59.75 + long mtime = 0;
59.76 +
59.77 + public void setModifiedTime(long mtime) {
59.78 + this.mtime = mtime;
59.79 + }
59.80 +
59.81 + public long getModifiedTime() {
59.82 + return mtime;
59.83 + }
59.84 +
59.85 + public void setOS(int os) {
59.86 + if((0<=os && os <=13) || os==255)
59.87 + this.os=os;
59.88 + else
59.89 + throw new IllegalArgumentException("os: "+os);
59.90 + }
59.91 +
59.92 + public int getOS(){
59.93 + return os;
59.94 + }
59.95 +
59.96 + public void setName(String name) {
59.97 + try{
59.98 + this.name=name.getBytes("ISO-8859-1");
59.99 + }
59.100 + catch(UnsupportedEncodingException e){
59.101 + throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
59.102 + }
59.103 + }
59.104 +
59.105 + public String getName(){
59.106 + if(name==null) return "";
59.107 + try {
59.108 + return new String(name, "ISO-8859-1");
59.109 + }
59.110 + catch (UnsupportedEncodingException e) {
59.111 + throw new IllegalArgumentException(e.toString());
59.112 + }
59.113 + }
59.114 +
59.115 + public void setComment(String comment) {
59.116 + try{
59.117 + this.comment=comment.getBytes("ISO-8859-1");
59.118 + }
59.119 + catch(UnsupportedEncodingException e){
59.120 + throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
59.121 + }
59.122 + }
59.123 +
59.124 + public String getComment(){
59.125 + if(comment==null) return "";
59.126 + try {
59.127 + return new String(comment, "ISO-8859-1");
59.128 + }
59.129 + catch (UnsupportedEncodingException e) {
59.130 + throw new IllegalArgumentException(e.toString());
59.131 + }
59.132 + }
59.133 +
59.134 + public void setCRC(long crc){
59.135 + this.crc = crc;
59.136 + }
59.137 +
59.138 + public long getCRC(){
59.139 + return crc;
59.140 + }
59.141 +/*
59.142 + void put(Deflate d){
59.143 + int flag = 0;
59.144 + if(text){
59.145 + flag |= 1; // FTEXT
59.146 + }
59.147 + if(fhcrc){
59.148 + flag |= 2; // FHCRC
59.149 + }
59.150 + if(extra!=null){
59.151 + flag |= 4; // FEXTRA
59.152 + }
59.153 + if(name!=null){
59.154 + flag |= 8; // FNAME
59.155 + }
59.156 + if(comment!=null){
59.157 + flag |= 16; // FCOMMENT
59.158 + }
59.159 + int xfl = 0;
59.160 + if(d.level == JZlib.Z_BEST_SPEED){
59.161 + xfl |= 4;
59.162 + }
59.163 + else if (d.level == JZlib.Z_BEST_COMPRESSION){
59.164 + xfl |= 2;
59.165 + }
59.166 +
59.167 + d.put_short((short)0x8b1f); // ID1 ID2
59.168 + d.put_byte((byte)8); // CM(Compression Method)
59.169 + d.put_byte((byte)flag);
59.170 + d.put_byte((byte)mtime);
59.171 + d.put_byte((byte)(mtime>>8));
59.172 + d.put_byte((byte)(mtime>>16));
59.173 + d.put_byte((byte)(mtime>>24));
59.174 + d.put_byte((byte)xfl);
59.175 + d.put_byte((byte)os);
59.176 +
59.177 + if(extra!=null){
59.178 + d.put_byte((byte)extra.length);
59.179 + d.put_byte((byte)(extra.length>>8));
59.180 + d.put_byte(extra, 0, extra.length);
59.181 + }
59.182 +
59.183 + if(name!=null){
59.184 + d.put_byte(name, 0, name.length);
59.185 + d.put_byte((byte)0);
59.186 + }
59.187 +
59.188 + if(comment!=null){
59.189 + d.put_byte(comment, 0, comment.length);
59.190 + d.put_byte((byte)0);
59.191 + }
59.192 + }
59.193 +*/
59.194 + @Override
59.195 + public Object clone() throws CloneNotSupportedException {
59.196 + GZIPHeader gheader = (GZIPHeader)super.clone();
59.197 + byte[] tmp;
59.198 + if(gheader.extra!=null){
59.199 + tmp=new byte[gheader.extra.length];
59.200 + FastJar.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
59.201 + gheader.extra = tmp;
59.202 + }
59.203 +
59.204 + if(gheader.name!=null){
59.205 + tmp=new byte[gheader.name.length];
59.206 + FastJar.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
59.207 + gheader.name = tmp;
59.208 + }
59.209 +
59.210 + if(gheader.comment!=null){
59.211 + tmp=new byte[gheader.comment.length];
59.212 + FastJar.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
59.213 + gheader.comment = tmp;
59.214 + }
59.215 +
59.216 + return gheader;
59.217 + }
59.218 +}
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/InfBlocks.java Sun May 11 14:01:18 2014 +0200
60.3 @@ -0,0 +1,616 @@
60.4 +/* -*-mode:java; c-basic-offset:2; -*- */
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 +
60.41 +
60.42 +final class InfBlocks{
60.43 + static final private int MANY=1440;
60.44 +
60.45 + // And'ing with mask[n] masks the lower n bits
60.46 + static final private int[] inflate_mask = {
60.47 + 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
60.48 + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
60.49 + 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
60.50 + 0x00007fff, 0x0000ffff
60.51 + };
60.52 +
60.53 + // Table for deflate from PKZIP's appnote.txt.
60.54 + static final int[] border = { // Order of the bit length code lengths
60.55 + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
60.56 + };
60.57 +
60.58 + static final private int Z_OK=0;
60.59 + static final private int Z_STREAM_END=1;
60.60 + static final private int Z_NEED_DICT=2;
60.61 + static final private int Z_ERRNO=-1;
60.62 + static final private int Z_STREAM_ERROR=-2;
60.63 + static final private int Z_DATA_ERROR=-3;
60.64 + static final private int Z_MEM_ERROR=-4;
60.65 + static final private int Z_BUF_ERROR=-5;
60.66 + static final private int Z_VERSION_ERROR=-6;
60.67 +
60.68 + static final private int TYPE=0; // get type bits (3, including end bit)
60.69 + static final private int LENS=1; // get lengths for stored
60.70 + static final private int STORED=2;// processing stored block
60.71 + static final private int TABLE=3; // get table lengths
60.72 + static final private int BTREE=4; // get bit lengths tree for a dynamic block
60.73 + static final private int DTREE=5; // get length, distance trees for a dynamic block
60.74 + static final private int CODES=6; // processing fixed or dynamic block
60.75 + static final private int DRY=7; // output remaining window bytes
60.76 + static final private int DONE=8; // finished last block, done
60.77 + static final private int BAD=9; // ot a data error--stuck here
60.78 +
60.79 + int mode; // current inflate_block mode
60.80 +
60.81 + int left; // if STORED, bytes left to copy
60.82 +
60.83 + int table; // table lengths (14 bits)
60.84 + int index; // index into blens (or border)
60.85 + int[] blens; // bit lengths of codes
60.86 + int[] bb=new int[1]; // bit length tree depth
60.87 + int[] tb=new int[1]; // bit length decoding tree
60.88 +
60.89 + int[] bl=new int[1];
60.90 + int[] bd=new int[1];
60.91 +
60.92 + int[][] tl=new int[1][];
60.93 + int[][] td=new int[1][];
60.94 + int[] tli=new int[1]; // tl_index
60.95 + int[] tdi=new int[1]; // td_index
60.96 +
60.97 + private final InfCodes codes; // if CODES, current state
60.98 +
60.99 + int last; // true if this block is the last block
60.100 +
60.101 + // mode independent information
60.102 + int bitk; // bits in bit buffer
60.103 + int bitb; // bit buffer
60.104 + int[] hufts; // single malloc for tree space
60.105 + byte[] window; // sliding window
60.106 + int end; // one byte after sliding window
60.107 + int read; // window read pointer
60.108 + int write; // window write pointer
60.109 + private boolean check;
60.110 +
60.111 + private final InfTree inftree=new InfTree();
60.112 +
60.113 + private final ZStream z;
60.114 +
60.115 + InfBlocks(ZStream z, int w){
60.116 + this.z=z;
60.117 + this.codes=new InfCodes(this.z, this);
60.118 + hufts=new int[MANY*3];
60.119 + window=new byte[w];
60.120 + end=w;
60.121 + this.check = (z.istate.wrap==0) ? false : true;
60.122 + mode = TYPE;
60.123 + reset();
60.124 + }
60.125 +
60.126 + void reset(){
60.127 + if(mode==BTREE || mode==DTREE){
60.128 + }
60.129 + if(mode==CODES){
60.130 + codes.free(z);
60.131 + }
60.132 + mode=TYPE;
60.133 + bitk=0;
60.134 + bitb=0;
60.135 + read=write=0;
60.136 + if(check){
60.137 + z.adler.reset();
60.138 + }
60.139 + }
60.140 +
60.141 + int proc(int r){
60.142 + int t; // temporary storage
60.143 + int b; // bit buffer
60.144 + int k; // bits in bit buffer
60.145 + int p; // input data pointer
60.146 + int n; // bytes available there
60.147 + int q; // output window write pointer
60.148 + int m; // bytes to end of window or read pointer
60.149 +
60.150 + // copy input/output information to locals (UPDATE macro restores)
60.151 + {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
60.152 + {q=write;m=(int)(q<read?read-q-1:end-q);}
60.153 +
60.154 + // process input based on current state
60.155 + while(true){
60.156 + switch (mode){
60.157 + case TYPE:
60.158 +
60.159 + while(k<(3)){
60.160 + if(n!=0){
60.161 + r=Z_OK;
60.162 + }
60.163 + else{
60.164 + bitb=b; bitk=k;
60.165 + z.avail_in=n;
60.166 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.167 + write=q;
60.168 + return inflate_flush(r);
60.169 + };
60.170 + n--;
60.171 + b|=(z.next_in[p++]&0xff)<<k;
60.172 + k+=8;
60.173 + }
60.174 + t = (int)(b & 7);
60.175 + last = t & 1;
60.176 +
60.177 + switch (t >>> 1){
60.178 + case 0: // stored
60.179 + {b>>>=(3);k-=(3);}
60.180 + t = k & 7; // go to byte boundary
60.181 +
60.182 + {b>>>=(t);k-=(t);}
60.183 + mode = LENS; // get length of stored block
60.184 + break;
60.185 + case 1: // fixed
60.186 + InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
60.187 + codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
60.188 +
60.189 + {b>>>=(3);k-=(3);}
60.190 +
60.191 + mode = CODES;
60.192 + break;
60.193 + case 2: // dynamic
60.194 +
60.195 + {b>>>=(3);k-=(3);}
60.196 +
60.197 + mode = TABLE;
60.198 + break;
60.199 + case 3: // illegal
60.200 +
60.201 + {b>>>=(3);k-=(3);}
60.202 + mode = BAD;
60.203 + z.msg = "invalid block type";
60.204 + r = Z_DATA_ERROR;
60.205 +
60.206 + bitb=b; bitk=k;
60.207 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.208 + write=q;
60.209 + return inflate_flush(r);
60.210 + }
60.211 + break;
60.212 + case LENS:
60.213 +
60.214 + while(k<(32)){
60.215 + if(n!=0){
60.216 + r=Z_OK;
60.217 + }
60.218 + else{
60.219 + bitb=b; bitk=k;
60.220 + z.avail_in=n;
60.221 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.222 + write=q;
60.223 + return inflate_flush(r);
60.224 + };
60.225 + n--;
60.226 + b|=(z.next_in[p++]&0xff)<<k;
60.227 + k+=8;
60.228 + }
60.229 +
60.230 + if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)){
60.231 + mode = BAD;
60.232 + z.msg = "invalid stored block lengths";
60.233 + r = Z_DATA_ERROR;
60.234 +
60.235 + bitb=b; bitk=k;
60.236 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.237 + write=q;
60.238 + return inflate_flush(r);
60.239 + }
60.240 + left = (b & 0xffff);
60.241 + b = k = 0; // dump bits
60.242 + mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
60.243 + break;
60.244 + case STORED:
60.245 + if (n == 0){
60.246 + bitb=b; bitk=k;
60.247 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.248 + write=q;
60.249 + return inflate_flush(r);
60.250 + }
60.251 +
60.252 + if(m==0){
60.253 + if(q==end&&read!=0){
60.254 + q=0; m=(int)(q<read?read-q-1:end-q);
60.255 + }
60.256 + if(m==0){
60.257 + write=q;
60.258 + r=inflate_flush(r);
60.259 + q=write;m=(int)(q<read?read-q-1:end-q);
60.260 + if(q==end&&read!=0){
60.261 + q=0; m=(int)(q<read?read-q-1:end-q);
60.262 + }
60.263 + if(m==0){
60.264 + bitb=b; bitk=k;
60.265 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.266 + write=q;
60.267 + return inflate_flush(r);
60.268 + }
60.269 + }
60.270 + }
60.271 + r=Z_OK;
60.272 +
60.273 + t = left;
60.274 + if(t>n) t = n;
60.275 + if(t>m) t = m;
60.276 + FastJar.arraycopy(z.next_in, p, window, q, t);
60.277 + p += t; n -= t;
60.278 + q += t; m -= t;
60.279 + if ((left -= t) != 0)
60.280 + break;
60.281 + mode = last!=0 ? DRY : TYPE;
60.282 + break;
60.283 + case TABLE:
60.284 +
60.285 + while(k<(14)){
60.286 + if(n!=0){
60.287 + r=Z_OK;
60.288 + }
60.289 + else{
60.290 + bitb=b; bitk=k;
60.291 + z.avail_in=n;
60.292 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.293 + write=q;
60.294 + return inflate_flush(r);
60.295 + };
60.296 + n--;
60.297 + b|=(z.next_in[p++]&0xff)<<k;
60.298 + k+=8;
60.299 + }
60.300 +
60.301 + table = t = (b & 0x3fff);
60.302 + if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
60.303 + {
60.304 + mode = BAD;
60.305 + z.msg = "too many length or distance symbols";
60.306 + r = Z_DATA_ERROR;
60.307 +
60.308 + bitb=b; bitk=k;
60.309 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.310 + write=q;
60.311 + return inflate_flush(r);
60.312 + }
60.313 + t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
60.314 + if(blens==null || blens.length<t){
60.315 + blens=new int[t];
60.316 + }
60.317 + else{
60.318 + for(int i=0; i<t; i++){blens[i]=0;}
60.319 + }
60.320 +
60.321 + {b>>>=(14);k-=(14);}
60.322 +
60.323 + index = 0;
60.324 + mode = BTREE;
60.325 + case BTREE:
60.326 + while (index < 4 + (table >>> 10)){
60.327 + while(k<(3)){
60.328 + if(n!=0){
60.329 + r=Z_OK;
60.330 + }
60.331 + else{
60.332 + bitb=b; bitk=k;
60.333 + z.avail_in=n;
60.334 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.335 + write=q;
60.336 + return inflate_flush(r);
60.337 + };
60.338 + n--;
60.339 + b|=(z.next_in[p++]&0xff)<<k;
60.340 + k+=8;
60.341 + }
60.342 +
60.343 + blens[border[index++]] = b&7;
60.344 +
60.345 + {b>>>=(3);k-=(3);}
60.346 + }
60.347 +
60.348 + while(index < 19){
60.349 + blens[border[index++]] = 0;
60.350 + }
60.351 +
60.352 + bb[0] = 7;
60.353 + t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
60.354 + if (t != Z_OK){
60.355 + r = t;
60.356 + if (r == Z_DATA_ERROR){
60.357 + blens=null;
60.358 + mode = BAD;
60.359 + }
60.360 +
60.361 + bitb=b; bitk=k;
60.362 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.363 + write=q;
60.364 + return inflate_flush(r);
60.365 + }
60.366 +
60.367 + index = 0;
60.368 + mode = DTREE;
60.369 + case DTREE:
60.370 + while (true){
60.371 + t = table;
60.372 + if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
60.373 + break;
60.374 + }
60.375 +
60.376 + int[] h;
60.377 + int i, j, c;
60.378 +
60.379 + t = bb[0];
60.380 +
60.381 + while(k<(t)){
60.382 + if(n!=0){
60.383 + r=Z_OK;
60.384 + }
60.385 + else{
60.386 + bitb=b; bitk=k;
60.387 + z.avail_in=n;
60.388 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.389 + write=q;
60.390 + return inflate_flush(r);
60.391 + };
60.392 + n--;
60.393 + b|=(z.next_in[p++]&0xff)<<k;
60.394 + k+=8;
60.395 + }
60.396 +
60.397 + if(tb[0]==-1){
60.398 + //System.err.println("null...");
60.399 + }
60.400 +
60.401 + t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
60.402 + c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
60.403 +
60.404 + if (c < 16){
60.405 + b>>>=(t);k-=(t);
60.406 + blens[index++] = c;
60.407 + }
60.408 + else { // c == 16..18
60.409 + i = c == 18 ? 7 : c - 14;
60.410 + j = c == 18 ? 11 : 3;
60.411 +
60.412 + while(k<(t+i)){
60.413 + if(n!=0){
60.414 + r=Z_OK;
60.415 + }
60.416 + else{
60.417 + bitb=b; bitk=k;
60.418 + z.avail_in=n;
60.419 + z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.420 + write=q;
60.421 + return inflate_flush(r);
60.422 + };
60.423 + n--;
60.424 + b|=(z.next_in[p++]&0xff)<<k;
60.425 + k+=8;
60.426 + }
60.427 +
60.428 + b>>>=(t);k-=(t);
60.429 +
60.430 + j += (b & inflate_mask[i]);
60.431 +
60.432 + b>>>=(i);k-=(i);
60.433 +
60.434 + i = index;
60.435 + t = table;
60.436 + if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
60.437 + (c == 16 && i < 1)){
60.438 + blens=null;
60.439 + mode = BAD;
60.440 + z.msg = "invalid bit length repeat";
60.441 + r = Z_DATA_ERROR;
60.442 +
60.443 + bitb=b; bitk=k;
60.444 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.445 + write=q;
60.446 + return inflate_flush(r);
60.447 + }
60.448 +
60.449 + c = c == 16 ? blens[i-1] : 0;
60.450 + do{
60.451 + blens[i++] = c;
60.452 + }
60.453 + while (--j!=0);
60.454 + index = i;
60.455 + }
60.456 + }
60.457 +
60.458 + tb[0]=-1;
60.459 + {
60.460 + bl[0] = 9; // must be <= 9 for lookahead assumptions
60.461 + bd[0] = 6; // must be <= 9 for lookahead assumptions
60.462 + t = table;
60.463 + t = inftree.inflate_trees_dynamic(257 + (t & 0x1f),
60.464 + 1 + ((t >> 5) & 0x1f),
60.465 + blens, bl, bd, tli, tdi, hufts, z);
60.466 +
60.467 + if (t != Z_OK){
60.468 + if (t == Z_DATA_ERROR){
60.469 + blens=null;
60.470 + mode = BAD;
60.471 + }
60.472 + r = t;
60.473 +
60.474 + bitb=b; bitk=k;
60.475 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.476 + write=q;
60.477 + return inflate_flush(r);
60.478 + }
60.479 + codes.init(bl[0], bd[0], hufts, tli[0], hufts, tdi[0]);
60.480 + }
60.481 + mode = CODES;
60.482 + case CODES:
60.483 + bitb=b; bitk=k;
60.484 + z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.485 + write=q;
60.486 +
60.487 + if ((r = codes.proc(r)) != Z_STREAM_END){
60.488 + return inflate_flush(r);
60.489 + }
60.490 + r = Z_OK;
60.491 + codes.free(z);
60.492 +
60.493 + p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
60.494 + q=write;m=(int)(q<read?read-q-1:end-q);
60.495 +
60.496 + if (last==0){
60.497 + mode = TYPE;
60.498 + break;
60.499 + }
60.500 + mode = DRY;
60.501 + case DRY:
60.502 + write=q;
60.503 + r=inflate_flush(r);
60.504 + q=write; m=(int)(q<read?read-q-1:end-q);
60.505 + if (read != write){
60.506 + bitb=b; bitk=k;
60.507 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.508 + write=q;
60.509 + return inflate_flush(r);
60.510 + }
60.511 + mode = DONE;
60.512 + case DONE:
60.513 + r = Z_STREAM_END;
60.514 +
60.515 + bitb=b; bitk=k;
60.516 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.517 + write=q;
60.518 + return inflate_flush(r);
60.519 + case BAD:
60.520 + r = Z_DATA_ERROR;
60.521 +
60.522 + bitb=b; bitk=k;
60.523 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.524 + write=q;
60.525 + return inflate_flush(r);
60.526 +
60.527 + default:
60.528 + r = Z_STREAM_ERROR;
60.529 +
60.530 + bitb=b; bitk=k;
60.531 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
60.532 + write=q;
60.533 + return inflate_flush(r);
60.534 + }
60.535 + }
60.536 + }
60.537 +
60.538 + void free(){
60.539 + reset();
60.540 + window=null;
60.541 + hufts=null;
60.542 + //ZFREE(z, s);
60.543 + }
60.544 +
60.545 + void set_dictionary(byte[] d, int start, int n){
60.546 + FastJar.arraycopy(d, start, window, 0, n);
60.547 + read = write = n;
60.548 + }
60.549 +
60.550 + // Returns true if inflate is currently at the end of a block generated
60.551 + // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
60.552 + int sync_point(){
60.553 + return mode == LENS ? 1 : 0;
60.554 + }
60.555 +
60.556 + // copy as much as possible from the sliding window to the output area
60.557 + int inflate_flush(int r){
60.558 + int n;
60.559 + int p;
60.560 + int q;
60.561 +
60.562 + // local copies of source and destination pointers
60.563 + p = z.next_out_index;
60.564 + q = read;
60.565 +
60.566 + // compute number of bytes to copy as far as end of window
60.567 + n = (int)((q <= write ? write : end) - q);
60.568 + if(n > z.avail_out) n = z.avail_out;
60.569 + if(n!=0 && r == Z_BUF_ERROR) r = Z_OK;
60.570 +
60.571 + // update counters
60.572 + z.avail_out -= n;
60.573 + z.total_out += n;
60.574 +
60.575 + // update check information
60.576 + if(check && n>0){
60.577 + z.adler.update(window, q, n);
60.578 + }
60.579 +
60.580 + // copy as far as end of window
60.581 + FastJar.arraycopy(window, q, z.next_out, p, n);
60.582 + p += n;
60.583 + q += n;
60.584 +
60.585 + // see if more to copy at beginning of window
60.586 + if (q == end){
60.587 + // wrap pointers
60.588 + q = 0;
60.589 + if (write == end)
60.590 + write = 0;
60.591 +
60.592 + // compute bytes to copy
60.593 + n = write - q;
60.594 + if (n > z.avail_out) n = z.avail_out;
60.595 + if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
60.596 +
60.597 + // update counters
60.598 + z.avail_out -= n;
60.599 + z.total_out += n;
60.600 +
60.601 + // update check information
60.602 + if(check && n>0){
60.603 + z.adler.update(window, q, n);
60.604 + }
60.605 +
60.606 + // copy
60.607 + FastJar.arraycopy(window, q, z.next_out, p, n);
60.608 + p += n;
60.609 + q += n;
60.610 + }
60.611 +
60.612 + // update pointers
60.613 + z.next_out_index = p;
60.614 + read = q;
60.615 +
60.616 + // done
60.617 + return r;
60.618 + }
60.619 +}
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/InfCodes.java Sun May 11 14:01:18 2014 +0200
61.3 @@ -0,0 +1,612 @@
61.4 +/* -*-mode:java; c-basic-offset:2; -*- */
61.5 +/*
61.6 +Copyright (c) 2000,2001,2002,2003 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 +final class InfCodes{
61.43 +
61.44 + static final private int[] inflate_mask = {
61.45 + 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
61.46 + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
61.47 + 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
61.48 + 0x00007fff, 0x0000ffff
61.49 + };
61.50 +
61.51 + static final private int Z_OK=0;
61.52 + static final private int Z_STREAM_END=1;
61.53 + static final private int Z_NEED_DICT=2;
61.54 + static final private int Z_ERRNO=-1;
61.55 + static final private int Z_STREAM_ERROR=-2;
61.56 + static final private int Z_DATA_ERROR=-3;
61.57 + static final private int Z_MEM_ERROR=-4;
61.58 + static final private int Z_BUF_ERROR=-5;
61.59 + static final private int Z_VERSION_ERROR=-6;
61.60 +
61.61 + // waiting for "i:"=input,
61.62 + // "o:"=output,
61.63 + // "x:"=nothing
61.64 + static final private int START=0; // x: set up for LEN
61.65 + static final private int LEN=1; // i: get length/literal/eob next
61.66 + static final private int LENEXT=2; // i: getting length extra (have base)
61.67 + static final private int DIST=3; // i: get distance next
61.68 + static final private int DISTEXT=4;// i: getting distance extra
61.69 + static final private int COPY=5; // o: copying bytes in window, waiting for space
61.70 + static final private int LIT=6; // o: got literal, waiting for output space
61.71 + static final private int WASH=7; // o: got eob, possibly still output waiting
61.72 + static final private int END=8; // x: got eob and all data flushed
61.73 + static final private int BADCODE=9;// x: got error
61.74 +
61.75 + int mode; // current inflate_codes mode
61.76 +
61.77 + // mode dependent information
61.78 + int len;
61.79 +
61.80 + int[] tree; // pointer into tree
61.81 + int tree_index=0;
61.82 + int need; // bits needed
61.83 +
61.84 + int lit;
61.85 +
61.86 + // if EXT or COPY, where and how much
61.87 + int get; // bits to get for extra
61.88 + int dist; // distance back to copy from
61.89 +
61.90 + byte lbits; // ltree bits decoded per branch
61.91 + byte dbits; // dtree bits decoder per branch
61.92 + int[] ltree; // literal/length/eob tree
61.93 + int ltree_index; // literal/length/eob tree
61.94 + int[] dtree; // distance tree
61.95 + int dtree_index; // distance tree
61.96 +
61.97 + private final ZStream z;
61.98 + private final InfBlocks s;
61.99 + InfCodes(ZStream z, InfBlocks s){
61.100 + this.z=z;
61.101 + this.s=s;
61.102 + }
61.103 +
61.104 + void init(int bl, int bd,
61.105 + int[] tl, int tl_index,
61.106 + int[] td, int td_index){
61.107 + mode=START;
61.108 + lbits=(byte)bl;
61.109 + dbits=(byte)bd;
61.110 + ltree=tl;
61.111 + ltree_index=tl_index;
61.112 + dtree = td;
61.113 + dtree_index=td_index;
61.114 + tree=null;
61.115 + }
61.116 +
61.117 + int proc(int r){
61.118 + int j; // temporary storage
61.119 + int[] t; // temporary pointer
61.120 + int tindex; // temporary pointer
61.121 + int e; // extra bits or operation
61.122 + int b=0; // bit buffer
61.123 + int k=0; // bits in bit buffer
61.124 + int p=0; // input data pointer
61.125 + int n; // bytes available there
61.126 + int q; // output window write pointer
61.127 + int m; // bytes to end of window or read pointer
61.128 + int f; // pointer to copy strings from
61.129 +
61.130 + // copy input/output information to locals (UPDATE macro restores)
61.131 + p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
61.132 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
61.133 +
61.134 + // process input and output based on current state
61.135 + while (true){
61.136 + switch (mode){
61.137 + // waiting for "i:"=input, "o:"=output, "x:"=nothing
61.138 + case START: // x: set up for LEN
61.139 + if (m >= 258 && n >= 10){
61.140 +
61.141 + s.bitb=b;s.bitk=k;
61.142 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.143 + s.write=q;
61.144 + r = inflate_fast(lbits, dbits,
61.145 + ltree, ltree_index,
61.146 + dtree, dtree_index,
61.147 + s, z);
61.148 +
61.149 + p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
61.150 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
61.151 +
61.152 + if (r != Z_OK){
61.153 + mode = r == Z_STREAM_END ? WASH : BADCODE;
61.154 + break;
61.155 + }
61.156 + }
61.157 + need = lbits;
61.158 + tree = ltree;
61.159 + tree_index=ltree_index;
61.160 +
61.161 + mode = LEN;
61.162 + case LEN: // i: get length/literal/eob next
61.163 + j = need;
61.164 +
61.165 + while(k<(j)){
61.166 + if(n!=0)r=Z_OK;
61.167 + else{
61.168 +
61.169 + s.bitb=b;s.bitk=k;
61.170 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.171 + s.write=q;
61.172 + return s.inflate_flush(r);
61.173 + }
61.174 + n--;
61.175 + b|=(z.next_in[p++]&0xff)<<k;
61.176 + k+=8;
61.177 + }
61.178 +
61.179 + tindex=(tree_index+(b&inflate_mask[j]))*3;
61.180 +
61.181 + b>>>=(tree[tindex+1]);
61.182 + k-=(tree[tindex+1]);
61.183 +
61.184 + e=tree[tindex];
61.185 +
61.186 + if(e == 0){ // literal
61.187 + lit = tree[tindex+2];
61.188 + mode = LIT;
61.189 + break;
61.190 + }
61.191 + if((e & 16)!=0 ){ // length
61.192 + get = e & 15;
61.193 + len = tree[tindex+2];
61.194 + mode = LENEXT;
61.195 + break;
61.196 + }
61.197 + if ((e & 64) == 0){ // next table
61.198 + need = e;
61.199 + tree_index = tindex/3+tree[tindex+2];
61.200 + break;
61.201 + }
61.202 + if ((e & 32)!=0){ // end of block
61.203 + mode = WASH;
61.204 + break;
61.205 + }
61.206 + mode = BADCODE; // invalid code
61.207 + z.msg = "invalid literal/length code";
61.208 + r = Z_DATA_ERROR;
61.209 +
61.210 + s.bitb=b;s.bitk=k;
61.211 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.212 + s.write=q;
61.213 + return s.inflate_flush(r);
61.214 +
61.215 + case LENEXT: // i: getting length extra (have base)
61.216 + j = get;
61.217 +
61.218 + while(k<(j)){
61.219 + if(n!=0)r=Z_OK;
61.220 + else{
61.221 +
61.222 + s.bitb=b;s.bitk=k;
61.223 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.224 + s.write=q;
61.225 + return s.inflate_flush(r);
61.226 + }
61.227 + n--; b|=(z.next_in[p++]&0xff)<<k;
61.228 + k+=8;
61.229 + }
61.230 +
61.231 + len += (b & inflate_mask[j]);
61.232 +
61.233 + b>>=j;
61.234 + k-=j;
61.235 +
61.236 + need = dbits;
61.237 + tree = dtree;
61.238 + tree_index=dtree_index;
61.239 + mode = DIST;
61.240 + case DIST: // i: get distance next
61.241 + j = need;
61.242 +
61.243 + while(k<(j)){
61.244 + if(n!=0)r=Z_OK;
61.245 + else{
61.246 +
61.247 + s.bitb=b;s.bitk=k;
61.248 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.249 + s.write=q;
61.250 + return s.inflate_flush(r);
61.251 + }
61.252 + n--; b|=(z.next_in[p++]&0xff)<<k;
61.253 + k+=8;
61.254 + }
61.255 +
61.256 + tindex=(tree_index+(b & inflate_mask[j]))*3;
61.257 +
61.258 + b>>=tree[tindex+1];
61.259 + k-=tree[tindex+1];
61.260 +
61.261 + e = (tree[tindex]);
61.262 + if((e & 16)!=0){ // distance
61.263 + get = e & 15;
61.264 + dist = tree[tindex+2];
61.265 + mode = DISTEXT;
61.266 + break;
61.267 + }
61.268 + if ((e & 64) == 0){ // next table
61.269 + need = e;
61.270 + tree_index = tindex/3 + tree[tindex+2];
61.271 + break;
61.272 + }
61.273 + mode = BADCODE; // invalid code
61.274 + z.msg = "invalid distance code";
61.275 + r = Z_DATA_ERROR;
61.276 +
61.277 + s.bitb=b;s.bitk=k;
61.278 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.279 + s.write=q;
61.280 + return s.inflate_flush(r);
61.281 +
61.282 + case DISTEXT: // i: getting distance extra
61.283 + j = get;
61.284 +
61.285 + while(k<(j)){
61.286 + if(n!=0)r=Z_OK;
61.287 + else{
61.288 +
61.289 + s.bitb=b;s.bitk=k;
61.290 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.291 + s.write=q;
61.292 + return s.inflate_flush(r);
61.293 + }
61.294 + n--; b|=(z.next_in[p++]&0xff)<<k;
61.295 + k+=8;
61.296 + }
61.297 +
61.298 + dist += (b & inflate_mask[j]);
61.299 +
61.300 + b>>=j;
61.301 + k-=j;
61.302 +
61.303 + mode = COPY;
61.304 + case COPY: // o: copying bytes in window, waiting for space
61.305 + f = q - dist;
61.306 + while(f < 0){ // modulo window size-"while" instead
61.307 + f += s.end; // of "if" handles invalid distances
61.308 + }
61.309 + while (len!=0){
61.310 +
61.311 + if(m==0){
61.312 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
61.313 + if(m==0){
61.314 + s.write=q; r=s.inflate_flush(r);
61.315 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
61.316 +
61.317 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
61.318 +
61.319 + if(m==0){
61.320 + s.bitb=b;s.bitk=k;
61.321 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.322 + s.write=q;
61.323 + return s.inflate_flush(r);
61.324 + }
61.325 + }
61.326 + }
61.327 +
61.328 + s.window[q++]=s.window[f++]; m--;
61.329 +
61.330 + if (f == s.end)
61.331 + f = 0;
61.332 + len--;
61.333 + }
61.334 + mode = START;
61.335 + break;
61.336 + case LIT: // o: got literal, waiting for output space
61.337 + if(m==0){
61.338 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
61.339 + if(m==0){
61.340 + s.write=q; r=s.inflate_flush(r);
61.341 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
61.342 +
61.343 + if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
61.344 + if(m==0){
61.345 + s.bitb=b;s.bitk=k;
61.346 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.347 + s.write=q;
61.348 + return s.inflate_flush(r);
61.349 + }
61.350 + }
61.351 + }
61.352 + r=Z_OK;
61.353 +
61.354 + s.window[q++]=(byte)lit; m--;
61.355 +
61.356 + mode = START;
61.357 + break;
61.358 + case WASH: // o: got eob, possibly more output
61.359 + if (k > 7){ // return unused byte, if any
61.360 + k -= 8;
61.361 + n++;
61.362 + p--; // can always return one
61.363 + }
61.364 +
61.365 + s.write=q; r=s.inflate_flush(r);
61.366 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
61.367 +
61.368 + if (s.read != s.write){
61.369 + s.bitb=b;s.bitk=k;
61.370 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.371 + s.write=q;
61.372 + return s.inflate_flush(r);
61.373 + }
61.374 + mode = END;
61.375 + case END:
61.376 + r = Z_STREAM_END;
61.377 + s.bitb=b;s.bitk=k;
61.378 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.379 + s.write=q;
61.380 + return s.inflate_flush(r);
61.381 +
61.382 + case BADCODE: // x: got error
61.383 +
61.384 + r = Z_DATA_ERROR;
61.385 +
61.386 + s.bitb=b;s.bitk=k;
61.387 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.388 + s.write=q;
61.389 + return s.inflate_flush(r);
61.390 +
61.391 + default:
61.392 + r = Z_STREAM_ERROR;
61.393 +
61.394 + s.bitb=b;s.bitk=k;
61.395 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.396 + s.write=q;
61.397 + return s.inflate_flush(r);
61.398 + }
61.399 + }
61.400 + }
61.401 +
61.402 + void free(ZStream z){
61.403 + // ZFREE(z, c);
61.404 + }
61.405 +
61.406 + // Called with number of bytes left to write in window at least 258
61.407 + // (the maximum string length) and number of input bytes available
61.408 + // at least ten. The ten bytes are six bytes for the longest length/
61.409 + // distance pair plus four bytes for overloading the bit buffer.
61.410 +
61.411 + int inflate_fast(int bl, int bd,
61.412 + int[] tl, int tl_index,
61.413 + int[] td, int td_index,
61.414 + InfBlocks s, ZStream z){
61.415 + int t; // temporary pointer
61.416 + int[] tp; // temporary pointer
61.417 + int tp_index; // temporary pointer
61.418 + int e; // extra bits or operation
61.419 + int b; // bit buffer
61.420 + int k; // bits in bit buffer
61.421 + int p; // input data pointer
61.422 + int n; // bytes available there
61.423 + int q; // output window write pointer
61.424 + int m; // bytes to end of window or read pointer
61.425 + int ml; // mask for literal/length tree
61.426 + int md; // mask for distance tree
61.427 + int c; // bytes to copy
61.428 + int d; // distance back to copy from
61.429 + int r; // copy source pointer
61.430 +
61.431 + int tp_index_t_3; // (tp_index+t)*3
61.432 +
61.433 + // load input, output, bit values
61.434 + p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
61.435 + q=s.write;m=q<s.read?s.read-q-1:s.end-q;
61.436 +
61.437 + // initialize masks
61.438 + ml = inflate_mask[bl];
61.439 + md = inflate_mask[bd];
61.440 +
61.441 + // do until not enough input or output space for fast loop
61.442 + do { // assume called with m >= 258 && n >= 10
61.443 + // get literal/length code
61.444 + while(k<(20)){ // max bits for literal/length code
61.445 + n--;
61.446 + b|=(z.next_in[p++]&0xff)<<k;k+=8;
61.447 + }
61.448 +
61.449 + t= b&ml;
61.450 + tp=tl;
61.451 + tp_index=tl_index;
61.452 + tp_index_t_3=(tp_index+t)*3;
61.453 + if ((e = tp[tp_index_t_3]) == 0){
61.454 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
61.455 +
61.456 + s.window[q++] = (byte)tp[tp_index_t_3+2];
61.457 + m--;
61.458 + continue;
61.459 + }
61.460 + do {
61.461 +
61.462 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
61.463 +
61.464 + if((e&16)!=0){
61.465 + e &= 15;
61.466 + c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
61.467 +
61.468 + b>>=e; k-=e;
61.469 +
61.470 + // decode distance base of block to copy
61.471 + while(k<(15)){ // max bits for distance code
61.472 + n--;
61.473 + b|=(z.next_in[p++]&0xff)<<k;k+=8;
61.474 + }
61.475 +
61.476 + t= b&md;
61.477 + tp=td;
61.478 + tp_index=td_index;
61.479 + tp_index_t_3=(tp_index+t)*3;
61.480 + e = tp[tp_index_t_3];
61.481 +
61.482 + do {
61.483 +
61.484 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
61.485 +
61.486 + if((e&16)!=0){
61.487 + // get extra bits to add to distance base
61.488 + e &= 15;
61.489 + while(k<(e)){ // get extra bits (up to 13)
61.490 + n--;
61.491 + b|=(z.next_in[p++]&0xff)<<k;k+=8;
61.492 + }
61.493 +
61.494 + d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
61.495 +
61.496 + b>>=(e); k-=(e);
61.497 +
61.498 + // do the copy
61.499 + m -= c;
61.500 + if (q >= d){ // offset before dest
61.501 + // just copy
61.502 + r=q-d;
61.503 + if(q-r>0 && 2>(q-r)){
61.504 + s.window[q++]=s.window[r++]; // minimum count is three,
61.505 + s.window[q++]=s.window[r++]; // so unroll loop a little
61.506 + c-=2;
61.507 + }
61.508 + else{
61.509 + FastJar.arraycopy(s.window, r, s.window, q, 2);
61.510 + q+=2; r+=2; c-=2;
61.511 + }
61.512 + }
61.513 + else{ // else offset after destination
61.514 + r=q-d;
61.515 + do{
61.516 + r+=s.end; // force pointer in window
61.517 + }while(r<0); // covers invalid distances
61.518 + e=s.end-r;
61.519 + if(c>e){ // if source crosses,
61.520 + c-=e; // wrapped copy
61.521 + if(q-r>0 && e>(q-r)){
61.522 + do{s.window[q++] = s.window[r++];}
61.523 + while(--e!=0);
61.524 + }
61.525 + else{
61.526 + FastJar.arraycopy(s.window, r, s.window, q, e);
61.527 + q+=e; r+=e; e=0;
61.528 + }
61.529 + r = 0; // copy rest from start of window
61.530 + }
61.531 +
61.532 + }
61.533 +
61.534 + // copy all or what's left
61.535 + if(q-r>0 && c>(q-r)){
61.536 + do{s.window[q++] = s.window[r++];}
61.537 + while(--c!=0);
61.538 + }
61.539 + else{
61.540 + FastJar.arraycopy(s.window, r, s.window, q, c);
61.541 + q+=c; r+=c; c=0;
61.542 + }
61.543 + break;
61.544 + }
61.545 + else if((e&64)==0){
61.546 + t+=tp[tp_index_t_3+2];
61.547 + t+=(b&inflate_mask[e]);
61.548 + tp_index_t_3=(tp_index+t)*3;
61.549 + e=tp[tp_index_t_3];
61.550 + }
61.551 + else{
61.552 + z.msg = "invalid distance code";
61.553 +
61.554 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
61.555 +
61.556 + s.bitb=b;s.bitk=k;
61.557 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.558 + s.write=q;
61.559 +
61.560 + return Z_DATA_ERROR;
61.561 + }
61.562 + }
61.563 + while(true);
61.564 + break;
61.565 + }
61.566 +
61.567 + if((e&64)==0){
61.568 + t+=tp[tp_index_t_3+2];
61.569 + t+=(b&inflate_mask[e]);
61.570 + tp_index_t_3=(tp_index+t)*3;
61.571 + if((e=tp[tp_index_t_3])==0){
61.572 +
61.573 + b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
61.574 +
61.575 + s.window[q++]=(byte)tp[tp_index_t_3+2];
61.576 + m--;
61.577 + break;
61.578 + }
61.579 + }
61.580 + else if((e&32)!=0){
61.581 +
61.582 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
61.583 +
61.584 + s.bitb=b;s.bitk=k;
61.585 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.586 + s.write=q;
61.587 +
61.588 + return Z_STREAM_END;
61.589 + }
61.590 + else{
61.591 + z.msg="invalid literal/length code";
61.592 +
61.593 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
61.594 +
61.595 + s.bitb=b;s.bitk=k;
61.596 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.597 + s.write=q;
61.598 +
61.599 + return Z_DATA_ERROR;
61.600 + }
61.601 + }
61.602 + while(true);
61.603 + }
61.604 + while(m>=258 && n>= 10);
61.605 +
61.606 + // not enough input or output--restore pointers and return
61.607 + c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
61.608 +
61.609 + s.bitb=b;s.bitk=k;
61.610 + z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
61.611 + s.write=q;
61.612 +
61.613 + return Z_OK;
61.614 + }
61.615 +}
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/InfTree.java Sun May 11 14:01:18 2014 +0200
62.3 @@ -0,0 +1,520 @@
62.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
62.5 +/*
62.6 +Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
62.7 +
62.8 +Redistribution and use in source and binary forms, with or without
62.9 +modification, are permitted provided that the following conditions are met:
62.10 +
62.11 + 1. Redistributions of source code must retain the above copyright notice,
62.12 + this list of conditions and the following disclaimer.
62.13 +
62.14 + 2. Redistributions in binary form must reproduce the above copyright
62.15 + notice, this list of conditions and the following disclaimer in
62.16 + the documentation and/or other materials provided with the distribution.
62.17 +
62.18 + 3. The names of the authors may not be used to endorse or promote products
62.19 + derived from this software without specific prior written permission.
62.20 +
62.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
62.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
62.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
62.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
62.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
62.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
62.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62.31 + */
62.32 +/*
62.33 + * This program is based on zlib-1.1.3, so all credit should go authors
62.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
62.35 + * and contributors of zlib.
62.36 + */
62.37 +
62.38 +package org.apidesign.bck2brwsr.emul.zip;
62.39 +
62.40 +
62.41 +
62.42 +final class InfTree{
62.43 +
62.44 + static final private int MANY=1440;
62.45 +
62.46 + static final private int Z_OK=0;
62.47 + static final private int Z_STREAM_END=1;
62.48 + static final private int Z_NEED_DICT=2;
62.49 + static final private int Z_ERRNO=-1;
62.50 + static final private int Z_STREAM_ERROR=-2;
62.51 + static final private int Z_DATA_ERROR=-3;
62.52 + static final private int Z_MEM_ERROR=-4;
62.53 + static final private int Z_BUF_ERROR=-5;
62.54 + static final private int Z_VERSION_ERROR=-6;
62.55 +
62.56 + static final int fixed_bl = 9;
62.57 + static final int fixed_bd = 5;
62.58 +
62.59 + static final int[] fixed_tl = {
62.60 + 96,7,256, 0,8,80, 0,8,16, 84,8,115,
62.61 + 82,7,31, 0,8,112, 0,8,48, 0,9,192,
62.62 + 80,7,10, 0,8,96, 0,8,32, 0,9,160,
62.63 + 0,8,0, 0,8,128, 0,8,64, 0,9,224,
62.64 + 80,7,6, 0,8,88, 0,8,24, 0,9,144,
62.65 + 83,7,59, 0,8,120, 0,8,56, 0,9,208,
62.66 + 81,7,17, 0,8,104, 0,8,40, 0,9,176,
62.67 + 0,8,8, 0,8,136, 0,8,72, 0,9,240,
62.68 + 80,7,4, 0,8,84, 0,8,20, 85,8,227,
62.69 + 83,7,43, 0,8,116, 0,8,52, 0,9,200,
62.70 + 81,7,13, 0,8,100, 0,8,36, 0,9,168,
62.71 + 0,8,4, 0,8,132, 0,8,68, 0,9,232,
62.72 + 80,7,8, 0,8,92, 0,8,28, 0,9,152,
62.73 + 84,7,83, 0,8,124, 0,8,60, 0,9,216,
62.74 + 82,7,23, 0,8,108, 0,8,44, 0,9,184,
62.75 + 0,8,12, 0,8,140, 0,8,76, 0,9,248,
62.76 + 80,7,3, 0,8,82, 0,8,18, 85,8,163,
62.77 + 83,7,35, 0,8,114, 0,8,50, 0,9,196,
62.78 + 81,7,11, 0,8,98, 0,8,34, 0,9,164,
62.79 + 0,8,2, 0,8,130, 0,8,66, 0,9,228,
62.80 + 80,7,7, 0,8,90, 0,8,26, 0,9,148,
62.81 + 84,7,67, 0,8,122, 0,8,58, 0,9,212,
62.82 + 82,7,19, 0,8,106, 0,8,42, 0,9,180,
62.83 + 0,8,10, 0,8,138, 0,8,74, 0,9,244,
62.84 + 80,7,5, 0,8,86, 0,8,22, 192,8,0,
62.85 + 83,7,51, 0,8,118, 0,8,54, 0,9,204,
62.86 + 81,7,15, 0,8,102, 0,8,38, 0,9,172,
62.87 + 0,8,6, 0,8,134, 0,8,70, 0,9,236,
62.88 + 80,7,9, 0,8,94, 0,8,30, 0,9,156,
62.89 + 84,7,99, 0,8,126, 0,8,62, 0,9,220,
62.90 + 82,7,27, 0,8,110, 0,8,46, 0,9,188,
62.91 + 0,8,14, 0,8,142, 0,8,78, 0,9,252,
62.92 + 96,7,256, 0,8,81, 0,8,17, 85,8,131,
62.93 + 82,7,31, 0,8,113, 0,8,49, 0,9,194,
62.94 + 80,7,10, 0,8,97, 0,8,33, 0,9,162,
62.95 + 0,8,1, 0,8,129, 0,8,65, 0,9,226,
62.96 + 80,7,6, 0,8,89, 0,8,25, 0,9,146,
62.97 + 83,7,59, 0,8,121, 0,8,57, 0,9,210,
62.98 + 81,7,17, 0,8,105, 0,8,41, 0,9,178,
62.99 + 0,8,9, 0,8,137, 0,8,73, 0,9,242,
62.100 + 80,7,4, 0,8,85, 0,8,21, 80,8,258,
62.101 + 83,7,43, 0,8,117, 0,8,53, 0,9,202,
62.102 + 81,7,13, 0,8,101, 0,8,37, 0,9,170,
62.103 + 0,8,5, 0,8,133, 0,8,69, 0,9,234,
62.104 + 80,7,8, 0,8,93, 0,8,29, 0,9,154,
62.105 + 84,7,83, 0,8,125, 0,8,61, 0,9,218,
62.106 + 82,7,23, 0,8,109, 0,8,45, 0,9,186,
62.107 + 0,8,13, 0,8,141, 0,8,77, 0,9,250,
62.108 + 80,7,3, 0,8,83, 0,8,19, 85,8,195,
62.109 + 83,7,35, 0,8,115, 0,8,51, 0,9,198,
62.110 + 81,7,11, 0,8,99, 0,8,35, 0,9,166,
62.111 + 0,8,3, 0,8,131, 0,8,67, 0,9,230,
62.112 + 80,7,7, 0,8,91, 0,8,27, 0,9,150,
62.113 + 84,7,67, 0,8,123, 0,8,59, 0,9,214,
62.114 + 82,7,19, 0,8,107, 0,8,43, 0,9,182,
62.115 + 0,8,11, 0,8,139, 0,8,75, 0,9,246,
62.116 + 80,7,5, 0,8,87, 0,8,23, 192,8,0,
62.117 + 83,7,51, 0,8,119, 0,8,55, 0,9,206,
62.118 + 81,7,15, 0,8,103, 0,8,39, 0,9,174,
62.119 + 0,8,7, 0,8,135, 0,8,71, 0,9,238,
62.120 + 80,7,9, 0,8,95, 0,8,31, 0,9,158,
62.121 + 84,7,99, 0,8,127, 0,8,63, 0,9,222,
62.122 + 82,7,27, 0,8,111, 0,8,47, 0,9,190,
62.123 + 0,8,15, 0,8,143, 0,8,79, 0,9,254,
62.124 + 96,7,256, 0,8,80, 0,8,16, 84,8,115,
62.125 + 82,7,31, 0,8,112, 0,8,48, 0,9,193,
62.126 +
62.127 + 80,7,10, 0,8,96, 0,8,32, 0,9,161,
62.128 + 0,8,0, 0,8,128, 0,8,64, 0,9,225,
62.129 + 80,7,6, 0,8,88, 0,8,24, 0,9,145,
62.130 + 83,7,59, 0,8,120, 0,8,56, 0,9,209,
62.131 + 81,7,17, 0,8,104, 0,8,40, 0,9,177,
62.132 + 0,8,8, 0,8,136, 0,8,72, 0,9,241,
62.133 + 80,7,4, 0,8,84, 0,8,20, 85,8,227,
62.134 + 83,7,43, 0,8,116, 0,8,52, 0,9,201,
62.135 + 81,7,13, 0,8,100, 0,8,36, 0,9,169,
62.136 + 0,8,4, 0,8,132, 0,8,68, 0,9,233,
62.137 + 80,7,8, 0,8,92, 0,8,28, 0,9,153,
62.138 + 84,7,83, 0,8,124, 0,8,60, 0,9,217,
62.139 + 82,7,23, 0,8,108, 0,8,44, 0,9,185,
62.140 + 0,8,12, 0,8,140, 0,8,76, 0,9,249,
62.141 + 80,7,3, 0,8,82, 0,8,18, 85,8,163,
62.142 + 83,7,35, 0,8,114, 0,8,50, 0,9,197,
62.143 + 81,7,11, 0,8,98, 0,8,34, 0,9,165,
62.144 + 0,8,2, 0,8,130, 0,8,66, 0,9,229,
62.145 + 80,7,7, 0,8,90, 0,8,26, 0,9,149,
62.146 + 84,7,67, 0,8,122, 0,8,58, 0,9,213,
62.147 + 82,7,19, 0,8,106, 0,8,42, 0,9,181,
62.148 + 0,8,10, 0,8,138, 0,8,74, 0,9,245,
62.149 + 80,7,5, 0,8,86, 0,8,22, 192,8,0,
62.150 + 83,7,51, 0,8,118, 0,8,54, 0,9,205,
62.151 + 81,7,15, 0,8,102, 0,8,38, 0,9,173,
62.152 + 0,8,6, 0,8,134, 0,8,70, 0,9,237,
62.153 + 80,7,9, 0,8,94, 0,8,30, 0,9,157,
62.154 + 84,7,99, 0,8,126, 0,8,62, 0,9,221,
62.155 + 82,7,27, 0,8,110, 0,8,46, 0,9,189,
62.156 + 0,8,14, 0,8,142, 0,8,78, 0,9,253,
62.157 + 96,7,256, 0,8,81, 0,8,17, 85,8,131,
62.158 + 82,7,31, 0,8,113, 0,8,49, 0,9,195,
62.159 + 80,7,10, 0,8,97, 0,8,33, 0,9,163,
62.160 + 0,8,1, 0,8,129, 0,8,65, 0,9,227,
62.161 + 80,7,6, 0,8,89, 0,8,25, 0,9,147,
62.162 + 83,7,59, 0,8,121, 0,8,57, 0,9,211,
62.163 + 81,7,17, 0,8,105, 0,8,41, 0,9,179,
62.164 + 0,8,9, 0,8,137, 0,8,73, 0,9,243,
62.165 + 80,7,4, 0,8,85, 0,8,21, 80,8,258,
62.166 + 83,7,43, 0,8,117, 0,8,53, 0,9,203,
62.167 + 81,7,13, 0,8,101, 0,8,37, 0,9,171,
62.168 + 0,8,5, 0,8,133, 0,8,69, 0,9,235,
62.169 + 80,7,8, 0,8,93, 0,8,29, 0,9,155,
62.170 + 84,7,83, 0,8,125, 0,8,61, 0,9,219,
62.171 + 82,7,23, 0,8,109, 0,8,45, 0,9,187,
62.172 + 0,8,13, 0,8,141, 0,8,77, 0,9,251,
62.173 + 80,7,3, 0,8,83, 0,8,19, 85,8,195,
62.174 + 83,7,35, 0,8,115, 0,8,51, 0,9,199,
62.175 + 81,7,11, 0,8,99, 0,8,35, 0,9,167,
62.176 + 0,8,3, 0,8,131, 0,8,67, 0,9,231,
62.177 + 80,7,7, 0,8,91, 0,8,27, 0,9,151,
62.178 + 84,7,67, 0,8,123, 0,8,59, 0,9,215,
62.179 + 82,7,19, 0,8,107, 0,8,43, 0,9,183,
62.180 + 0,8,11, 0,8,139, 0,8,75, 0,9,247,
62.181 + 80,7,5, 0,8,87, 0,8,23, 192,8,0,
62.182 + 83,7,51, 0,8,119, 0,8,55, 0,9,207,
62.183 + 81,7,15, 0,8,103, 0,8,39, 0,9,175,
62.184 + 0,8,7, 0,8,135, 0,8,71, 0,9,239,
62.185 + 80,7,9, 0,8,95, 0,8,31, 0,9,159,
62.186 + 84,7,99, 0,8,127, 0,8,63, 0,9,223,
62.187 + 82,7,27, 0,8,111, 0,8,47, 0,9,191,
62.188 + 0,8,15, 0,8,143, 0,8,79, 0,9,255
62.189 + };
62.190 + static final int[] fixed_td = {
62.191 + 80,5,1, 87,5,257, 83,5,17, 91,5,4097,
62.192 + 81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
62.193 + 80,5,3, 88,5,513, 84,5,33, 92,5,8193,
62.194 + 82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
62.195 + 80,5,2, 87,5,385, 83,5,25, 91,5,6145,
62.196 + 81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
62.197 + 80,5,4, 88,5,769, 84,5,49, 92,5,12289,
62.198 + 82,5,13, 90,5,3073, 86,5,193, 192,5,24577
62.199 + };
62.200 +
62.201 + // Tables for deflate from PKZIP's appnote.txt.
62.202 + static final int[] cplens = { // Copy lengths for literal codes 257..285
62.203 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
62.204 + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
62.205 + };
62.206 +
62.207 + // see note #13 above about 258
62.208 + static final int[] cplext = { // Extra bits for literal codes 257..285
62.209 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
62.210 + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
62.211 + };
62.212 +
62.213 + static final int[] cpdist = { // Copy offsets for distance codes 0..29
62.214 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
62.215 + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
62.216 + 8193, 12289, 16385, 24577
62.217 + };
62.218 +
62.219 + static final int[] cpdext = { // Extra bits for distance codes
62.220 + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
62.221 + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
62.222 + 12, 12, 13, 13};
62.223 +
62.224 + // If BMAX needs to be larger than 16, then h and x[] should be uLong.
62.225 + static final int BMAX=15; // maximum bit length of any code
62.226 +
62.227 + int[] hn = null; // hufts used in space
62.228 + int[] v = null; // work area for huft_build
62.229 + int[] c = null; // bit length count table
62.230 + int[] r = null; // table entry for structure assignment
62.231 + int[] u = null; // table stack
62.232 + int[] x = null; // bit offsets, then code stack
62.233 +
62.234 + private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
62.235 + int bindex,
62.236 + int n, // number of codes (assumed <= 288)
62.237 + int s, // number of simple-valued codes (0..s-1)
62.238 + int[] d, // list of base values for non-simple codes
62.239 + int[] e, // list of extra bits for non-simple codes
62.240 + int[] t, // result: starting table
62.241 + int[] m, // maximum lookup bits, returns actual
62.242 + int[] hp,// space for trees
62.243 + int[] hn,// hufts used in space
62.244 + int[] v // working area: values in order of bit length
62.245 + ){
62.246 + // Given a list of code lengths and a maximum table size, make a set of
62.247 + // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
62.248 + // if the given code set is incomplete (the tables are still built in this
62.249 + // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
62.250 + // lengths), or Z_MEM_ERROR if not enough memory.
62.251 +
62.252 + int a; // counter for codes of length k
62.253 + int f; // i repeats in table every f entries
62.254 + int g; // maximum code length
62.255 + int h; // table level
62.256 + int i; // counter, current code
62.257 + int j; // counter
62.258 + int k; // number of bits in current code
62.259 + int l; // bits per table (returned in m)
62.260 + int mask; // (1 << w) - 1, to avoid cc -O bug on HP
62.261 + int p; // pointer into c[], b[], or v[]
62.262 + int q; // points to current table
62.263 + int w; // bits before this table == (l * h)
62.264 + int xp; // pointer into x
62.265 + int y; // number of dummy codes added
62.266 + int z; // number of entries in current table
62.267 +
62.268 + // Generate counts for each bit length
62.269 +
62.270 + p = 0; i = n;
62.271 + do {
62.272 + c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX
62.273 + }while(i!=0);
62.274 +
62.275 + if(c[0] == n){ // null input--all zero length codes
62.276 + t[0] = -1;
62.277 + m[0] = 0;
62.278 + return Z_OK;
62.279 + }
62.280 +
62.281 + // Find minimum and maximum length, bound *m by those
62.282 + l = m[0];
62.283 + for (j = 1; j <= BMAX; j++)
62.284 + if(c[j]!=0) break;
62.285 + k = j; // minimum code length
62.286 + if(l < j){
62.287 + l = j;
62.288 + }
62.289 + for (i = BMAX; i!=0; i--){
62.290 + if(c[i]!=0) break;
62.291 + }
62.292 + g = i; // maximum code length
62.293 + if(l > i){
62.294 + l = i;
62.295 + }
62.296 + m[0] = l;
62.297 +
62.298 + // Adjust last length count to fill out codes, if needed
62.299 + for (y = 1 << j; j < i; j++, y <<= 1){
62.300 + if ((y -= c[j]) < 0){
62.301 + return Z_DATA_ERROR;
62.302 + }
62.303 + }
62.304 + if ((y -= c[i]) < 0){
62.305 + return Z_DATA_ERROR;
62.306 + }
62.307 + c[i] += y;
62.308 +
62.309 + // Generate starting offsets into the value table for each length
62.310 + x[1] = j = 0;
62.311 + p = 1; xp = 2;
62.312 + while (--i!=0) { // note that i == g from above
62.313 + x[xp] = (j += c[p]);
62.314 + xp++;
62.315 + p++;
62.316 + }
62.317 +
62.318 + // Make a table of values in order of bit lengths
62.319 + i = 0; p = 0;
62.320 + do {
62.321 + if ((j = b[bindex+p]) != 0){
62.322 + v[x[j]++] = i;
62.323 + }
62.324 + p++;
62.325 + }
62.326 + while (++i < n);
62.327 + n = x[g]; // set n to length of v
62.328 +
62.329 + // Generate the Huffman codes and for each, make the table entries
62.330 + x[0] = i = 0; // first Huffman code is zero
62.331 + p = 0; // grab values in bit order
62.332 + h = -1; // no tables yet--level -1
62.333 + w = -l; // bits decoded == (l * h)
62.334 + u[0] = 0; // just to keep compilers happy
62.335 + q = 0; // ditto
62.336 + z = 0; // ditto
62.337 +
62.338 + // go through the bit lengths (k already is bits in shortest code)
62.339 + for (; k <= g; k++){
62.340 + a = c[k];
62.341 + while (a--!=0){
62.342 + // here i is the Huffman code of length k bits for value *p
62.343 + // make tables up to required level
62.344 + while (k > w + l){
62.345 + h++;
62.346 + w += l; // previous table always l bits
62.347 + // compute minimum size table less than or equal to l bits
62.348 + z = g - w;
62.349 + z = (z > l) ? l : z; // table size upper limit
62.350 + if((f=1<<(j=k-w))>a+1){ // try a k-w bit table
62.351 + // too few codes for k-w bit table
62.352 + f -= a + 1; // deduct codes from patterns left
62.353 + xp = k;
62.354 + if(j < z){
62.355 + while (++j < z){ // try smaller tables up to z bits
62.356 + if((f <<= 1) <= c[++xp])
62.357 + break; // enough codes to use up j bits
62.358 + f -= c[xp]; // else deduct codes from patterns
62.359 + }
62.360 + }
62.361 + }
62.362 + z = 1 << j; // table entries for j-bit table
62.363 +
62.364 + // allocate new table
62.365 + if (hn[0] + z > MANY){ // (note: doesn't matter for fixed)
62.366 + return Z_DATA_ERROR; // overflow of MANY
62.367 + }
62.368 + u[h] = q = /*hp+*/ hn[0]; // DEBUG
62.369 + hn[0] += z;
62.370 +
62.371 + // connect to last table, if there is one
62.372 + if(h!=0){
62.373 + x[h]=i; // save pattern for backing up
62.374 + r[0]=(byte)j; // bits in this table
62.375 + r[1]=(byte)l; // bits to dump before this table
62.376 + j=i>>>(w - l);
62.377 + r[2] = (int)(q - u[h-1] - j); // offset to this table
62.378 + FastJar.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
62.379 + }
62.380 + else{
62.381 + t[0] = q; // first table is returned result
62.382 + }
62.383 + }
62.384 +
62.385 + // set up table entry in r
62.386 + r[1] = (byte)(k - w);
62.387 + if (p >= n){
62.388 + r[0] = 128 + 64; // out of values--invalid code
62.389 + }
62.390 + else if (v[p] < s){
62.391 + r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
62.392 + r[2] = v[p++]; // simple code is just the value
62.393 + }
62.394 + else{
62.395 + r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
62.396 + r[2]=d[v[p++] - s];
62.397 + }
62.398 +
62.399 + // fill code-like entries with r
62.400 + f=1<<(k-w);
62.401 + for (j=i>>>w;j<z;j+=f){
62.402 + FastJar.arraycopy(r, 0, hp, (q+j)*3, 3);
62.403 + }
62.404 +
62.405 + // backwards increment the k-bit code i
62.406 + for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
62.407 + i ^= j;
62.408 + }
62.409 + i ^= j;
62.410 +
62.411 + // backup over finished tables
62.412 + mask = (1 << w) - 1; // needed on HP, cc -O bug
62.413 + while ((i & mask) != x[h]){
62.414 + h--; // don't need to update q
62.415 + w -= l;
62.416 + mask = (1 << w) - 1;
62.417 + }
62.418 + }
62.419 + }
62.420 + // Return Z_BUF_ERROR if we were given an incomplete table
62.421 + return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
62.422 + }
62.423 +
62.424 + int inflate_trees_bits(int[] c, // 19 code lengths
62.425 + int[] bb, // bits tree desired/actual depth
62.426 + int[] tb, // bits tree result
62.427 + int[] hp, // space for trees
62.428 + ZStream z // for messages
62.429 + ){
62.430 + int result;
62.431 + initWorkArea(19);
62.432 + hn[0]=0;
62.433 + result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
62.434 +
62.435 + if(result == Z_DATA_ERROR){
62.436 + z.msg = "oversubscribed dynamic bit lengths tree";
62.437 + }
62.438 + else if(result == Z_BUF_ERROR || bb[0] == 0){
62.439 + z.msg = "incomplete dynamic bit lengths tree";
62.440 + result = Z_DATA_ERROR;
62.441 + }
62.442 + return result;
62.443 + }
62.444 +
62.445 + int inflate_trees_dynamic(int nl, // number of literal/length codes
62.446 + int nd, // number of distance codes
62.447 + int[] c, // that many (total) code lengths
62.448 + int[] bl, // literal desired/actual bit depth
62.449 + int[] bd, // distance desired/actual bit depth
62.450 + int[] tl, // literal/length tree result
62.451 + int[] td, // distance tree result
62.452 + int[] hp, // space for trees
62.453 + ZStream z // for messages
62.454 + ){
62.455 + int result;
62.456 +
62.457 + // build literal/length tree
62.458 + initWorkArea(288);
62.459 + hn[0]=0;
62.460 + result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
62.461 + if (result != Z_OK || bl[0] == 0){
62.462 + if(result == Z_DATA_ERROR){
62.463 + z.msg = "oversubscribed literal/length tree";
62.464 + }
62.465 + else if (result != Z_MEM_ERROR){
62.466 + z.msg = "incomplete literal/length tree";
62.467 + result = Z_DATA_ERROR;
62.468 + }
62.469 + return result;
62.470 + }
62.471 +
62.472 + // build distance tree
62.473 + initWorkArea(288);
62.474 + result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
62.475 +
62.476 + if (result != Z_OK || (bd[0] == 0 && nl > 257)){
62.477 + if (result == Z_DATA_ERROR){
62.478 + z.msg = "oversubscribed distance tree";
62.479 + }
62.480 + else if (result == Z_BUF_ERROR) {
62.481 + z.msg = "incomplete distance tree";
62.482 + result = Z_DATA_ERROR;
62.483 + }
62.484 + else if (result != Z_MEM_ERROR){
62.485 + z.msg = "empty distance tree with lengths";
62.486 + result = Z_DATA_ERROR;
62.487 + }
62.488 + return result;
62.489 + }
62.490 +
62.491 + return Z_OK;
62.492 + }
62.493 +
62.494 + static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
62.495 + int[] bd, //distance desired/actual bit depth
62.496 + int[][] tl,//literal/length tree result
62.497 + int[][] td,//distance tree result
62.498 + ZStream z //for memory allocation
62.499 + ){
62.500 + bl[0]=fixed_bl;
62.501 + bd[0]=fixed_bd;
62.502 + tl[0]=fixed_tl;
62.503 + td[0]=fixed_td;
62.504 + return Z_OK;
62.505 + }
62.506 +
62.507 + private void initWorkArea(int vsize){
62.508 + if(hn==null){
62.509 + hn=new int[1];
62.510 + v=new int[vsize];
62.511 + c=new int[BMAX+1];
62.512 + r=new int[3];
62.513 + u=new int[BMAX];
62.514 + x=new int[BMAX+1];
62.515 + }
62.516 + if(v.length<vsize){ v=new int[vsize]; }
62.517 + for(int i=0; i<vsize; i++){v[i]=0;}
62.518 + for(int i=0; i<BMAX+1; i++){c[i]=0;}
62.519 + for(int i=0; i<3; i++){r[i]=0;}
62.520 + FastJar.arraycopy(c, 0, u, 0, BMAX);
62.521 + FastJar.arraycopy(c, 0, x, 0, BMAX+1);
62.522 + }
62.523 +}
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/Inflate.java Sun May 11 14:01:18 2014 +0200
63.3 @@ -0,0 +1,727 @@
63.4 +/* -*-mode:java; c-basic-offset:2; -*- */
63.5 +/*
63.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
63.7 +
63.8 +Redistribution and use in source and binary forms, with or without
63.9 +modification, are permitted provided that the following conditions are met:
63.10 +
63.11 + 1. Redistributions of source code must retain the above copyright notice,
63.12 + this list of conditions and the following disclaimer.
63.13 +
63.14 + 2. Redistributions in binary form must reproduce the above copyright
63.15 + notice, this list of conditions and the following disclaimer in
63.16 + the documentation and/or other materials provided with the distribution.
63.17 +
63.18 + 3. The names of the authors may not be used to endorse or promote products
63.19 + derived from this software without specific prior written permission.
63.20 +
63.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
63.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
63.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
63.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
63.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
63.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
63.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
63.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
63.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
63.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63.31 + */
63.32 +/*
63.33 + * This program is based on zlib-1.1.3, so all credit should go authors
63.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
63.35 + * and contributors of zlib.
63.36 + */
63.37 +
63.38 +package org.apidesign.bck2brwsr.emul.zip;
63.39 +
63.40 +
63.41 +
63.42 +final class Inflate{
63.43 +
63.44 + static final private int MAX_WBITS=15; // 32K LZ77 window
63.45 +
63.46 + // preset dictionary flag in zlib header
63.47 + static final private int PRESET_DICT=0x20;
63.48 +
63.49 + static final int Z_NO_FLUSH=0;
63.50 + static final int Z_PARTIAL_FLUSH=1;
63.51 + static final int Z_SYNC_FLUSH=2;
63.52 + static final int Z_FULL_FLUSH=3;
63.53 + static final int Z_FINISH=4;
63.54 +
63.55 + static final private int Z_DEFLATED=8;
63.56 +
63.57 + static final private int Z_OK=0;
63.58 + static final private int Z_STREAM_END=1;
63.59 + static final private int Z_NEED_DICT=2;
63.60 + static final private int Z_ERRNO=-1;
63.61 + static final private int Z_STREAM_ERROR=-2;
63.62 + static final private int Z_DATA_ERROR=-3;
63.63 + static final private int Z_MEM_ERROR=-4;
63.64 + static final private int Z_BUF_ERROR=-5;
63.65 + static final private int Z_VERSION_ERROR=-6;
63.66 +
63.67 + static final private int METHOD=0; // waiting for method byte
63.68 + static final private int FLAG=1; // waiting for flag byte
63.69 + static final private int DICT4=2; // four dictionary check bytes to go
63.70 + static final private int DICT3=3; // three dictionary check bytes to go
63.71 + static final private int DICT2=4; // two dictionary check bytes to go
63.72 + static final private int DICT1=5; // one dictionary check byte to go
63.73 + static final int DICT0=6; // waiting for inflateSetDictionary
63.74 + static final private int BLOCKS=7; // decompressing blocks
63.75 + static final private int CHECK4=8; // four check bytes to go
63.76 + static final private int CHECK3=9; // three check bytes to go
63.77 + static final private int CHECK2=10; // two check bytes to go
63.78 + static final private int CHECK1=11; // one check byte to go
63.79 + static final private int DONE=12; // finished check, done
63.80 + static final private int BAD=13; // got an error--stay here
63.81 +
63.82 + static final private int HEAD=14;
63.83 + static final private int LENGTH=15;
63.84 + static final private int TIME=16;
63.85 + static final private int OS=17;
63.86 + static final private int EXLEN=18;
63.87 + static final private int EXTRA=19;
63.88 + static final private int NAME=20;
63.89 + static final private int COMMENT=21;
63.90 + static final private int HCRC=22;
63.91 + static final private int FLAGS=23;
63.92 +
63.93 + int mode; // current inflate mode
63.94 +
63.95 + // mode dependent information
63.96 + int method; // if FLAGS, method byte
63.97 +
63.98 + // if CHECK, check values to compare
63.99 + long was = -1; // computed check value
63.100 + long need; // stream check value
63.101 +
63.102 + // if BAD, inflateSync's marker bytes count
63.103 + int marker;
63.104 +
63.105 + // mode independent information
63.106 + int wrap; // flag for no wrapper
63.107 + int wbits; // log2(window size) (8..15, defaults to 15)
63.108 +
63.109 + InfBlocks blocks; // current inflate_blocks state
63.110 +
63.111 + private final ZStream z;
63.112 +
63.113 + private int flags;
63.114 +
63.115 + private int need_bytes = -1;
63.116 + private byte[] crcbuf=new byte[4];
63.117 +
63.118 + GZIPHeader gheader = null;
63.119 +
63.120 + int inflateReset(){
63.121 + if(z == null) return Z_STREAM_ERROR;
63.122 +
63.123 + z.total_in = z.total_out = 0;
63.124 + z.msg = null;
63.125 + this.mode = HEAD;
63.126 + this.need_bytes = -1;
63.127 + this.blocks.reset();
63.128 + return Z_OK;
63.129 + }
63.130 +
63.131 + int inflateEnd(){
63.132 + if(blocks != null){
63.133 + blocks.free();
63.134 + }
63.135 + return Z_OK;
63.136 + }
63.137 +
63.138 + Inflate(ZStream z){
63.139 + this.z=z;
63.140 + }
63.141 +
63.142 + int inflateInit(int w){
63.143 + z.msg = null;
63.144 + blocks = null;
63.145 +
63.146 + // handle undocumented wrap option (no zlib header or check)
63.147 + wrap = 0;
63.148 + if(w < 0){
63.149 + w = - w;
63.150 + }
63.151 + else {
63.152 + wrap = (w >> 4) + 1;
63.153 + if(w < 48)
63.154 + w &= 15;
63.155 + }
63.156 +
63.157 + if(w<8 ||w>15){
63.158 + inflateEnd();
63.159 + return Z_STREAM_ERROR;
63.160 + }
63.161 + if(blocks != null && wbits != w){
63.162 + blocks.free();
63.163 + blocks=null;
63.164 + }
63.165 +
63.166 + // set window size
63.167 + wbits=w;
63.168 +
63.169 + this.blocks=new InfBlocks(z, 1<<w);
63.170 +
63.171 + // reset state
63.172 + inflateReset();
63.173 +
63.174 + return Z_OK;
63.175 + }
63.176 +
63.177 + int inflate(int f){
63.178 + int hold = 0;
63.179 +
63.180 + int r;
63.181 + int b;
63.182 +
63.183 + if(z == null || z.next_in == null){
63.184 + if(f == Z_FINISH && this.mode==HEAD)
63.185 + return Z_OK;
63.186 + return Z_STREAM_ERROR;
63.187 + }
63.188 +
63.189 + f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
63.190 + r = Z_BUF_ERROR;
63.191 + while (true){
63.192 +
63.193 + switch (this.mode){
63.194 + case HEAD:
63.195 + if(wrap==0){
63.196 + this.mode = BLOCKS;
63.197 + break;
63.198 + }
63.199 +
63.200 + try { r=readBytes(2, r, f); }
63.201 + catch(Return e){ return e.r; }
63.202 +
63.203 + if((wrap&2)!=0 && this.need == 0x8b1fL) { // gzip header
63.204 + z.adler=new CRC32();
63.205 + checksum(2, this.need);
63.206 +
63.207 + if(gheader==null)
63.208 + gheader=new GZIPHeader();
63.209 +
63.210 + this.mode = FLAGS;
63.211 + break;
63.212 + }
63.213 +
63.214 + flags = 0;
63.215 +
63.216 + this.method = ((int)this.need)&0xff;
63.217 + b=((int)(this.need>>8))&0xff;
63.218 +
63.219 + if((wrap&1)==0 || // check if zlib header allowed
63.220 + (((this.method << 8)+b) % 31)!=0){
63.221 + this.mode = BAD;
63.222 + z.msg = "incorrect header check";
63.223 + // since zlib 1.2, it is allowted to inflateSync for this case.
63.224 + /*
63.225 + this.marker = 5; // can't try inflateSync
63.226 + */
63.227 + break;
63.228 + }
63.229 +
63.230 + if((this.method&0xf)!=Z_DEFLATED){
63.231 + this.mode = BAD;
63.232 + z.msg="unknown compression method";
63.233 + // since zlib 1.2, it is allowted to inflateSync for this case.
63.234 + /*
63.235 + this.marker = 5; // can't try inflateSync
63.236 + */
63.237 + break;
63.238 + }
63.239 +
63.240 + if((this.method>>4)+8>this.wbits){
63.241 + this.mode = BAD;
63.242 + z.msg="invalid window size";
63.243 + // since zlib 1.2, it is allowted to inflateSync for this case.
63.244 + /*
63.245 + this.marker = 5; // can't try inflateSync
63.246 + */
63.247 + break;
63.248 + }
63.249 +
63.250 + z.adler=new Adler32();
63.251 +
63.252 + if((b&PRESET_DICT)==0){
63.253 + this.mode = BLOCKS;
63.254 + break;
63.255 + }
63.256 + this.mode = DICT4;
63.257 + case DICT4:
63.258 +
63.259 + if(z.avail_in==0)return r;r=f;
63.260 +
63.261 + z.avail_in--; z.total_in++;
63.262 + this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
63.263 + this.mode=DICT3;
63.264 + case DICT3:
63.265 +
63.266 + if(z.avail_in==0)return r;r=f;
63.267 +
63.268 + z.avail_in--; z.total_in++;
63.269 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
63.270 + this.mode=DICT2;
63.271 + case DICT2:
63.272 +
63.273 + if(z.avail_in==0)return r;r=f;
63.274 +
63.275 + z.avail_in--; z.total_in++;
63.276 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
63.277 + this.mode=DICT1;
63.278 + case DICT1:
63.279 +
63.280 + if(z.avail_in==0)return r;r=f;
63.281 +
63.282 + z.avail_in--; z.total_in++;
63.283 + this.need += (z.next_in[z.next_in_index++]&0xffL);
63.284 + z.adler.reset(this.need);
63.285 + this.mode = DICT0;
63.286 + return Z_NEED_DICT;
63.287 + case DICT0:
63.288 + this.mode = BAD;
63.289 + z.msg = "need dictionary";
63.290 + this.marker = 0; // can try inflateSync
63.291 + return Z_STREAM_ERROR;
63.292 + case BLOCKS:
63.293 + r = this.blocks.proc(r);
63.294 + if(r == Z_DATA_ERROR){
63.295 + this.mode = BAD;
63.296 + this.marker = 0; // can try inflateSync
63.297 + break;
63.298 + }
63.299 + if(r == Z_OK){
63.300 + r = f;
63.301 + }
63.302 + if(r != Z_STREAM_END){
63.303 + return r;
63.304 + }
63.305 + r = f;
63.306 + this.was=z.adler.getValue();
63.307 + this.blocks.reset();
63.308 + if(this.wrap==0){
63.309 + this.mode=DONE;
63.310 + break;
63.311 + }
63.312 + this.mode=CHECK4;
63.313 + case CHECK4:
63.314 +
63.315 + if(z.avail_in==0)return r;r=f;
63.316 +
63.317 + z.avail_in--; z.total_in++;
63.318 + this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
63.319 + this.mode=CHECK3;
63.320 + case CHECK3:
63.321 +
63.322 + if(z.avail_in==0)return r;r=f;
63.323 +
63.324 + z.avail_in--; z.total_in++;
63.325 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
63.326 + this.mode = CHECK2;
63.327 + case CHECK2:
63.328 +
63.329 + if(z.avail_in==0)return r;r=f;
63.330 +
63.331 + z.avail_in--; z.total_in++;
63.332 + this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
63.333 + this.mode = CHECK1;
63.334 + case CHECK1:
63.335 +
63.336 + if(z.avail_in==0)return r;r=f;
63.337 +
63.338 + z.avail_in--; z.total_in++;
63.339 + this.need+=(z.next_in[z.next_in_index++]&0xffL);
63.340 +
63.341 + if(flags!=0){ // gzip
63.342 + this.need = ((this.need&0xff000000)>>24 |
63.343 + (this.need&0x00ff0000)>>8 |
63.344 + (this.need&0x0000ff00)<<8 |
63.345 + (this.need&0x0000ffff)<<24)&0xffffffffL;
63.346 + }
63.347 +
63.348 + if(((int)(this.was)) != ((int)(this.need))){
63.349 + z.msg = "incorrect data check";
63.350 + // chack is delayed
63.351 + /*
63.352 + this.mode = BAD;
63.353 + this.marker = 5; // can't try inflateSync
63.354 + break;
63.355 + */
63.356 + }
63.357 + else if(flags!=0 && gheader!=null){
63.358 + gheader.crc = this.need;
63.359 + }
63.360 +
63.361 + this.mode = LENGTH;
63.362 + case LENGTH:
63.363 + if (wrap!=0 && flags!=0) {
63.364 +
63.365 + try { r=readBytes(4, r, f); }
63.366 + catch(Return e){ return e.r; }
63.367 +
63.368 + if(z.msg!=null && z.msg.equals("incorrect data check")){
63.369 + this.mode = BAD;
63.370 + this.marker = 5; // can't try inflateSync
63.371 + break;
63.372 + }
63.373 +
63.374 + if (this.need != (z.total_out & 0xffffffffL)) {
63.375 + z.msg = "incorrect length check";
63.376 + this.mode = BAD;
63.377 + break;
63.378 + }
63.379 + z.msg = null;
63.380 + }
63.381 + else {
63.382 + if(z.msg!=null && z.msg.equals("incorrect data check")){
63.383 + this.mode = BAD;
63.384 + this.marker = 5; // can't try inflateSync
63.385 + break;
63.386 + }
63.387 + }
63.388 +
63.389 + this.mode = DONE;
63.390 + case DONE:
63.391 + return Z_STREAM_END;
63.392 + case BAD:
63.393 + return Z_DATA_ERROR;
63.394 +
63.395 + case FLAGS:
63.396 +
63.397 + try { r=readBytes(2, r, f); }
63.398 + catch(Return e){ return e.r; }
63.399 +
63.400 + flags = ((int)this.need)&0xffff;
63.401 +
63.402 + if ((flags & 0xff) != Z_DEFLATED) {
63.403 + z.msg = "unknown compression method";
63.404 + this.mode = BAD;
63.405 + break;
63.406 + }
63.407 + if ((flags & 0xe000)!=0) {
63.408 + z.msg = "unknown header flags set";
63.409 + this.mode = BAD;
63.410 + break;
63.411 + }
63.412 +
63.413 + if ((flags & 0x0200)!=0){
63.414 + checksum(2, this.need);
63.415 + }
63.416 +
63.417 + this.mode = TIME;
63.418 +
63.419 + case TIME:
63.420 + try { r=readBytes(4, r, f); }
63.421 + catch(Return e){ return e.r; }
63.422 + if(gheader!=null)
63.423 + gheader.time = this.need;
63.424 + if ((flags & 0x0200)!=0){
63.425 + checksum(4, this.need);
63.426 + }
63.427 + this.mode = OS;
63.428 + case OS:
63.429 + try { r=readBytes(2, r, f); }
63.430 + catch(Return e){ return e.r; }
63.431 + if(gheader!=null){
63.432 + gheader.xflags = ((int)this.need)&0xff;
63.433 + gheader.os = (((int)this.need)>>8)&0xff;
63.434 + }
63.435 + if ((flags & 0x0200)!=0){
63.436 + checksum(2, this.need);
63.437 + }
63.438 + this.mode = EXLEN;
63.439 + case EXLEN:
63.440 + if ((flags & 0x0400)!=0) {
63.441 + try { r=readBytes(2, r, f); }
63.442 + catch(Return e){ return e.r; }
63.443 + if(gheader!=null){
63.444 + gheader.extra = new byte[((int)this.need)&0xffff];
63.445 + }
63.446 + if ((flags & 0x0200)!=0){
63.447 + checksum(2, this.need);
63.448 + }
63.449 + }
63.450 + else if(gheader!=null){
63.451 + gheader.extra=null;
63.452 + }
63.453 + this.mode = EXTRA;
63.454 +
63.455 + case EXTRA:
63.456 + if ((flags & 0x0400)!=0) {
63.457 + try {
63.458 + r=readBytes(r, f);
63.459 + if(gheader!=null){
63.460 + byte[] foo = tmp_array;
63.461 + tmp_array=null;
63.462 + if(foo.length == gheader.extra.length){
63.463 + FastJar.arraycopy(foo, 0, gheader.extra, 0, foo.length);
63.464 + }
63.465 + else{
63.466 + z.msg = "bad extra field length";
63.467 + this.mode = BAD;
63.468 + break;
63.469 + }
63.470 + }
63.471 + }
63.472 + catch(Return e){ return e.r; }
63.473 + }
63.474 + else if(gheader!=null){
63.475 + gheader.extra=null;
63.476 + }
63.477 + this.mode = NAME;
63.478 + case NAME:
63.479 + if ((flags & 0x0800)!=0) {
63.480 + try {
63.481 + r=readString(r, f);
63.482 + if(gheader!=null){
63.483 + gheader.name=tmp_array;
63.484 + }
63.485 + tmp_array=null;
63.486 + }
63.487 + catch(Return e){ return e.r; }
63.488 + }
63.489 + else if(gheader!=null){
63.490 + gheader.name=null;
63.491 + }
63.492 + this.mode = COMMENT;
63.493 + case COMMENT:
63.494 + if ((flags & 0x1000)!=0) {
63.495 + try {
63.496 + r=readString(r, f);
63.497 + if(gheader!=null){
63.498 + gheader.comment=tmp_array;
63.499 + }
63.500 + tmp_array=null;
63.501 + }
63.502 + catch(Return e){ return e.r; }
63.503 + }
63.504 + else if(gheader!=null){
63.505 + gheader.comment=null;
63.506 + }
63.507 + this.mode = HCRC;
63.508 + case HCRC:
63.509 + if ((flags & 0x0200)!=0) {
63.510 + try { r=readBytes(2, r, f); }
63.511 + catch(Return e){ return e.r; }
63.512 + if(gheader!=null){
63.513 + gheader.hcrc=(int)(this.need&0xffff);
63.514 + }
63.515 + if(this.need != (z.adler.getValue()&0xffffL)){
63.516 + this.mode = BAD;
63.517 + z.msg = "header crc mismatch";
63.518 + this.marker = 5; // can't try inflateSync
63.519 + break;
63.520 + }
63.521 + }
63.522 + z.adler = new CRC32();
63.523 +
63.524 + this.mode = BLOCKS;
63.525 + break;
63.526 + default:
63.527 + return Z_STREAM_ERROR;
63.528 + }
63.529 + }
63.530 + }
63.531 +
63.532 + int inflateSetDictionary(byte[] dictionary, int dictLength){
63.533 + if(z==null || (this.mode != DICT0 && this.wrap != 0)){
63.534 + return Z_STREAM_ERROR;
63.535 + }
63.536 +
63.537 + int index=0;
63.538 + int length = dictLength;
63.539 +
63.540 + if(this.mode==DICT0){
63.541 + long adler_need=z.adler.getValue();
63.542 + z.adler.reset();
63.543 + z.adler.update(dictionary, 0, dictLength);
63.544 + if(z.adler.getValue()!=adler_need){
63.545 + return Z_DATA_ERROR;
63.546 + }
63.547 + }
63.548 +
63.549 + z.adler.reset();
63.550 +
63.551 + if(length >= (1<<this.wbits)){
63.552 + length = (1<<this.wbits)-1;
63.553 + index=dictLength - length;
63.554 + }
63.555 + this.blocks.set_dictionary(dictionary, index, length);
63.556 + this.mode = BLOCKS;
63.557 + return Z_OK;
63.558 + }
63.559 +
63.560 + static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
63.561 +
63.562 + int inflateSync(){
63.563 + int n; // number of bytes to look at
63.564 + int p; // pointer to bytes
63.565 + int m; // number of marker bytes found in a row
63.566 + long r, w; // temporaries to save total_in and total_out
63.567 +
63.568 + // set up
63.569 + if(z == null)
63.570 + return Z_STREAM_ERROR;
63.571 + if(this.mode != BAD){
63.572 + this.mode = BAD;
63.573 + this.marker = 0;
63.574 + }
63.575 + if((n=z.avail_in)==0)
63.576 + return Z_BUF_ERROR;
63.577 +
63.578 + p=z.next_in_index;
63.579 + m=this.marker;
63.580 + // search
63.581 + while (n!=0 && m < 4){
63.582 + if(z.next_in[p] == mark[m]){
63.583 + m++;
63.584 + }
63.585 + else if(z.next_in[p]!=0){
63.586 + m = 0;
63.587 + }
63.588 + else{
63.589 + m = 4 - m;
63.590 + }
63.591 + p++; n--;
63.592 + }
63.593 +
63.594 + // restore
63.595 + z.total_in += p-z.next_in_index;
63.596 + z.next_in_index = p;
63.597 + z.avail_in = n;
63.598 + this.marker = m;
63.599 +
63.600 + // return no joy or set up to restart on a new block
63.601 + if(m != 4){
63.602 + return Z_DATA_ERROR;
63.603 + }
63.604 + r=z.total_in; w=z.total_out;
63.605 + inflateReset();
63.606 + z.total_in=r; z.total_out = w;
63.607 + this.mode = BLOCKS;
63.608 +
63.609 + return Z_OK;
63.610 + }
63.611 +
63.612 + // Returns true if inflate is currently at the end of a block generated
63.613 + // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
63.614 + // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
63.615 + // but removes the length bytes of the resulting empty stored block. When
63.616 + // decompressing, PPP checks that at the end of input packet, inflate is
63.617 + // waiting for these length bytes.
63.618 + int inflateSyncPoint(){
63.619 + if(z == null || this.blocks == null)
63.620 + return Z_STREAM_ERROR;
63.621 + return this.blocks.sync_point();
63.622 + }
63.623 +
63.624 + private int readBytes(int n, int r, int f) throws Return{
63.625 + if(need_bytes == -1){
63.626 + need_bytes=n;
63.627 + this.need=0;
63.628 + }
63.629 + while(need_bytes>0){
63.630 + if(z.avail_in==0){ throw new Return(r); }; r=f;
63.631 + z.avail_in--; z.total_in++;
63.632 + this.need = this.need |
63.633 + ((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8));
63.634 + need_bytes--;
63.635 + }
63.636 + if(n==2){
63.637 + this.need&=0xffffL;
63.638 + }
63.639 + else if(n==4) {
63.640 + this.need&=0xffffffffL;
63.641 + }
63.642 + need_bytes=-1;
63.643 + return r;
63.644 + }
63.645 + class Return extends Exception{
63.646 + int r;
63.647 + Return(int r){this.r=r; }
63.648 + }
63.649 +
63.650 + private byte[] tmp_array;
63.651 + private int readString(int r, int f) throws Return{
63.652 + int b=0;
63.653 + byte[] arr = new byte[4092];
63.654 + int at = 0;
63.655 + do {
63.656 + if(z.avail_in==0){ throw new Return(r); }; r=f;
63.657 + z.avail_in--; z.total_in++;
63.658 + b = z.next_in[z.next_in_index];
63.659 + if(b!=0) arr = append(arr, z.next_in[z.next_in_index], at++);
63.660 + z.adler.update(z.next_in, z.next_in_index, 1);
63.661 + z.next_in_index++;
63.662 + }while(b!=0);
63.663 +
63.664 + tmp_array = copy(arr, at);
63.665 +
63.666 + return r;
63.667 + }
63.668 +
63.669 + private int readBytes(int r, int f) throws Return{
63.670 + int b=0;
63.671 + byte[] arr = new byte[4092];
63.672 + int at = 0;
63.673 + while(this.need>0){
63.674 + if(z.avail_in==0){ throw new Return(r); }; r=f;
63.675 + z.avail_in--; z.total_in++;
63.676 + b = z.next_in[z.next_in_index];
63.677 + arr = append(arr, z.next_in[z.next_in_index], at++);
63.678 + z.adler.update(z.next_in, z.next_in_index, 1);
63.679 + z.next_in_index++;
63.680 + this.need--;
63.681 + }
63.682 +
63.683 + tmp_array = copy(arr, at);
63.684 +
63.685 + return r;
63.686 + }
63.687 +
63.688 + private static byte[] copy(byte[] arr, int len) {
63.689 + byte[] ret = new byte[len];
63.690 + FastJar.arraycopy(arr, 0, ret, 0, len);
63.691 + return ret;
63.692 + }
63.693 + private static byte[] append(byte[] arr, byte b, int index) {
63.694 + arr[index] = b;
63.695 + return arr;
63.696 + }
63.697 +
63.698 + private void checksum(int n, long v){
63.699 + for(int i=0; i<n; i++){
63.700 + crcbuf[i]=(byte)(v&0xff);
63.701 + v>>=8;
63.702 + }
63.703 + z.adler.update(crcbuf, 0, n);
63.704 + }
63.705 +
63.706 + public GZIPHeader getGZIPHeader(){
63.707 + return gheader;
63.708 + }
63.709 +
63.710 + boolean inParsingHeader(){
63.711 + switch(mode){
63.712 + case HEAD:
63.713 + case DICT4:
63.714 + case DICT3:
63.715 + case DICT2:
63.716 + case DICT1:
63.717 + case FLAGS:
63.718 + case TIME:
63.719 + case OS:
63.720 + case EXLEN:
63.721 + case EXTRA:
63.722 + case NAME:
63.723 + case COMMENT:
63.724 + case HCRC:
63.725 + return true;
63.726 + default:
63.727 + return false;
63.728 + }
63.729 + }
63.730 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
64.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java Sun May 11 14:01:18 2014 +0200
64.3 @@ -0,0 +1,338 @@
64.4 +/*
64.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64.7 + *
64.8 + * This code is free software; you can redistribute it and/or modify it
64.9 + * under the terms of the GNU General Public License version 2 only, as
64.10 + * published by the Free Software Foundation. Oracle designates this
64.11 + * particular file as subject to the "Classpath" exception as provided
64.12 + * by Oracle in the LICENSE file that accompanied this code.
64.13 + *
64.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
64.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
64.17 + * version 2 for more details (a copy is included in the LICENSE file that
64.18 + * accompanied this code).
64.19 + *
64.20 + * You should have received a copy of the GNU General Public License version
64.21 + * 2 along with this work; if not, write to the Free Software Foundation,
64.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
64.23 + *
64.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
64.25 + * or visit www.oracle.com if you need additional information or have any
64.26 + * questions.
64.27 + */
64.28 +
64.29 +package org.apidesign.bck2brwsr.emul.zip;
64.30 +
64.31 +import java.util.zip.*;
64.32 +import java.io.IOException;
64.33 +
64.34 +/**
64.35 + * This class provides support for general purpose decompression using the
64.36 + * popular ZLIB compression library. The ZLIB compression library was
64.37 + * initially developed as part of the PNG graphics standard and is not
64.38 + * protected by patents. It is fully described in the specifications at
64.39 + * the <a href="package-summary.html#package_description">java.util.zip
64.40 + * package description</a>.
64.41 + *
64.42 + * <p>The following code fragment demonstrates a trivial compression
64.43 + * and decompression of a string using <tt>Deflater</tt> and
64.44 + * <tt>Inflater</tt>.
64.45 + *
64.46 + * <blockquote><pre>
64.47 + * try {
64.48 + * // Encode a String into bytes
64.49 + * String inputString = "blahblahblah\u20AC\u20AC";
64.50 + * byte[] input = inputString.getBytes("UTF-8");
64.51 + *
64.52 + * // Compress the bytes
64.53 + * byte[] output = new byte[100];
64.54 + * Deflater compresser = new Deflater();
64.55 + * compresser.setInput(input);
64.56 + * compresser.finish();
64.57 + * int compressedDataLength = compresser.deflate(output);
64.58 + *
64.59 + * // Decompress the bytes
64.60 + * Inflater decompresser = new Inflater();
64.61 + * decompresser.setInput(output, 0, compressedDataLength);
64.62 + * byte[] result = new byte[100];
64.63 + * int resultLength = decompresser.inflate(result);
64.64 + * decompresser.end();
64.65 + *
64.66 + * // Decode the bytes into a String
64.67 + * String outputString = new String(result, 0, resultLength, "UTF-8");
64.68 + * } catch(java.io.UnsupportedEncodingException ex) {
64.69 + * // handle
64.70 + * } catch (java.util.zip.DataFormatException ex) {
64.71 + * // handle
64.72 + * }
64.73 + * </pre></blockquote>
64.74 + *
64.75 + * @see Deflater
64.76 + * @author David Connelly
64.77 + *
64.78 + */
64.79 +public
64.80 +class Inflater extends java.util.zip.Inflater {
64.81 + private final boolean nowrap;
64.82 + private JzLibInflater impl;
64.83 +
64.84 + /**
64.85 + * Creates a new decompressor. If the parameter 'nowrap' is true then
64.86 + * the ZLIB header and checksum fields will not be used. This provides
64.87 + * compatibility with the compression format used by both GZIP and PKZIP.
64.88 + * <p>
64.89 + * Note: When using the 'nowrap' option it is also necessary to provide
64.90 + * an extra "dummy" byte as input. This is required by the ZLIB native
64.91 + * library in order to support certain optimizations.
64.92 + *
64.93 + * @param nowrap if true then support GZIP compatible compression
64.94 + */
64.95 + public Inflater(boolean nowrap) {
64.96 + this.nowrap = nowrap;
64.97 + reset();
64.98 + }
64.99 +
64.100 + /**
64.101 + * Creates a new decompressor.
64.102 + */
64.103 + public Inflater() {
64.104 + this(false);
64.105 + }
64.106 +
64.107 + /**
64.108 + * Sets input data for decompression. Should be called whenever
64.109 + * needsInput() returns true indicating that more input data is
64.110 + * required.
64.111 + * @param b the input data bytes
64.112 + * @param off the start offset of the input data
64.113 + * @param len the length of the input data
64.114 + * @see Inflater#needsInput
64.115 + */
64.116 + public void setInput(byte[] b, int off, int len) {
64.117 + if (b == null) {
64.118 + throw new NullPointerException();
64.119 + }
64.120 + if (off < 0 || len < 0 || off > b.length - len) {
64.121 + throw new ArrayIndexOutOfBoundsException();
64.122 + }
64.123 + impl.setInput(b, off, len, false);
64.124 + }
64.125 +
64.126 + /**
64.127 + * Sets input data for decompression. Should be called whenever
64.128 + * needsInput() returns true indicating that more input data is
64.129 + * required.
64.130 + * @param b the input data bytes
64.131 + * @see Inflater#needsInput
64.132 + */
64.133 + public void setInput(byte[] b) {
64.134 + setInput(b, 0, b.length);
64.135 + }
64.136 +
64.137 + /**
64.138 + * Sets the preset dictionary to the given array of bytes. Should be
64.139 + * called when inflate() returns 0 and needsDictionary() returns true
64.140 + * indicating that a preset dictionary is required. The method getAdler()
64.141 + * can be used to get the Adler-32 value of the dictionary needed.
64.142 + * @param b the dictionary data bytes
64.143 + * @param off the start offset of the data
64.144 + * @param len the length of the data
64.145 + * @see Inflater#needsDictionary
64.146 + * @see Inflater#getAdler
64.147 + */
64.148 + public void setDictionary(byte[] b, int off, int len) {
64.149 + if (b == null) {
64.150 + throw new NullPointerException();
64.151 + }
64.152 + if (off < 0 || len < 0 || off > b.length - len) {
64.153 + throw new ArrayIndexOutOfBoundsException();
64.154 + }
64.155 + byte[] arr;
64.156 + if (off == 0) {
64.157 + arr = b;
64.158 + } else {
64.159 + arr = new byte[len];
64.160 + FastJar.arraycopy(b, off, arr, 0, len);
64.161 + }
64.162 + impl.setDictionary(arr, len);
64.163 + }
64.164 +
64.165 + /**
64.166 + * Sets the preset dictionary to the given array of bytes. Should be
64.167 + * called when inflate() returns 0 and needsDictionary() returns true
64.168 + * indicating that a preset dictionary is required. The method getAdler()
64.169 + * can be used to get the Adler-32 value of the dictionary needed.
64.170 + * @param b the dictionary data bytes
64.171 + * @see Inflater#needsDictionary
64.172 + * @see Inflater#getAdler
64.173 + */
64.174 + public void setDictionary(byte[] b) {
64.175 + impl.setDictionary(b, b.length);
64.176 + }
64.177 +
64.178 + /**
64.179 + * Returns the total number of bytes remaining in the input buffer.
64.180 + * This can be used to find out what bytes still remain in the input
64.181 + * buffer after decompression has finished.
64.182 + * @return the total number of bytes remaining in the input buffer
64.183 + */
64.184 + public int getRemaining() {
64.185 + return impl.getAvailIn();
64.186 + }
64.187 +
64.188 + /**
64.189 + * Returns true if no data remains in the input buffer. This can
64.190 + * be used to determine if #setInput should be called in order
64.191 + * to provide more input.
64.192 + * @return true if no data remains in the input buffer
64.193 + */
64.194 + public boolean needsInput() {
64.195 + return getRemaining() <= 0;
64.196 + }
64.197 +
64.198 + /**
64.199 + * Returns true if a preset dictionary is needed for decompression.
64.200 + * @return true if a preset dictionary is needed for decompression
64.201 + * @see Inflater#setDictionary
64.202 + */
64.203 + public boolean needsDictionary() {
64.204 + return impl.needDict();
64.205 + }
64.206 +
64.207 + /**
64.208 + * Returns true if the end of the compressed data stream has been
64.209 + * reached.
64.210 + * @return true if the end of the compressed data stream has been
64.211 + * reached
64.212 + */
64.213 + public boolean finished() {
64.214 + return impl.finished();
64.215 + }
64.216 +
64.217 + /**
64.218 + * Uncompresses bytes into specified buffer. Returns actual number
64.219 + * of bytes uncompressed. A return value of 0 indicates that
64.220 + * needsInput() or needsDictionary() should be called in order to
64.221 + * determine if more input data or a preset dictionary is required.
64.222 + * In the latter case, getAdler() can be used to get the Adler-32
64.223 + * value of the dictionary required.
64.224 + * @param b the buffer for the uncompressed data
64.225 + * @param off the start offset of the data
64.226 + * @param len the maximum number of uncompressed bytes
64.227 + * @return the actual number of uncompressed bytes
64.228 + * @exception DataFormatException if the compressed data format is invalid
64.229 + * @see Inflater#needsInput
64.230 + * @see Inflater#needsDictionary
64.231 + */
64.232 + public int inflate(byte[] b, int off, int len)
64.233 + throws DataFormatException
64.234 + {
64.235 + if (b == null) {
64.236 + throw new NullPointerException();
64.237 + }
64.238 + if (off < 0 || len < 0 || off > b.length - len) {
64.239 + throw new ArrayIndexOutOfBoundsException();
64.240 + }
64.241 + impl.setOutput(b, off, len);
64.242 + int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
64.243 + return impl.next_out_index - off;
64.244 + }
64.245 +
64.246 + /**
64.247 + * Uncompresses bytes into specified buffer. Returns actual number
64.248 + * of bytes uncompressed. A return value of 0 indicates that
64.249 + * needsInput() or needsDictionary() should be called in order to
64.250 + * determine if more input data or a preset dictionary is required.
64.251 + * In the latter case, getAdler() can be used to get the Adler-32
64.252 + * value of the dictionary required.
64.253 + * @param b the buffer for the uncompressed data
64.254 + * @return the actual number of uncompressed bytes
64.255 + * @exception DataFormatException if the compressed data format is invalid
64.256 + * @see Inflater#needsInput
64.257 + * @see Inflater#needsDictionary
64.258 + */
64.259 + public int inflate(byte[] b) throws DataFormatException {
64.260 + return inflate(b, 0, b.length);
64.261 + }
64.262 +
64.263 + /**
64.264 + * Returns the ADLER-32 value of the uncompressed data.
64.265 + * @return the ADLER-32 value of the uncompressed data
64.266 + */
64.267 + public int getAdler() {
64.268 + return (int) impl.getAdler();
64.269 + }
64.270 +
64.271 + /**
64.272 + * Returns the total number of compressed bytes input so far.
64.273 + *
64.274 + * <p>Since the number of bytes may be greater than
64.275 + * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
64.276 + * the preferred means of obtaining this information.</p>
64.277 + *
64.278 + * @return the total number of compressed bytes input so far
64.279 + */
64.280 + public int getTotalIn() {
64.281 + return (int) getBytesRead();
64.282 + }
64.283 +
64.284 + /**
64.285 + * Returns the total number of compressed bytes input so far.</p>
64.286 + *
64.287 + * @return the total (non-negative) number of compressed bytes input so far
64.288 + * @since 1.5
64.289 + */
64.290 + public long getBytesRead() {
64.291 + return impl.total_in;
64.292 + }
64.293 +
64.294 + /**
64.295 + * Returns the total number of uncompressed bytes output so far.
64.296 + *
64.297 + * <p>Since the number of bytes may be greater than
64.298 + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
64.299 + * the preferred means of obtaining this information.</p>
64.300 + *
64.301 + * @return the total number of uncompressed bytes output so far
64.302 + */
64.303 + public int getTotalOut() {
64.304 + return (int) getBytesWritten();
64.305 + }
64.306 +
64.307 + /**
64.308 + * Returns the total number of uncompressed bytes output so far.</p>
64.309 + *
64.310 + * @return the total (non-negative) number of uncompressed bytes output so far
64.311 + * @since 1.5
64.312 + */
64.313 + public long getBytesWritten() {
64.314 + return impl.total_out;
64.315 + }
64.316 +
64.317 + /**
64.318 + * Resets inflater so that a new set of input data can be processed.
64.319 + */
64.320 + public void reset() {
64.321 + impl = new JzLibInflater(15, nowrap);
64.322 + }
64.323 +
64.324 + /**
64.325 + * Closes the decompressor and discards any unprocessed input.
64.326 + * This method should be called when the decompressor is no longer
64.327 + * being used, but will also be called automatically by the finalize()
64.328 + * method. Once this method is called, the behavior of the Inflater
64.329 + * object is undefined.
64.330 + */
64.331 + public void end() {
64.332 + impl.end();
64.333 + }
64.334 +
64.335 + /**
64.336 + * Closes the decompressor when garbage is collected.
64.337 + */
64.338 + protected void finalize() {
64.339 + end();
64.340 + }
64.341 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
65.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java Sun May 11 14:01:18 2014 +0200
65.3 @@ -0,0 +1,137 @@
65.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
65.5 +/*
65.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
65.7 +
65.8 +Redistribution and use in source and binary forms, with or without
65.9 +modification, are permitted provided that the following conditions are met:
65.10 +
65.11 + 1. Redistributions of source code must retain the above copyright notice,
65.12 + this list of conditions and the following disclaimer.
65.13 +
65.14 + 2. Redistributions in binary form must reproduce the above copyright
65.15 + notice, this list of conditions and the following disclaimer in
65.16 + the documentation and/or other materials provided with the distribution.
65.17 +
65.18 + 3. The names of the authors may not be used to endorse or promote products
65.19 + derived from this software without specific prior written permission.
65.20 +
65.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
65.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
65.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
65.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
65.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
65.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
65.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
65.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
65.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
65.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65.31 + */
65.32 +/*
65.33 + * This program is based on zlib-1.1.3, so all credit should go authors
65.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
65.35 + * and contributors of zlib.
65.36 + */
65.37 +
65.38 +package org.apidesign.bck2brwsr.emul.zip;
65.39 +
65.40 +final class JzLibInflater extends ZStream{
65.41 +
65.42 + static final private int MAX_WBITS=15; // 32K LZ77 window
65.43 + static final private int DEF_WBITS=MAX_WBITS;
65.44 +
65.45 + public static final int Z_NO_FLUSH=0;
65.46 + static final private int Z_PARTIAL_FLUSH=1;
65.47 + static final private int Z_SYNC_FLUSH=2;
65.48 + static final private int Z_FULL_FLUSH=3;
65.49 + static final private int Z_FINISH=4;
65.50 +
65.51 + static final private int MAX_MEM_LEVEL=9;
65.52 +
65.53 + static final private int Z_OK=0;
65.54 + static final private int Z_STREAM_END=1;
65.55 + static final private int Z_NEED_DICT=2;
65.56 + static final private int Z_ERRNO=-1;
65.57 + static final private int Z_STREAM_ERROR=-2;
65.58 + static final private int Z_DATA_ERROR=-3;
65.59 + static final private int Z_MEM_ERROR=-4;
65.60 + static final private int Z_BUF_ERROR=-5;
65.61 + static final private int Z_VERSION_ERROR=-6;
65.62 +
65.63 + public JzLibInflater() {
65.64 + super();
65.65 + init();
65.66 + }
65.67 +
65.68 + public JzLibInflater(int w) {
65.69 + this(w, false);
65.70 + }
65.71 +
65.72 + public JzLibInflater(int w, boolean nowrap) {
65.73 + super();
65.74 + int ret = init(w, nowrap);
65.75 + if(ret!=Z_OK)
65.76 + throw new IllegalStateException(ret+": "+msg);
65.77 + }
65.78 +
65.79 + private boolean finished = false;
65.80 +
65.81 + public int init(){
65.82 + return init(DEF_WBITS);
65.83 + }
65.84 +
65.85 + public int init(boolean nowrap){
65.86 + return init(DEF_WBITS, nowrap);
65.87 + }
65.88 +
65.89 + public int init(int w){
65.90 + return init(w, false);
65.91 + }
65.92 +
65.93 + public int init(int w, boolean nowrap){
65.94 + finished = false;
65.95 + istate=new Inflate(this);
65.96 + return istate.inflateInit(nowrap?-w:w);
65.97 + }
65.98 +
65.99 + public int inflate(int f){
65.100 + if(istate==null) return Z_STREAM_ERROR;
65.101 + int ret = istate.inflate(f);
65.102 + if(ret == Z_STREAM_END)
65.103 + finished = true;
65.104 + return ret;
65.105 + }
65.106 +
65.107 + public int end(){
65.108 + finished = true;
65.109 + if(istate==null) return Z_STREAM_ERROR;
65.110 + int ret=istate.inflateEnd();
65.111 +// istate = null;
65.112 + return ret;
65.113 + }
65.114 +
65.115 + public int sync(){
65.116 + if(istate == null)
65.117 + return Z_STREAM_ERROR;
65.118 + return istate.inflateSync();
65.119 + }
65.120 +
65.121 + public int syncPoint(){
65.122 + if(istate == null)
65.123 + return Z_STREAM_ERROR;
65.124 + return istate.inflateSyncPoint();
65.125 + }
65.126 +
65.127 + public int setDictionary(byte[] dictionary, int dictLength){
65.128 + if(istate == null)
65.129 + return Z_STREAM_ERROR;
65.130 + return istate.inflateSetDictionary(dictionary, dictLength);
65.131 + }
65.132 +
65.133 + public boolean finished(){
65.134 + return istate.mode==12 /*DONE*/;
65.135 + }
65.136 +
65.137 + public boolean needDict() {
65.138 + return istate == null ? false : istate.mode == Inflate.DICT0;
65.139 + }
65.140 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java Sun May 11 14:01:18 2014 +0200
66.3 @@ -0,0 +1,253 @@
66.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
66.5 +/*
66.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
66.7 +
66.8 +Redistribution and use in source and binary forms, with or without
66.9 +modification, are permitted provided that the following conditions are met:
66.10 +
66.11 + 1. Redistributions of source code must retain the above copyright notice,
66.12 + this list of conditions and the following disclaimer.
66.13 +
66.14 + 2. Redistributions in binary form must reproduce the above copyright
66.15 + notice, this list of conditions and the following disclaimer in
66.16 + the documentation and/or other materials provided with the distribution.
66.17 +
66.18 + 3. The names of the authors may not be used to endorse or promote products
66.19 + derived from this software without specific prior written permission.
66.20 +
66.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
66.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
66.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
66.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
66.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
66.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
66.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
66.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
66.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
66.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66.31 + */
66.32 +/*
66.33 + * This program is based on zlib-1.1.3, so all credit should go authors
66.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
66.35 + * and contributors of zlib.
66.36 + */
66.37 +
66.38 +package org.apidesign.bck2brwsr.emul.zip;
66.39 +
66.40 +
66.41 +
66.42 +/**
66.43 + * ZStream
66.44 + *
66.45 + * @deprecated Not for public use in the future.
66.46 + */
66.47 +@Deprecated
66.48 +class ZStream{
66.49 +
66.50 + static final private int MAX_WBITS=15; // 32K LZ77 window
66.51 + static final private int DEF_WBITS=MAX_WBITS;
66.52 +
66.53 + static final private int Z_NO_FLUSH=0;
66.54 + static final private int Z_PARTIAL_FLUSH=1;
66.55 + static final private int Z_SYNC_FLUSH=2;
66.56 + static final private int Z_FULL_FLUSH=3;
66.57 + static final private int Z_FINISH=4;
66.58 +
66.59 + static final private int MAX_MEM_LEVEL=9;
66.60 +
66.61 + static final private int Z_OK=0;
66.62 + static final private int Z_STREAM_END=1;
66.63 + static final private int Z_NEED_DICT=2;
66.64 + static final private int Z_ERRNO=-1;
66.65 + static final private int Z_STREAM_ERROR=-2;
66.66 + static final private int Z_DATA_ERROR=-3;
66.67 + static final private int Z_MEM_ERROR=-4;
66.68 + static final private int Z_BUF_ERROR=-5;
66.69 + static final private int Z_VERSION_ERROR=-6;
66.70 +
66.71 + public byte[] next_in; // next input byte
66.72 + public int next_in_index;
66.73 + public int avail_in; // number of bytes available at next_in
66.74 + public long total_in; // total nb of input bytes read so far
66.75 +
66.76 + public byte[] next_out; // next output byte should be put there
66.77 + public int next_out_index;
66.78 + public int avail_out; // remaining free space at next_out
66.79 + public long total_out; // total nb of bytes output so far
66.80 +
66.81 + public String msg;
66.82 +
66.83 + Inflate istate;
66.84 +
66.85 + int data_type; // best guess about the data type: ascii or binary
66.86 +
66.87 + Checksum adler;
66.88 +
66.89 + public ZStream(){
66.90 + this(new Adler32());
66.91 + }
66.92 +
66.93 + public ZStream(Checksum adler){
66.94 + this.adler=adler;
66.95 + }
66.96 +
66.97 + public int inflateInit(){
66.98 + return inflateInit(DEF_WBITS);
66.99 + }
66.100 + public int inflateInit(boolean nowrap){
66.101 + return inflateInit(DEF_WBITS, nowrap);
66.102 + }
66.103 + public int inflateInit(int w){
66.104 + return inflateInit(w, false);
66.105 + }
66.106 +
66.107 + public int inflateInit(int w, boolean nowrap){
66.108 + istate=new Inflate(this);
66.109 + return istate.inflateInit(nowrap?-w:w);
66.110 + }
66.111 +
66.112 + public int inflate(int f){
66.113 + if(istate==null) return Z_STREAM_ERROR;
66.114 + return istate.inflate(f);
66.115 + }
66.116 + public int inflateEnd(){
66.117 + if(istate==null) return Z_STREAM_ERROR;
66.118 + int ret=istate.inflateEnd();
66.119 +// istate = null;
66.120 + return ret;
66.121 + }
66.122 +
66.123 + public int inflateSync(){
66.124 + if(istate == null)
66.125 + return Z_STREAM_ERROR;
66.126 + return istate.inflateSync();
66.127 + }
66.128 + public int inflateSyncPoint(){
66.129 + if(istate == null)
66.130 + return Z_STREAM_ERROR;
66.131 + return istate.inflateSyncPoint();
66.132 + }
66.133 + public int inflateSetDictionary(byte[] dictionary, int dictLength){
66.134 + if(istate == null)
66.135 + return Z_STREAM_ERROR;
66.136 + return istate.inflateSetDictionary(dictionary, dictLength);
66.137 + }
66.138 + public boolean inflateFinished(){
66.139 + return istate.mode==12 /*DONE*/;
66.140 + }
66.141 +
66.142 +
66.143 + public long getAdler(){
66.144 + return adler.getValue();
66.145 + }
66.146 +
66.147 + public void free(){
66.148 + next_in=null;
66.149 + next_out=null;
66.150 + msg=null;
66.151 + }
66.152 +
66.153 + public void setOutput(byte[] buf){
66.154 + setOutput(buf, 0, buf.length);
66.155 + }
66.156 +
66.157 + public void setOutput(byte[] buf, int off, int len){
66.158 + next_out = buf;
66.159 + next_out_index = off;
66.160 + avail_out = len;
66.161 + }
66.162 +
66.163 + public void setInput(byte[] buf){
66.164 + setInput(buf, 0, buf.length, false);
66.165 + }
66.166 +
66.167 + public void setInput(byte[] buf, boolean append){
66.168 + setInput(buf, 0, buf.length, append);
66.169 + }
66.170 +
66.171 + public void setInput(byte[] buf, int off, int len, boolean append){
66.172 + if(len<=0 && append && next_in!=null) return;
66.173 +
66.174 + if(avail_in>0 && append){
66.175 + byte[] tmp = new byte[avail_in+len];
66.176 + FastJar.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
66.177 + FastJar.arraycopy(buf, off, tmp, avail_in, len);
66.178 + next_in=tmp;
66.179 + next_in_index=0;
66.180 + avail_in+=len;
66.181 + }
66.182 + else{
66.183 + next_in=buf;
66.184 + next_in_index=off;
66.185 + avail_in=len;
66.186 + }
66.187 + }
66.188 +
66.189 + public byte[] getNextIn(){
66.190 + return next_in;
66.191 + }
66.192 +
66.193 + public void setNextIn(byte[] next_in){
66.194 + this.next_in = next_in;
66.195 + }
66.196 +
66.197 + public int getNextInIndex(){
66.198 + return next_in_index;
66.199 + }
66.200 +
66.201 + public void setNextInIndex(int next_in_index){
66.202 + this.next_in_index = next_in_index;
66.203 + }
66.204 +
66.205 + public int getAvailIn(){
66.206 + return avail_in;
66.207 + }
66.208 +
66.209 + public void setAvailIn(int avail_in){
66.210 + this.avail_in = avail_in;
66.211 + }
66.212 +
66.213 + public byte[] getNextOut(){
66.214 + return next_out;
66.215 + }
66.216 +
66.217 + public void setNextOut(byte[] next_out){
66.218 + this.next_out = next_out;
66.219 + }
66.220 +
66.221 + public int getNextOutIndex(){
66.222 + return next_out_index;
66.223 + }
66.224 +
66.225 + public void setNextOutIndex(int next_out_index){
66.226 + this.next_out_index = next_out_index;
66.227 + }
66.228 +
66.229 + public int getAvailOut(){
66.230 + return avail_out;
66.231 +
66.232 + }
66.233 +
66.234 + public void setAvailOut(int avail_out){
66.235 + this.avail_out = avail_out;
66.236 + }
66.237 +
66.238 + public long getTotalOut(){
66.239 + return total_out;
66.240 + }
66.241 +
66.242 + public long getTotalIn(){
66.243 + return total_in;
66.244 + }
66.245 +
66.246 + public String getMessage(){
66.247 + return msg;
66.248 + }
66.249 +
66.250 + /**
66.251 + * Those methods are expected to be override by Inflater and Deflater.
66.252 + * In the future, they will become abstract methods.
66.253 + */
66.254 + public int end(){ return Z_OK; }
66.255 + public boolean finished(){ return false; }
66.256 +}
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
67.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java Sun May 11 14:01:18 2014 +0200
67.3 @@ -0,0 +1,84 @@
67.4 +/*
67.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67.7 + *
67.8 + * This code is free software; you can redistribute it and/or modify it
67.9 + * under the terms of the GNU General Public License version 2 only, as
67.10 + * published by the Free Software Foundation. Oracle designates this
67.11 + * particular file as subject to the "Classpath" exception as provided
67.12 + * by Oracle in the LICENSE file that accompanied this code.
67.13 + *
67.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
67.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
67.17 + * version 2 for more details (a copy is included in the LICENSE file that
67.18 + * accompanied this code).
67.19 + *
67.20 + * You should have received a copy of the GNU General Public License version
67.21 + * 2 along with this work; if not, write to the Free Software Foundation,
67.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67.23 + *
67.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
67.25 + * or visit www.oracle.com if you need additional information or have any
67.26 + * questions.
67.27 + */
67.28 +
67.29 +package org.apidesign.bck2brwsr.emul.zip;
67.30 +
67.31 +/*
67.32 + * This class defines the constants that are used by the classes
67.33 + * which manipulate Zip64 files.
67.34 + */
67.35 +
67.36 +public class ZipConstants64 {
67.37 +
67.38 + /*
67.39 + * ZIP64 constants
67.40 + */
67.41 + static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006"
67.42 + static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007"
67.43 + static final int ZIP64_ENDHDR = 56; // ZIP64 end header size
67.44 + static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size
67.45 + static final int ZIP64_EXTHDR = 24; // EXT header size
67.46 + static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID
67.47 +
67.48 + static final int ZIP64_MAGICCOUNT = 0xFFFF;
67.49 + static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
67.50 +
67.51 + /*
67.52 + * Zip64 End of central directory (END) header field offsets
67.53 + */
67.54 + static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir
67.55 + static final int ZIP64_ENDVEM = 12; // version made by
67.56 + static final int ZIP64_ENDVER = 14; // version needed to extract
67.57 + static final int ZIP64_ENDNMD = 16; // number of this disk
67.58 + static final int ZIP64_ENDDSK = 20; // disk number of start
67.59 + static final int ZIP64_ENDTOD = 24; // total number of entries on this disk
67.60 + static final int ZIP64_ENDTOT = 32; // total number of entries
67.61 + static final int ZIP64_ENDSIZ = 40; // central directory size in bytes
67.62 + static final int ZIP64_ENDOFF = 48; // offset of first CEN header
67.63 + static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector
67.64 +
67.65 + /*
67.66 + * Zip64 End of central directory locator field offsets
67.67 + */
67.68 + static final int ZIP64_LOCDSK = 4; // disk number start
67.69 + static final int ZIP64_LOCOFF = 8; // offset of zip64 end
67.70 + static final int ZIP64_LOCTOT = 16; // total number of disks
67.71 +
67.72 + /*
67.73 + * Zip64 Extra local (EXT) header field offsets
67.74 + */
67.75 + static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value
67.76 + static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte
67.77 + static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte
67.78 +
67.79 + /*
67.80 + * Language encoding flag EFS
67.81 + */
67.82 + static final int EFS = 0x800; // If this bit is set the filename and
67.83 + // comment fields for this file must be
67.84 + // encoded using UTF-8.
67.85 +
67.86 + private ZipConstants64() {}
67.87 +}
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
68.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java Sun May 11 14:01:18 2014 +0200
68.3 @@ -0,0 +1,468 @@
68.4 +/*
68.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
68.7 + *
68.8 + * This code is free software; you can redistribute it and/or modify it
68.9 + * under the terms of the GNU General Public License version 2 only, as
68.10 + * published by the Free Software Foundation. Oracle designates this
68.11 + * particular file as subject to the "Classpath" exception as provided
68.12 + * by Oracle in the LICENSE file that accompanied this code.
68.13 + *
68.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
68.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
68.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
68.17 + * version 2 for more details (a copy is included in the LICENSE file that
68.18 + * accompanied this code).
68.19 + *
68.20 + * You should have received a copy of the GNU General Public License version
68.21 + * 2 along with this work; if not, write to the Free Software Foundation,
68.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
68.23 + *
68.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
68.25 + * or visit www.oracle.com if you need additional information or have any
68.26 + * questions.
68.27 + */
68.28 +
68.29 +package org.apidesign.bck2brwsr.emul.zip;
68.30 +
68.31 +import java.util.zip.*;
68.32 +import java.io.InputStream;
68.33 +import java.io.IOException;
68.34 +import java.io.EOFException;
68.35 +import java.io.PushbackInputStream;
68.36 +import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*;
68.37 +import static java.util.zip.ZipInputStream.*;
68.38 +
68.39 +/**
68.40 + * This class implements an input stream filter for reading files in the
68.41 + * ZIP file format. Includes support for both compressed and uncompressed
68.42 + * entries.
68.43 + *
68.44 + * @author David Connelly
68.45 + */
68.46 +public
68.47 +class ZipInputStream extends InflaterInputStream {
68.48 + private ZipEntry entry;
68.49 + private int flag;
68.50 + private CRC32 crc = new CRC32();
68.51 + private long remaining;
68.52 + private byte[] tmpbuf = new byte[512];
68.53 +
68.54 + private static final int STORED = ZipEntry.STORED;
68.55 + private static final int DEFLATED = ZipEntry.DEFLATED;
68.56 +
68.57 + private boolean closed = false;
68.58 + // this flag is set to true after EOF has reached for
68.59 + // one entry
68.60 + private boolean entryEOF = false;
68.61 +
68.62 + /**
68.63 + * Check to make sure that this stream has not been closed
68.64 + */
68.65 + private void ensureOpen() throws IOException {
68.66 + if (closed) {
68.67 + throw new IOException("Stream closed");
68.68 + }
68.69 + }
68.70 +
68.71 + /**
68.72 + * Creates a new ZIP input stream.
68.73 + *
68.74 + * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
68.75 + * decode the entry names.
68.76 + *
68.77 + * @param in the actual input stream
68.78 + */
68.79 + public ZipInputStream(InputStream in) {
68.80 +// this(in, "UTF-8");
68.81 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
68.82 + //usesDefaultInflater = true;
68.83 + if(in == null) {
68.84 + throw new NullPointerException("in is null");
68.85 + }
68.86 + }
68.87 +
68.88 + /**
68.89 + * Creates a new ZIP input stream.
68.90 + *
68.91 + * @param in the actual input stream
68.92 + *
68.93 + * @param charset
68.94 + * The {@linkplain java.nio.charset.Charset charset} to be
68.95 + * used to decode the ZIP entry name (ignored if the
68.96 + * <a href="package-summary.html#lang_encoding"> language
68.97 + * encoding bit</a> of the ZIP entry's general purpose bit
68.98 + * flag is set).
68.99 + *
68.100 + * @since 1.7
68.101 + *
68.102 + public ZipInputStream(InputStream in, Charset charset) {
68.103 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
68.104 + usesDefaultInflater = true;
68.105 + if(in == null) {
68.106 + throw new NullPointerException("in is null");
68.107 + }
68.108 + if (charset == null)
68.109 + throw new NullPointerException("charset is null");
68.110 + this.zc = ZipCoder.get(charset);
68.111 + }
68.112 + */
68.113 +
68.114 + /**
68.115 + * Reads the next ZIP file entry and positions the stream at the
68.116 + * beginning of the entry data.
68.117 + * @return the next ZIP file entry, or null if there are no more entries
68.118 + * @exception ZipException if a ZIP file error has occurred
68.119 + * @exception IOException if an I/O error has occurred
68.120 + */
68.121 + public ZipEntry getNextEntry() throws IOException {
68.122 + ensureOpen();
68.123 + if (entry != null) {
68.124 + closeEntry();
68.125 + }
68.126 + crc.reset();
68.127 + inf.reset();
68.128 + if ((entry = readLOC()) == null) {
68.129 + return null;
68.130 + }
68.131 + if (entry.getMethod() == STORED) {
68.132 + remaining = entry.getSize();
68.133 + }
68.134 + entryEOF = false;
68.135 + return entry;
68.136 + }
68.137 +
68.138 + /**
68.139 + * Closes the current ZIP entry and positions the stream for reading the
68.140 + * next entry.
68.141 + * @exception ZipException if a ZIP file error has occurred
68.142 + * @exception IOException if an I/O error has occurred
68.143 + */
68.144 + public void closeEntry() throws IOException {
68.145 + ensureOpen();
68.146 + while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
68.147 + entryEOF = true;
68.148 + }
68.149 +
68.150 + /**
68.151 + * Returns 0 after EOF has reached for the current entry data,
68.152 + * otherwise always return 1.
68.153 + * <p>
68.154 + * Programs should not count on this method to return the actual number
68.155 + * of bytes that could be read without blocking.
68.156 + *
68.157 + * @return 1 before EOF and 0 after EOF has reached for current entry.
68.158 + * @exception IOException if an I/O error occurs.
68.159 + *
68.160 + */
68.161 + public int available() throws IOException {
68.162 + ensureOpen();
68.163 + if (entryEOF) {
68.164 + return 0;
68.165 + } else {
68.166 + return 1;
68.167 + }
68.168 + }
68.169 +
68.170 + /**
68.171 + * Reads from the current ZIP entry into an array of bytes.
68.172 + * If <code>len</code> is not zero, the method
68.173 + * blocks until some input is available; otherwise, no
68.174 + * bytes are read and <code>0</code> is returned.
68.175 + * @param b the buffer into which the data is read
68.176 + * @param off the start offset in the destination array <code>b</code>
68.177 + * @param len the maximum number of bytes read
68.178 + * @return the actual number of bytes read, or -1 if the end of the
68.179 + * entry is reached
68.180 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
68.181 + * @exception IndexOutOfBoundsException if <code>off</code> is negative,
68.182 + * <code>len</code> is negative, or <code>len</code> is greater than
68.183 + * <code>b.length - off</code>
68.184 + * @exception ZipException if a ZIP file error has occurred
68.185 + * @exception IOException if an I/O error has occurred
68.186 + */
68.187 + public int read(byte[] b, int off, int len) throws IOException {
68.188 + ensureOpen();
68.189 + if (off < 0 || len < 0 || off > b.length - len) {
68.190 + throw new IndexOutOfBoundsException();
68.191 + } else if (len == 0) {
68.192 + return 0;
68.193 + }
68.194 +
68.195 + if (entry == null) {
68.196 + return -1;
68.197 + }
68.198 + switch (entry.getMethod()) {
68.199 + case DEFLATED:
68.200 + len = super.read(b, off, len);
68.201 + if (len == -1) {
68.202 + readEnd(entry);
68.203 + entryEOF = true;
68.204 + entry = null;
68.205 + } else {
68.206 + crc.update(b, off, len);
68.207 + }
68.208 + return len;
68.209 + case STORED:
68.210 + if (remaining <= 0) {
68.211 + entryEOF = true;
68.212 + entry = null;
68.213 + return -1;
68.214 + }
68.215 + if (len > remaining) {
68.216 + len = (int)remaining;
68.217 + }
68.218 + len = in.read(b, off, len);
68.219 + if (len == -1) {
68.220 + throw new ZipException("unexpected EOF");
68.221 + }
68.222 + crc.update(b, off, len);
68.223 + remaining -= len;
68.224 + if (remaining == 0 && entry.getCrc() != crc.getValue()) {
68.225 + throw new ZipException(
68.226 + "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
68.227 + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
68.228 + }
68.229 + return len;
68.230 + default:
68.231 + throw new ZipException("invalid compression method");
68.232 + }
68.233 + }
68.234 +
68.235 + /**
68.236 + * Skips specified number of bytes in the current ZIP entry.
68.237 + * @param n the number of bytes to skip
68.238 + * @return the actual number of bytes skipped
68.239 + * @exception ZipException if a ZIP file error has occurred
68.240 + * @exception IOException if an I/O error has occurred
68.241 + * @exception IllegalArgumentException if n < 0
68.242 + */
68.243 + public long skip(long n) throws IOException {
68.244 + if (n < 0) {
68.245 + throw new IllegalArgumentException("negative skip length");
68.246 + }
68.247 + ensureOpen();
68.248 + int max = (int)Math.min(n, Integer.MAX_VALUE);
68.249 + int total = 0;
68.250 + while (total < max) {
68.251 + int len = max - total;
68.252 + if (len > tmpbuf.length) {
68.253 + len = tmpbuf.length;
68.254 + }
68.255 + len = read(tmpbuf, 0, len);
68.256 + if (len == -1) {
68.257 + entryEOF = true;
68.258 + break;
68.259 + }
68.260 + total += len;
68.261 + }
68.262 + return total;
68.263 + }
68.264 +
68.265 + /**
68.266 + * Closes this input stream and releases any system resources associated
68.267 + * with the stream.
68.268 + * @exception IOException if an I/O error has occurred
68.269 + */
68.270 + public void close() throws IOException {
68.271 + if (!closed) {
68.272 + super.close();
68.273 + closed = true;
68.274 + }
68.275 + }
68.276 +
68.277 + private byte[] b = new byte[256];
68.278 +
68.279 + /*
68.280 + * Reads local file (LOC) header for next entry.
68.281 + */
68.282 + private ZipEntry readLOC() throws IOException {
68.283 + try {
68.284 + readFully(tmpbuf, 0, LOCHDR);
68.285 + } catch (EOFException e) {
68.286 + return null;
68.287 + }
68.288 + if (get32(tmpbuf, 0) != LOCSIG) {
68.289 + return null;
68.290 + }
68.291 + // get flag first, we need check EFS.
68.292 + flag = get16(tmpbuf, LOCFLG);
68.293 + // get the entry name and create the ZipEntry first
68.294 + int len = get16(tmpbuf, LOCNAM);
68.295 + int blen = b.length;
68.296 + if (len > blen) {
68.297 + do
68.298 + blen = blen * 2;
68.299 + while (len > blen);
68.300 + b = new byte[blen];
68.301 + }
68.302 + readFully(b, 0, len);
68.303 + // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
68.304 + ZipEntry e = createZipEntry(((flag & EFS) != 0)
68.305 + ? toStringUTF8(b, len)
68.306 + : toString(b, len));
68.307 + // now get the remaining fields for the entry
68.308 + if ((flag & 1) == 1) {
68.309 + throw new ZipException("encrypted ZIP entry not supported");
68.310 + }
68.311 + e.setMethod(get16(tmpbuf, LOCHOW));
68.312 + e.setTime(get32(tmpbuf, LOCTIM));
68.313 + if ((flag & 8) == 8) {
68.314 + /* "Data Descriptor" present */
68.315 + if (e.getMethod() != DEFLATED) {
68.316 + throw new ZipException(
68.317 + "only DEFLATED entries can have EXT descriptor");
68.318 + }
68.319 + } else {
68.320 + e.setCrc(get32(tmpbuf, LOCCRC));
68.321 + e.setCompressedSize(get32(tmpbuf, LOCSIZ));
68.322 + e.setSize(get32(tmpbuf, LOCLEN));
68.323 + }
68.324 + len = get16(tmpbuf, LOCEXT);
68.325 + if (len > 0) {
68.326 + byte[] bb = new byte[len];
68.327 + readFully(bb, 0, len);
68.328 + e.setExtra(bb);
68.329 + // extra fields are in "HeaderID(2)DataSize(2)Data... format
68.330 + if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
68.331 + int off = 0;
68.332 + while (off + 4 < len) {
68.333 + int sz = get16(bb, off + 2);
68.334 + if (get16(bb, off) == ZIP64_EXTID) {
68.335 + off += 4;
68.336 + // LOC extra zip64 entry MUST include BOTH original and
68.337 + // compressed file size fields
68.338 + if (sz < 16 || (off + sz) > len ) {
68.339 + // Invalid zip64 extra fields, simply skip. Even it's
68.340 + // rare, it's possible the entry size happens to be
68.341 + // the magic value and it "accidnetly" has some bytes
68.342 + // in extra match the id.
68.343 + return e;
68.344 + }
68.345 + e.setSize(get64(bb, off));
68.346 + e.setCompressedSize(get64(bb, off + 8));
68.347 + break;
68.348 + }
68.349 + off += (sz + 4);
68.350 + }
68.351 + }
68.352 + }
68.353 + return e;
68.354 + }
68.355 +
68.356 + /**
68.357 + * Creates a new <code>ZipEntry</code> object for the specified
68.358 + * entry name.
68.359 + *
68.360 + * @param name the ZIP file entry name
68.361 + * @return the ZipEntry just created
68.362 + */
68.363 + protected ZipEntry createZipEntry(String name) {
68.364 + return new ZipEntry(name);
68.365 + }
68.366 +
68.367 + /*
68.368 + * Reads end of deflated entry as well as EXT descriptor if present.
68.369 + */
68.370 + private void readEnd(ZipEntry e) throws IOException {
68.371 + int n = inf.getRemaining();
68.372 + if (n > 0) {
68.373 + ((PushbackInputStream)in).unread(buf, len - n, n);
68.374 + }
68.375 + if ((flag & 8) == 8) {
68.376 + /* "Data Descriptor" present */
68.377 + if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
68.378 + inf.getBytesRead() > ZIP64_MAGICVAL) {
68.379 + // ZIP64 format
68.380 + readFully(tmpbuf, 0, ZIP64_EXTHDR);
68.381 + long sig = get32(tmpbuf, 0);
68.382 + if (sig != EXTSIG) { // no EXTSIG present
68.383 + e.setCrc(sig);
68.384 + e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
68.385 + e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
68.386 + ((PushbackInputStream)in).unread(
68.387 + tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
68.388 + } else {
68.389 + e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
68.390 + e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
68.391 + e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
68.392 + }
68.393 + } else {
68.394 + readFully(tmpbuf, 0, EXTHDR);
68.395 + long sig = get32(tmpbuf, 0);
68.396 + if (sig != EXTSIG) { // no EXTSIG present
68.397 + e.setCrc(sig);
68.398 + e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
68.399 + e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
68.400 + ((PushbackInputStream)in).unread(
68.401 + tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
68.402 + } else {
68.403 + e.setCrc(get32(tmpbuf, EXTCRC));
68.404 + e.setCompressedSize(get32(tmpbuf, EXTSIZ));
68.405 + e.setSize(get32(tmpbuf, EXTLEN));
68.406 + }
68.407 + }
68.408 + }
68.409 + if (e.getSize() != inf.getBytesWritten()) {
68.410 + throw new ZipException(
68.411 + "invalid entry size (expected " + e.getSize() +
68.412 + " but got " + inf.getBytesWritten() + " bytes)");
68.413 + }
68.414 + if (e.getCompressedSize() != inf.getBytesRead()) {
68.415 + throw new ZipException(
68.416 + "invalid entry compressed size (expected " + e.getCompressedSize() +
68.417 + " but got " + inf.getBytesRead() + " bytes)");
68.418 + }
68.419 + if (e.getCrc() != crc.getValue()) {
68.420 + throw new ZipException(
68.421 + "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
68.422 + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
68.423 + }
68.424 + }
68.425 +
68.426 + /*
68.427 + * Reads bytes, blocking until all bytes are read.
68.428 + */
68.429 + private void readFully(byte[] b, int off, int len) throws IOException {
68.430 + while (len > 0) {
68.431 + int n = in.read(b, off, len);
68.432 + if (n == -1) {
68.433 + throw new EOFException();
68.434 + }
68.435 + off += n;
68.436 + len -= n;
68.437 + }
68.438 + }
68.439 +
68.440 + /*
68.441 + * Fetches unsigned 16-bit value from byte array at specified offset.
68.442 + * The bytes are assumed to be in Intel (little-endian) byte order.
68.443 + */
68.444 + private static final int get16(byte b[], int off) {
68.445 + return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
68.446 + }
68.447 +
68.448 + /*
68.449 + * Fetches unsigned 32-bit value from byte array at specified offset.
68.450 + * The bytes are assumed to be in Intel (little-endian) byte order.
68.451 + */
68.452 + private static final long get32(byte b[], int off) {
68.453 + return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
68.454 + }
68.455 +
68.456 + /*
68.457 + * Fetches signed 64-bit value from byte array at specified offset.
68.458 + * The bytes are assumed to be in Intel (little-endian) byte order.
68.459 + */
68.460 + private static final long get64(byte b[], int off) {
68.461 + return get32(b, off) | (get32(b, off+4) << 32);
68.462 + }
68.463 +
68.464 + private static String toStringUTF8(byte[] arr, int len) {
68.465 + return new String(arr, 0, len);
68.466 + }
68.467 +
68.468 + private static String toString(byte[] b, int len) {
68.469 + return new String(b, 0, len);
68.470 + }
68.471 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
69.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/vmzip/ZipResources.java Sun May 11 14:01:18 2014 +0200
69.3 @@ -0,0 +1,108 @@
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.vmzip;
69.22 +
69.23 +import java.io.ByteArrayInputStream;
69.24 +import java.io.IOException;
69.25 +import java.io.InputStream;
69.26 +import org.apidesign.bck2brwsr.core.Exported;
69.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
69.28 +import org.apidesign.bck2brwsr.emul.zip.FastJar;
69.29 +import org.apidesign.vm4brwsr.Bck2Brwsr;
69.30 +
69.31 +/** Conversion from classpath to load function.
69.32 + *
69.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
69.34 + */
69.35 +@Exported
69.36 +public final class ZipResources implements Bck2Brwsr.Resources {
69.37 + private final FastJar fj;
69.38 +
69.39 + @Exported
69.40 + public ZipResources(byte[] zipData) throws IOException {
69.41 +// long bef = timeNow();
69.42 + fj = new FastJar(zipData);
69.43 + for (FastJar.Entry e : fj.list()) {
69.44 + putRes(e.name, e);
69.45 + }
69.46 +// log("Iterating thru " + path + " took " + (timeNow() - bef) + "ms");
69.47 + }
69.48 +
69.49 + @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
69.50 + private static native int length(Object arr);
69.51 + @JavaScriptBody(args = { "arr", "index", "value" }, body = "arr[index] = value; return value;")
69.52 + private static native Object set(Object arr, int index, Object value);
69.53 +
69.54 + @JavaScriptBody(args = { "msg" }, body = "if (typeof console !== 'undefined') console.log(msg.toString());")
69.55 + private static native void log(String msg);
69.56 +
69.57 + private byte[] findRes(String res) throws IOException {
69.58 + Object arr = findResImpl(res);
69.59 + if (arr instanceof FastJar.Entry) {
69.60 + double bef = timeNow();
69.61 + InputStream zip = fj.getInputStream((FastJar.Entry)arr);
69.62 + arr = readFully(new byte[512], zip);
69.63 + putRes(res, arr);
69.64 + log("Reading " + res + " took " + (timeNow() - bef) + "ms");
69.65 + }
69.66 + return (byte[]) arr;
69.67 + }
69.68 +
69.69 + @Override
69.70 + public InputStream get(String resource) throws IOException {
69.71 + byte[] arr = findRes(resource);
69.72 + return arr == null ? null : new ByteArrayInputStream(arr);
69.73 + }
69.74 +
69.75 + @JavaScriptBody(args = { "res" }, body = "var r = this[res]; return r ? r : null;")
69.76 + private native Object findResImpl(String res);
69.77 +
69.78 + @JavaScriptBody(args = { "res", "arr" }, body = "this[res] = arr;")
69.79 + private native void putRes(String res, Object arr);
69.80 +
69.81 + @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(0);")
69.82 + private static native void enlargeBytes(byte[] arr, int len);
69.83 +
69.84 + @JavaScriptBody(args = { "arr", "len" }, body = "arr.splice(len, arr.length - len);")
69.85 + private static native void sliceArray(byte[] arr, int len);
69.86 +
69.87 + private static Object readFully(byte[] arr, InputStream zip) throws IOException {
69.88 + int offset = 0;
69.89 + for (;;) {
69.90 + int len = zip.read(arr, offset, arr.length - offset);
69.91 + if (len == -1) {
69.92 + break;
69.93 + }
69.94 + offset += len;
69.95 + if (offset == arr.length) {
69.96 + enlargeBytes(arr, arr.length + 4096);
69.97 + }
69.98 + }
69.99 + sliceArray(arr, offset);
69.100 + return arr;
69.101 + }
69.102 +
69.103 + @JavaScriptBody(args = {}, body =
69.104 + "if (typeof window.performance === 'undefined') return -1;\n"
69.105 + + "if (typeof window.performance.now === 'undefined') return -1;\n"
69.106 + + "return window.performance.now();"
69.107 + )
69.108 + private static native double timeNow();
69.109 +
69.110 +
69.111 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
70.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/CRC32Test.java Sun May 11 14:01:18 2014 +0200
70.3 @@ -0,0 +1,41 @@
70.4 +/**
70.5 + * Back 2 Browser Bytecode Translator
70.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
70.7 + *
70.8 + * This program is free software: you can redistribute it and/or modify
70.9 + * it under the terms of the GNU General Public License as published by
70.10 + * the Free Software Foundation, version 2 of the License.
70.11 + *
70.12 + * This program is distributed in the hope that it will be useful,
70.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
70.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70.15 + * GNU General Public License for more details.
70.16 + *
70.17 + * You should have received a copy of the GNU General Public License
70.18 + * along with this program. Look for COPYING file in the top folder.
70.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
70.20 + */
70.21 +package org.apidesign.bck2brwsr.emul.zip;
70.22 +
70.23 +import java.io.UnsupportedEncodingException;
70.24 +import java.util.zip.CRC32;
70.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
70.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
70.27 +import org.testng.annotations.Factory;
70.28 +
70.29 +/**
70.30 + *
70.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
70.32 + */
70.33 +public class CRC32Test {
70.34 +
70.35 + @Compare public long crc1() throws UnsupportedEncodingException {
70.36 + CRC32 crc = new CRC32();
70.37 + crc.update("Hello World!".getBytes("UTF-8"));
70.38 + return crc.getValue();
70.39 + }
70.40 +
70.41 + @Factory public static Object[] create() {
70.42 + return VMTest.create(CRC32Test.class);
70.43 + }
70.44 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
71.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipArchive.java Sun May 11 14:01:18 2014 +0200
71.3 @@ -0,0 +1,184 @@
71.4 +/**
71.5 + * Back 2 Browser Bytecode Translator
71.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
71.7 + *
71.8 + * This program is free software: you can redistribute it and/or modify
71.9 + * it under the terms of the GNU General Public License as published by
71.10 + * the Free Software Foundation, version 2 of the License.
71.11 + *
71.12 + * This program is distributed in the hope that it will be useful,
71.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
71.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71.15 + * GNU General Public License for more details.
71.16 + *
71.17 + * You should have received a copy of the GNU General Public License
71.18 + * along with this program. Look for COPYING file in the top folder.
71.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
71.20 + */
71.21 +package org.apidesign.bck2brwsr.emul.zip;
71.22 +
71.23 +import java.io.ByteArrayOutputStream;
71.24 +import java.io.IOException;
71.25 +import java.io.InputStream;
71.26 +import java.util.zip.ZipEntry;
71.27 +
71.28 +/**
71.29 + *
71.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
71.31 + */
71.32 +final class ZipArchive {
71.33 + private Entry first;
71.34 +
71.35 + public static ZipArchive createZip(InputStream is) throws IOException {
71.36 + ZipArchive a = new ZipArchive();
71.37 + readZip(is, a);
71.38 + return a;
71.39 + }
71.40 +
71.41 + public static ZipArchive createReal(InputStream is) throws IOException {
71.42 + ZipArchive a = new ZipArchive();
71.43 + realZip(is, a);
71.44 + return a;
71.45 + }
71.46 +
71.47 + /**
71.48 + * Registers entry name and data
71.49 + */
71.50 + final void register(String entry, InputStream is) throws IOException {
71.51 + byte[] arr = new byte[12 * 4096];
71.52 + for (int i = 0; i < arr.length; i++) {
71.53 + int ch = is.read();
71.54 + if (ch == -1) {
71.55 + byte[] tmp = new byte[i];
71.56 + FastJar.arraycopy(arr, 0, tmp, 0, i);
71.57 + arr = tmp;
71.58 + break;
71.59 + }
71.60 + arr[i] = (byte) ch;
71.61 + }
71.62 + first = new Entry (entry, arr, first);
71.63 + }
71.64 +
71.65 + @Override
71.66 + public String toString() {
71.67 + StringBuilder sb = new StringBuilder();
71.68 + Entry e = first;
71.69 + while (e != null) {
71.70 + String string = e.name;
71.71 + byte[] bs = e.arr;
71.72 + sb.append(string).append(" = ").append(toString(bs)).append("\n");
71.73 + e = e.next;
71.74 + }
71.75 + return sb.toString();
71.76 + }
71.77 +
71.78 + public void assertEquals(ZipArchive zip, String msg) {
71.79 + boolean ok = true;
71.80 + StringBuilder sb = new StringBuilder();
71.81 + sb.append(msg);
71.82 + Entry e = first;
71.83 + while (e != null) {
71.84 + String string = e.name;
71.85 + byte[] bs = e.arr;
71.86 + byte[] other = zip.find(string);
71.87 + e = e.next;
71.88 +
71.89 + sb.append("\n");
71.90 + if (other == null) {
71.91 + sb.append("EXTRA ").append(string).append(" = ").append(toString(bs));
71.92 + ok = false;
71.93 + continue;
71.94 + }
71.95 + if (equals(bs, other)) {
71.96 + sb.append("OK ").append(string);
71.97 + continue;
71.98 + } else {
71.99 + sb.append("DIFF ").append(string).append(" = ").append(toString(bs)).append("\n");
71.100 + sb.append(" TO").append(string).append(" = ").append(toString(other)).append("\n");
71.101 + ok = false;
71.102 + continue;
71.103 + }
71.104 + }
71.105 + e = zip.first;
71.106 + while (e != null) {
71.107 + String string = e.name;
71.108 + if (find(string) == null) {
71.109 + sb.append("MISS ").append(string).append(" = ").append(toString(e.arr));
71.110 + ok = false;
71.111 + }
71.112 + e = e.next;
71.113 + }
71.114 + if (!ok) {
71.115 + assert false : sb.toString();
71.116 + }
71.117 + }
71.118 +
71.119 + public static void readZip(InputStream is, ZipArchive data) throws IOException {
71.120 + ZipInputStream zip = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(is);
71.121 + for (;;) {
71.122 + ZipEntry en = zip.getNextEntry();
71.123 + if (en == null) {
71.124 + return;
71.125 + }
71.126 + data.register(en.getName(), zip);
71.127 + }
71.128 + }
71.129 +
71.130 + public static void realZip(InputStream is, ZipArchive data) throws IOException {
71.131 + java.util.zip.ZipInputStream zip = new java.util.zip.ZipInputStream(is);
71.132 + for (;;) {
71.133 + ZipEntry en = zip.getNextEntry();
71.134 + if (en == null) {
71.135 + return;
71.136 + }
71.137 + data.register(en.getName(), zip);
71.138 + }
71.139 + }
71.140 +
71.141 + private byte[] find(String name) {
71.142 + Entry e = first;
71.143 + while (e != null) {
71.144 + if (e.name.equals(name)) {
71.145 + return e.arr;
71.146 + }
71.147 + e = e.next;
71.148 + }
71.149 + return null;
71.150 + }
71.151 +
71.152 + private boolean equals(byte[] bs, byte[] other) {
71.153 + if (bs.length != other.length) {
71.154 + return false;
71.155 + }
71.156 + for (int i = 0; i < bs.length; i++) {
71.157 + if (bs[i] != other[i]) {
71.158 + return false;
71.159 + }
71.160 + }
71.161 + return true;
71.162 + }
71.163 +
71.164 + private Object toString(byte[] arr) {
71.165 + StringBuilder sb = new StringBuilder();
71.166 + sb.append("[");
71.167 + String sep = "";
71.168 + for (int i = 0; i < arr.length; i++) {
71.169 + sb.append(sep).append(arr[i]);
71.170 + sep = ", ";
71.171 + }
71.172 + sb.append("]");
71.173 + return sb.toString();
71.174 + }
71.175 +
71.176 + private static final class Entry {
71.177 + final String name;
71.178 + final byte[] arr;
71.179 + final Entry next;
71.180 +
71.181 + public Entry(String name, byte[] arr, Entry next) {
71.182 + this.name = name;
71.183 + this.arr = arr;
71.184 + this.next = next;
71.185 + }
71.186 + }
71.187 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipCompatibilityTest.java Sun May 11 14:01:18 2014 +0200
72.3 @@ -0,0 +1,43 @@
72.4 +/**
72.5 + * Back 2 Browser Bytecode Translator
72.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
72.7 + *
72.8 + * This program is free software: you can redistribute it and/or modify
72.9 + * it under the terms of the GNU General Public License as published by
72.10 + * the Free Software Foundation, version 2 of the License.
72.11 + *
72.12 + * This program is distributed in the hope that it will be useful,
72.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
72.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72.15 + * GNU General Public License for more details.
72.16 + *
72.17 + * You should have received a copy of the GNU General Public License
72.18 + * along with this program. Look for COPYING file in the top folder.
72.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
72.20 + */
72.21 +package org.apidesign.bck2brwsr.emul.zip;
72.22 +
72.23 +import java.io.IOException;
72.24 +import java.io.InputStream;
72.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
72.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
72.27 +import org.testng.annotations.Factory;
72.28 +
72.29 +/**
72.30 + *
72.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
72.32 + */
72.33 +public class ZipCompatibilityTest {
72.34 + @Compare
72.35 + public String testDemoStaticCalculator() throws IOException {
72.36 + InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
72.37 + ZipArchive zip = ZipArchive.createZip(is);
72.38 + final String ts = zip.toString();
72.39 + return ts.substring(0, 4096) + ts.hashCode();
72.40 + }
72.41 +
72.42 + @Factory
72.43 + public static Object[] create() {
72.44 + return VMTest.create(ZipCompatibilityTest.class);
72.45 + }
72.46 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/emul/zip/ZipVsJzLibTest.java Sun May 11 14:01:18 2014 +0200
73.3 @@ -0,0 +1,39 @@
73.4 +/**
73.5 + * Back 2 Browser Bytecode Translator
73.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
73.7 + *
73.8 + * This program is free software: you can redistribute it and/or modify
73.9 + * it under the terms of the GNU General Public License as published by
73.10 + * the Free Software Foundation, version 2 of the License.
73.11 + *
73.12 + * This program is distributed in the hope that it will be useful,
73.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
73.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73.15 + * GNU General Public License for more details.
73.16 + *
73.17 + * You should have received a copy of the GNU General Public License
73.18 + * along with this program. Look for COPYING file in the top folder.
73.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
73.20 + */
73.21 +package org.apidesign.bck2brwsr.emul.zip;
73.22 +
73.23 +import java.io.IOException;
73.24 +import java.io.InputStream;
73.25 +import org.testng.annotations.Test;
73.26 +
73.27 +/**
73.28 + *
73.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
73.30 + */
73.31 +public class ZipVsJzLibTest {
73.32 + @Test public void r() throws IOException {
73.33 + InputStream is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
73.34 + ZipArchive zip = ZipArchive.createZip(is);
73.35 +
73.36 + is = getClass().getResourceAsStream("demo.static.calculator-TEST.jar");
73.37 + ZipArchive real = ZipArchive.createReal(is);
73.38 +
73.39 + real.assertEquals(zip, "Are they the same?");
73.40 + }
73.41 +
73.42 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
74.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipEntryTest.java Sun May 11 14:01:18 2014 +0200
74.3 @@ -0,0 +1,66 @@
74.4 +/**
74.5 + * Back 2 Browser Bytecode Translator
74.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
74.7 + *
74.8 + * This program is free software: you can redistribute it and/or modify
74.9 + * it under the terms of the GNU General Public License as published by
74.10 + * the Free Software Foundation, version 2 of the License.
74.11 + *
74.12 + * This program is distributed in the hope that it will be useful,
74.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
74.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74.15 + * GNU General Public License for more details.
74.16 + *
74.17 + * You should have received a copy of the GNU General Public License
74.18 + * along with this program. Look for COPYING file in the top folder.
74.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
74.20 + */
74.21 +package org.apidesign.bck2brwsr.vmtest.impl;
74.22 +
74.23 +import java.io.IOException;
74.24 +import java.io.InputStream;
74.25 +import org.apidesign.bck2brwsr.emul.zip.FastJar;
74.26 +import org.testng.annotations.Test;
74.27 +import static org.testng.Assert.*;
74.28 +
74.29 +/**
74.30 + *
74.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
74.32 + */
74.33 +@GenerateZip(name = "five.zip", contents = {
74.34 + "1.txt", "one",
74.35 + "2.txt", "duo",
74.36 + "3.txt", "three",
74.37 + "4.txt", "four",
74.38 + "5.txt", "five"
74.39 +})
74.40 +public class ZipEntryTest {
74.41 + @Test
74.42 + public void readEntriesEffectively() throws IOException {
74.43 + InputStream is = ZipEntryTest.class.getResourceAsStream("five.zip");
74.44 + byte[] arr = new byte[is.available()];
74.45 + int len = is.read(arr);
74.46 + assertEquals(len, arr.length, "Read fully");
74.47 +
74.48 + FastJar fj = new FastJar(arr);
74.49 + FastJar.Entry[] entrs = fj.list();
74.50 +
74.51 + assertEquals(5, entrs.length, "Five entries");
74.52 +
74.53 + for (int i = 1; i <= 5; i++) {
74.54 + FastJar.Entry en = entrs[i - 1];
74.55 + assertEquals(en.name, i + ".txt");
74.56 +// assertEquals(cis.cnt, 0, "Content of the file should be skipped, not read");
74.57 + }
74.58 +
74.59 + assertContent("three", fj.getInputStream(entrs[3 - 1]), "read OK");
74.60 + assertContent("five", fj.getInputStream(entrs[5 - 1]), "read OK");
74.61 + }
74.62 +
74.63 + private static void assertContent(String exp, InputStream is, String msg) throws IOException {
74.64 + byte[] arr = new byte[512];
74.65 + int len = is.read(arr);
74.66 + String s = new String(arr, 0, len);
74.67 + assertEquals(exp, s, msg);
74.68 + }
74.69 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
75.2 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Sun May 11 14:01:18 2014 +0200
75.3 @@ -0,0 +1,116 @@
75.4 +/**
75.5 + * Back 2 Browser Bytecode Translator
75.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
75.7 + *
75.8 + * This program is free software: you can redistribute it and/or modify
75.9 + * it under the terms of the GNU General Public License as published by
75.10 + * the Free Software Foundation, version 2 of the License.
75.11 + *
75.12 + * This program is distributed in the hope that it will be useful,
75.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
75.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75.15 + * GNU General Public License for more details.
75.16 + *
75.17 + * You should have received a copy of the GNU General Public License
75.18 + * along with this program. Look for COPYING file in the top folder.
75.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
75.20 + */
75.21 +package org.apidesign.bck2brwsr.vmtest.impl;
75.22 +
75.23 +import java.io.IOException;
75.24 +import java.io.InputStream;
75.25 +import java.util.zip.ZipEntry;
75.26 +import java.util.zip.ZipInputStream;
75.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
75.28 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
75.29 +import org.apidesign.bck2brwsr.vmtest.Compare;
75.30 +import org.apidesign.bck2brwsr.vmtest.Http;
75.31 +import org.apidesign.bck2brwsr.vmtest.VMTest;
75.32 +import org.testng.annotations.Factory;
75.33 +
75.34 +/**
75.35 + *
75.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
75.37 + */
75.38 +@GenerateZip(name = "readAnEntry.zip", contents = {
75.39 + "my/main/file.txt", "Hello World!"
75.40 +})
75.41 +public class ZipFileTest {
75.42 +
75.43 + @Compare public String readAnEntry() throws IOException {
75.44 + InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip");
75.45 + ZipInputStream zip = new ZipInputStream(is);
75.46 + ZipEntry entry = zip.getNextEntry();
75.47 + assertEquals(entry.getName(), "my/main/file.txt", "Correct entry");
75.48 +
75.49 + byte[] arr = new byte[4096];
75.50 + int len = zip.read(arr);
75.51 +
75.52 + assertEquals(zip.getNextEntry(), null, "No next entry");
75.53 +
75.54 + final String ret = new String(arr, 0, len, "UTF-8");
75.55 + return ret;
75.56 + }
75.57 +
75.58 + @JavaScriptBody(args = { "res", "path" }, body =
75.59 + "var myvm = bck2brwsr.apply(null, path);\n"
75.60 + + "var cls = myvm.loadClass('java.lang.String');\n"
75.61 + + "return cls.getClass__Ljava_lang_Class_2().getResourceAsStream__Ljava_io_InputStream_2Ljava_lang_String_2(res);\n"
75.62 + )
75.63 + private static native Object loadVMResource(String res, String...path);
75.64 +
75.65 + @Http({
75.66 + @Http.Resource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip")
75.67 + })
75.68 + @BrwsrTest public void canVmLoadResourceFromZip() throws IOException {
75.69 + Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar");
75.70 + assert res instanceof InputStream : "Got array of bytes: " + res;
75.71 + InputStream is = (InputStream)res;
75.72 +
75.73 + byte[] arr = new byte[4096];
75.74 + int len = is.read(arr);
75.75 +
75.76 + final String ret = new String(arr, 0, len, "UTF-8");
75.77 +
75.78 + assertEquals(ret, "Hello World!", "Can read the bytes");
75.79 + }
75.80 +
75.81 + @GenerateZip(name = "cpattr.zip", contents = {
75.82 + "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n"
75.83 + + "Created-By: hand\n"
75.84 + + "Class-Path: realJar.jar\n\n\n"
75.85 + })
75.86 + @Http({
75.87 + @Http.Resource(path = "/readComplexEntry.jar", mimeType = "x-application/zip", content = "", resource="cpattr.zip"),
75.88 + @Http.Resource(path = "/realJar.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip"),
75.89 + })
75.90 + @BrwsrTest public void understandsClassPathAttr() throws IOException {
75.91 + Object res = loadVMResource("/my/main/file.txt", "/readComplexEntry.jar");
75.92 + assert res instanceof InputStream : "Got array of bytes: " + res;
75.93 + InputStream is = (InputStream)res;
75.94 +
75.95 + byte[] arr = new byte[4096];
75.96 + int len = is.read(arr);
75.97 +
75.98 + final String ret = new String(arr, 0, len, "UTF-8");
75.99 +
75.100 + assertEquals(ret, "Hello World!", "Can read the bytes from secondary JAR");
75.101 + }
75.102 +
75.103 + private static void assertEquals(Object real, Object exp, String msg) {
75.104 + if (real == null) {
75.105 + if (exp == null) {
75.106 + return;
75.107 + }
75.108 + } else {
75.109 + if (real.equals(exp)) {
75.110 + return;
75.111 + }
75.112 + }
75.113 + assert false : msg + " exp: " + exp + " real: " + real;
75.114 + }
75.115 +
75.116 + @Factory public static Object[] create() {
75.117 + return VMTest.create(ZipFileTest.class);
75.118 + }
75.119 +}
76.1 Binary file rt/emul/zip/src/test/resources/org/apidesign/bck2brwsr/emul/zip/demo.static.calculator-TEST.jar has changed
77.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue May 06 17:46:47 2014 +0200
77.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sun May 11 14:01:18 2014 +0200
77.3 @@ -19,6 +19,7 @@
77.4
77.5 import java.io.IOException;
77.6 import java.io.InputStream;
77.7 +import java.util.Locale;
77.8 import static org.apidesign.vm4brwsr.ByteCodeParser.*;
77.9
77.10 /** Translator of the code inside class files to JavaScript.
77.11 @@ -1118,7 +1119,11 @@
77.12 break;
77.13 case opc_dup: {
77.14 final Variable v = smapper.get(0);
77.15 - emit(smapper, this, "var @1 = @2;", smapper.pushT(v.getType()), v);
77.16 + if (smapper.isDirty()) {
77.17 + emit(smapper, this, "var @1 = @2;", smapper.pushT(v.getType()), v);
77.18 + } else {
77.19 + smapper.assign(this, v.getType(), v);
77.20 + }
77.21 break;
77.22 }
77.23 case opc_dup2: {
77.24 @@ -1529,7 +1534,18 @@
77.25 case '_': sb.append("_1"); break;
77.26 case ';': sb.append("_2"); break;
77.27 case '[': sb.append("_3"); break;
77.28 - default: sb.append(ch); break;
77.29 + default:
77.30 + if (Character.isJavaIdentifierPart(ch)) {
77.31 + sb.append(ch);
77.32 + } else {
77.33 + sb.append("_0");
77.34 + String hex = Integer.toHexString(ch).toLowerCase(Locale.ENGLISH);
77.35 + for (int m = hex.length(); m < 4; m++) {
77.36 + sb.append("0");
77.37 + }
77.38 + sb.append(hex);
77.39 + }
77.40 + break;
77.41 }
77.42 }
77.43 return sb.toString();
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
78.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClassPath.java Sun May 11 14:01:18 2014 +0200
78.3 @@ -0,0 +1,156 @@
78.4 +/**
78.5 + * Back 2 Browser Bytecode Translator
78.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
78.7 + *
78.8 + * This program is free software: you can redistribute it and/or modify
78.9 + * it under the terms of the GNU General Public License as published by
78.10 + * the Free Software Foundation, version 2 of the License.
78.11 + *
78.12 + * This program is distributed in the hope that it will be useful,
78.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
78.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78.15 + * GNU General Public License for more details.
78.16 + *
78.17 + * You should have received a copy of the GNU General Public License
78.18 + * along with this program. Look for COPYING file in the top folder.
78.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
78.20 + */
78.21 +package org.apidesign.vm4brwsr;
78.22 +
78.23 +import java.io.ByteArrayInputStream;
78.24 +import java.io.IOException;
78.25 +import java.io.InputStream;
78.26 +import java.net.URL;
78.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
78.28 +
78.29 +/** Conversion from classpath to load function.
78.30 + *
78.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
78.32 + */
78.33 +final class ClassPath {
78.34 + private ClassPath() {
78.35 + }
78.36 +
78.37 + public static void init() {
78.38 + }
78.39 + @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
78.40 + private static native int length(Object arr);
78.41 + @JavaScriptBody(args = { "arr", "index" }, body = "return arr[index];")
78.42 + private static native Object at(Object arr, int index);
78.43 + @JavaScriptBody(args = { "arr", "index", "value" }, body = "arr[index] = value; return value;")
78.44 + private static native Object set(Object arr, int index, Object value);
78.45 +
78.46 + private static boolean doingToZip;
78.47 + public static byte[] loadFromCp(Object classpath, String res, int skip)
78.48 + throws IOException, ClassNotFoundException {
78.49 + for (int i = 0; i < length(classpath); i++) {
78.50 + Object c = at(classpath, i);
78.51 + if (c instanceof String && !doingToZip) {
78.52 + try {
78.53 + doingToZip = true;
78.54 + String url = (String)c;
78.55 + final Bck2Brwsr.Resources z = toZip(url);
78.56 + c = set(classpath, i, z);
78.57 + final byte[] man = readBytes(z, "META-INF/MANIFEST.MF");
78.58 + if (man != null) {
78.59 + String mainClass = processClassPathAttr(man, url, classpath);
78.60 +// if (mainClass != null) {
78.61 +// Class.forName(mainClass);
78.62 +// }
78.63 + }
78.64 + } catch (IOException ex) {
78.65 + set(classpath, i, ex);
78.66 + log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
78.67 + } finally {
78.68 + doingToZip = false;
78.69 + }
78.70 + }
78.71 + if (res != null) {
78.72 + byte[] checkRes;
78.73 + if (c instanceof Bck2Brwsr.Resources) {
78.74 + checkRes = readBytes((Bck2Brwsr.Resources)c, res);
78.75 + if (checkRes != null && --skip < 0) {
78.76 + return checkRes;
78.77 + }
78.78 + } else {
78.79 + checkRes = callFunction(c, res, skip);
78.80 + if (checkRes != null) {
78.81 + return checkRes;
78.82 + }
78.83 + }
78.84 + }
78.85 + }
78.86 + return null;
78.87 + }
78.88 +
78.89 + @JavaScriptBody(args = { "fn", "res", "skip" }, body =
78.90 + "if (typeof fn === 'function') return fn(res, skip);\n"
78.91 + + "return null;"
78.92 + )
78.93 + private static native byte[] callFunction(Object fn, String res, int skip);
78.94 +
78.95 + @JavaScriptBody(args = { "msg" }, body = "if (typeof console !== 'undefined') console.log(msg.toString());")
78.96 + private static native void log(String msg);
78.97 +
78.98 + private static String processClassPathAttr(final byte[] man, String url, Object classpath) throws IOException {
78.99 + try (ParseMan is = new ParseMan(new ByteArrayInputStream(man))) {
78.100 + String cp = is.toString();
78.101 + if (cp != null) {
78.102 + cp = cp.trim();
78.103 + for (int p = 0; p < cp.length();) {
78.104 + int n = cp.indexOf(' ', p);
78.105 + if (n == -1) {
78.106 + n = cp.length();
78.107 + }
78.108 + String el = cp.substring(p, n);
78.109 + URL u = new URL(new URL(url), el);
78.110 + classpath = addToArray(classpath, u.toString());
78.111 + p = n + 1;
78.112 + }
78.113 + }
78.114 + return is.getMainClass();
78.115 + }
78.116 + }
78.117 +
78.118 + private static Object addToArray(Object arr, String value) {
78.119 + final int last = length(arr);
78.120 + Object ret = enlargeArray(arr, last + 1);
78.121 + set(ret, last, value);
78.122 + return ret;
78.123 + }
78.124 +
78.125 + @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(null); return arr;")
78.126 + private static native Object enlargeArray(Object arr, int len);
78.127 +
78.128 + private static Bck2Brwsr.Resources toZip(String path) throws IOException {
78.129 + URL u = new URL(path);
78.130 + byte[] zipData = (byte[]) u.getContent(new Class[]{byte[].class});
78.131 + Bck2Brwsr.Resources r;
78.132 + try {
78.133 + Class<?> fastJar = Class.forName("org.apidesign.bck2brwsr.vmzip.ZipResources");
78.134 + return (Bck2Brwsr.Resources) fastJar.getConstructor(byte[].class).newInstance(zipData);
78.135 + } catch (Exception ex) {
78.136 + log("Reading JARs is only possible with enum.zip module included: " + ex.getMessage());
78.137 + ex.printStackTrace();
78.138 + throw new IOException(ex);
78.139 + }
78.140 + }
78.141 +
78.142 + private static byte[] readBytes(Bck2Brwsr.Resources r, String res) throws IOException {
78.143 + InputStream is = r.get(res);
78.144 + if (is == null) {
78.145 + return null;
78.146 + }
78.147 + byte[] arr = new byte[is.available()];
78.148 + int off = 0;
78.149 + for (;;) {
78.150 + int len = is.read(arr, off, arr.length - off);
78.151 + if (len == -1) {
78.152 + break;
78.153 + }
78.154 + off += len;
78.155 + }
78.156 + is.close();
78.157 + return arr;
78.158 + }
78.159 +}
79.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java Tue May 06 17:46:47 2014 +0200
79.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java Sun May 11 14:01:18 2014 +0200
79.3 @@ -23,6 +23,7 @@
79.4 final class StackMapper {
79.5 private final TypeArray stackTypeIndexPairs;
79.6 private final StringArray stackValues;
79.7 + private boolean dirty;
79.8
79.9 public StackMapper() {
79.10 stackTypeIndexPairs = new TypeArray();
79.11 @@ -32,6 +33,7 @@
79.12 public void clear() {
79.13 stackTypeIndexPairs.clear();
79.14 stackValues.clear();
79.15 + dirty = false;
79.16 }
79.17
79.18 public void syncWithFrameStack(final TypeArray frameStack) {
79.19 @@ -70,7 +72,7 @@
79.20 void assign(Appendable out, int varType, CharSequence s) throws IOException {
79.21 pushTypeAndValue(varType, s);
79.22 }
79.23 -
79.24 +
79.25 void replace(Appendable out, int varType, String format, CharSequence... arr)
79.26 throws IOException {
79.27 StringBuilder sb = new StringBuilder();
79.28 @@ -78,6 +80,7 @@
79.29 String[] values = stackValues.toArray();
79.30 final int last = stackTypeIndexPairs.getSize() - 1;
79.31 values[last] = sb.toString();
79.32 + dirty = true;
79.33 final int value = (last << 8) | (varType & 0xff);
79.34 stackTypeIndexPairs.set(last, value);
79.35 }
79.36 @@ -92,6 +95,11 @@
79.37 CharSequence var = getVariable(stackTypeIndexPairs.get(i));
79.38 ByteCodeToJavaScript.emitImpl(out, "var @1 = @2;", var, val);
79.39 }
79.40 + dirty = false;
79.41 + }
79.42 +
79.43 + public boolean isDirty() {
79.44 + return dirty;
79.45 }
79.46
79.47 public CharSequence popI() {
79.48 @@ -216,6 +224,7 @@
79.49 } else {
79.50 stackValues.add(val);
79.51 }
79.52 + dirty = true;
79.53 }
79.54
79.55 private void popImpl(final int count) {
80.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Tue May 06 17:46:47 2014 +0200
80.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Sun May 11 14:01:18 2014 +0200
80.3 @@ -55,7 +55,7 @@
80.4 assert assertsOn = true;
80.5 if (assertsOn) {
80.6 VMLazy.init();
80.7 - Zips.init();
80.8 + ClassPath.init();
80.9 }
80.10 }
80.11
80.12 @@ -612,15 +612,18 @@
80.13 protected void generatePrologue() throws IOException {
80.14 append("bck2brwsr.registerExtension(function(exports) {\n"
80.15 + " var vm = {};\n");
80.16 - append(" function link(n, inst) {\n"
80.17 - + " var cls = n['replace__Ljava_lang_String_2CC']"
80.18 - + "('/', '_').toString();\n"
80.19 - + " var dot = n['replace__Ljava_lang_String_2CC']"
80.20 - + "('/', '.').toString();\n"
80.21 - + " exports.loadClass(dot);\n"
80.22 - + " vm[cls] = exports[cls];\n"
80.23 - + " return vm[cls](inst);\n"
80.24 - + " };\n");
80.25 + append(" function link(n) {\n"
80.26 + + " return function() {\n"
80.27 + + " var cls = n['replace__Ljava_lang_String_2CC']"
80.28 + + "('/', '_').toString();\n"
80.29 + + " var dot = n['replace__Ljava_lang_String_2CC']"
80.30 + + "('/', '.').toString();\n"
80.31 + + " exports.loadClass(dot);\n"
80.32 + + " vm[cls] = exports[cls];\n"
80.33 + + " return vm[cls](arguments);\n"
80.34 + + " };\n"
80.35 + + " };\n"
80.36 + );
80.37 }
80.38
80.39 @Override
80.40 @@ -633,10 +636,9 @@
80.41 if (isExternalClass(className)) {
80.42 append("\n").append(assignClass(
80.43 className.replace('/', '_')))
80.44 - .append("function() {\n return link('")
80.45 + .append("link('")
80.46 .append(className)
80.47 - .append("', arguments.length == 0 || arguments[0] === true);"
80.48 - + "\n};");
80.49 + .append("');");
80.50
80.51 return null;
80.52 }
81.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Tue May 06 17:46:47 2014 +0200
81.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Sun May 11 14:01:18 2014 +0200
81.3 @@ -49,13 +49,13 @@
81.4 }
81.5
81.6 static byte[] loadBytes(Object loader, String name, Object[] arguments, int skip) throws Exception {
81.7 - return Zips.loadFromCp(arguments, name, skip);
81.8 + return ClassPath.loadFromCp(arguments, name, skip);
81.9 }
81.10
81.11 private Object load(String name, boolean instance)
81.12 throws IOException, ClassNotFoundException {
81.13 String res = name.replace('.', '/') + ".class";
81.14 - byte[] arr = Zips.loadFromCp(args, res, 0);
81.15 + byte[] arr = ClassPath.loadFromCp(args, res, 0);
81.16 if (arr == null) {
81.17 throw new ClassNotFoundException(name);
81.18 }
82.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java Tue May 06 17:46:47 2014 +0200
82.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
82.3 @@ -1,190 +0,0 @@
82.4 -/**
82.5 - * Back 2 Browser Bytecode Translator
82.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
82.7 - *
82.8 - * This program is free software: you can redistribute it and/or modify
82.9 - * it under the terms of the GNU General Public License as published by
82.10 - * the Free Software Foundation, version 2 of the License.
82.11 - *
82.12 - * This program is distributed in the hope that it will be useful,
82.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
82.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82.15 - * GNU General Public License for more details.
82.16 - *
82.17 - * You should have received a copy of the GNU General Public License
82.18 - * along with this program. Look for COPYING file in the top folder.
82.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
82.20 - */
82.21 -package org.apidesign.vm4brwsr;
82.22 -
82.23 -import java.io.ByteArrayInputStream;
82.24 -import java.io.IOException;
82.25 -import java.io.InputStream;
82.26 -import java.net.URL;
82.27 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
82.28 -import org.apidesign.bck2brwsr.emul.zip.FastJar;
82.29 -
82.30 -/** Conversion from classpath to load function.
82.31 - *
82.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
82.33 - */
82.34 -final class Zips {
82.35 - private final FastJar fj;
82.36 -
82.37 - private Zips(String path, byte[] zipData) throws IOException {
82.38 - long bef = timeNow();
82.39 - fj = new FastJar(zipData);
82.40 - for (FastJar.Entry e : fj.list()) {
82.41 - putRes(e.name, e);
82.42 - }
82.43 - log("Iterating thru " + path + " took " + (timeNow() - bef) + "ms");
82.44 - }
82.45 -
82.46 - public static void init() {
82.47 - }
82.48 - @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
82.49 - private static native int length(Object arr);
82.50 - @JavaScriptBody(args = { "arr", "index" }, body = "return arr[index];")
82.51 - private static native Object at(Object arr, int index);
82.52 - @JavaScriptBody(args = { "arr", "index", "value" }, body = "arr[index] = value; return value;")
82.53 - private static native Object set(Object arr, int index, Object value);
82.54 -
82.55 - public static byte[] loadFromCp(Object classpath, String res, int skip)
82.56 - throws IOException, ClassNotFoundException {
82.57 - for (int i = 0; i < length(classpath); i++) {
82.58 - Object c = at(classpath, i);
82.59 - if (c instanceof String) {
82.60 - try {
82.61 - String url = (String)c;
82.62 - final Zips z = toZip(url);
82.63 - c = set(classpath, i, z);
82.64 - final byte[] man = z.findRes("META-INF/MANIFEST.MF");
82.65 - if (man != null) {
82.66 - String mainClass = processClassPathAttr(man, url, classpath);
82.67 -// if (mainClass != null) {
82.68 -// Class.forName(mainClass);
82.69 -// }
82.70 - }
82.71 - } catch (IOException ex) {
82.72 - set(classpath, i, ex);
82.73 - log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
82.74 - }
82.75 - }
82.76 - if (res != null) {
82.77 - byte[] checkRes;
82.78 - if (c instanceof Zips) {
82.79 - checkRes = ((Zips)c).findRes(res);
82.80 - if (checkRes != null && --skip < 0) {
82.81 - return checkRes;
82.82 - }
82.83 - } else {
82.84 - checkRes = callFunction(c, res, skip);
82.85 - if (checkRes != null) {
82.86 - return checkRes;
82.87 - }
82.88 - }
82.89 - }
82.90 - }
82.91 - return null;
82.92 - }
82.93 -
82.94 - @JavaScriptBody(args = { "fn", "res", "skip" }, body =
82.95 - "if (typeof fn === 'function') return fn(res, skip);\n"
82.96 - + "return null;"
82.97 - )
82.98 - private static native byte[] callFunction(Object fn, String res, int skip);
82.99 -
82.100 - @JavaScriptBody(args = { "msg" }, body = "if (typeof console !== 'undefined') console.log(msg.toString());")
82.101 - private static native void log(String msg);
82.102 -
82.103 - private byte[] findRes(String res) throws IOException {
82.104 - Object arr = findResImpl(res);
82.105 - if (arr instanceof FastJar.Entry) {
82.106 - long bef = timeNow();
82.107 - InputStream zip = fj.getInputStream((FastJar.Entry)arr);
82.108 - arr = readFully(new byte[512], zip);
82.109 - putRes(res, arr);
82.110 - log("Reading " + res + " took " + (timeNow() - bef) + "ms");
82.111 - }
82.112 - return (byte[]) arr;
82.113 - }
82.114 -
82.115 - @JavaScriptBody(args = { "res" }, body = "var r = this[res]; return r ? r : null;")
82.116 - private native Object findResImpl(String res);
82.117 -
82.118 - @JavaScriptBody(args = { "res", "arr" }, body = "this[res] = arr;")
82.119 - private native void putRes(String res, Object arr);
82.120 -
82.121 - private static Zips toZip(String path) throws IOException {
82.122 - URL u = new URL(path);
82.123 - byte[] zipData = (byte[]) u.getContent(new Class[] { byte[].class });
82.124 - return new Zips(path, zipData);
82.125 - }
82.126 -
82.127 - private static String processClassPathAttr(final byte[] man, String url, Object classpath) throws IOException {
82.128 - try (ParseMan is = new ParseMan(new ByteArrayInputStream(man))) {
82.129 - String cp = is.toString();
82.130 - if (cp != null) {
82.131 - cp = cp.trim();
82.132 - for (int p = 0; p < cp.length();) {
82.133 - int n = cp.indexOf(' ', p);
82.134 - if (n == -1) {
82.135 - n = cp.length();
82.136 - }
82.137 - String el = cp.substring(p, n);
82.138 - URL u = new URL(new URL(url), el);
82.139 - classpath = addToArray(classpath, u.toString());
82.140 - p = n + 1;
82.141 - }
82.142 - }
82.143 - return is.getMainClass();
82.144 - }
82.145 - }
82.146 -
82.147 - private static Object addToArray(Object arr, String value) {
82.148 - final int last = length(arr);
82.149 - Object ret = enlargeArray(arr, last + 1);
82.150 - set(ret, last, value);
82.151 - return ret;
82.152 - }
82.153 -
82.154 - @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(null); return arr;")
82.155 - private static native Object enlargeArray(Object arr, int len);
82.156 - @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(0);")
82.157 - private static native void enlargeBytes(byte[] arr, int len);
82.158 -
82.159 - @JavaScriptBody(args = { "arr", "len" }, body = "arr.splice(len, arr.length - len);")
82.160 - private static native void sliceArray(byte[] arr, int len);
82.161 -
82.162 - private static Object readFully(byte[] arr, InputStream zip) throws IOException {
82.163 - int offset = 0;
82.164 - for (;;) {
82.165 - int len = zip.read(arr, offset, arr.length - offset);
82.166 - if (len == -1) {
82.167 - break;
82.168 - }
82.169 - offset += len;
82.170 - if (offset == arr.length) {
82.171 - enlargeBytes(arr, arr.length + 4096);
82.172 - }
82.173 - }
82.174 - sliceArray(arr, offset);
82.175 - return arr;
82.176 - }
82.177 -
82.178 - private static long timeNow() {
82.179 - double time = m();
82.180 - if (time >= 0) {
82.181 - return (long)time;
82.182 - }
82.183 - return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
82.184 - }
82.185 - @JavaScriptBody(args = {}, body =
82.186 - "if (typeof window.performance === 'undefined') return -1;\n"
82.187 - + "if (typeof window.performance.now === 'undefined') return -1;\n"
82.188 - + "return window.performance.now();"
82.189 - )
82.190 - private static native double m();
82.191 -
82.192 -
82.193 -}
83.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java Tue May 06 17:46:47 2014 +0200
83.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java Sun May 11 14:01:18 2014 +0200
83.3 @@ -25,8 +25,7 @@
83.4
83.5 import java.io.IOException;
83.6 import java.io.InputStream;
83.7 -import static org.testng.Assert.assertEquals;
83.8 -import static org.testng.Assert.assertTrue;
83.9 +import static org.testng.Assert.*;
83.10 import org.testng.annotations.AfterClass;
83.11 import org.testng.annotations.BeforeClass;
83.12 import org.testng.annotations.Test;
83.13 @@ -52,6 +51,32 @@
83.14 assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
83.15 }
83.16
83.17 + @Test public void betterConstructor() {
83.18 + String s = code;
83.19 + int beg = s.indexOf("c.initInflater__IIZ");
83.20 + int end = s.indexOf("c.initInflater__IIZ.access");
83.21 +
83.22 + assertTrue(beg > 0, "Found initInflater method in " + code);
83.23 + assertTrue(beg < end, "Found end of initInflater method in " + code);
83.24 +
83.25 + String method = s.substring(beg, end);
83.26 +
83.27 + assertEquals(method.indexOf("stA1"), -1, "No need for stA1 register:\n" + method);
83.28 + }
83.29 +
83.30 + @Test public void deepConstructor() {
83.31 + String s = code;
83.32 + int beg = s.indexOf("c.intHolder__I");
83.33 + int end = s.indexOf("c.intHolder__I.access");
83.34 +
83.35 + assertTrue(beg > 0, "Found intHolder method in " + code);
83.36 + assertTrue(beg < end, "Found end of intHolder method in " + code);
83.37 +
83.38 + String method = s.substring(beg, end);
83.39 +
83.40 + assertEquals(method.indexOf("stA3"), -1, "No need for stA3 register on second constructor:\n" + method);
83.41 + }
83.42 +
83.43 @Test public void emptyConstructorRequiresNoStack() {
83.44 String s = code;
83.45 int beg = s.indexOf("CLS.cons__V");
84.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java Tue May 06 17:46:47 2014 +0200
84.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java Sun May 11 14:01:18 2014 +0200
84.3 @@ -142,6 +142,18 @@
84.4 return i.sum(nowrap?-w:w, 1);
84.5 }
84.6
84.7 + public static int intHolder() {
84.8 + return new IntHolder(new Integer(10)).i.intValue();
84.9 + }
84.10 +
84.11 + private static class IntHolder {
84.12 + Integer i;
84.13 +
84.14 + public IntHolder(Integer i) {
84.15 + this.i = i;
84.16 + }
84.17 + }
84.18 +
84.19 public static String toStringArr() {
84.20 class N implements Next {
84.21 int idx = 0;
85.1 --- a/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Tue May 06 17:46:47 2014 +0200
85.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Sun May 11 14:01:18 2014 +0200
85.3 @@ -18,8 +18,10 @@
85.4 package org.apidesign.bck2brwsr.vmtest.impl;
85.5
85.6 import java.io.IOException;
85.7 +import java.util.HashSet;
85.8 import java.util.LinkedHashMap;
85.9 import java.util.Map;
85.10 +import java.util.Set;
85.11 import org.apidesign.bck2brwsr.launcher.Launcher;
85.12 import org.testng.annotations.AfterGroups;
85.13 import org.testng.annotations.BeforeGroups;
85.14 @@ -44,7 +46,14 @@
85.15 if (js == null && create) {
85.16 final String p = System.getProperty("vmtest.js", "script"); // NOI18N
85.17 switch (p) {
85.18 - case "brwsr": js = Launcher.createBrowser(null); break; // NOI18N
85.19 + case "brwsr": // NOI18N
85.20 + String cmd = null;
85.21 + String pb = System.getProperty("vmtest.brwsrs"); // NOI18N
85.22 + if (pb != null) {
85.23 + cmd = pb.split(",")[0]; // NOI18N
85.24 + }
85.25 + js = brwsr(cmd);
85.26 + break;
85.27 case "script": js = Launcher.createJavaScript(); break; // NOI18N
85.28 default: throw new IllegalArgumentException(
85.29 "Unknown value of vmtest.js property: " + p
85.30 @@ -65,20 +74,22 @@
85.31
85.32 @BeforeGroups("run")
85.33 public void initializeLauncher() throws IOException {
85.34 + Set<Launcher> all = new HashSet<>(brwsrs.values());
85.35 if (js(false) != null) {
85.36 - js(true).initialize();
85.37 + all.add(js(true));
85.38 }
85.39 - for (Launcher launcher : brwsrs.values()) {
85.40 + for (Launcher launcher : all) {
85.41 launcher.initialize();
85.42 }
85.43 }
85.44
85.45 @AfterGroups("run")
85.46 public void shutDownLauncher() throws IOException, InterruptedException {
85.47 + Set<Launcher> all = new HashSet<>(brwsrs.values());
85.48 if (js(false) != null) {
85.49 - js(true).shutdown();
85.50 + all.add(js(true));
85.51 }
85.52 - for (Launcher launcher : brwsrs.values()) {
85.53 + for (Launcher launcher : all) {
85.54 launcher.shutdown();
85.55 }
85.56 }