Search in sources :

Example 51 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.

the class IoTestUtil method createTestJar.

@NotNull
public static File createTestJar(@NotNull File jarFile, @NotNull String... namesAndTexts) {
    try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(jarFile))) {
        for (int i = 0; i < namesAndTexts.length; i += 2) {
            stream.putNextEntry(new ZipEntry(namesAndTexts[i]));
            stream.write(namesAndTexts[i + 1].getBytes(CharsetToolkit.UTF8_CHARSET));
            stream.closeEntry();
        }
        return jarFile;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.

the class UpdateableZipTest method createTestUtilZip.

/*
  public void testAppendToIdeaJar() throws Exception {
    //ProfilingUtil.startCPUProfiling();
    for (int i = 0; i < 20; i++) {
      long tm = System.currentTimeMillis();
      JBZipFile jbZip = new JBZipFile(new File("/Users/max/idea.jar"));
      long tm2 = System.currentTimeMillis();

      System.out.print("Loaded in: " + (tm2 - tm) + " msec ");

      jbZip.getOrCreateEntry("/somenewtext.txt").setData("New text".getBytes());
      jbZip.close();

      long tm3 = System.currentTimeMillis();
      System.out.println("Updated in: " + (tm3 - tm2) + " msec");
    }
    //ProfilingUtil.captureCPUSnapshot();
  }
  */
private File createTestUtilZip() throws Exception {
    File zipFile = FileUtil.createTempFile("test", ".zip");
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
    appendEntry(zos, "/first", "first".getBytes());
    appendEntry(zos, "/second", "second".getBytes());
    zos.close();
    return zipFile;
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipFile(java.util.zip.ZipFile)

Example 53 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project gerrit by GerritCodeReview.

the class AsciiDoctor method invoke.

private void invoke(String... parameters) throws IOException {
    CmdLineParser parser = new CmdLineParser(this);
    try {
        parser.parseArgument(parameters);
        if (inputFiles.isEmpty()) {
            throw new CmdLineException(parser, "asciidoctor: FAILED: input file missing");
        }
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        System.exit(1);
        return;
    }
    if (revnumberFile != null) {
        try (BufferedReader reader = new BufferedReader(new FileReader(revnumberFile))) {
            revnumber = reader.readLine();
        }
    }
    if (mktmp) {
        tmpdir = Files.createTempDirectory("asciidoctor-").toFile();
    }
    if (bazel) {
        renderFiles(inputFiles, null);
    } else {
        try (ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(Paths.get(zipFile)))) {
            renderFiles(inputFiles, zip);
            File[] cssFiles = tmpdir.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.endsWith(".css");
                }
            });
            for (File css : cssFiles) {
                zipFile(css, css.getName(), zip);
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) CmdLineParser(org.kohsuke.args4j.CmdLineParser) ZipOutputStream(java.util.zip.ZipOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 54 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project gerrit by GerritCodeReview.

the class DocIndexer method zip.

private byte[] zip(RAMDirectory dir) throws IOException {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    try (ZipOutputStream zip = new ZipOutputStream(buf)) {
        for (String name : dir.listAll()) {
            try (IndexInput in = dir.openInput(name, null)) {
                int len = (int) in.length();
                byte[] tmp = new byte[len];
                ZipEntry entry = new ZipEntry(name);
                entry.setSize(len);
                in.readBytes(tmp, 0, len);
                zip.putNextEntry(entry);
                zip.write(tmp, 0, len);
                zip.closeEntry();
            }
        }
    }
    return buf.toByteArray();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) IndexInput(org.apache.lucene.store.IndexInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 55 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project adempiere by adempiere.

the class MAttachment method saveLOBDataToDB.

/**
	 * 	Save Entry Data in Zip File format into the database.
	 *	@return true if saved
	 */
private boolean saveLOBDataToDB() {
    if (m_items == null || m_items.size() == 0) {
        setBinaryData(null);
        return true;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipOutputStream zip = new ZipOutputStream(out);
    zip.setMethod(ZipOutputStream.DEFLATED);
    zip.setLevel(Deflater.BEST_COMPRESSION);
    zip.setComment("adempiere");
    //
    try {
        for (int i = 0; i < m_items.size(); i++) {
            MAttachmentEntry item = getEntry(i);
            ZipEntry entry = new ZipEntry(item.getName());
            entry.setTime(System.currentTimeMillis());
            entry.setMethod(ZipEntry.DEFLATED);
            zip.putNextEntry(entry);
            byte[] data = item.getData();
            zip.write(data, 0, data.length);
            zip.closeEntry();
            log.fine(entry.getName() + " - " + entry.getCompressedSize() + " (" + entry.getSize() + ") " + (entry.getCompressedSize() * 100 / entry.getSize()) + "%");
        }
        //	zip.finish();
        zip.close();
        byte[] zipData = out.toByteArray();
        log.fine("Length=" + zipData.length);
        setBinaryData(zipData);
        return true;
    } catch (Exception e) {
        log.log(Level.SEVERE, "saveLOBData", e);
    }
    setBinaryData(null);
    return false;
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

ZipOutputStream (java.util.zip.ZipOutputStream)1168 ZipEntry (java.util.zip.ZipEntry)745 FileOutputStream (java.io.FileOutputStream)561 File (java.io.File)486 IOException (java.io.IOException)393 FileInputStream (java.io.FileInputStream)193 ByteArrayOutputStream (java.io.ByteArrayOutputStream)186 BufferedOutputStream (java.io.BufferedOutputStream)177 ZipFile (java.util.zip.ZipFile)163 InputStream (java.io.InputStream)144 Test (org.junit.Test)128 OutputStream (java.io.OutputStream)109 ByteArrayInputStream (java.io.ByteArrayInputStream)94 ZipInputStream (java.util.zip.ZipInputStream)88 Path (java.nio.file.Path)82 BufferedInputStream (java.io.BufferedInputStream)61 ArrayList (java.util.ArrayList)55 FileNotFoundException (java.io.FileNotFoundException)51 Date (java.util.Date)44 HashMap (java.util.HashMap)44