Skip to content

Commit baa9a64

Browse files
committed
GZip tests failing in Java
1 parent cf74c31 commit baa9a64

File tree

2 files changed

+63
-36
lines changed

2 files changed

+63
-36
lines changed
16.5 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/test/Test_Zipin.java

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,98 @@
55
import java.io.FileInputStream;
66
import java.io.InputStream;
77
import java.net.URL;
8+
import java.util.Arrays;
89
import java.util.zip.GZIPInputStream;
910
import java.util.zip.ZipEntry;
1011
import java.util.zip.ZipInputStream;
1112

13+
import javajs.util.AU;
1214
import javajs.util.Rdr;
1315
import javajs.util.ZipTools;
1416

1517
public class Test_Zipin extends Test_ {
1618

19+
static boolean j2sHeadless = true;
20+
1721
@SuppressWarnings("unused")
1822
public static void main(String[] args) {
1923

2024
try {
21-
2225

2326
InputStream is = Test_Zipin.class.getResourceAsStream("3c9k.xml.gz");
24-
GZIPInputStream gzis = new GZIPInputStream(is, 8096);
25-
String s = new String((byte[]) Rdr.getStreamAsBytes(new BufferedInputStream(gzis), null), "utf-8");
27+
28+
System.out.println("unzipping");
29+
GZIPInputStream gzis = new GZIPInputStream(is, 8096);
30+
BufferedInputStream gis = new BufferedInputStream(gzis);
31+
byte[] buf = new byte[8096];
32+
byte[] bytes = new byte[buf.length];
33+
int len = 0;
34+
int totalLen = 0;
35+
while ((len = gis.read(buf, 0, buf.length)) > 0) {
36+
totalLen += len;
37+
if (totalLen >= bytes.length)
38+
bytes = Arrays.copyOf(bytes, bytes.length << 1);
39+
System.arraycopy(buf, 0, bytes, totalLen - len, len);
40+
}
41+
gis.close();
42+
if (bytes.length > totalLen) {
43+
bytes = Arrays.copyOf(bytes, totalLen);
44+
}
45+
String s = new String(bytes);
2646
System.out.println(s.length());
2747
assert (s.length() == 2957648);
2848
gzis.close();
2949

30-
3150
InputStream bzis = Test_Zipin.class.getResourceAsStream("test2.txt.bz2");
3251
bzis = ZipTools.newBZip2InputStream(bzis);
3352
s = new String((byte[]) Rdr.getStreamAsBytes(new BufferedInputStream(bzis), null), "utf-8");
3453
System.out.println(s);
3554
assert (s.equals("test2 here"));
3655
bzis.close();
56+
3757

38-
String path = (/** @j2sNative 1?"https://./swingjs/j2s/test/t.zip": */
39-
"https://chemapps.stolaf.edu/jmol/jsmol/data/sage.zip");
40-
URL url = new URL(path);
41-
System.out.println("getting " + url);
42-
InputStream fis = url.openStream();
43-
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
44-
ZipEntry ze = zis.getNextEntry();
45-
String test = ze.getName() + " " + ze.getSize();
46-
System.out.println(test);
47-
assert (test.equals("[Content_Types].xml 1548") || test.equals("obj_490758.pmesh 95301"));// "obj_490758.pmesh
48-
// 95301"));
49-
int hashcode = 0;
50-
byte[] bytes = null;
51-
out: while (ze != null) {
52-
while ((ze = zis.getNextEntry()) != null && ze.isDirectory()) {
53-
}
54-
;
55-
if (ze.getName().equals("xl/calcChain.xml")) {
56-
bytes = new byte[(int) ze.getSize()];
57-
zis.read(bytes);
58-
break out;
59-
}
60-
}
61-
zis.close();
62-
s = new String(bytes);
63-
hashcode = s.hashCode();
64-
System.out.println("hashcode = " + hashcode);
6558
if (/** @j2sNative true || */
66-
false) {
67-
bytes = ze.getBytes();
59+
false) {
60+
61+
62+
63+
String path = (/** @j2sNative 1?"https://./swingjs/j2s/test/t.zip": */
64+
"https://chemapps.stolaf.edu/jmol/jsmol/data/sage.zip");
65+
URL url = new URL(path);
66+
System.out.println("getting " + url);
67+
InputStream fis = url.openStream();
68+
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
69+
ZipEntry ze = zis.getNextEntry();
70+
String test = ze.getName() + " " + ze.getSize();
71+
System.out.println(test);
72+
assert (test.equals("[Content_Types].xml 1548") || test.equals("obj_490758.pmesh 95301"));// "obj_490758.pmesh
73+
// 95301"));
74+
int hashcode = 0;
75+
bytes = null;
76+
out: while (ze != null) {
77+
while ((ze = zis.getNextEntry()) != null && ze.isDirectory()) {
78+
System.out.println(ze.getName());
79+
}
80+
;
81+
System.out.println(ze.getName());
82+
if (ze.getName().equals("xl/calcChain.xml")) {
83+
bytes = new byte[(int) ze.getSize()];
84+
zis.read(bytes);
85+
break out;
86+
}
87+
}
88+
zis.close();
6889
s = new String(bytes);
69-
System.out.println("hashcode = " + s.hashCode());
70-
assert(s.hashCode() == hashcode);
90+
hashcode = s.hashCode();
91+
System.out.println("hashcode = " + hashcode);
92+
if (/** @j2sNative true || */
93+
false) {
94+
bytes = ze.getBytes();
95+
s = new String(bytes);
96+
System.out.println("hashcode = " + s.hashCode());
97+
assert (s.hashCode() == hashcode);
98+
}
7199
}
72-
73100
System.out.println("Test_Zipin OK");
74101
} catch (Exception e) {
75102
e.printStackTrace();

0 commit comments

Comments
 (0)