forked from openrs2/openrs2
parent
a52d58e8b5
commit
892d21df10
@ -0,0 +1,25 @@ |
|||||||
|
plugins { |
||||||
|
`maven-publish` |
||||||
|
kotlin("jvm") |
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation(project(":common")) |
||||||
|
implementation("org.apache.commons:commons-compress:${Versions.commonsCompress}") |
||||||
|
} |
||||||
|
|
||||||
|
publishing { |
||||||
|
publications.create<MavenPublication>("maven") { |
||||||
|
from(components["java"]) |
||||||
|
|
||||||
|
pom { |
||||||
|
packaging = "jar" |
||||||
|
name.set("OpenRS2 Compression") |
||||||
|
description.set( |
||||||
|
""" |
||||||
|
Provides headerless implementations of bzip2 and gzip. |
||||||
|
""".trimIndent() |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package dev.openrs2.compress.bzip2 |
||||||
|
|
||||||
|
import dev.openrs2.common.io.SkipOutputStream |
||||||
|
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream |
||||||
|
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream |
||||||
|
import java.io.ByteArrayInputStream |
||||||
|
import java.io.InputStream |
||||||
|
import java.io.OutputStream |
||||||
|
import java.io.SequenceInputStream |
||||||
|
|
||||||
|
object Bzip2 { |
||||||
|
private const val BLOCK_SIZE = 1 |
||||||
|
private val HEADER = byteArrayOf('B'.toByte(), 'Z'.toByte(), 'h'.toByte(), ('0' + BLOCK_SIZE).toByte()) |
||||||
|
|
||||||
|
fun createHeaderlessInputStream(input: InputStream): InputStream { |
||||||
|
return BZip2CompressorInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input)) |
||||||
|
} |
||||||
|
|
||||||
|
fun createHeaderlessOutputStream(output: OutputStream): OutputStream { |
||||||
|
return BZip2CompressorOutputStream(SkipOutputStream(output, HEADER.size.toLong()), BLOCK_SIZE) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package dev.openrs2.compress.gzip |
||||||
|
|
||||||
|
import dev.openrs2.common.io.SkipOutputStream |
||||||
|
import java.io.ByteArrayInputStream |
||||||
|
import java.io.InputStream |
||||||
|
import java.io.OutputStream |
||||||
|
import java.io.SequenceInputStream |
||||||
|
import java.util.zip.Deflater |
||||||
|
import java.util.zip.GZIPInputStream |
||||||
|
|
||||||
|
object Gzip { |
||||||
|
private val HEADER = byteArrayOf(0x1F, 0x8B.toByte()) |
||||||
|
|
||||||
|
fun createHeaderlessInputStream(input: InputStream): InputStream { |
||||||
|
return GZIPInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input)) |
||||||
|
} |
||||||
|
|
||||||
|
fun createHeaderlessOutputStream(output: OutputStream, level: Int = Deflater.BEST_COMPRESSION): OutputStream { |
||||||
|
return GzipLevelOutputStream(SkipOutputStream(output, HEADER.size.toLong()), level) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
package dev.openrs2.compress.gzip |
||||||
|
|
||||||
|
import java.io.OutputStream |
||||||
|
import java.util.zip.GZIPOutputStream |
||||||
|
|
||||||
|
class GzipLevelOutputStream(output: OutputStream, level: Int) : GZIPOutputStream(output) { |
||||||
|
init { |
||||||
|
def.setLevel(level) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue