本文整理匯總了Java中org.apache.http.util.CharArrayBuffer類的典型用法代碼示例。如果您正苦於以下問題:Java CharArrayBuffer類的具體用法?Java CharArrayBuffer怎麽用?Java CharArrayBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CharArrayBuffer類屬於org.apache.http.util包,在下文中一共展示了CharArrayBuffer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseHeader
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
public HeaderElement parseHeader(
final CharArrayBuffer buffer,
final ParserCursor cursor) throws ParseException {
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
NameValuePair nvp = parseNameValuePair(buffer, cursor);
List<NameValuePair> params = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
NameValuePair param = parseNameValuePair(buffer, cursor);
params.add(param);
}
return new BasicHeaderElement(
nvp.getName(),
nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
示例2: parseChallenge
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
@Override
protected void parseChallenge(
final CharArrayBuffer buffer,
int beginIndex,
int endIndex ) throws MalformedChallengeException {
String challenge = buffer.substringTrimmed(beginIndex, endIndex);
if (log.isDebugEnabled()) {
log.debug("Received challenge '" + challenge + "' from the auth server");
}
if (state == State.UNINITIATED) {
token = base64codec.decode(challenge.getBytes());
state = State.CHALLENGE_RECEIVED;
} else {
log.debug("Authentication already attempted");
state = State.FAILED;
}
}
示例3: parse
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string
* using the given character encoding.
*
* @param s
* text to parse.
* @param charset
* Encoding to use when decoding the parameters.
*
* @since 4.2
*/
public static List<NameValuePair> parse (final String s, final Charset charset) {
if (s == null) {
return Collections.emptyList();
}
BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
ParserCursor cursor = new ParserCursor(0, buffer.length());
List<NameValuePair> list = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
if (nvp.getName().length() > 0) {
list.add(new BasicNameValuePair(
decodeFormFields(nvp.getName(), charset),
decodeFormFields(nvp.getValue(), charset)));
}
}
return list;
}
示例4: formatCookies
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
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;
}
示例5: formatCookies
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
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());
buffer.append("=");
String s = cookie.getValue();
if (s != null) {
buffer.append(s);
}
}
List<Header> headers = new ArrayList<Header>(1);
headers.add(new BufferedHeader(buffer));
return headers;
}
示例6: formatCookieAsVer
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* Return a string suitable for sending in a <tt>"Cookie"</tt> header
* as defined in RFC 2109 for backward compatibility with cookie version 0
* @param buffer The char array buffer to use for output
* @param cookie The {@link Cookie} to be formatted as string
* @param version The version to use.
*/
protected void formatCookieAsVer(final CharArrayBuffer buffer,
final Cookie cookie, int version) {
formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version);
if (cookie.getPath() != null) {
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PATH_ATTR)) {
buffer.append("; ");
formatParamAsVer(buffer, "$Path", cookie.getPath(), version);
}
}
if (cookie.getDomain() != null) {
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
buffer.append("; ");
formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version);
}
}
}
示例7: parseChallenge
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
@Override
protected void parseChallenge(
final CharArrayBuffer buffer,
int beginIndex, int endIndex) throws MalformedChallengeException {
String challenge = buffer.substringTrimmed(beginIndex, endIndex);
if (challenge.length() == 0) {
if (this.state == State.UNINITIATED) {
this.state = State.CHALLENGE_RECEIVED;
} else {
this.state = State.FAILED;
}
this.challenge = null;
} else {
this.state = State.MSG_TYPE2_RECEVIED;
this.challenge = challenge;
}
}
示例8: parseChallenge
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
@Override
protected void parseChallenge(
final CharArrayBuffer buffer,
int beginIndex, int endIndex) throws MalformedChallengeException {
String challenge = buffer.substringTrimmed(beginIndex, endIndex);
if (log.isDebugEnabled()) {
log.debug("Received challenge '" + challenge + "' from the auth server");
}
if (state == State.UNINITIATED) {
token = base64codec.decode(challenge.getBytes());
state = State.CHALLENGE_RECEIVED;
} else {
log.debug("Authentication already attempted");
state = State.FAILED;
}
}
示例9: doFormatValue
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* Actually formats the value of a name-value pair.
* This does not include a leading = character.
* Called from {@link #formatNameValuePair formatNameValuePair}.
*
* @param buffer the buffer to append to, never <code>null</code>
* @param value the value to append, never <code>null</code>
* @param quote <code>true</code> to always format with quotes,
* <code>false</code> to use quotes only when necessary
*/
protected void doFormatValue(final CharArrayBuffer buffer,
final String value,
boolean quote) {
if (!quote) {
for (int i = 0; (i < value.length()) && !quote; i++) {
quote = isSeparator(value.charAt(i));
}
}
if (quote) {
buffer.append('"');
}
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (isUnsafe(ch)) {
buffer.append('\\');
}
buffer.append(ch);
}
if (quote) {
buffer.append('"');
}
}
示例10: parseElements
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* 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 final static
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);
}
示例11: parseHeaderElement
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* Parses an element with the given parser.
*
* @param value the header element to parse
* @param parser the parser to use, or <code>null</code> for default
*
* @return the parsed header element
*/
public final static
HeaderElement parseHeaderElement(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.parseHeaderElement(buffer, cursor);
}
示例12: parseParameters
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* 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 final static
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);
}
示例13: parseNameValuePair
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* Parses a name-value-pair with the given parser.
*
* @param value the NVP to parse
* @param parser the parser to use, or <code>null</code> for default
*
* @return the parsed name-value pair
*/
public final static
NameValuePair parseNameValuePair(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.parseNameValuePair(buffer, cursor);
}
示例14: getCondensedHeader
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
/**
* Gets a header representing all of the header values with the given name.
* If more that one header with the given name exists the values will be
* combined with a "," as per RFC 2616.
*
* <p>Header name comparison is case insensitive.
*
* @param name the name of the header(s) to get
* @return a header with a condensed value or <code>null</code> if no
* headers by the given name are present
*/
public Header getCondensedHeader(String name) {
Header[] headers = getHeaders(name);
if (headers.length == 0) {
return null;
} else if (headers.length == 1) {
return headers[0];
} else {
CharArrayBuffer valueBuffer = new CharArrayBuffer(128);
valueBuffer.append(headers[0].getValue());
for (int i = 1; i < headers.length; i++) {
valueBuffer.append(", ");
valueBuffer.append(headers[i].getValue());
}
return new BasicHeader(name.toLowerCase(Locale.ENGLISH), valueBuffer.toString());
}
}
示例15: bufferHeaderValue
import org.apache.http.util.CharArrayBuffer; //導入依賴的package包/類
private void bufferHeaderValue() {
this.cursor = null;
this.buffer = null;
while (this.headerIt.hasNext()) {
Header h = this.headerIt.nextHeader();
if (h instanceof FormattedHeader) {
this.buffer = ((FormattedHeader) h).getBuffer();
this.cursor = new ParserCursor(0, this.buffer.length());
this.cursor.updatePos(((FormattedHeader) h).getValuePos());
break;
} else {
String value = h.getValue();
if (value != null) {
this.buffer = new CharArrayBuffer(value.length());
this.buffer.append(value);
this.cursor = new ParserCursor(0, this.buffer.length());
break;
}
}
}
}