List of utility methods to do ZipEntry Add
void | addZipEntry(String pathName, byte[] contents, ZipOutputStream zos) Adds the zip entry. ZipEntry entry = new ZipEntry(pathName);
entry.setSize(contents.length);
zos.putNextEntry(entry);
zos.write(contents);
zos.closeEntry();
|
void | addZipEntry(ZipOutputStream zipOut, File file, String prefix) add Zip Entry byte[] buf = new byte[1024]; FileInputStream in = new FileInputStream(file); addZipEntryRecursive(zipOut, file, prefix); int len; while ((len = in.read(buf)) > 0) { zipOut.write(buf, 0, len); zipOut.closeEntry(); ... |
void | addZipEntry(ZipOutputStream zipOutputStream, File entryFile, String parentPath) add Zip Entry if (entryFile.isDirectory()) { String dirPath = parentPath + entryFile.getName() + PATH_SEPARATOR; File[] files = entryFile.listFiles(); if (files.length == 0) { zipOutputStream.putNextEntry(new ZipEntry(dirPath)); } else { for (int i = 0; i < files.length; i++) { addZipEntry(zipOutputStream, files[i], dirPath); ... |
void | addZipEntry(ZipOutputStream zos, File fileToZip, File baseFolder) Add a zip entry into the provided ZipOutputStream .
if (!baseFolder.isDirectory()) { throw new IllegalArgumentException(baseFolder.getPath() + " is not a directory."); if (fileToZip.isDirectory()) { final File[] files = fileToZip.listFiles(); for (final File file : files) { addZipEntry(zos, file, baseFolder); } else { final String filePathToZip; final int start; try { filePathToZip = fileToZip.getCanonicalPath(); start = baseFolder.getCanonicalPath().length() + 1; } catch (final IOException e1) { throw new IllegalStateException(e1); final int end = filePathToZip.length(); String entryName = filePathToZip.substring(start, end); entryName = entryName.replace(File.separatorChar, '/'); final FileInputStream inputStream; try { inputStream = new FileInputStream(filePathToZip); } catch (final FileNotFoundException e) { throw new IllegalStateException(e); addEntryInputStream(zos, entryName, inputStream); |
void | addZipEntryFromStream(InputStream is, ZipOutputStream os, String filename) add Zip Entry From Stream byte[] buf = new byte[INT]; os.putNextEntry(new ZipEntry(filename)); int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); os.closeEntry(); |
void | addZipEntryRecursive(ZipOutputStream zipOut, File file, String prefix) If the file is a file, it is added to the output stream with the given prefix. if (file.isDirectory()) { String[] files = file.list(); for (String filename : files) { addZipEntryRecursive(zipOut, new File(file, filename), prefix + file.getName() + "/"); } else { zipOut.putNextEntry(new ZipEntry(prefix + file.getName())); |