@Test public void testUnzipFile() { System.out.println("Test: " + "testUnzipFile"); File zipFile = new File(FileHelperTest.sampleDir + "test_zip.zip"); boolean result = false; try { result = FileHelper.unzipFile(this.tempDir, zipFile); } catch (FileNotFoundException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); fail(ex.getMessage()); } catch (IOException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); fail(ex.getMessage()); } assertTrue(result); }
public static boolean unzipFile(String outputDirectory, File zipFile) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = null; BufferedOutputStream dest = null; try { zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry = null; final int BUFFER = 2048; while ((entry = zis.getNextEntry()) != null) { String fileName = entry.getName(); int count = 0; byte data[] = new byte[BUFFER]; String destinationFileName = entry.getName().contains(File.pathSeparator) ? entry.getName().substring(entry.getName().lastIndexOf(File.pathSeparator)) : entry.getName(); String destinationPath = outputDirectory + java.io.File.separator + destinationFileName; FileOutputStream fos = new FileOutputStream(destinationPath); dest = new BufferedOutputStream(fos, BUFFER); log.debug(new StringBuilder("Unzipping: ").append(fileName).append(" to ").append(destinationPath).toString()); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); log.trace(new StringBuilder("Unzipped: ").append(fileName).append(" to ").append(destinationPath).toString()); } } finally { if (zis != null) { IOUtils.closeQuietly(zis); } if (dest != null) { IOUtils.closeQuietly(dest); } } return true; }
FileHelper { public static boolean unzipFile(String outputDirectory, File zipFile) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = null; BufferedOutputStream dest = null; try { zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry = null; final int BUFFER = 2048; while ((entry = zis.getNextEntry()) != null) { String fileName = entry.getName(); int count = 0; byte data[] = new byte[BUFFER]; String destinationFileName = entry.getName().contains(File.pathSeparator) ? entry.getName().substring(entry.getName().lastIndexOf(File.pathSeparator)) : entry.getName(); String destinationPath = outputDirectory + java.io.File.separator + destinationFileName; FileOutputStream fos = new FileOutputStream(destinationPath); dest = new BufferedOutputStream(fos, BUFFER); log.debug(new StringBuilder("Unzipping: ").append(fileName).append(" to ").append(destinationPath).toString()); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); log.trace(new StringBuilder("Unzipped: ").append(fileName).append(" to ").append(destinationPath).toString()); } } finally { if (zis != null) { IOUtils.closeQuietly(zis); } if (dest != null) { IOUtils.closeQuietly(dest); } } return true; } }
FileHelper { public static boolean unzipFile(String outputDirectory, File zipFile) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = null; BufferedOutputStream dest = null; try { zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry = null; final int BUFFER = 2048; while ((entry = zis.getNextEntry()) != null) { String fileName = entry.getName(); int count = 0; byte data[] = new byte[BUFFER]; String destinationFileName = entry.getName().contains(File.pathSeparator) ? entry.getName().substring(entry.getName().lastIndexOf(File.pathSeparator)) : entry.getName(); String destinationPath = outputDirectory + java.io.File.separator + destinationFileName; FileOutputStream fos = new FileOutputStream(destinationPath); dest = new BufferedOutputStream(fos, BUFFER); log.debug(new StringBuilder("Unzipping: ").append(fileName).append(" to ").append(destinationPath).toString()); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); log.trace(new StringBuilder("Unzipped: ").append(fileName).append(" to ").append(destinationPath).toString()); } } finally { if (zis != null) { IOUtils.closeQuietly(zis); } if (dest != null) { IOUtils.closeQuietly(dest); } } return true; }  }
FileHelper { public static boolean unzipFile(String outputDirectory, File zipFile) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = null; BufferedOutputStream dest = null; try { zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry = null; final int BUFFER = 2048; while ((entry = zis.getNextEntry()) != null) { String fileName = entry.getName(); int count = 0; byte data[] = new byte[BUFFER]; String destinationFileName = entry.getName().contains(File.pathSeparator) ? entry.getName().substring(entry.getName().lastIndexOf(File.pathSeparator)) : entry.getName(); String destinationPath = outputDirectory + java.io.File.separator + destinationFileName; FileOutputStream fos = new FileOutputStream(destinationPath); dest = new BufferedOutputStream(fos, BUFFER); log.debug(new StringBuilder("Unzipping: ").append(fileName).append(" to ").append(destinationPath).toString()); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); log.trace(new StringBuilder("Unzipped: ").append(fileName).append(" to ").append(destinationPath).toString()); } } finally { if (zis != null) { IOUtils.closeQuietly(zis); } if (dest != null) { IOUtils.closeQuietly(dest); } } return true; }  static byte[] base64Encode(final File input); static byte[] base64Encode(final byte[] input); static byte[] getByteArrayFromFile(File file); static boolean renameFile(final File fromFile, final String toFileName); static boolean copyFileToPath(final File inFile, final String outFilePath); static boolean copyFileToPath(final File inFile, final String outPath, boolean deleteOriginalFile); static Collection<File> wipeOldFiles(File directory, Long cutoffTime, boolean deleteDirectory); static boolean createDir(File directory); static boolean createDir(String directory); static boolean deleteDirRecursively(File directory); static boolean deleteDirRecursively(String directory); static boolean deleteFileQuietly(String filePath); static boolean deleteFileQuietly(File file); static boolean deleteFile(String filePath); static boolean deleteFile(File file); static boolean doesDirectoryOrFileExist(String filePath); static File findFile(String file, String rootPath); static List<String> getFileList(String filePath, boolean recursive); static List<String> getFileList(String filePath, String[] extensions, boolean recursive); static Collection<File> getFileCollection(String filePath, boolean recursive); static Collection<?> getFileCollection(String filePath, String[] extensions, boolean recursive); static String getSystemTemp(); static boolean zipDirectory(String inputDirectory, String absoluteFileName); static boolean unzipFile(String outputDirectory, File zipFile); static String createUserDirectory(String applicationUserSpaceDir); static boolean updateTimestamp(final String path, final boolean recursive); static Boolean validateShapeFile(final File shapeFile); static Boolean validateShapeZIP(final File shapeZip); }
FileHelper { public static boolean unzipFile(String outputDirectory, File zipFile) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = null; BufferedOutputStream dest = null; try { zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry = null; final int BUFFER = 2048; while ((entry = zis.getNextEntry()) != null) { String fileName = entry.getName(); int count = 0; byte data[] = new byte[BUFFER]; String destinationFileName = entry.getName().contains(File.pathSeparator) ? entry.getName().substring(entry.getName().lastIndexOf(File.pathSeparator)) : entry.getName(); String destinationPath = outputDirectory + java.io.File.separator + destinationFileName; FileOutputStream fos = new FileOutputStream(destinationPath); dest = new BufferedOutputStream(fos, BUFFER); log.debug(new StringBuilder("Unzipping: ").append(fileName).append(" to ").append(destinationPath).toString()); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); log.trace(new StringBuilder("Unzipped: ").append(fileName).append(" to ").append(destinationPath).toString()); } } finally { if (zis != null) { IOUtils.closeQuietly(zis); } if (dest != null) { IOUtils.closeQuietly(dest); } } return true; }  static byte[] base64Encode(final File input); static byte[] base64Encode(final byte[] input); static byte[] getByteArrayFromFile(File file); static boolean renameFile(final File fromFile, final String toFileName); static boolean copyFileToPath(final File inFile, final String outFilePath); static boolean copyFileToPath(final File inFile, final String outPath, boolean deleteOriginalFile); static Collection<File> wipeOldFiles(File directory, Long cutoffTime, boolean deleteDirectory); static boolean createDir(File directory); static boolean createDir(String directory); static boolean deleteDirRecursively(File directory); static boolean deleteDirRecursively(String directory); static boolean deleteFileQuietly(String filePath); static boolean deleteFileQuietly(File file); static boolean deleteFile(String filePath); static boolean deleteFile(File file); static boolean doesDirectoryOrFileExist(String filePath); static File findFile(String file, String rootPath); static List<String> getFileList(String filePath, boolean recursive); static List<String> getFileList(String filePath, String[] extensions, boolean recursive); static Collection<File> getFileCollection(String filePath, boolean recursive); static Collection<?> getFileCollection(String filePath, String[] extensions, boolean recursive); static String getSystemTemp(); static boolean zipDirectory(String inputDirectory, String absoluteFileName); static boolean unzipFile(String outputDirectory, File zipFile); static String createUserDirectory(String applicationUserSpaceDir); static boolean updateTimestamp(final String path, final boolean recursive); static Boolean validateShapeFile(final File shapeFile); static Boolean validateShapeZIP(final File shapeZip);  }