Class: GeoScript::Util::Bytes

Inherits:
Object
  • Object
show all
Defined in:
lib/geoscript/util/bytes.rb

Class Method Summary collapse

Class Method Details

.byte_to_string(byte, base) ⇒ Object



27
28
29
30
31
# File 'lib/geoscript/util/bytes.rb', line 27

def self.byte_to_string(byte, base)
  n = Math.log(256, base).ceil
  s = byte < 0 ? JInt.to_string(((b.abs ^ 0xff) + 0x01), base) : JInt.to_string(b, base)
  "%0#{n}d" % s
end

.decode(str, base) ⇒ Object

str.to_java_bytes



6
7
8
9
10
11
12
13
14
# File 'lib/geoscript/util/bytes.rb', line 6

def self.decode(str, base) # str.to_java_bytes
  #n = Math.log(256, base).ceil
  #bytes = []
  #(0...str.size).step(n) do |i|
  #  bytes << string_to_byte(str[i...(i + n)].join(''), base)
  #end
  #bytes.to_java java.lang.Byte
  str.to_java_bytes
end

.encode(bytes, base) ⇒ Object

bytes.from_java_bytes



16
17
18
19
20
21
22
23
24
25
# File 'lib/geoscript/util/bytes.rb', line 16

def self.encode(bytes, base) # bytes.from_java_bytes
  #bytes_array = []
  #
  #bytes.each do |byte|
  #  bytes_array << byte_to_string(byte, base)
  #end
  #
  #bytes_array.join ''
  bytes.from_java_bytes
end

.string_to_byte(string, base) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/geoscript/util/bytes.rb', line 33

def self.string_to_byte(string, base)
  int = string.to_i(base)
  if int > 128
    -1 * ((int ^ 0xff) + 0x01)
  else
    int
  end
end