List of usage examples for java.util.zip ZipOutputStream closeEntry
public void closeEntry() throws IOException
From source file:com.fredhopper.core.connector.index.FileUtils.java
public static void addToZipFile(final File file, final ZipOutputStream zos) throws IOException { final FileInputStream fis = new FileInputStream(file); final ZipEntry zipEntry = new ZipEntry(file.getName()); zos.putNextEntry(zipEntry);//from w w w. ja va 2 s . c o m final byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); fis.close(); }
From source file:io.lavagna.service.LavagnaExporter.java
private static void writeEntry(String entryName, Object toSerialize, ZipOutputStream zf, OutputStreamWriter osw) { try {//from w ww. j a va 2s . com zf.putNextEntry(new ZipEntry(entryName)); Json.GSON.toJson(toSerialize, osw); osw.flush(); zf.flush(); zf.closeEntry(); } catch (IOException ioe) { throw new IllegalStateException("error while serializing entry " + entryName, ioe); } }
From source file:org.apache.hadoop.hive.ql.metadata.JarUtils.java
private static void copyToZipStream(InputStream is, ZipEntry entry, ZipOutputStream zos) throws IOException { zos.putNextEntry(entry);// www. j av a 2 s . c om IOUtils.copy(is, zos); is.close(); zos.closeEntry(); }
From source file:com.youTransactor.uCube.LogManager.java
public static void getLogs(OutputStream out) throws IOException { File logDir = context.getDir(LOG_DIR, Context.MODE_PRIVATE); if (logDir.listFiles().length > 0) { ZipOutputStream zout = new ZipOutputStream(out); for (File file : logDir.listFiles()) { ZipEntry entry = new ZipEntry(file.getName()); zout.putNextEntry(entry);// www. j a va 2s.c om IOUtils.copy(new FileInputStream(file), zout); zout.closeEntry(); } zout.close(); } }
From source file:Main.java
public static void compressFiles(File files[], File fileCompressed) throws IOException { byte[] buffer = new byte[SIZE_OF_BUFFER]; ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(fileCompressed)); for (int i = 0; i < files.length; i++) { FileInputStream fileInputStream = new FileInputStream(files[i]); zipOutputStream.putNextEntry(new ZipEntry(files[i].getPath())); int size; while ((size = fileInputStream.read(buffer)) > 0) zipOutputStream.write(buffer, 0, size); zipOutputStream.closeEntry(); fileInputStream.close();//from w w w . j a v a 2 s . c o m } zipOutputStream.close(); }
From source file:de.nx42.maps4cim.util.Compression.java
/** * Compresses the input file using the zip file format and stores the * resulting zip file in the desired location * @param input the file to compress//from w ww . ja v a 2 s.c om * @param zipOutput the resulting zip file * @return the resulting zip file * @throws IOException if there is an error accessing the input file or * writing the output zip file */ public static File storeAsZip(File input, File zipOutput) throws IOException { // create new zip output stream ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipOutput)); ZipEntry ze = new ZipEntry(input.getName()); zos.putNextEntry(ze); // use file as input stream and copy bytes InputStream in = new FileInputStream(input); ByteStreams.copy(in, zos); // close current zip entry and all streams zos.closeEntry(); in.close(); zos.close(); return zipOutput; }
From source file:com.mcleodmoores.mvn.natives.UnpackDependenciesMojoTest.java
private static Artifact createArtifact(final File tmp, final String type, final String member) throws IOException { final File zipFile = new File(tmp, type + ".zip"); try (final FileOutputStream out = new FileOutputStream(zipFile)) { final ZipOutputStream zipStream = new ZipOutputStream(out); final ZipEntry license = new ZipEntry("LICENSE"); zipStream.putNextEntry(license); zipStream.write(26);/*w w w.j a v a 2 s . c o m*/ zipStream.closeEntry(); final ZipEntry payload = new ZipEntry(member); zipStream.putNextEntry(payload); zipStream.write(26); zipStream.closeEntry(); zipStream.close(); } final Artifact artifact = Mockito.mock(Artifact.class); Mockito.when(artifact.getType()).thenReturn(type); Mockito.when(artifact.getGroupId()).thenReturn("uk.co.beerdragon"); Mockito.when(artifact.getArtifactId()).thenReturn("test-" + type); Mockito.when(artifact.getVersion()).thenReturn("SNAPSHOT"); Mockito.when(artifact.getFile()).thenReturn(zipFile); return artifact; }
From source file:com.formkiq.core.util.Zips.java
/** * Create Zip file.//from www. j av a 2 s. c o m * @param map {@link Map} * @return byte[] zip file * @throws IOException IOException */ public static byte[] zipFile(final Map<String, byte[]> map) throws IOException { ByteArrayOutputStream bs = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(bs); for (Map.Entry<String, byte[]> e : map.entrySet()) { String name = e.getKey(); byte[] data = e.getValue(); ZipEntry ze = new ZipEntry(name); zip.putNextEntry(ze); zip.write(data, 0, data.length); zip.closeEntry(); } zip.finish(); byte[] bytes = bs.toByteArray(); IOUtils.closeQuietly(bs); IOUtils.closeQuietly(zip); return bytes; }
From source file:eu.openanalytics.rsb.message.MultiFilesResult.java
/** * Zips all the files contained in a multifiles result except if the result is * not successful, in that case returns the first file (which should be the only * one and contain a plain text error message). * //from w w w . j a va 2s. c o m * @param result * @return * @throws FileNotFoundException * @throws IOException */ public static File zipResultFilesIfNotError(final MultiFilesResult result) throws FileNotFoundException, IOException { final File[] resultFiles = result.getPayload(); if ((!result.isSuccess()) && (resultFiles.length == 1)) { return resultFiles[0]; } final File resultZipFile = new File(result.getTemporaryDirectory(), result.getJobId() + ".zip"); final ZipOutputStream resultZOS = new ZipOutputStream(new FileOutputStream(resultZipFile)); for (final File resultFile : resultFiles) { resultZOS.putNextEntry(new ZipEntry(resultFile.getName())); final FileInputStream fis = new FileInputStream(resultFile); IOUtils.copy(fis, resultZOS); IOUtils.closeQuietly(fis); resultZOS.closeEntry(); } IOUtils.closeQuietly(resultZOS); return resultZipFile; }
From source file:Main.java
public static void zipChildren(File folder, String prefix, ZipOutputStream out) throws IOException { File[] files = folder.listFiles(); if (files == null) return;//from ww w . j a v a 2 s .co m for (File file : files) { if (file.isFile()) { String name = prefix + file.getName(); ZipEntry entry = new ZipEntry(name); entry.setTime(file.lastModified()); out.putNextEntry(entry); loadFromFile(file, out); out.closeEntry(); } else if (file.isDirectory()) { zipChildren(file, prefix + file.getName() + "/", out); } } }