use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicHeaderValueParser method parseParameters.
/**
* Parses parameters with the given parser.
*
* @param value the parameter list to parse
* @param parser the parser to use, or <code>null</code> for default
*
* @return array holding the parameters, never <code>null</code>
*/
public static final NameValuePair[] parseParameters(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.parseParameters(buffer, cursor);
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicLineFormatter method formatHeader.
// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header) {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
}
CharArrayBuffer result = null;
if (header instanceof FormattedHeader) {
// If the header is backed by a buffer, re-use the buffer
result = ((FormattedHeader) header).getBuffer();
} else {
result = initBuffer(buffer);
doFormatHeader(result, header);
}
return result;
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicLineFormatter method appendProtocolVersion.
// non-javadoc, see interface LineFormatter
public CharArrayBuffer appendProtocolVersion(final CharArrayBuffer buffer, final ProtocolVersion version) {
if (version == null) {
throw new IllegalArgumentException("Protocol version may not be null");
}
// can't use initBuffer, that would clear the argument!
CharArrayBuffer result = buffer;
final int len = estimateProtocolVersionLen(version);
if (result == null) {
result = new CharArrayBuffer(len);
} else {
result.ensureCapacity(len);
}
result.append(version.getProtocol());
result.append('/');
result.append(Integer.toString(version.getMajor()));
result.append('.');
result.append(Integer.toString(version.getMinor()));
return result;
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BrowserCompatSpec method parse.
public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
String headervalue = header.getValue();
boolean isNetscapeCookie = false;
int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
if (i1 != -1) {
i1 += "expires=".length();
int i2 = headervalue.indexOf(';', i1);
if (i2 == -1) {
i2 = headervalue.length();
}
try {
DateUtils.parseDate(headervalue.substring(i1, i2), this.datepatterns);
isNetscapeCookie = true;
} catch (DateParseException e) {
// Does not look like a valid expiry date
}
}
HeaderElement[] elems = null;
if (isNetscapeCookie) {
NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
CharArrayBuffer buffer;
ParserCursor cursor;
if (header instanceof FormattedHeader) {
buffer = ((FormattedHeader) header).getBuffer();
cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
} else {
String s = header.getValue();
if (s == null) {
throw new MalformedCookieException("Header value is null");
}
buffer = new CharArrayBuffer(s.length());
buffer.append(s);
cursor = new ParserCursor(0, buffer.length());
}
elems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
} else {
elems = header.getElements();
}
return parse(elems, origin);
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class NetscapeDraftSpec method formatCookies.
public List<Header> formatCookies(final List<Cookie> cookies) {
if (cookies == null) {
throw new IllegalArgumentException("List of cookies may not be null");
}
if (cookies.isEmpty()) {
throw new IllegalArgumentException("List of cookies may not be empty");
}
CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
buffer.append(cookie.getName());
String s = cookie.getValue();
if (s != null) {
buffer.append("=");
buffer.append(s);
}
}
List<Header> headers = new ArrayList<Header>(1);
headers.add(new BufferedHeader(buffer));
return headers;
}
Aggregations