mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 04:12:06 +01:00
Make use of new ArmoredOutputStream.Builder
This commit is contained in:
parent
8cdb7ee4e0
commit
e167fa37f3
2 changed files with 22 additions and 30 deletions
|
@ -30,7 +30,6 @@ import org.pgpainless.algorithm.StreamEncoding;
|
|||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -91,20 +90,6 @@ public final class EncryptionStream extends OutputStream {
|
|||
|
||||
LOGGER.debug("Wrap encryption output in ASCII armor");
|
||||
armorOutputStream = ArmoredOutputStreamFactory.get(outermostStream, options);
|
||||
if (options.hasComment()) {
|
||||
String[] commentLines = options.getComment().split("\n");
|
||||
for (String commentLine : commentLines) {
|
||||
if (!commentLine.trim().isEmpty()) {
|
||||
ArmorUtils.addCommentHeader(armorOutputStream, commentLine.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.hasVersion()) {
|
||||
String version = options.getVersion().trim();
|
||||
if (!version.isEmpty()) {
|
||||
ArmorUtils.setVersionHeader(armorOutputStream, version);
|
||||
}
|
||||
}
|
||||
outermostStream = armorOutputStream;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,18 @@ public final class ArmoredOutputStreamFactory {
|
|||
|
||||
}
|
||||
|
||||
private static ArmoredOutputStream.Builder getBuilder() {
|
||||
ArmoredOutputStream.Builder builder = ArmoredOutputStream.builder();
|
||||
builder.clearHeaders();
|
||||
if (version != null && !version.isEmpty()) {
|
||||
builder.setVersion(version);
|
||||
}
|
||||
for (String comment : comment) {
|
||||
builder.addComment(comment);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an {@link OutputStream} inside a preconfigured {@link ArmoredOutputStream}.
|
||||
*
|
||||
|
@ -37,16 +49,7 @@ public final class ArmoredOutputStreamFactory {
|
|||
*/
|
||||
@Nonnull
|
||||
public static ArmoredOutputStream get(@Nonnull OutputStream outputStream) {
|
||||
ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream);
|
||||
armoredOutputStream.clearHeaders();
|
||||
if (version != null && !version.isEmpty()) {
|
||||
armoredOutputStream.setHeader(ArmorUtils.HEADER_VERSION, version);
|
||||
}
|
||||
|
||||
for (String comment : comment) {
|
||||
ArmorUtils.addCommentHeader(armoredOutputStream, comment);
|
||||
}
|
||||
return armoredOutputStream;
|
||||
return getBuilder().build(outputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,13 +61,17 @@ public final class ArmoredOutputStreamFactory {
|
|||
*/
|
||||
@Nonnull
|
||||
public static ArmoredOutputStream get(@Nonnull OutputStream outputStream, @Nonnull ProducerOptions options) {
|
||||
ArmoredOutputStream.Builder builder = getBuilder();
|
||||
if (options.isHideArmorHeaders()) {
|
||||
ArmoredOutputStream armorOut = new ArmoredOutputStream(outputStream);
|
||||
armorOut.clearHeaders();
|
||||
return armorOut;
|
||||
} else {
|
||||
return get(outputStream);
|
||||
builder.clearHeaders();
|
||||
}
|
||||
if (options.hasVersion()) {
|
||||
builder.setVersion(options.getVersion());
|
||||
}
|
||||
if (options.hasComment()) {
|
||||
builder.setComment(options.getComment());
|
||||
}
|
||||
return builder.build(outputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue