use of java.util.zip.ZipOutputStream in project poi by apache.
the class ZipContentTypeManager method saveImpl.
@SuppressWarnings("resource")
@Override
public boolean saveImpl(Document content, OutputStream out) {
ZipOutputStream zos = null;
if (out instanceof ZipOutputStream)
zos = (ZipOutputStream) out;
else
zos = new ZipOutputStream(out);
ZipEntry partEntry = new ZipEntry(CONTENT_TYPES_PART_NAME);
try {
// Referenced in ZIP
zos.putNextEntry(partEntry);
// Saving data in the ZIP file
if (!StreamHelper.saveXmlInStream(content, zos)) {
return false;
}
zos.closeEntry();
} catch (IOException ioe) {
logger.log(POILogger.ERROR, "Cannot write: " + CONTENT_TYPES_PART_NAME + " in Zip !", ioe);
return false;
}
return true;
}
use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.
the class ArtifactBuilderOverwriteTest method createArchive.
private String createArchive(String relativeArchivePath, String fileNameInArchive, String text) {
try {
File file = new File(getOrCreateProjectDir(), relativeArchivePath);
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file));
try {
output.putNextEntry(new ZipEntry(fileNameInArchive));
output.write(text.getBytes(CharsetToolkit.UTF8));
output.closeEntry();
} finally {
output.close();
}
return FileUtil.toSystemIndependentName(file.getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of java.util.zip.ZipOutputStream in project asterixdb by apache.
the class AsterixEventServiceUtil method zipDir.
public static void zipDir(File sourceDir, File destFile) throws IOException {
FileOutputStream fos = new FileOutputStream(destFile);
ZipOutputStream zos = new ZipOutputStream(fos);
zipDir(EMPTY_STRING, sourceDir, destFile, zos);
zos.close();
}
use of java.util.zip.ZipOutputStream in project robovm by robovm.
the class ZipFileTest method createZipFile.
/**
* Compresses the given number of files, each of the given size, into a .zip archive.
*/
private File createZipFile(int entryCount, int entrySize) throws IOException {
File result = createTemporaryZipFile();
byte[] writeBuffer = new byte[8192];
Random random = new Random();
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(result)));
for (int entry = 0; entry < entryCount; ++entry) {
ZipEntry ze = new ZipEntry(Integer.toHexString(entry));
out.putNextEntry(ze);
for (int i = 0; i < entrySize; i += writeBuffer.length) {
random.nextBytes(writeBuffer);
int byteCount = Math.min(writeBuffer.length, entrySize - i);
out.write(writeBuffer, 0, byteCount);
}
out.closeEntry();
}
out.close();
return result;
}
use of java.util.zip.ZipOutputStream in project robovm by robovm.
the class ZipFileTest method testSTORED.
public void testSTORED() throws IOException {
ZipOutputStream out = createZipOutputStream(createTemporaryZipFile());
CRC32 crc = new CRC32();
// Missing CRC, size, and compressed size => failure.
try {
ZipEntry ze = new ZipEntry("a");
ze.setMethod(ZipEntry.STORED);
out.putNextEntry(ze);
fail();
} catch (ZipException expected) {
}
// Missing CRC and compressed size => failure.
try {
ZipEntry ze = new ZipEntry("a");
ze.setMethod(ZipEntry.STORED);
ze.setSize(0);
out.putNextEntry(ze);
fail();
} catch (ZipException expected) {
}
// Missing CRC and size => failure.
try {
ZipEntry ze = new ZipEntry("a");
ze.setMethod(ZipEntry.STORED);
ze.setSize(0);
ze.setCompressedSize(0);
out.putNextEntry(ze);
fail();
} catch (ZipException expected) {
}
// Missing size and compressed size => failure.
try {
ZipEntry ze = new ZipEntry("a");
ze.setMethod(ZipEntry.STORED);
ze.setCrc(crc.getValue());
out.putNextEntry(ze);
fail();
} catch (ZipException expected) {
}
// Missing size is copied from compressed size.
{
ZipEntry ze = new ZipEntry("okay1");
ze.setMethod(ZipEntry.STORED);
ze.setCrc(crc.getValue());
assertEquals(-1, ze.getSize());
assertEquals(-1, ze.getCompressedSize());
ze.setCompressedSize(0);
assertEquals(-1, ze.getSize());
assertEquals(0, ze.getCompressedSize());
out.putNextEntry(ze);
assertEquals(0, ze.getSize());
assertEquals(0, ze.getCompressedSize());
}
// Missing compressed size is copied from size.
{
ZipEntry ze = new ZipEntry("okay2");
ze.setMethod(ZipEntry.STORED);
ze.setCrc(crc.getValue());
assertEquals(-1, ze.getSize());
assertEquals(-1, ze.getCompressedSize());
ze.setSize(0);
assertEquals(0, ze.getSize());
assertEquals(-1, ze.getCompressedSize());
out.putNextEntry(ze);
assertEquals(0, ze.getSize());
assertEquals(0, ze.getCompressedSize());
}
// Mismatched size and compressed size => failure.
try {
ZipEntry ze = new ZipEntry("a");
ze.setMethod(ZipEntry.STORED);
ze.setCrc(crc.getValue());
ze.setCompressedSize(1);
ze.setSize(0);
out.putNextEntry(ze);
fail();
} catch (ZipException expected) {
}
// Everything present => success.
ZipEntry ze = new ZipEntry("okay");
ze.setMethod(ZipEntry.STORED);
ze.setCrc(crc.getValue());
ze.setSize(0);
ze.setCompressedSize(0);
out.putNextEntry(ze);
out.close();
}
Aggregations