Sha256: 7e1f924bcdd718f785530e61d12c8e889243fd092acf7e2b61b52d9cdc7b73f0

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

module PkernelJce
  module IoUtils
    
    def IoUtils.file_to_memory_byte_array(path)
      if path.nil? or path.empty?
        raise PkernelJce::Error, "Given path '#{path}' to load to memory is nil or empty"
      else
        f = java.io.File.new(path)
        b = Java::byte[f.length].new
        dis = java.io.DataInputStream.new(java.io.FileInputStream.new(f))
        dis.readFully(b)
        dis.close

        b
      end
    end
    # end file_to_memory_byte_array
    #

    def IoUtils.ensure_java_bytes(bin)
      if not bin.java_kind_of?(Java::byte[])
        bin.to_java_bytes
      elsif bin.is_a?(String)
        bin = bin.to_java.getBytes
      else
        bin
      end
    end
    # end ensure_java_bytes
    #

    def IoUtils.to_hex(bin)
      String.from_java_bytes(org.bouncycastle.util.encoders.Hex.encode(bin))
    end

    def IoUtils.from_hex(str)
      org.bouncycastle.util.encoders.Hex.decode(str)
    end

  end
  # end IoUtils
  #

end
# end PkernelJce
# 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pkernel_jce-0.7.0 lib/pkernel_jce/io_utils.rb