Class: Ccrypto::Java::Compression
- Inherits:
-
Object
- Object
- Ccrypto::Java::Compression
- Includes:
- DataConversion, TR::CondUtils
- Defined in:
- lib/ccrypto/java/engines/compression_engine.rb
Instance Method Summary collapse
- #final ⇒ Object
-
#initialize(*args, &block) ⇒ Compression
constructor
A new instance of Compression.
-
#update(val) ⇒ Object
returns compressed output length.
Methods included from DataConversion
#from_b64, #from_b64_mime, #from_hex, included, #logger, #to_b64, #to_b64_mime, #to_bin, #to_hex, #to_java_bytes, #to_str
Constructor Details
#initialize(*args, &block) ⇒ Compression
Returns a new instance of Compression.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ccrypto/java/engines/compression_engine.rb', line 10 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 |
Instance Method Details
#final ⇒ Object
59 60 61 |
# File 'lib/ccrypto/java/engines/compression_engine.rb', line 59 def final end |
#update(val) ⇒ Object
returns compressed output length
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ccrypto/java/engines/compression_engine.rb', line 38 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 |