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);
}
}
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;
}
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);
}
}
}
}
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();
}
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;
}
Aggregations