280 while (i < n) { 281 int d = Math.min(n - i, 8192); 282 out.write(bs, i, d); 283 i += d; 284 } 285 } finally { 286 out.close(); 287 } 288 } 289 290 public static void mkdirs(File d, String what) 291 throws IOException 292 { 293 if (!d.mkdirs()) 294 throw new IOException(d + ": Cannot create " + what + " directory"); 295 } 296 297 private static class NonClosingInputStream 298 extends FilterInputStream 299 { 300 301 private NonClosingInputStream(InputStream out) { 302 super(out); 303 } 304 305 public void close() { } 306 307 } 308 309 public static InputStream nonClosingStream(InputStream out) { 310 return new NonClosingInputStream(out); 311 } 312 313 private static class JarEntryOutputStream 314 extends FilterOutputStream 315 { 316 317 CRC32 crc; 318 ByteArrayOutputStream baos; 319 CheckedOutputStream cos; 320 JarOutputStream jos; 321 boolean deflate; 322 String path; 323 324 private JarEntryOutputStream(JarOutputStream jos, 325 boolean deflate, 326 CRC32 crc, 327 ByteArrayOutputStream baos, 328 CheckedOutputStream cos, 329 String path) 330 { 331 super(cos); 332 this.jos = jos; 333 this.deflate = deflate; 334 this.crc = crc; 335 this.baos = baos; 336 this.cos = cos; 337 this.path = path; 338 } 339 340 public void close() throws IOException { 341 cos.close(); 342 JarEntry je = new JarEntry(path); 343 if (deflate) { 344 je.setMethod(JarEntry.DEFLATED); 345 } else { 346 je.setMethod(JarEntry.STORED); 347 je.setCrc(crc.getValue()); 348 je.setSize(baos.size()); 349 je.setCompressedSize(baos.size()); 350 } 351 jos.putNextEntry(je); 352 baos.writeTo(jos); 353 jos.closeEntry(); 354 } 355 356 } 357 358 public static JarEntryOutputStream 359 newOutputStream(JarOutputStream jos, boolean deflate, String path) 360 { 361 // Gee, dac, that zip API sure is broken, isn't it? 362 CRC32 crc = new CRC32(); 363 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 364 CheckedOutputStream cos = new CheckedOutputStream(baos, crc); 365 return new JarEntryOutputStream(jos, deflate, crc, baos, cos, path); 366 } 367 368 public static JarEntryOutputStream 369 newOutputStream(JarOutputStream jos, String path) 370 { 371 return newOutputStream(jos, false, path); 372 } 373 } | 280 while (i < n) { 281 int d = Math.min(n - i, 8192); 282 out.write(bs, i, d); 283 i += d; 284 } 285 } finally { 286 out.close(); 287 } 288 } 289 290 public static void mkdirs(File d, String what) 291 throws IOException 292 { 293 if (!d.mkdirs()) 294 throw new IOException(d + ": Cannot create " + what + " directory"); 295 } 296 297 private static class NonClosingInputStream 298 extends FilterInputStream 299 { 300 private NonClosingInputStream(InputStream out) { 301 super(out); 302 } 303 304 public void close() { } 305 } 306 307 public static InputStream nonClosingStream(InputStream out) { 308 return new NonClosingInputStream(out); 309 } 310 311 private static class JarEntryOutputStream 312 extends FilterOutputStream 313 { 314 315 CRC32 crc; 316 ByteArrayOutputStream baos; 317 CheckedOutputStream cos; 318 JarOutputStream jos; 319 boolean deflate; 320 String path; 321 322 private JarEntryOutputStream(JarOutputStream jos, boolean deflate, 323 CRC32 crc, ByteArrayOutputStream baos, 324 CheckedOutputStream cos, String path) 325 { 326 super(cos); 327 this.jos = jos; 328 this.deflate = deflate; 329 this.crc = crc; 330 this.baos = baos; 331 this.cos = cos; 332 this.path = path; 333 } 334 335 public void close() throws IOException { 336 cos.close(); 337 JarEntry je = new JarEntry(path); 338 if (deflate) { 339 je.setMethod(JarEntry.DEFLATED); 340 } else { 341 je.setMethod(JarEntry.STORED); 342 je.setCrc(crc.getValue()); 343 je.setSize(baos.size()); 344 je.setCompressedSize(baos.size()); 345 } 346 jos.putNextEntry(je); 347 baos.writeTo(jos); 348 jos.closeEntry(); 349 } 350 } 351 352 public static OutputStream newOutputStream(JarOutputStream jos, 353 boolean deflate, String path) 354 { 355 // Gee, dac, that zip API sure is broken, isn't it? 356 CRC32 crc = new CRC32(); 357 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 358 CheckedOutputStream cos = new CheckedOutputStream(baos, crc); 359 return new JarEntryOutputStream(jos, deflate, crc, baos, cos, path); 360 } 361 362 public static OutputStream newOutputStream(JarOutputStream jos, 363 String path) 364 { 365 return newOutputStream(jos, false, path); 366 } 367 } |