Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public class ModifyCompression extends AbstractProcessor {
.build();

public static final PropertyDescriptor OUTPUT_COMPRESSION_STRATEGY = new PropertyDescriptor.Builder()
.name("Output Compression Strategy")
.name("Output Compression Strategy")
.description("The strategy to use for compressing output FlowFiles")
.allowableValues(EnumSet.complementOf(EnumSet.of(CompressionStrategy.MIME_TYPE_ATTRIBUTE)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum CompressionStrategy implements DescribedValue {
GZIP("gzip", "GZIP", ".gz", "application/gzip", "application/x-gzip"),
DEFLATE("deflate", "Deflate", ".zlib", "application/deflate", "application/x-deflate"),
BZIP2("bzip2", "BZIP2", ".bz2", "application/x-bzip2", "application/bzip2"),
XZ_LZMA2("xz-lzma2", "XZ-LZMA2", ".xz", "application/x-lzma"),
XZ_LZMA2("xz-lzma2", "XZ-LZMA2", ".xz", "application/x-xz"),
LZMA("lzma", "LZMA", ".lzma", "application/x-lzma"),
SNAPPY("snappy", "Snappy", ".snappy", "application/x-snappy"),
SNAPPY_HADOOP("snappy-hadoop", "Snappy-Hadoop", ".snappy", "application/x-snappy-hadoop"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.XZOutputStream;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
Expand Down Expand Up @@ -407,6 +411,41 @@ void testWhereDecompressionNotNeeded(Relationship toRelationship) throws Excepti
runner.assertAllFlowFilesTransferred(expectedRelationship, 1);
}

@Test
public void testXzlzma2DecompressWithMimeType() throws Exception {
final String content = "Content for compression";
final byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
final LZMA2Options options = new LZMA2Options();
final ByteArrayOutputStream compressedOutput = new ByteArrayOutputStream();
try (XZOutputStream xzOut = new XZOutputStream(compressedOutput, options)) {
xzOut.write(contentBytes, 0, contentBytes.length);
xzOut.finish();
}

runner.setProperty(ModifyCompression.INPUT_COMPRESSION_STRATEGY, CompressionStrategy.MIME_TYPE_ATTRIBUTE);
runner.setProperty(ModifyCompression.OUTPUT_FILENAME_STRATEGY, FilenameStrategy.UPDATED);
final Map<String, String> attributes = Map.of(CoreAttributes.MIME_TYPE.key(), "application/x-xz");
runner.enqueue(compressedOutput.toByteArray(), attributes);

runner.run();

runner.assertAllFlowFilesTransferred(ModifyCompression.REL_SUCCESS, 1);
final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ModifyCompression.REL_SUCCESS).getFirst();
flowFile.assertContentEquals(content);
}

@Test
public void testXzlzma2Compress() {
runner.setProperty(ModifyCompression.OUTPUT_COMPRESSION_STRATEGY, CompressionStrategy.XZ_LZMA2);
final String content = "Content for compression";
runner.enqueue(content);
runner.run();

runner.assertAllFlowFilesTransferred(ModifyCompression.REL_SUCCESS, 1);
final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ModifyCompression.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/x-xz");
}

private static Stream<Arguments> toRelationshipWhenDecompressionNotNeeded() {
final Relationship noRelationSpecified = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ public class CompressContent extends AbstractProcessor {
Map.entry("application/bzip2", COMPRESSION_FORMAT_BZIP2),
Map.entry("application/x-bzip2", COMPRESSION_FORMAT_BZIP2),
Map.entry("application/x-lzma", COMPRESSION_FORMAT_LZMA),
Map.entry("application/x-xz", COMPRESSION_FORMAT_XZ_LZMA2),
Map.entry("application/x-snappy", COMPRESSION_FORMAT_SNAPPY),
Map.entry("application/x-snappy-hadoop", COMPRESSION_FORMAT_SNAPPY_HADOOP),
Map.entry("application/x-snappy-framed", COMPRESSION_FORMAT_SNAPPY_FRAMED),
Map.entry("application/x-lz4-framed", COMPRESSION_FORMAT_LZ4_FRAMED),
Map.entry("application/zstd", COMPRESSION_FORMAT_ZSTD),
Map.entry("application/x-brotli", COMPRESSION_FORMAT_BROTLI));
Map.entry("application/x-brotli", COMPRESSION_FORMAT_BROTLI)
);

@Override
public Set<Relationship> getRelationships() {
Expand Down
Loading
Loading