Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
package org.openrs2.cache
|
|
|
|
import org.openrs2.compress.bzip2.Bzip2
|
|
import org.openrs2.compress.gzip.JagexGzipOutputStream
|
|
import org.openrs2.compress.lzma.Lzma
|
|
import java.io.InputStream
|
|
import java.io.OutputStream
|
|
import java.util.zip.GZIPInputStream
|
|
|
|
public enum class Js5CompressionType {
|
|
UNCOMPRESSED,
|
|
BZIP2,
|
|
GZIP,
|
|
LZMA;
|
|
|
|
public fun createInputStream(input: InputStream, length: Int): InputStream {
|
|
return when (this) {
|
|
UNCOMPRESSED -> input
|
|
BZIP2 -> Bzip2.createHeaderlessInputStream(input)
|
|
GZIP -> GZIPInputStream(input)
|
|
LZMA -> Lzma.createHeaderlessInputStream(input, length.toLong())
|
|
}
|
|
}
|
|
|
|
public fun createOutputStream(output: OutputStream): OutputStream {
|
|
return when (this) {
|
|
UNCOMPRESSED -> output
|
|
BZIP2 -> Bzip2.createHeaderlessOutputStream(output)
|
|
GZIP -> JagexGzipOutputStream(output)
|
|
/*
|
|
* LZMA at -9 has significantly higher CPU/memory requirements for
|
|
* both compression _and_ decompression, so we use the default of
|
|
* -6. Using a higher level for the typical file size in the
|
|
* RuneScape cache probably provides insignificant returns, as
|
|
* described in the LZMA documentation.
|
|
*/
|
|
LZMA -> Lzma.createHeaderlessOutputStream(output, Lzma.DEFAULT_COMPRESSION)
|
|
}
|
|
}
|
|
|
|
public companion object {
|
|
private val values = values()
|
|
|
|
@JvmStatic
|
|
public fun fromOrdinal(ordinal: Int): Js5CompressionType? {
|
|
return if (ordinal >= 0 && ordinal < values.size) {
|
|
values[ordinal]
|
|
} else {
|
|
null
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|