Module: PkernelJce::IoUtils
- Defined in:
- lib/pkernel_jce/io_utils.rb
Class Method Summary collapse
-
.ensure_java_bytes(bin) ⇒ Object
end file_to_memory_byte_array.
- .file_to_memory_byte_array(path) ⇒ Object
- .from_hex(str) ⇒ Object
-
.to_hex(bin) ⇒ Object
end ensure_java_bytes.
Class Method Details
.ensure_java_bytes(bin) ⇒ Object
end file_to_memory_byte_array
21 22 23 24 25 26 27 |
# File 'lib/pkernel_jce/io_utils.rb', line 21 def IoUtils.ensure_java_bytes(bin) if not bin.java_kind_of?(Java::byte[]) bin.to_java_bytes else bin end end |
.file_to_memory_byte_array(path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pkernel_jce/io_utils.rb', line 5 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 |
.from_hex(str) ⇒ Object
35 36 37 |
# File 'lib/pkernel_jce/io_utils.rb', line 35 def IoUtils.from_hex(str) org.bouncycastle.util.encoders.Hex.decode(str) end |
.to_hex(bin) ⇒ Object
end ensure_java_bytes
31 32 33 |
# File 'lib/pkernel_jce/io_utils.rb', line 31 def IoUtils.to_hex(bin) String.from_java_bytes(org.bouncycastle.util.encoders.Hex.encode(bin)) end |