-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement chunk decompression for #3.
- Loading branch information
Showing
17 changed files
with
348 additions
and
19 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
10 changes: 10 additions & 0 deletions
10
...ession-api/src/main/java/io/github/zchunk/compression/api/err/DecompressionException.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,10 @@ | ||
package io.github.zchunk.compression.api.err; | ||
|
||
public class DecompressionException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 8784156714006343592L; | ||
|
||
public DecompressionException(String message) { | ||
super(message); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>zchunk-parent</artifactId> | ||
<groupId>io.github.zchunk</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>zchunk-compression-none</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.zchunk</groupId> | ||
<artifactId>compression-api</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
26 changes: 26 additions & 0 deletions
26
...n-none/src/main/java/io/github/zchunk/compression/algo/none/NoneCompressionAlgorithm.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,26 @@ | ||
package io.github.zchunk.compression.algo.none; | ||
|
||
import io.github.zchunk.compressedint.CompressedInt; | ||
import io.github.zchunk.compressedint.CompressedIntFactory; | ||
import io.github.zchunk.compression.api.CompressionAlgorithm; | ||
|
||
import java.io.InputStream; | ||
import java.util.function.BiFunction; | ||
|
||
public class NoneCompressionAlgorithm implements CompressionAlgorithm { | ||
|
||
@Override | ||
public CompressedInt getCompressionTypeValue() { | ||
return CompressedIntFactory.valueOf(0L); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "none"; | ||
} | ||
|
||
@Override | ||
public BiFunction<InputStream, byte[], InputStream> getOutputStreamSupplier() { | ||
return (a, b) -> a; | ||
} | ||
} |
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>zchunk-parent</artifactId> | ||
<groupId>io.github.zchunk</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>zchunk-compression-zstd</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.zchunk</groupId> | ||
<artifactId>compression-api</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- actual implementation --> | ||
<!-- https://mvnrepository.com/artifact/com.github.luben/zstd-jni --> | ||
<dependency> | ||
<groupId>com.github.luben</groupId> | ||
<artifactId>zstd-jni</artifactId> | ||
<version>1.4.0-1</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
</project> |
49 changes: 49 additions & 0 deletions
49
...n-zstd/src/main/java/io/github/zchunk/compression/algo/zstd/ZStdCompressionAlgorithm.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,49 @@ | ||
package io.github.zchunk.compression.algo.zstd; | ||
|
||
import com.github.luben.zstd.ZstdInputStream; | ||
import io.github.zchunk.compressedint.CompressedInt; | ||
import io.github.zchunk.compressedint.CompressedIntFactory; | ||
import io.github.zchunk.compression.api.CompressionAlgorithm; | ||
import io.github.zchunk.compression.api.err.DecompressionException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.function.BiFunction; | ||
|
||
public class ZStdCompressionAlgorithm implements CompressionAlgorithm { | ||
|
||
private static final CompressedInt TWO = CompressedIntFactory.valueOf(2L); | ||
private static final String ALGORITHM_NAME_ZSTD = "zstd"; | ||
|
||
@Override | ||
public CompressedInt getCompressionTypeValue() { | ||
return TWO; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return ALGORITHM_NAME_ZSTD; | ||
} | ||
|
||
@Override | ||
public BiFunction<InputStream, byte[], InputStream> getOutputStreamSupplier() { | ||
return createZstdInputStream(); | ||
} | ||
|
||
private BiFunction<InputStream, byte[], InputStream> createZstdInputStream() { | ||
return (compressedInputStream, dict) -> { | ||
try { | ||
final ZstdInputStream zstdInputStream = new ZstdInputStream(compressedInputStream); | ||
if (!Arrays.equals(new byte[0], dict)) { | ||
zstdInputStream.setDict(dict); | ||
} | ||
|
||
return zstdInputStream; | ||
} catch (final IOException e) { | ||
throw new DecompressionException("Unable to create input stream."); | ||
} | ||
}; | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.