Mercurial > dive4elements > framework
comparison artifacts-common/src/main/java/de/intevation/artifacts/common/utils/FileTools.java @ 435:e39e23320a23
Fixed small problem with extractiong zip files.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sat, 06 Oct 2012 14:20:40 +0200 |
parents | c40729bfe06d |
children | b79a3598818c |
comparison
equal
deleted
inserted
replaced
434:403a6793077c | 435:e39e23320a23 |
---|---|
356 if (!destDir.exists()) { | 356 if (!destDir.exists()) { |
357 destDir.mkdir(); | 357 destDir.mkdir(); |
358 } | 358 } |
359 | 359 |
360 ZipFile zipFile = new ZipFile(archive); | 360 ZipFile zipFile = new ZipFile(archive); |
361 Enumeration entries = zipFile.entries(); | 361 try { |
362 | 362 Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
363 byte[] buffer = new byte[16384]; | 363 |
364 int len; | 364 byte [] buffer = new byte[16384]; |
365 while (entries.hasMoreElements()) { | 365 |
366 ZipEntry entry = (ZipEntry) entries.nextElement(); | 366 while (entries.hasMoreElements()) { |
367 | 367 ZipEntry entry = entries.nextElement(); |
368 String entryFileName = entry.getName(); | 368 |
369 | 369 String entryFileName = entry.getName(); |
370 File dir = dir = buildDirectoryHierarchyFor(entryFileName, destDir); | 370 |
371 if (!dir.exists()) { | 371 File dir = buildDirectoryHierarchyFor(entryFileName, destDir); |
372 dir.mkdirs(); | 372 if (!dir.exists()) { |
373 } | 373 dir.mkdirs(); |
374 | 374 } |
375 if (!entry.isDirectory()) { | 375 |
376 BufferedOutputStream bos = new BufferedOutputStream( | 376 if (!entry.isDirectory()) { |
377 new FileOutputStream(new File(destDir, entryFileName))); | 377 BufferedInputStream bis = new BufferedInputStream( |
378 | 378 zipFile.getInputStream(entry)); |
379 BufferedInputStream bis = new BufferedInputStream(zipFile | 379 try { |
380 .getInputStream(entry)); | 380 BufferedOutputStream bos = new BufferedOutputStream( |
381 | 381 new FileOutputStream(new File(destDir, entryFileName))); |
382 while ((len = bis.read(buffer)) > 0) { | 382 |
383 bos.write(buffer, 0, len); | 383 try { |
384 } | 384 int len; |
385 | 385 while ((len = bis.read(buffer)) > 0) { |
386 bos.flush(); | 386 bos.write(buffer, 0, len); |
387 bos.close(); | 387 } |
388 bis.close(); | 388 bos.flush(); |
389 } | 389 } |
390 } | 390 finally { |
391 zipFile.close(); | 391 bos.close(); |
392 } | |
393 } | |
394 finally { | |
395 bis.close(); | |
396 } | |
397 } // is file | |
398 } | |
399 } | |
400 finally { | |
401 zipFile.close(); | |
402 } | |
392 } | 403 } |
393 | 404 |
394 private static File buildDirectoryHierarchyFor( | 405 private static File buildDirectoryHierarchyFor( |
395 String entryName, | 406 String entryName, |
396 File destDir) | 407 File destDir) |
397 { | 408 { |
398 int lastIndex = entryName.lastIndexOf('/'); | 409 int lastIndex = entryName.lastIndexOf('/'); |
399 String entryFileName = entryName.substring(lastIndex + 1); | |
400 String internalPathToEntry = entryName.substring(0, lastIndex + 1); | 410 String internalPathToEntry = entryName.substring(0, lastIndex + 1); |
401 return new File(destDir, internalPathToEntry); | 411 return new File(destDir, internalPathToEntry); |
402 } | 412 } |
403 | 413 |
404 /** | 414 /** |