-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa03abc
commit fb135f2
Showing
9 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/ru/olegcherednik/zip4jvm/io/writers/ZipEntryNoDataDescriptorWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package ru.olegcherednik.zip4jvm.io.writers; | ||
|
||
import ru.olegcherednik.zip4jvm.io.out.data.DataOutput; | ||
import ru.olegcherednik.zip4jvm.io.out.data.EncryptedDataOutput; | ||
import ru.olegcherednik.zip4jvm.io.out.entry.PayloadCalculationOutputStream; | ||
import ru.olegcherednik.zip4jvm.io.out.entry.compressed.CompressedEntryOutputStream; | ||
import ru.olegcherednik.zip4jvm.io.out.entry.xxx.DataDescriptorOut; | ||
import ru.olegcherednik.zip4jvm.io.out.entry.xxx.LocalFileHeaderOut; | ||
import ru.olegcherednik.zip4jvm.io.out.entry.xxx.UpdateZip64; | ||
import ru.olegcherednik.zip4jvm.model.entry.ZipEntry; | ||
import ru.olegcherednik.zip4jvm.utils.function.Writer; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* @author Oleg Cherednik | ||
* @since 26.02.2023 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class ZipEntryNoDataDescriptorWriter implements Writer { | ||
|
||
private static final String COMPRESSED_DATA = | ||
ZipEntryNoDataDescriptorWriter.class.getSimpleName() + ".entryCompressedDataOffs"; | ||
|
||
private final ZipEntry zipEntry; | ||
|
||
@Override | ||
public void write(DataOutput out) throws IOException { | ||
// 1. compression | ||
// 2. encryption | ||
zipEntry.setDiskNo(out.getDiskNo()); | ||
|
||
/* | ||
The series of | ||
[local file header] | ||
[encryption header] | ||
[file data] | ||
[data descriptor] | ||
*/ | ||
|
||
new LocalFileHeaderOut().write(zipEntry, out); | ||
out.mark(COMPRESSED_DATA); | ||
|
||
EncryptedDataOutput encryptedDataOutput = EncryptedDataOutput.create(zipEntry, out); | ||
CompressedEntryOutputStream cos = CompressedEntryOutputStream.create(zipEntry, encryptedDataOutput); | ||
|
||
encryptedDataOutput.writeEncryptionHeader(); | ||
|
||
try (InputStream in = zipEntry.getInputStream(); | ||
PayloadCalculationOutputStream os = new PayloadCalculationOutputStream(zipEntry, cos)) { | ||
IOUtils.copyLarge(in, os); | ||
} | ||
|
||
encryptedDataOutput.encodingAccomplished(); | ||
zipEntry.setCompressedSize(out.getWrittenBytesAmount(COMPRESSED_DATA)); | ||
new UpdateZip64().update(zipEntry); | ||
|
||
new DataDescriptorOut().write(zipEntry, out); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return '+' + zipEntry.getFileName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters