List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:localization.split.java
public static Vector<String> readzipfile(String filepath) { Vector<String> v = new Vector<String>(); byte[] buffer = new byte[1024]; String outputFolder = filepath.substring(0, filepath.lastIndexOf(".")); System.out.println(outputFolder); try {//from ww w . jav a 2s . c om File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(new FileInputStream(filepath)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + "\\" + fileName); v.addElement(newFile.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (Exception e) { } return v; }
From source file:ZipFileUtil.java
/** * @param zipFile//from w w w . j a va 2 s . c o m * @param jiniHomeParentDir */ public static void unzipFileIntoDirectory(ZipFile zipFile, File jiniHomeParentDir) { Enumeration files = zipFile.entries(); File f = null; FileOutputStream fos = null; while (files.hasMoreElements()) { try { ZipEntry entry = (ZipEntry) files.nextElement(); InputStream eis = zipFile.getInputStream(entry); byte[] buffer = new byte[1024]; int bytesRead = 0; f = new File(jiniHomeParentDir.getAbsolutePath() + File.separator + entry.getName()); if (entry.isDirectory()) { f.mkdirs(); continue; } else { f.getParentFile().mkdirs(); f.createNewFile(); } fos = new FileOutputStream(f); while ((bytesRead = eis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } catch (IOException e) { e.printStackTrace(); continue; } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { // ignore } } } } }
From source file:com.jcalvopinam.core.Unzipping.java
private static void joinAndUnzipFile(File inputFile, CustomFile customFile) throws IOException { ZipInputStream is = null;/* w w w . jav a2 s . co m*/ File path = inputFile.getParentFile(); List<InputStream> fileInputStream = new ArrayList<>(); for (String fileName : path.list()) { if (fileName.startsWith(customFile.getFileName()) && fileName.endsWith(Extensions.ZIP.getExtension())) { fileInputStream.add(new FileInputStream(String.format("%s%s", customFile.getPath(), fileName))); System.out.println(String.format("File found: %s", fileName)); } } if (fileInputStream.size() > 0) { String fileNameOutput = String.format("%s%s", customFile.getPath(), customFile.getFileName()); OutputStream os = new BufferedOutputStream(new FileOutputStream(fileNameOutput)); try { System.out.println("Please wait while the files are joined: "); ZipEntry ze; for (InputStream inputStream : fileInputStream) { is = new ZipInputStream(inputStream); ze = is.getNextEntry(); customFile.setFileName(String.format("%s_%s", REBUILT, ze.getName())); byte[] buffer = new byte[CustomFile.BYTE_SIZE]; for (int readBytes; (readBytes = is.read(buffer, 0, CustomFile.BYTE_SIZE)) > -1;) { os.write(buffer, 0, readBytes); System.out.print("."); } } } finally { os.flush(); os.close(); is.close(); renameFinalFile(customFile, fileNameOutput); } } else { throw new FileNotFoundException("Error: The file not exist!"); } System.out.println("\nEnded process!"); }
From source file:b2s.idea.mavenize.JarCombiner.java
private static void copyContentsOf(File input, ZipOutputStream output, JarContext context) throws IOException { ZipFile zip = null;// ww w. j a v a 2s. c o m try { zip = new ZipFile(input); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (fileCanBeIgnored(entry, context)) { continue; } if (isServiceEntry(entry)) { context.addService(entry.getName(), contentsOf(entry, zip)); continue; } output.putNextEntry(new ZipEntry(entry.getName())); output.write(contentsOf(entry, zip)); output.flush(); output.closeEntry(); context.addVisitedEntry(entry); } } finally { close(zip); } }
From source file:com.nuvolect.securesuite.util.OmniZip.java
public static List<String> getFilesList(OmniFile zipOmni) { ZipInputStream zis = new ZipInputStream(zipOmni.getFileInputStream()); List<String> arrayList = new ArrayList<>(); ZipEntry entry = null; try {//from w ww . ja v a 2 s . co m while ((entry = zis.getNextEntry()) != null) { arrayList.add(entry.getName()); } zis.close(); } catch (IOException e) { LogUtil.logException(LogUtil.LogType.OMNI_ZIP, e); } return arrayList; }
From source file:Main.java
private static void extractFileToPath(ZipFile nar, String targetPath, ZipEntry e, boolean ignorename, boolean strip) throws FileNotFoundException, IOException { File f = null;/* w ww. j a v a2 s . c o m*/ if (ignorename) f = new File(targetPath); else { f = new File(targetPath + "/" + (strip ? stripExtraLevel(e.getName()) : e.getName())); } File fP = f.getParentFile(); if (fP != null && fP.exists() == false) { boolean s = fP.mkdirs(); Log.d(TAG, "fp make" + s); } FileOutputStream os = new FileOutputStream(f); InputStream is = nar.getInputStream(e); copyFile(is, os); }
From source file:de.micromata.genome.gdbfs.FileSystemUtils.java
/** * Copy from zip.// w w w . j a va2 s.c o m * * @param ze the ze * @param zin the zin * @param target the target */ public static void copyFromZip(ZipEntry ze, ZipInputStream zin, FsObject target) { String name = ze.getName(); name = normalizeZipName(name); ze.getTime(); if (name.endsWith("/") == true) { String fqName = mergeDirNames(target.getName(), name); fqName = fqName.substring(0, fqName.length() - 1); if (target.getFileSystem().existsForWrite(fqName) == true) { return; } target.getFileSystem().mkdirs(fqName); } else { String fqName = mergeDirNames(target.getName(), name); String pd = AbstractFileSystem.getParentDirString(fqName); if (target.getFileSystem().exists(pd) == false) { target.getFileSystem().mkdirs(pd); } target.getFileSystem().writeBinaryFile(fqName, zin, true); } }
From source file:ZipUtil.java
public static void unZipZipFileToLocation(File zipFile, File targetDir) throws IOException { if (!targetDir.isDirectory()) { throw new Exception("Target is not a directory."); }/*from www .j a va2 s .c o m*/ FileInputStream flInStr = new FileInputStream(zipFile); try { ZipInputStream zis = new ZipInputStream(flInStr); try { ZipEntry entry = null; while ((entry = zis.getNextEntry()) != null) { String name = entry.getName(); File newFile = new File(targetDir, name); if (entry.isDirectory() && !newFile.exists()) { newFile.mkdirs(); } else if (!entry.isDirectory()) { if (newFile.exists()) { newFile.delete(); } File parentDir = newFile.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); } FileOutputStream stmOut = new FileOutputStream(newFile); try { simpleInputStreamToOutputStream(zis, stmOut); } finally { stmOut.close(); } } } //end while. } finally { zis.close(); } } finally { flInStr.close(); } }
From source file:com.twinsoft.convertigo.engine.util.ZipUtils.java
/*** Added by julienda - 08/09/2012 * Return the project name by reading the first directory into the archive (.car) * @param path: the archive path/* w w w . j a v a2 s .co m*/ * @return filename: the project name * @throws IOException */ public static String getProjectName(String path) throws IOException { Engine.logEngine.trace("PATH: " + path); ZipInputStream zis = new ZipInputStream(new FileInputStream(path)); ZipEntry ze = null; String fileName = null; try { if ((ze = zis.getNextEntry()) != null) { fileName = ze.getName().replaceAll("/.*", ""); Engine.logEngine.trace("ZipUtils.getProjectName() - fileName: " + fileName); } } finally { zis.close(); } return fileName; }
From source file:net.sf.jasperreports.samples.wizards.SampleNewWizard.java
public static void unpackArchive(File theFile, File targetDir, IProgressMonitor monitor, Set<String> cpaths, Set<String> lpaths) { byte[] buffer = new byte[1024]; ZipInputStream zis = null;// w w w . jav a2 s.c o m try { zis = new ZipInputStream(new FileInputStream(theFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { File file = new File(targetDir, File.separator + ze.getName()); new File(file.getParent()).mkdirs(); String fname = file.getName(); if (ze.isDirectory()) { if (fname.equals("src")) cpaths.add(ze.getName()); } else { FileOutputStream fos = new FileOutputStream(file); int len; while ((len = zis.read(buffer)) > 0) fos.write(buffer, 0, len); fos.close(); } if (file.getParentFile().getName().equals("lib") && (fname.endsWith(".jar") || fname.endsWith(".zip"))) lpaths.add(ze.getName()); if (monitor.isCanceled()) { zis.close(); return; } ze = zis.getNextEntry(); } } catch (IOException e) { e.printStackTrace(); } finally { try { zis.closeEntry(); zis.close(); } catch (IOException e) { e.printStackTrace(); } } }