@@ -171,10 +171,27 @@ cobbzilla-utils is available under the Apache License, version 2: http://www.apa | |||||
<artifactId>commons-compress</artifactId> | <artifactId>commons-compress</artifactId> | ||||
<version>${commons-compress.version}</version> | <version>${commons-compress.version}</version> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>org.meteogroup.jbrotli</groupId> | |||||
<artifactId>jbrotli</artifactId> | |||||
<version>0.5.0</version> | |||||
<!-- <dependency>--> | |||||
<!-- <groupId>org.meteogroup.jbrotli</groupId>--> | |||||
<!-- <artifactId>jbrotli</artifactId>--> | |||||
<!-- <version>0.5.0</version>--> | |||||
<!-- </dependency>--> | |||||
<!-- <dependency>--> | |||||
<!-- <groupId>org.meteogroup.jbrotli</groupId>--> | |||||
<!-- <artifactId>jbrotli-native-linux-x86-amd64</artifactId>--> | |||||
<!-- <version>0.5.0</version>--> | |||||
<!-- </dependency>--> | |||||
<!-- https://mvnrepository.com/artifact/com.nixxcode.jvmbrotli/jvmbrotli --> | |||||
<dependency> | |||||
<groupId>com.nixxcode.jvmbrotli</groupId> | |||||
<artifactId>jvmbrotli</artifactId> | |||||
<version>0.2.0</version> | |||||
</dependency> | |||||
<!-- https://mvnrepository.com/artifact/com.nixxcode.jvmbrotli/jvmbrotli-linux-x86-amd64 --> | |||||
<dependency> | |||||
<groupId>com.nixxcode.jvmbrotli</groupId> | |||||
<artifactId>jvmbrotli-linux-x86-amd64</artifactId> | |||||
<version>0.2.0</version> | |||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
@@ -1,10 +1,11 @@ | |||||
package org.cobbzilla.util.http; | package org.cobbzilla.util.http; | ||||
import com.fasterxml.jackson.annotation.JsonCreator; | import com.fasterxml.jackson.annotation.JsonCreator; | ||||
import com.nixxcode.jvmbrotli.common.BrotliLoader; | |||||
import com.nixxcode.jvmbrotli.dec.BrotliInputStream; | |||||
import com.nixxcode.jvmbrotli.enc.BrotliOutputStream; | |||||
import lombok.AllArgsConstructor; | import lombok.AllArgsConstructor; | ||||
import org.cobbzilla.util.io.FilterInputStreamViaOutputStream; | import org.cobbzilla.util.io.FilterInputStreamViaOutputStream; | ||||
import org.meteogroup.jbrotli.io.BrotliInputStream; | |||||
import org.meteogroup.jbrotli.io.BrotliOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
@@ -23,6 +24,10 @@ public enum HttpContentEncodingType { | |||||
br (BrotliInputStream::new, BrotliOutputStream::new, BrotliOutputStream.class), | br (BrotliInputStream::new, BrotliOutputStream::new, BrotliOutputStream.class), | ||||
bro (BrotliInputStream::new, BrotliOutputStream::new, BrotliOutputStream.class); | bro (BrotliInputStream::new, BrotliOutputStream::new, BrotliOutputStream.class); | ||||
static { | |||||
BrotliLoader.isBrotliAvailable(); | |||||
} | |||||
private final HttpContentEncodingInputWrapper inputWrapper; | private final HttpContentEncodingInputWrapper inputWrapper; | ||||
private final HttpContentEncodingOutputWrapper outputWrapper; | private final HttpContentEncodingOutputWrapper outputWrapper; | ||||
private final HttpContentEncodingInputAsOutputWrapper inputAsOutputWrapper; | private final HttpContentEncodingInputAsOutputWrapper inputAsOutputWrapper; | ||||
@@ -0,0 +1,35 @@ | |||||
package org.cobbzilla.util.http; | |||||
import org.apache.commons.io.IOUtils; | |||||
import org.apache.commons.lang3.RandomUtils; | |||||
import org.cobbzilla.util.system.Bytes; | |||||
import org.junit.Test; | |||||
import java.io.*; | |||||
import static org.junit.Assert.assertArrayEquals; | |||||
public class HttpContentEncodingTypeTest { | |||||
@Test public void testEncodingTypes () throws Exception { | |||||
for (HttpContentEncodingType encoding : HttpContentEncodingType.values()) { | |||||
testEncodingType(encoding); | |||||
} | |||||
} | |||||
private void testEncodingType(HttpContentEncodingType encoding) throws IOException { | |||||
final byte[] expectedData = RandomUtils.nextBytes((int) (65*Bytes.KB)); | |||||
final ByteArrayInputStream in = new ByteArrayInputStream(expectedData); | |||||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); | |||||
final OutputStream encOut = encoding.wrapOutput(out); | |||||
IOUtils.copyLarge(in, encOut); | |||||
in.close(); | |||||
encOut.close(); | |||||
final InputStream decIn = encoding.wrapInput(new ByteArrayInputStream(out.toByteArray())); | |||||
final ByteArrayOutputStream actualData = new ByteArrayOutputStream(); | |||||
IOUtils.copyLarge(decIn, actualData); | |||||
assertArrayEquals("data was not the same", expectedData, actualData.toByteArray()); | |||||
} | |||||
} |