97 }
98 }
99
100 static void test(String csn, String name, String comment)
101 throws Exception
102 {
103 byte[] bb = "This is the content of the zipfile".getBytes("ISO-8859-1");
104 Charset cs = Charset.forName(csn);
105 ByteArrayOutputStream baos = new ByteArrayOutputStream();
106 try (ZipOutputStream zos = new ZipOutputStream(baos, cs)) {
107 ZipEntry e = new ZipEntry(name);
108 e.setComment(comment);
109 zos.putNextEntry(e);
110 zos.write(bb, 0, bb.length);
111 zos.closeEntry();
112 }
113 ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
114 testZipInputStream(bis, cs, name, comment, bb);
115
116 if ("utf-8".equals(csn)) {
117 // EFS should be set
118 bis.reset();
119 testZipInputStream(bis, Charset.forName("MS932"), name, comment, bb);
120 }
121
122 File f = new File(new File(System.getProperty("test.dir", ".")),
123 "zfcoding.zip");
124 try (FileOutputStream fos = new FileOutputStream(f)) {
125 baos.writeTo(fos);
126 }
127 testZipFile(f, cs, name, comment, bb);
128 if ("utf-8".equals(csn)) {
129 testZipFile(f, Charset.forName("MS932"), name, comment, bb);
130 }
131 f.delete();
132 }
133 }
|
97 }
98 }
99
100 static void test(String csn, String name, String comment)
101 throws Exception
102 {
103 byte[] bb = "This is the content of the zipfile".getBytes("ISO-8859-1");
104 Charset cs = Charset.forName(csn);
105 ByteArrayOutputStream baos = new ByteArrayOutputStream();
106 try (ZipOutputStream zos = new ZipOutputStream(baos, cs)) {
107 ZipEntry e = new ZipEntry(name);
108 e.setComment(comment);
109 zos.putNextEntry(e);
110 zos.write(bb, 0, bb.length);
111 zos.closeEntry();
112 }
113 ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
114 testZipInputStream(bis, cs, name, comment, bb);
115
116 if ("utf-8".equals(csn)) {
117 // USE_UTF8 should be set
118 bis.reset();
119 testZipInputStream(bis, Charset.forName("MS932"), name, comment, bb);
120 }
121
122 File f = new File(new File(System.getProperty("test.dir", ".")),
123 "zfcoding.zip");
124 try (FileOutputStream fos = new FileOutputStream(f)) {
125 baos.writeTo(fos);
126 }
127 testZipFile(f, cs, name, comment, bb);
128 if ("utf-8".equals(csn)) {
129 testZipFile(f, Charset.forName("MS932"), name, comment, bb);
130 }
131 f.delete();
132 }
133 }
|