use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicHeaderValueParser method parseElements.
// public default constructor
/**
* Parses elements with the given parser.
*
* @param value the header value to parse
* @param parser the parser to use, or <code>null</code> for default
*
* @return array holding the header elements, never <code>null</code>
*/
public static final HeaderElement[] parseElements(final String value, HeaderValueParser parser) throws ParseException {
if (value == null) {
throw new IllegalArgumentException("Value to parse may not be null");
}
if (parser == null)
parser = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseElements(buffer, cursor);
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicLineFormatter method formatStatusLine.
// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatStatusLine(final CharArrayBuffer buffer, final StatusLine statline) {
if (statline == null) {
throw new IllegalArgumentException("Status line may not be null");
}
CharArrayBuffer result = initBuffer(buffer);
doFormatStatusLine(result, statline);
return result;
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicLineFormatter method formatRequestLine.
// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer, RequestLine reqline) {
if (reqline == null) {
throw new IllegalArgumentException("Request line may not be null");
}
CharArrayBuffer result = initBuffer(buffer);
doFormatRequestLine(result, reqline);
return result;
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class AndroidHttpClientConnection method parseResponseHeader.
/**
* Parses the response headers and adds them to the
* given {@code headers} object, and returns the response StatusLine
* @param headers store parsed header to headers.
* @throws IOException
* @return StatusLine
* @see HttpClientConnection#receiveResponseHeader()
*/
public StatusLine parseResponseHeader(Headers headers) throws IOException, ParseException {
assertOpen();
CharArrayBuffer current = new CharArrayBuffer(64);
if (inbuffer.readLine(current) == -1) {
throw new NoHttpResponseException("The target server failed to respond");
}
// Create the status line from the status string
StatusLine statusline = BasicLineParser.DEFAULT.parseStatusLine(current, new ParserCursor(0, current.length()));
if (HttpLog.LOGV)
HttpLog.v("read: " + statusline);
int statusCode = statusline.getStatusCode();
// Parse header body
CharArrayBuffer previous = null;
int headerNumber = 0;
while (true) {
if (current == null) {
current = new CharArrayBuffer(64);
} else {
// This must be he buffer used to parse the status
current.clear();
}
int l = inbuffer.readLine(current);
if (l == -1 || current.length() < 1) {
break;
}
// Parse the header name and value
// Check for folded headers first
// Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2
// discussion on folded headers
char first = current.charAt(0);
if ((first == ' ' || first == '\t') && previous != null) {
// we have continuation folded header
// so append value
int start = 0;
int length = current.length();
while (start < length) {
char ch = current.charAt(start);
if (ch != ' ' && ch != '\t') {
break;
}
start++;
}
if (maxLineLength > 0 && previous.length() + 1 + current.length() - start > maxLineLength) {
throw new IOException("Maximum line length limit exceeded");
}
previous.append(' ');
previous.append(current, start, current.length() - start);
} else {
if (previous != null) {
headers.parseHeader(previous);
}
headerNumber++;
previous = current;
current = null;
}
if (maxHeaderCount > 0 && headerNumber >= maxHeaderCount) {
throw new IOException("Maximum header count exceeded");
}
}
if (previous != null) {
headers.parseHeader(previous);
}
if (statusCode >= 200) {
this.metrics.incrementResponseCount();
}
return statusline;
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class HttpHost method toURI.
/**
* Return the host URI, as a string.
*
* @return the host URI
*/
public String toURI() {
CharArrayBuffer buffer = new CharArrayBuffer(32);
buffer.append(this.schemeName);
buffer.append("://");
buffer.append(this.hostname);
if (this.port != -1) {
buffer.append(':');
buffer.append(Integer.toString(this.port));
}
return buffer.toString();
}
Aggregations