List of usage examples for org.apache.http.util CharArrayBuffer indexOf
public int indexOf(int i, int i2, int i3)
From source file:com.subgraph.vega.ui.httpeditor.parser.ParserBase.java
/** * Get the next word from a buffer containing a line. * //from www . j a v a 2 s .c o m * @param lnBuf Buffer containing line. * @param lnCursor Parser cursor for lnBuf. Adjusted to one character after the word. * @return Next word, or null if none is found. */ protected String nextWord(final CharArrayBuffer lnBuf, final ParserCursor lnCursor) { skipSpHt(lnBuf, lnCursor); int idxPos = lnCursor.getPos(); int idxLineEnd = lnBuf.indexOf(' ', idxPos, lnCursor.getUpperBound()); if (idxLineEnd < 0) { if (idxPos == lnCursor.getUpperBound()) { return null; } idxLineEnd = lnCursor.getUpperBound(); } lnCursor.updatePos(idxLineEnd); return lnBuf.substringTrimmed(idxPos, idxLineEnd); }
From source file:com.subgraph.vega.ui.httpeditor.parser.ParserBase.java
/** * Get the next line of characters from a CharArrayBuffer into another CharArrayBuffer. Treats LF and CRLF as valid * line delimiters. Treats the entire buffer as a line if no line delimiters are found. * /*ww w.j ava 2 s .c o m*/ * @param src Source buffer to read line from. * @param srcCursor Parser cursor for src. Adjusted to discard line delimiters. * @param dst Destination buffer for characters from line. * @return Number of characters in line minus line delimiters, or < 0 if none found. */ protected int readLine(final CharArrayBuffer src, final ParserCursor srcCursor, final CharArrayBuffer dst) { if (srcCursor.atEnd()) { return -1; } int idxPos = srcCursor.getPos(); int idxLf = src.indexOf(HTTP.LF, idxPos, srcCursor.getUpperBound()); int idxEnd; if (idxLf > 0) { if (src.charAt(idxLf - 1) == HTTP.CR) { idxEnd = idxLf - 1; } else { idxEnd = idxLf; } } else { idxEnd = srcCursor.getUpperBound(); idxLf = idxEnd - 1; } dst.append(src, idxPos, idxEnd - idxPos); srcCursor.updatePos(idxLf + 1); return idxEnd - idxPos; }
From source file:com.subgraph.vega.ui.httpeditor.parser.ParserBase.java
/** * Get the next header line of characters from a CharArrayBuffer into another CharArrayBuffer. Treats LF and CRLF as * valid line delimiters. Treats the entire buffer as a line if no line delimiters are found. Supports folded header * field values as per the HTTP/1.1 specification. * //from w w w .jav a2 s. com * @param src Source buffer to read line from. * @param srcCursor Parser cursor for src. Adjusted to discard line delimiters. * @param dst Destination buffer for characters from line. * @return Number of characters in line minus line delimiters, or < 0 if none found. */ protected int readLineHeader(final CharArrayBuffer src, final ParserCursor srcCursor, final CharArrayBuffer dst) { if (srcCursor.atEnd()) { return -1; } int idxPos = srcCursor.getPos(); int chCnt = 0; int idxLf, idxEnd; do { idxLf = src.indexOf(HTTP.LF, idxPos, srcCursor.getUpperBound()); if (idxLf > 0) { if (src.charAt(idxLf - 1) == HTTP.CR) { idxEnd = idxLf - 1; } else { idxEnd = idxLf; } } else { idxEnd = srcCursor.getUpperBound(); idxLf = idxEnd - 1; } if (chCnt != 0) { while (idxPos < idxEnd && (src.charAt(idxPos) == HTTP.HT || src.charAt(idxPos) == HTTP.SP)) { idxPos++; } if (idxPos != idxEnd) { dst.append(' '); } } dst.append(src, idxPos, idxEnd - idxPos); chCnt += idxEnd - idxPos; idxPos = idxLf + 1; srcCursor.updatePos(idxPos); } while (idxPos < srcCursor.getUpperBound() && (src.charAt(idxPos) == HTTP.HT || src.charAt(idxPos) == HTTP.SP)); return chCnt; }