Class: Higgs::Tar::JRawIO

Inherits:
Object
  • Object
show all
Defined in:
lib/higgs/jcompat.rb

Constant Summary collapse

CVS_ID =
'$Id: jcompat.rb 794 2008-08-05 13:43:03Z toki $'

Instance Method Summary collapse

Constructor Details

#initialize(path, mode = 'r') ⇒ JRawIO

Returns a new instance of JRawIO.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/higgs/jcompat.rb', line 23

def initialize(path, mode='r')
  read_only = true
  case (mode)
  when String
    if (mode =~ /w/) then
      read_only = false
    end
  when Integer
    if ((mode & (File::WRONLY | File::RDWR)) != 0) then
      read_only = false
    end
  end
  @io = java.io.RandomAccessFile.new(path, read_only ? 'r' : 'rw')
  @buf = make_java_byte_array(1024)
  @closed = false
end

Instance Method Details

#closeObject



82
83
84
85
86
# File 'lib/higgs/jcompat.rb', line 82

def close
  @io.close
  @closed = true
  nil
end

#closed?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/higgs/jcompat.rb', line 88

def closed?
  @closed
end

#flushObject



69
70
# File 'lib/higgs/jcompat.rb', line 69

def flush
end

#fsyncObject



72
73
74
75
# File 'lib/higgs/jcompat.rb', line 72

def fsync
  @io.getFD.sync
  nil
end

#read(size) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/higgs/jcompat.rb', line 40

def read(size)
  @buf = make_java_byte_array(size) if (@buf.length < size)
  read_size = @io.read(@buf, 0, size)
  if (read_size > 0) then
    String.from_java_bytes(@buf)[0, read_size]
  elsif (read_size == 0) then
    ""
  else
    nil
  end
end

#seek(pos) ⇒ Object Also known as: pos=



61
62
63
64
# File 'lib/higgs/jcompat.rb', line 61

def seek(pos)
  @io.seek(pos)
  nil
end

#tellObject Also known as: pos



57
58
59
# File 'lib/higgs/jcompat.rb', line 57

def tell
  @io.getFilePointer
end

#truncate(size) ⇒ Object



77
78
79
80
# File 'lib/higgs/jcompat.rb', line 77

def truncate(size)
  @io.setLength(size)
  nil
end

#write(str) ⇒ Object



52
53
54
55
# File 'lib/higgs/jcompat.rb', line 52

def write(str)
  @io.write(str.to_java_bytes)
  nil
end