class HTTPClient::JavaSocketWrap

Constants

BUF_SIZE

Public Class Methods

new(socket, debug_dev = nil) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 21
def initialize(socket, debug_dev = nil)
  @socket = socket
  @debug_dev = debug_dev
  @outstr = @socket.getOutputStream
  @instr = BufferedInputStream.new(@socket.getInputStream)
  @buf = (' ' * BUF_SIZE).to_java_bytes
  @bufstr = ''
end

Public Instance Methods

<<(str) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 85
def <<(str)
  rv = @outstr.write(str.to_java_bytes)
  debug(str)
  rv
end
close() click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 30
def close
  @socket.close
end
closed?() click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 34
def closed?
  @socket.isClosed
end
eof?() click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 38
def eof?
  @socket.isClosed
end
flush() click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 91
def flush
  @socket.flush
end
gets(rs) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 43
def gets(rs)
  while (size = @bufstr.index(rs)).nil?
    if fill() == -1
      size = @bufstr.size
      break
    end
  end
  str = @bufstr.slice!(0, size + rs.size)
  debug(str)
  str
end
read(size, buf = nil) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 55
def read(size, buf = nil)
  while @bufstr.size < size
    if fill() == -1
      break
    end
  end
  str = @bufstr.slice!(0, size)
  debug(str)
  if buf
    buf.replace(str)
  else
    str
  end
end
readpartial(size, buf = nil) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 70
def readpartial(size, buf = nil)
  while @bufstr.size == 0
    if fill() == -1
      raise EOFError.new('end of file reached')
    end
  end
  str = @bufstr.slice!(0, size)
  debug(str)
  if buf
    buf.replace(str)
  else
    str
  end
end
sync() click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 95
def sync
  true
end
sync=(sync) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 99
def sync=(sync)
  unless sync
    raise "sync = false is not supported. This option was introduced for backward compatibility just in case."
  end
end

Private Instance Methods

debug(str) click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 115
def debug(str)
  @debug_dev << str if @debug_dev && str
end
fill() click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 107
def fill
  size = @instr.read(@buf)
  if size > 0
    @bufstr << String.from_java_bytes(@buf, Encoding::BINARY)[0, size]
  end
  size
end