List of usage examples for org.apache.http.protocol HTTP CR
int CR
To view the source code for org.apache.http.protocol HTTP CR.
Click Source Link
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. * /*from w ww . j av a2 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 a2s. 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 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; }
From source file:org.deviceconnect.message.http.impl.factory.AbstractHttpMessageFactory.java
/** * HTTP???dConnect???./*from w w w . j a v a 2 s . co m*/ * @param dmessage dConnect * @param message HTTP */ protected void parseHttpBody(final DConnectMessage dmessage, final M message) { mLogger.entering(getClass().getName(), "newDConnectMessage", new Object[] { dmessage, message }); HttpEntity entity = getHttpEntity(message); if (entity != null) { MimeStreamParser parser = new MimeStreamParser(new MimeEntityConfig()); MultipartContentHandler handler = new MultipartContentHandler(dmessage); parser.setContentHandler(handler); StringBuilder headerBuffer = new StringBuilder(); for (Header header : message.getAllHeaders()) { headerBuffer.append(header.getName()); headerBuffer.append(": "); headerBuffer.append(header.getValue()); headerBuffer.append(Character.toChars(HTTP.CR)); headerBuffer.append(Character.toChars(HTTP.LF)); mLogger.fine("header: " + header.getName() + ":" + header.getValue()); } headerBuffer.append(Character.toChars(HTTP.CR)); headerBuffer.append(Character.toChars(HTTP.LF)); try { parser.parse(new SequenceInputStream( new ByteArrayInputStream(headerBuffer.toString().getBytes("US-ASCII")), entity.getContent())); } catch (IllegalStateException e) { mLogger.log(Level.FINE, e.toString(), e); mLogger.warning(e.toString()); } catch (MimeException e) { mLogger.log(Level.FINE, e.toString(), e); mLogger.warning(e.toString()); } catch (IOException e) { mLogger.log(Level.FINE, e.toString(), e); mLogger.warning(e.toString()); } } mLogger.exiting(getClass().getName(), "newDConnectMessage"); }
From source file:org.vietspider.net.apache.AbstractSessionInputBuffer.java
private int lineFromLineBuffer(final CharArrayBuffer charbuffer) throws IOException { // discard LF if found int l = this.linebuffer.length(); if (l > 0) { if (this.linebuffer.byteAt(l - 1) == HTTP.LF) { l--;/*from w ww. j a v a2s.c o m*/ this.linebuffer.setLength(l); } // discard CR if found if (l > 0) { if (this.linebuffer.byteAt(l - 1) == HTTP.CR) { l--; this.linebuffer.setLength(l); } } } l = this.linebuffer.length(); if (this.ascii) { charbuffer.append(this.linebuffer, 0, l); } else { String s = new String(this.linebuffer.buffer(), 0, l, this.charset); charbuffer.append(s); } return l; }
From source file:org.vietspider.net.apache.AbstractSessionInputBuffer.java
private int lineFromReadBuffer(final CharArrayBuffer charbuffer, int pos) throws IOException { int off = this.bufferpos; int len;/*from ww w. ja v a2 s. c o m*/ this.bufferpos = pos + 1; if (pos > 0 && this.buffer[pos - 1] == HTTP.CR) { // skip CR if found pos--; } len = pos - off; if (this.ascii) { charbuffer.append(this.buffer, off, len); } else { String s = new String(this.buffer, off, len, this.charset); charbuffer.append(s); } return len; }