module Fishwife
  class HijackIo
    def initialize(async_context)
      @async_context = async_context
    end

    def write(str)
      @async_context.response.output_stream.print(str)
    end

    def flush
      @async_context.response.writer.flush
    end

    def close
      @async_context.complete
    end

    def close_write(str)
      write(str)
      close
    end

    def closed?
    end

    def read(*)
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end

    def read_nonblock(*)
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end

    def write_nonblock(*)
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end

    def close_read
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end
  end
end

module Fishwife
  class HijackIo
    def initialize(async_context)
      @async_context = async_context
    end

    def write(str)
      @async_context.response.output_stream.write(str.to_java_bytes)
    end

    def flush
      @async_context.response.writer.flush
    end

    def close
      @async_context.complete
    end

    def close_write(str)
      write(str)
      close
    end

    def closed?
    end

    def read(*)
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end

    def read_nonblock(*)
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end

    def write_nonblock(*)
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end

    def close_read
      raise NotImplementedError, '##{__method__} on hijacked IO is not supported'
    end
  end
end

Write raw bytes instead of converting through Java strings
Write raw bytes instead of converting through Java strings