while (retry) { int i = locateLF(); if (i != -1) { return lineFromReadBuffer(charbuffer, i); } else { if (hasBufferedData()) { int len = this.bufferlen - this.bufferpos; this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = this.bufferlen; noRead = fillBuffer(); if (noRead == -1) { retry = false; return lineFromLineBuffer(charbuffer);
public int read(final byte[] b) throws IOException { if (b == null) { return 0; } return read(b, 0, b.length); }
public String readLine() throws IOException { CharArrayBuffer charbuffer = new CharArrayBuffer(64); int l = readLine(charbuffer); if (l != -1) { return charbuffer.toString(); } else { return null; } }
public int read() throws IOException { int noRead = 0; while (!hasBufferedData()) { noRead = fillBuffer(); if (noRead == -1) { return -1; } } return this.buffer[this.bufferpos++] & 0xff; }
@Override protected int fillBuffer() throws IOException { final int i = super.fillBuffer(); this.eof = i == -1; return i; }
private int lineFromReadBuffer(final CharArrayBuffer charbuffer, final int position) throws IOException { final int off = this.bufferpos; int i = position; this.bufferpos = i + 1; if (i > off && this.buffer[i - 1] == HTTP.CR) { // skip CR if found i--; } int len = i - off; if (this.ascii) { charbuffer.append(this.buffer, off, len); } else { final ByteBuffer bbuf = ByteBuffer.wrap(this.buffer, off, len); len = appendDecoded(charbuffer, bbuf); } return len; }
/** * Initializes this session input buffer. * * @param instream the source input stream. * @param buffersize the size of the internal buffer. * @param params HTTP parameters. */ protected void init(final InputStream instream, final int buffersize, final HttpParams params) { Args.notNull(instream, "Input stream"); Args.notNegative(buffersize, "Buffer size"); Args.notNull(params, "HTTP parameters"); this.instream = instream; this.buffer = new byte[buffersize]; this.bufferpos = 0; this.bufferlen = 0; this.linebuffer = new ByteArrayBuffer(buffersize); final String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET); this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII; this.ascii = this.charset.equals(Consts.ASCII); this.decoder = null; this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512); this.metrics = createTransportMetrics(); final CodingErrorAction a1 = (CodingErrorAction) params.getParameter( CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION); this.onMalformedCharAction = a1 != null ? a1 : CodingErrorAction.REPORT; final CodingErrorAction a2 = (CodingErrorAction) params.getParameter( CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION); this.onUnmappableCharAction = a2 != null? a2 : CodingErrorAction.REPORT; }
public int read(final byte[] b, int off, int len) throws IOException { if (b == null) { return 0; } int noRead = 0; while (!hasBufferedData()) { noRead = fillBuffer(); if (noRead == -1) { return -1; } } int chunk = this.bufferlen - this.bufferpos; if (chunk > len) { chunk = len; } System.arraycopy(this.buffer, this.bufferpos, b, off, chunk); this.bufferpos += chunk; return chunk; }
@Override protected int fillBuffer() throws IOException { final int i = super.fillBuffer(); this.eof = i == -1; return i; }
private int lineFromReadBuffer(final CharArrayBuffer charbuffer, final int position) throws IOException { final int off = this.bufferpos; int i = position; this.bufferpos = i + 1; if (i > off && this.buffer[i - 1] == HTTP.CR) { // skip CR if found i--; } int len = i - off; if (this.ascii) { charbuffer.append(this.buffer, off, len); } else { final ByteBuffer bbuf = ByteBuffer.wrap(this.buffer, off, len); len = appendDecoded(charbuffer, bbuf); } return len; }
/** * Initializes this session input buffer. * * @param instream the source input stream. * @param buffersize the size of the internal buffer. * @param params HTTP parameters. */ protected void init(final InputStream instream, final int buffersize, final HttpParams params) { Args.notNull(instream, "Input stream"); Args.notNegative(buffersize, "Buffer size"); Args.notNull(params, "HTTP parameters"); this.instream = instream; this.buffer = new byte[buffersize]; this.bufferpos = 0; this.bufferlen = 0; this.linebuffer = new ByteArrayBuffer(buffersize); final String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET); this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII; this.ascii = this.charset.equals(Consts.ASCII); this.decoder = null; this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512); this.metrics = createTransportMetrics(); final CodingErrorAction a1 = (CodingErrorAction) params.getParameter( CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION); this.onMalformedCharAction = a1 != null ? a1 : CodingErrorAction.REPORT; final CodingErrorAction a2 = (CodingErrorAction) params.getParameter( CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION); this.onUnmappableCharAction = a2 != null? a2 : CodingErrorAction.REPORT; }
while (retry) { int i = locateLF(); if (i != -1) { return lineFromReadBuffer(charbuffer, i); } else { if (hasBufferedData()) { int len = this.bufferlen - this.bufferpos; this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = this.bufferlen; noRead = fillBuffer(); if (noRead == -1) { retry = false; return lineFromLineBuffer(charbuffer);
public int read() throws IOException { int noRead; while (!hasBufferedData()) { noRead = fillBuffer(); if (noRead == -1) { return -1; } } return this.buffer[this.bufferpos++] & 0xff; }
public int read(final byte[] b) throws IOException { if (b == null) { return 0; } return read(b, 0, b.length); }
public String readLine() throws IOException { CharArrayBuffer charbuffer = new CharArrayBuffer(64); int l = readLine(charbuffer); if (l != -1) { return charbuffer.toString(); } else { return null; } }
@Override protected int fillBuffer() throws IOException { final int i = super.fillBuffer(); this.eof = i == -1; return i; }
private int lineFromReadBuffer(final CharArrayBuffer charbuffer, final int position) throws IOException { final int off = this.bufferpos; int i = position; this.bufferpos = i + 1; if (i > off && this.buffer[i - 1] == HTTP.CR) { // skip CR if found i--; } int len = i - off; if (this.ascii) { charbuffer.append(this.buffer, off, len); } else { final ByteBuffer bbuf = ByteBuffer.wrap(this.buffer, off, len); len = appendDecoded(charbuffer, bbuf); } return len; }