List of usage examples for java.util.zip ZipOutputStream write
public synchronized void write(byte[] b, int off, int len) throws IOException
From source file:org.egov.wtms.web.controller.reports.GenerateConnectionBillController.java
private ZipOutputStream addFilesToZip(final InputStream inputStream, final String noticeNo, final ZipOutputStream out) { final byte[] buffer = new byte[1024]; try {/*from w w w.ja v a2 s . c o m*/ out.setLevel(Deflater.DEFAULT_COMPRESSION); out.putNextEntry(new ZipEntry(noticeNo.replaceAll("/", "_"))); int len; while ((len = inputStream.read(buffer)) > 0) out.write(buffer, 0, len); inputStream.close(); } catch (final IllegalArgumentException iae) { LOGGER.error("Exception in addFilesToZip : ", iae); } catch (final FileNotFoundException fnfe) { LOGGER.error("Exception in addFilesToZip : ", fnfe); } catch (final IOException ioe) { LOGGER.error("Exception in addFilesToZip : ", ioe); } return out; }
From source file:jeffaschenk.tomcat.instance.generator.builders.TomcatInstanceBuilderHelper.java
/** * Zip File into Archive/* w w w . j ava 2 s .c om*/ * * @param GENERATION_LOGGER Reference * @param zipFilePath Zip file Destination. * @param fileFolder Folder to be zipped Up ... * @throws IOException */ protected static boolean zipFile(GenerationLogger GENERATION_LOGGER, String zipFilePath, String fileFolder) throws IOException { /** * First get All Nodes with Folder */ List<String> fileList = new ArrayList<>(); generateFileListForCompression(new File(fileFolder), fileList); File sourceFolder = new File(fileFolder); byte[] buffer = new byte[8192]; try { FileOutputStream fos = new FileOutputStream(zipFilePath); ZipOutputStream zos = new ZipOutputStream(fos); GENERATION_LOGGER.info("Compressing Instance Generation to Zip: " + zipFilePath); /** * Loop Over Files */ for (String filename : fileList) { String zipEntryName = filename.substring(sourceFolder.getParent().length() + 1, filename.length()); ZipEntry ze = new ZipEntry(zipEntryName); zos.putNextEntry(ze); FileInputStream in = new FileInputStream(filename); int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); } in.close(); GENERATION_LOGGER.debug("File Added to Archive: " + zipEntryName); } /** * Close */ zos.closeEntry(); zos.close(); return true; } catch (IOException ex) { GENERATION_LOGGER.error(ex.getMessage()); ex.printStackTrace(); return false; } }
From source file:com.Candy.center.AboutCandy.java
private boolean zip() { String[] source = { systemfile, logfile, last_kmsgfile, kmsgfile }; try {/*from w w w.j a va2s . c om*/ ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile)); for (int i = 0; i < source.length; i++) { String file = source[i].substring(source[i].lastIndexOf("/"), source[i].length()); FileInputStream in = new FileInputStream(source[i]); out.putNextEntry(new ZipEntry(file)); int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); in.close(); } out.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:br.univali.celine.lms.utils.zip.Zip.java
private void addDir(File dirObj, ZipOutputStream out, int rootLen) throws IOException { File[] files = dirObj.listFiles(); byte[] tmpBuf = new byte[1024]; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { addDir(files[i], out, rootLen); continue; }//from w ww. j a v a 2 s. c o m FileInputStream in = new FileInputStream(files[i].getAbsolutePath()); out.putNextEntry(new ZipEntry(files[i].getAbsolutePath().substring(rootLen))); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } out.closeEntry(); in.close(); } }
From source file:org.dbgl.util.FileUtils.java
public static void zipEntry(final File orgFile, final File fileEntry, final ZipOutputStream zos) throws IOException { ZipEntry anEntry = new ZipEntry(PlatformUtils.toArchivePath(fileEntry, orgFile.isDirectory())); anEntry.setTime(orgFile.lastModified()); if (orgFile.isFile() && !orgFile.canWrite()) anEntry.setExtra(new byte[] { 1 }); zos.putNextEntry(anEntry);//from w ww.j a v a2s.c om if (orgFile.isFile()) { byte[] readBuffer = new byte[ZIP_BUFFER]; int bytes = 0; FileInputStream is = new FileInputStream(orgFile); while ((bytes = is.read(readBuffer)) != -1) zos.write(readBuffer, 0, bytes); is.close(); } zos.closeEntry(); }
From source file:io.fabric8.maven.generator.springboot.SpringBootGenerator.java
private void copyFilesToFatJar(List<File> libs, List<File> classes, File target) throws IOException { File tmpZip = File.createTempFile(target.getName(), null); tmpZip.delete();//w w w. ja v a2 s. com // Using Apache commons rename, because renameTo has issues across file systems FileUtils.moveFile(target, tmpZip); byte[] buffer = new byte[8192]; ZipInputStream zin = new ZipInputStream(new FileInputStream(tmpZip)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target)); for (ZipEntry ze = zin.getNextEntry(); ze != null; ze = zin.getNextEntry()) { if (matchesFatJarEntry(libs, ze.getName(), true) || matchesFatJarEntry(classes, ze.getName(), false)) { continue; } out.putNextEntry(ze); for (int read = zin.read(buffer); read > -1; read = zin.read(buffer)) { out.write(buffer, 0, read); } out.closeEntry(); } for (File lib : libs) { try (InputStream in = new FileInputStream(lib)) { out.putNextEntry(createZipEntry(lib, getFatJarFullPath(lib, true))); for (int read = in.read(buffer); read > -1; read = in.read(buffer)) { out.write(buffer, 0, read); } out.closeEntry(); } } for (File cls : classes) { try (InputStream in = new FileInputStream(cls)) { out.putNextEntry(createZipEntry(cls, getFatJarFullPath(cls, false))); for (int read = in.read(buffer); read > -1; read = in.read(buffer)) { out.write(buffer, 0, read); } out.closeEntry(); } } out.close(); tmpZip.delete(); }
From source file:edu.jhuapl.graphs.controller.GraphController.java
public static String zipGraphs(List<GraphObject> graphs, String tempDir, String userId) throws GraphException { if (graphs != null && graphs.size() > 0) { byte[] byteBuffer = new byte[1024]; String zipFileName = getUniqueId(userId) + ".zip"; try {/*w w w . j a va 2 s .c o m*/ File zipFile = new File(tempDir, zipFileName); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); boolean hasGraphs = false; for (GraphObject graph : graphs) { if (graph != null) { byte[] renderedGraph = graph.getRenderedGraph().getData(); ByteArrayInputStream in = new ByteArrayInputStream(renderedGraph); int len; zos.putNextEntry(new ZipEntry(graph.getImageFileName())); while ((len = in.read(byteBuffer)) > 0) { zos.write(byteBuffer, 0, len); } in.close(); zos.closeEntry(); hasGraphs = true; } } zos.close(); if (hasGraphs) { return zipFileName; } else { return null; } } catch (IOException e) { throw new GraphException("Could not write zip", e); } } return null; }
From source file:edu.harvard.iq.dvn.core.analysis.NetworkDataServiceBean.java
private void addZipEntry(ZipOutputStream zout, String inputFileName, String outputFileName) throws IOException { FileInputStream tmpin = new FileInputStream(inputFileName); byte[] dataBuffer = new byte[8192]; int i = 0;//from ww w. j a v a 2 s . co m ZipEntry e = new ZipEntry(outputFileName); zout.putNextEntry(e); while ((i = tmpin.read(dataBuffer)) > 0) { zout.write(dataBuffer, 0, i); zout.flush(); } tmpin.close(); zout.closeEntry(); }
From source file:org.candlepin.sync.Exporter.java
private void addSignatureToArchive(ZipOutputStream out, byte[] signature) throws IOException, FileNotFoundException { log.debug("Adding signature to archive."); out.putNextEntry(new ZipEntry("signature")); out.write(signature, 0, signature.length); out.closeEntry();/*from w w w . j ava 2 s . c om*/ }
From source file:nc.noumea.mairie.appock.services.impl.ExportExcelServiceImpl.java
private void addToZipFile(File file, String nomFichier, ZipOutputStream zos) throws IOException { FileInputStream fis = new FileInputStream(file); ZipEntry zipEntry = new ZipEntry(nomFichier); zos.putNextEntry(zipEntry);/*from w ww .j av a 2s . c o m*/ byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); fis.close(); }