91 for (int i = 0; i < iterations; i++) { |
91 for (int i = 0; i < iterations; i++) { |
92 bb.putDouble(0, Math.random()); |
92 bb.putDouble(0, Math.random()); |
93 baos.write(bb.array(), 0, DATA_SIZE); |
93 baos.write(bb.array(), 0, DATA_SIZE); |
94 } |
94 } |
95 data = baos.toByteArray(); |
95 data = baos.toByteArray(); |
96 |
96 try (FileOutputStream fos = new FileOutputStream(largeFile); |
97 ZipOutputStream zos = new ZipOutputStream( |
97 BufferedOutputStream bos = new BufferedOutputStream(fos); |
98 new BufferedOutputStream(new FileOutputStream(largeFile))); |
98 ZipOutputStream zos = new ZipOutputStream(bos)) |
99 long length = 0; |
99 { |
100 while (length < fileSize) { |
100 long length = 0; |
101 ZipEntry ze = new ZipEntry("entry-" + length); |
101 while (length < fileSize) { |
102 lastEntryName = ze.getName(); |
102 ZipEntry ze = new ZipEntry("entry-" + length); |
103 zos.putNextEntry(ze); |
103 lastEntryName = ze.getName(); |
104 zos.write(data, 0, data.length); |
104 zos.putNextEntry(ze); |
105 zos.closeEntry(); |
105 zos.write(data, 0, data.length); |
106 length = largeFile.length(); |
106 zos.closeEntry(); |
|
107 length = largeFile.length(); |
|
108 } |
|
109 System.out.println("Last entry written is " + lastEntryName); |
107 } |
110 } |
108 System.out.println("Last entry written is " + lastEntryName); |
|
109 zos.close(); |
|
110 } |
111 } |
111 |
112 |
112 static void readLargeZip() throws Throwable { |
113 static void readLargeZip() throws Throwable { |
113 ZipFile zipFile = new ZipFile(largeFile); |
114 try (ZipFile zipFile = new ZipFile(largeFile)) { |
114 ZipEntry entry = null; |
115 ZipEntry entry = null; |
115 String entryName = null; |
116 String entryName = null; |
116 int count = 0; |
117 int count = 0; |
117 Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
118 Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
118 while (entries.hasMoreElements()) { |
119 while (entries.hasMoreElements()) { |
119 entry = entries.nextElement(); |
120 entry = entries.nextElement(); |
120 entryName = entry.getName(); |
121 entryName = entry.getName(); |
121 count++; |
122 count++; |
|
123 } |
|
124 System.out.println("Number of entries read: " + count); |
|
125 System.out.println("Last entry read is " + entryName); |
|
126 check(!entry.isDirectory()); |
|
127 if (check(entryName.equals(lastEntryName))) { |
|
128 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
129 InputStream is = zipFile.getInputStream(entry); |
|
130 byte buf[] = new byte[4096]; |
|
131 int len; |
|
132 while ((len = is.read(buf)) >= 0) { |
|
133 baos.write(buf, 0, len); |
|
134 } |
|
135 baos.close(); |
|
136 is.close(); |
|
137 check(Arrays.equals(data, baos.toByteArray())); |
|
138 } |
122 } |
139 } |
123 System.out.println("Number of entries read: " + count); |
|
124 System.out.println("Last entry read is " + entryName); |
|
125 check(!entry.isDirectory()); |
|
126 if (check(entryName.equals(lastEntryName))) { |
|
127 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
128 InputStream is = zipFile.getInputStream(entry); |
|
129 byte buf[] = new byte[4096]; |
|
130 int len; |
|
131 while ((len = is.read(buf)) >= 0) { |
|
132 baos.write(buf, 0, len); |
|
133 } |
|
134 baos.close(); |
|
135 is.close(); |
|
136 check(Arrays.equals(data, baos.toByteArray())); |
|
137 } |
|
138 try { |
|
139 zipFile.close(); |
|
140 } catch (IOException ioe) {/* what can you do */ } |
|
141 } |
140 } |
142 |
141 |
143 //--------------------- Infrastructure --------------------------- |
142 //--------------------- Infrastructure --------------------------- |
144 static volatile int passed = 0, failed = 0; |
143 static volatile int passed = 0, failed = 0; |
145 static void pass() {passed++;} |
144 static void pass() {passed++;} |