List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry addExtraField
public void addExtraField(ZipExtraField ze)
From source file:cz.muni.fi.xklinec.zipstream.Mallory.java
/** * Adds given number of bytes as a null padding to extra field. * Minimal padding is 8B. Maximal padding is PAD_BLOCK_MAX. * /* ww w .jav a2s .c o m*/ * @param ze * @param padlen */ public void addExtraPadding(ZipArchiveEntry ze, int padlen) { if (padlen < EXTRA_FIELD_SIZE) { throw new IllegalArgumentException( "Cannot add padding less than 8 B (due to compulsory extra field structure). Given size " + padlen); } if (padlen > PAD_BLOCK_MAX) { throw new IllegalArgumentException( "Specified padding is too big, maximal size is " + PAD_BLOCK_MAX + " given size is " + padlen); } byte[] paddBuff = new byte[padlen - EXTRA_FIELD_SIZE]; UnrecognizedExtraField zextra = new UnrecognizedExtraField(); zextra.setHeaderId(new ZipShort(PAD_SIGNATURE)); zextra.setLocalFileDataData(new byte[0]); zextra.setCentralDirectoryData(paddBuff); ze.addExtraField(zextra); }
From source file:org.apache.james.mailbox.backup.ZipAssertTest.java
@Test public void containsExactlyExtraFieldsShouldNotThrowWhenUnexpectedField() throws Exception { try (ZipArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(destination)) { ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File("any"), ENTRY_NAME);/* www .j a va 2 s. c o m*/ archiveEntry.addExtraField(EXTRA_FIELD); archiveOutputStream.putArchiveEntry(archiveEntry); IOUtils.copy(new ByteArrayInputStream(ENTRY_CONTENT), archiveOutputStream); archiveOutputStream.closeArchiveEntry(); archiveOutputStream.finish(); } try (ZipFile zipFile = new ZipFile(destination)) { assertThatCode(() -> assertThatZip(zipFile) .containsOnlyEntriesMatching(hasName(ENTRY_NAME).containsExtraFields())) .doesNotThrowAnyException(); } }
From source file:org.apache.james.mailbox.backup.ZipAssertTest.java
@Test public void containsExactlyExtraFieldsShouldNotThrowWhenContainingExpectedExtraFields() throws Exception { try (ZipArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(destination)) { ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File("any"), ENTRY_NAME);/*from www . ja va 2 s.co m*/ archiveEntry.addExtraField(EXTRA_FIELD); archiveOutputStream.putArchiveEntry(archiveEntry); IOUtils.copy(new ByteArrayInputStream(ENTRY_CONTENT), archiveOutputStream); archiveOutputStream.closeArchiveEntry(); archiveOutputStream.finish(); } try (ZipFile zipFile = new ZipFile(destination)) { assertThatCode(() -> assertThatZip(zipFile) .containsOnlyEntriesMatching(hasName(ENTRY_NAME).containsExtraFields(EXTRA_FIELD))) .doesNotThrowAnyException(); } }
From source file:org.apache.james.mailbox.backup.Zipper.java
private void storeInArchive(Mailbox mailbox, ZipArchiveOutputStream archiveOutputStream) throws IOException { String name = mailbox.getName(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new Directory(name), name);/*w ww . jav a 2 s. c o m*/ archiveEntry.addExtraField(new MailboxIdExtraField(mailbox.getMailboxId().serialize())); archiveEntry.addExtraField(new UidValidityExtraField(mailbox.getUidValidity())); archiveOutputStream.putArchiveEntry(archiveEntry); archiveOutputStream.closeArchiveEntry(); }
From source file:org.apache.james.mailbox.backup.Zipper.java
private void storeInArchive(MailboxMessage message, ZipArchiveOutputStream archiveOutputStream) throws IOException { String entryId = message.getMessageId().serialize(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File(entryId), entryId);// w w w . ja v a 2s .c o m archiveEntry.addExtraField(new SizeExtraField(message.getFullContentOctets())); archiveEntry.addExtraField(new UidExtraField(message.getUid().asLong())); archiveEntry.addExtraField(new MessageIdExtraField(message.getMessageId().serialize())); archiveEntry.addExtraField(new MailboxIdExtraField(message.getMailboxId().serialize())); archiveEntry.addExtraField(new InternalDateExtraField(message.getInternalDate())); archiveEntry.addExtraField(new FlagsExtraField(message.createFlags())); archiveOutputStream.putArchiveEntry(archiveEntry); IOUtils.copy(message.getFullContent(), archiveOutputStream); archiveOutputStream.closeArchiveEntry(); }
From source file:org.callimachusproject.io.CarOutputStream.java
private synchronized void putArchiveEntry(String name, long time, String type, MetaTypeExtraField mtype) throws IOException { if (!closed.add(name)) throw new IllegalStateException("Entry has already been added: " + name); ZipArchiveEntry entry = new ZipArchiveEntry(name); entry.setTime(time);// w w w . ja v a 2s . c o m entry.addExtraField(mtype); if (type != null) { entry.addExtraField(new ContentTypeExtraField(type)); } zipStream.putArchiveEntry(entry); }