Class: Rubylet::Input

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rubylet/input.rb

Overview

Wraps servlet InputStream with a buffer to support Rack required #rewind.

Constant Summary collapse

MAX_BUFFER =

500 kiB

500 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Input

Returns a new instance of Input.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubylet/input.rb', line 12

def initialize(req)
  @stream = java.io.BufferedInputStream.new(req.getInputStream,
                                            req.getContentLength)
  if req.getContentLength > 0 && req.getContentLength < MAX_BUFFER
    @stream.mark(req.getContentLength)
  else
    # TODO: buffer to a file or something; use jruby-rack's RewindableInputStream
    req.getServletContext.log(
      "WARN: input stream of size #{req.getContentLength}; " +
      "rack #rewind only supported to first #{MAX_BUFFER/1024} kiB")
    @stream.mark(MAX_BUFFER)
  end
  
  @io = stream.to_io
end

Instance Method Details

#rewindObject



28
29
30
# File 'lib/rubylet/input.rb', line 28

def rewind
  @stream.reset
end