List of usage examples for java.util.zip ZipOutputStream flush
public void flush() throws IOException
From source file:org.jboss.windup.util.RPMToZipTransformer.java
public static File convertRpmToZip(File file) throws Exception { LOG.info("File: " + file.getAbsolutePath()); FileInputStream fis = new FileInputStream(file); ReadableChannelWrapper in = new ReadableChannelWrapper(Channels.newChannel(fis)); InputStream uncompressed = new GZIPInputStream(fis); in = new ReadableChannelWrapper(Channels.newChannel(uncompressed)); String rpmZipName = file.getName(); rpmZipName = StringUtils.replace(rpmZipName, ".", "-"); rpmZipName = rpmZipName + ".zip"; String rpmZipPath = FilenameUtils.getFullPath(file.getAbsolutePath()); File rpmZipOutput = new File(rpmZipPath + File.separator + rpmZipName); LOG.info("Converting RPM: " + file.getName() + " to ZIP: " + rpmZipOutput.getName()); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(rpmZipOutput)); String rpmName = file.getName(); rpmName = StringUtils.replace(rpmName, ".", "-"); CpioHeader header;/*from w ww . j a v a2s . com*/ int total = 0; do { header = new CpioHeader(); total = header.read(in, total); if (header.getFileSize() > 0) { BoundedInputStream bis = new BoundedInputStream(uncompressed, header.getFileSize()); String relPath = FilenameUtils.separatorsToSystem(header.getName()); relPath = StringUtils.removeStart(relPath, "."); relPath = StringUtils.removeStart(relPath, "/"); relPath = rpmName + File.separator + relPath; relPath = StringUtils.replace(relPath, "\\", "/"); ZipEntry zipEntry = new ZipEntry(relPath); zos.putNextEntry(zipEntry); IOUtils.copy(bis, zos); } else { final int skip = header.getFileSize(); if (uncompressed.skip(skip) != skip) throw new RuntimeException("Skip failed."); } total += header.getFileSize(); } while (!header.isLast()); zos.flush(); zos.close(); return rpmZipOutput; }
From source file:org.eclairjs.nashorn.Utils.java
/** * Zip up all files (or those that match filesToInclude[]) under a directory into a zipfile with the given name. * @param folderToZip {String} folder containing files to zip * @param zipFile {String} zipfile name for destination * @param filesToInclude {String[]} files to include - if omitted everything under folder will be zipped * @throws FileNotFoundException folder to zip up not found * @throws IOException problem in creating zipfile *///from w ww .ja va 2 s . c om @SuppressWarnings({ "rawtypes", "unchecked" }) public static void zipFile(String folderToZip, String zipFile, String[] filesToInclude) throws FileNotFoundException, IOException { Logger logger = Logger.getLogger(Utils.class); logger.debug("zipFile: " + folderToZip); ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile)); boolean excludeContainingFolder = false; File srcFile = new File(folderToZip); if (excludeContainingFolder && srcFile.isDirectory()) { for (String fileName : srcFile.list()) { addToZip("", folderToZip + "/" + fileName, zipOut, filesToInclude); } } else { addToZip("", folderToZip, zipOut, filesToInclude); } zipOut.flush(); zipOut.close(); logger.debug("Successfully created zipFile: " + zipFile); }
From source file:org.geoserver.catalog.rest.DataStoreFileUploadTest.java
@Test public void testPropertyFileUploadZipped() throws Exception { byte[] bytes = propertyFile(); //compress/*from www . j av a 2s .c o m*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zout = new ZipOutputStream(out); zout.putNextEntry(new ZipEntry("pds.properties")); zout.write(bytes); zout.flush(); zout.close(); put("/rest/workspaces/gs/datastores/pds/file.properties", out.toByteArray(), "application/zip"); Document dom = getAsDOM("wfs?request=getfeature&typename=gs:pds"); assertFeatures(dom); }
From source file:org.rhq.helpers.bundleGen.BundleGen.java
/** * Copy a file to the passed Zip Output Stream * @param zos OutputStream for a new Zip file * @param filedir directory of the file to copy * @param fileName name of the file to copy * @throws IOException If anything here goes wrong. *//*from w w w . j a va2s. c o m*/ private void copyToOutputStream(ZipOutputStream zos, String filedir, String fileName) throws IOException { ZipEntry entry = new ZipEntry(fileName); zos.putNextEntry(entry); FileInputStream fis = new FileInputStream(new File(filedir, fileName)); try { StreamUtil.copy(fis, zos, false); zos.flush(); log.debug("Added [" + fileName + "]"); } finally { fis.close(); } }
From source file:uk.sipperfly.utils.ZipUtils.java
public void zipIt(String zipFile) { try {// w w w. j a va 2s .com ZipOutputStream zip = null; FileOutputStream fileWriter = null; fileWriter = new FileOutputStream(zipFile); zip = new ZipOutputStream(fileWriter); addFolderToZip("", sourceFolder, zip); zip.flush(); zip.close(); fileWriter.flush(); fileWriter.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ZipUtils.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(ZipUtils.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.coinblesk.client.backup.BackupDialogFragment.java
private void addZipEntry(String filename, byte[] data, ZipOutputStream zos) throws IOException { ZipEntry entry = new ZipEntry(filename); zos.putNextEntry(entry);/*from w w w. j av a 2 s .c o m*/ zos.write(data); zos.closeEntry(); zos.flush(); }
From source file:com.dbi.jmmerge.MapController.java
@RequestMapping(value = "maps/{server}", produces = "application/zip") public byte[] downloadMap(@PathVariable("server") String server, HttpServletResponse response) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bufstream = new BufferedOutputStream(baos); ZipOutputStream zip = new ZipOutputStream(bufstream); addDirectoryContents(null, new File(storageDir, server), zip); zip.finish();//from w w w . ja va2s .c o m zip.flush(); IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bufstream); IOUtils.closeQuietly(baos); response.setStatus(HttpServletResponse.SC_OK); response.addHeader("Content-Disposition", "attachment; filename=\"" + server + ".zip\""); return baos.toByteArray(); }
From source file:com.joliciel.talismane.machineLearning.linearsvm.LinearSVMModel.java
@Override public void writeDataToStream(ZipOutputStream zos) { try {// www . j a v a 2 s. co m zos.putNextEntry(new ZipEntry("featureIndexMap.obj")); ObjectOutputStream out = new ObjectOutputStream(zos); try { out.writeObject(featureIndexMap); } finally { out.flush(); } zos.flush(); zos.putNextEntry(new ZipEntry("outcomes.obj")); out = new ObjectOutputStream(zos); try { out.writeObject(outcomes); } finally { out.flush(); } zos.flush(); } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:com.intuit.tank.service.impl.v1.agent.AgentServiceV1.java
@Override @Nonnull/* w ww. j ava2s. c o m*/ public Response getSupportFiles() { ResponseBuilder responseBuilder = Response.ok(); // AuthUtil.checkLoggedIn(servletContext); final FileStorage fileStorage = FileStorageFactory.getFileStorage(new TankConfig().getJarDir(), false); final File harnessJar = new File(servletContext.getRealPath("/tools/" + HARNESS_JAR)); LOG.info("harnessJar = " + harnessJar.getAbsolutePath()); final List<FileData> files = fileStorage.listFileData(""); StreamingOutput streamingOutput = new StreamingOutput() { @Override public void write(OutputStream output) throws IOException, WebApplicationException { ZipOutputStream zip = new ZipOutputStream(output); try { boolean harnessJarExists = harnessJar.exists(); if (harnessJarExists) { addFileToZip(HARNESS_JAR, new FileInputStream(harnessJar), zip); zip.flush(); } for (FileData fileData : files) { if (harnessJarExists && fileData.getFileName().equals(HARNESS_JAR)) { LOG.info("Not adding harness because we found it in the war."); } else { addFileToZip(fileData.getFileName(), fileStorage.readFileData(fileData), zip); zip.flush(); } } } catch (Exception e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(zip); } } }; String filename = "agent-support-files.zip"; responseBuilder.header("Content-Disposition", "attachment; filename=\"" + filename + "\""); responseBuilder.entity(streamingOutput); return responseBuilder.build(); }
From source file:com.joliciel.talismane.parser.ParsingConstrainerImpl.java
@Override public void onCompleteParse() { if (this.transitionSystem == null) this.transitionSystem = TalismaneSession.getTransitionSystem(); if (this.file != null) { try {//from w w w .j ava2s. co m ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file, false)); zos.putNextEntry(new ZipEntry("ParsingConstrainer.obj")); ObjectOutputStream oos = new ObjectOutputStream(zos); try { oos.writeObject(this); } finally { oos.flush(); } zos.flush(); zos.close(); } catch (IOException ioe) { LogUtils.logError(LOG, ioe); throw new RuntimeException(ioe); } } }