Skip to content

Commit

Permalink
compressing streams
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Dec 12, 2024
1 parent 6bf072d commit 389e4d0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/kotlin/de/gmuth/ipp/attributes/Compression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import de.gmuth.ipp.core.IppAttribute
import de.gmuth.ipp.core.IppAttributeBuilder
import de.gmuth.ipp.core.IppAttributesGroup
import de.gmuth.ipp.core.IppTag.Keyword
import java.io.InputStream
import java.io.OutputStream
import java.util.zip.DeflaterInputStream
import java.util.zip.DeflaterOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream

enum class Compression(private val keyword: String) : IppAttributeBuilder {
enum class Compression(val keyword: String) : IppAttributeBuilder {

COMPRESS("compress"), // RFC 1977
DEFLATE("deflate"), // RFC 1951
Expand All @@ -23,4 +29,19 @@ enum class Compression(private val keyword: String) : IppAttributeBuilder {
fun fromString(string: String) =
Compression.values().single { it.keyword == string }
}

fun getCompressingOutputStream(outputStream: OutputStream) = when (this) {
NONE -> outputStream
GZIP -> GZIPOutputStream(outputStream)
DEFLATE -> DeflaterOutputStream(outputStream)
else -> throw NotImplementedError("compression '$this'")
}

fun getUncompressingInputStream(inputStream: InputStream) = when (this) {
NONE -> inputStream
GZIP -> GZIPInputStream(inputStream)
DEFLATE -> DeflaterInputStream(inputStream)
else -> throw NotImplementedError("compression '$this'")
// Apache ZCompressorInputStream?
}
}

0 comments on commit 389e4d0

Please sign in to comment.