Java Code Examples for org.apache.commons.compress.archivers.zip.ZipArchiveEntry#addExtraField()
The following examples show how to use
org.apache.commons.compress.archivers.zip.ZipArchiveEntry#addExtraField() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Zipper.java From james-project with Apache License 2.0 | 6 votes |
private void storeInArchive(MailboxWithAnnotations mailboxWithAnnotations, ZipArchiveOutputStream archiveOutputStream) throws IOException { Mailbox mailbox = mailboxWithAnnotations.mailbox; List<MailboxAnnotation> annotations = mailboxWithAnnotations.annotations; String name = mailbox.getName(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new Directory(name), name); archiveEntry.addExtraField(EntryTypeExtraField.TYPE_MAILBOX); archiveEntry.addExtraField(new MailboxIdExtraField(mailbox.getMailboxId().serialize())); archiveEntry.addExtraField(new UidValidityExtraField(mailbox.getUidValidity().asLong())); archiveOutputStream.putArchiveEntry(archiveEntry); archiveOutputStream.closeArchiveEntry(); storeAllAnnotationsInArchive(archiveOutputStream, annotations, name); }
Example 2
Source File: ZipAssertTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void containsOnlyExtraFieldsShouldNotThrowWhenUnexpectedField() throws Exception { try (ZipArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(destination)) { ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File("any"), ENTRY_NAME); 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(); } }
Example 3
Source File: ZipAssertTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void containsOnlyExtraFieldsShouldNotThrowWhenContainingExpectedExtraFields() throws Exception { try (ZipArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(destination)) { ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File("any"), ENTRY_NAME); 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(); } }
Example 4
Source File: DeletedMessageZipper.java From james-project with Apache License 2.0 | 5 votes |
@VisibleForTesting ZipArchiveEntry createEntry(ZipArchiveOutputStream zipOutputStream, DeletedMessage message) throws IOException { MessageId messageId = message.getMessageId(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) zipOutputStream.createArchiveEntry( new File(messageId.serialize()), messageId.serialize() + EML_FILE_EXTENSION); archiveEntry.addExtraField(new MessageIdExtraField(messageId)); archiveEntry.addExtraField(new SizeExtraField(message.getSize())); return archiveEntry; }
Example 5
Source File: Zipper.java From james-project with Apache License 2.0 | 5 votes |
private void storeAllAnnotationsInArchive(ZipArchiveOutputStream archiveOutputStream, List<MailboxAnnotation> annotations, String name) throws IOException { if (!annotations.isEmpty()) { String annotationsDirectoryPath = name + "/" + ANNOTATION_DIRECTORY; ZipArchiveEntry annotationDirectory = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry( new Directory(annotationsDirectoryPath), annotationsDirectoryPath); annotationDirectory.addExtraField(EntryTypeExtraField.TYPE_MAILBOX_ANNOTATION_DIR); archiveOutputStream.putArchiveEntry(annotationDirectory); archiveOutputStream.closeArchiveEntry(); annotations.forEach(Throwing.consumer(annotation -> storeInArchive(annotation, annotationsDirectoryPath, archiveOutputStream))); } }
Example 6
Source File: Zipper.java From james-project with Apache License 2.0 | 5 votes |
private void storeInArchive(MailboxAnnotation annotation, String directory, ZipArchiveOutputStream archiveOutputStream) throws IOException { String entryId = directory + "/" + annotation.getKey().asString(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File(entryId), entryId); archiveEntry.addExtraField(EntryTypeExtraField.TYPE_MAILBOX_ANNOTATION); archiveOutputStream.putArchiveEntry(archiveEntry); annotation.getValue().ifPresent(value -> { try (PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(archiveOutputStream, Charsets.UTF_8), AUTO_FLUSH)) { printWriter.print(value); } }); archiveOutputStream.closeArchiveEntry(); }
Example 7
Source File: Zipper.java From james-project with Apache License 2.0 | 5 votes |
private ZipArchiveEntry createMessageZipArchiveEntry(MessageResult message, ZipArchiveOutputStream archiveOutputStream, String entryId) throws IOException { ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File(entryId), entryId); archiveEntry.addExtraField(EntryTypeExtraField.TYPE_MESSAGE); archiveEntry.addExtraField(new SizeExtraField(message.getSize())); 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.getFlags())); return archiveEntry; }