Sha256: d894c8fa64948d4aa37f4dc1b6551f3493651e3855efaba3d2237cc374df7470
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require_relative '../data_conversion' module Ccrypto module Java class Compression include DataConversion include TR::CondUtils def initialize(*args, &block) @config = args.first raise CompressionError, "Compress Config is expected. Given #{@config}" if not @config.is_a?(Ccrypto::CompressionConfig) case @config.level when :best_compression teLogger.debug "Compression with best compression" @eng = java.util.zip.Deflater.new(java.util.zip.Deflater::BEST_COMPRESSION) when :best_speed teLogger.debug "Compression with best speed" @eng = java.util.zip.Deflater.new(java.util.zip.Deflater::BEST_SPEED) when :no_compression teLogger.debug "No compression" @eng = java.util.zip.Deflater.new(java.util.zip.Deflater::NO_COMPRESSION) else teLogger.debug "Default compression" @eng = java.util.zip.Deflater.new(java.util.zip.Deflater::DEFAULT_COMPRESSION) end teLogger.debug "Default strategy" @eng.setStrategy(java.util.zip.Deflater::DEFAULT_STRATEGY) @os = java.io.ByteArrayOutputStream.new end # returns compressed output length def update(val) if val.length > 0 teLogger.debug "Given #{val.length} bytes for compression" @eng.setInput(to_java_bytes(val)) @eng.finish baos = java.io.ByteArrayOutputStream.new buf = ::Java::byte[READ_BUF_SIZE].new while not @eng.finished done = @eng.deflate(buf) @os.write(buf,0,done) end @os.toByteArray else ::Java::byte[0].new end end def final end private def teLogger Java.logger(:comp_eng) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ccrypto-java-0.2.0 | lib/ccrypto/java/engines/compression_engine.rb |