本文整理匯總了Java中org.apache.http.util.CharArrayBuffer.append方法的典型用法代碼示例。如果您正苦於以下問題:Java CharArrayBuffer.append方法的具體用法?Java CharArrayBuffer.append怎麽用?Java CharArrayBuffer.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.util.CharArrayBuffer
的用法示例。
在下文中一共展示了CharArrayBuffer.append方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: lineFromReadBuffer
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
private int lineFromReadBuffer(final CharArrayBuffer charbuffer, int pos)
throws IOException {
int off = this.bufferpos;
int len;
this.bufferpos = pos + 1;
if (pos > off && this.buffer[pos - 1] == HTTP.CR) {
// skip CR if found
pos--;
}
len = pos - off;
if (this.ascii) {
charbuffer.append(this.buffer, off, len);
} else {
ByteBuffer bbuf = ByteBuffer.wrap(this.buffer, off, len);
len = appendDecoded(charbuffer, bbuf);
}
return len;
}
示例3: doFormatRequestLine
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Actually formats a request line.
* Called from {@link #formatRequestLine}.
*
* @param buffer the empty buffer into which to format,
* never <code>null</code>
* @param reqline the request line to format, never <code>null</code>
*/
protected void doFormatRequestLine(final CharArrayBuffer buffer,
final RequestLine reqline) {
final String method = reqline.getMethod();
final String uri = reqline.getUri();
// room for "GET /index.html HTTP/1.1"
int len = method.length() + 1 + uri.length() + 1 +
estimateProtocolVersionLen(reqline.getProtocolVersion());
buffer.ensureCapacity(len);
buffer.append(method);
buffer.append(' ');
buffer.append(uri);
buffer.append(' ');
appendProtocolVersion(buffer, reqline.getProtocolVersion());
}
示例4: doFormatHeader
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Actually formats a header.
* Called from {@link #formatHeader}.
*
* @param buffer the empty buffer into which to format,
* never <code>null</code>
* @param header the header to format, never <code>null</code>
*/
protected void doFormatHeader(final CharArrayBuffer buffer,
final Header header) {
final String name = header.getName();
final String value = header.getValue();
int len = name.length() + 2;
if (value != null) {
len += value.length();
}
buffer.ensureCapacity(len);
buffer.append(name);
buffer.append(": ");
if (value != null) {
buffer.append(value);
}
}
示例5: 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('"');
}
}
示例6: 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);
}
示例7: doFormatStatusLine
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Actually formats a status line.
* Called from {@link #formatStatusLine}.
*
* @param buffer the empty buffer into which to format,
* never <code>null</code>
* @param statline the status line to format, never <code>null</code>
*/
protected void doFormatStatusLine(final CharArrayBuffer buffer,
final StatusLine statline) {
int len = estimateProtocolVersionLen(statline.getProtocolVersion())
+ 1 + 3 + 1; // room for "HTTP/1.1 200 "
final String reason = statline.getReasonPhrase();
if (reason != null) {
len += reason.length();
}
buffer.ensureCapacity(len);
appendProtocolVersion(buffer, statline.getProtocolVersion());
buffer.append(' ');
buffer.append(Integer.toString(statline.getStatusCode()));
buffer.append(' '); // keep whitespace even if reason phrase is empty
if (reason != null) {
buffer.append(reason);
}
}
示例8: 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);
}
示例9: 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);
}
示例10: lineFromLineBuffer
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Reads a complete line of characters up to a line delimiter from this
* session buffer. The line delimiter itself is discarded. If no char is
* available because the end of the stream has been reached,
* <code>null</code> is returned. This method blocks until input data is
* available, end of file is detected, or an exception is thrown.
* <p>
* This method treats a lone LF as a valid line delimiters in addition
* to CR-LF required by the HTTP specification.
*
* @return HTTP line as a string
* @exception IOException if an I/O error occurs.
*/
private int lineFromLineBuffer(final CharArrayBuffer charbuffer)
throws IOException {
// discard LF if found
int len = this.linebuffer.length();
if (len > 0) {
if (this.linebuffer.byteAt(len - 1) == HTTP.LF) {
len--;
}
// discard CR if found
if (len > 0) {
if (this.linebuffer.byteAt(len - 1) == HTTP.CR) {
len--;
}
}
}
if (this.ascii) {
charbuffer.append(this.linebuffer, 0, len);
} else {
ByteBuffer bbuf = ByteBuffer.wrap(this.linebuffer.buffer(), 0, len);
len = appendDecoded(charbuffer, bbuf);
}
this.linebuffer.clear();
return len;
}
示例11: parseProtocolVersion
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
public final static
ProtocolVersion parseProtocolVersion(String value,
LineParser parser)
throws ParseException {
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null.");
}
if (parser == null)
parser = BasicLineParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseProtocolVersion(buffer, cursor);
}
示例12: parseRequestLine
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
public final static
RequestLine parseRequestLine(final String value,
LineParser parser)
throws ParseException {
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null.");
}
if (parser == null)
parser = BasicLineParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseRequestLine(buffer, cursor);
}
示例13: parseHeader
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
public final static
Header parseHeader(final String value,
LineParser parser)
throws ParseException {
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null");
}
if (parser == null)
parser = BasicLineParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
return parser.parseHeader(buffer);
}
示例14: authenticate
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Returns a Diadoc <tt>Authorization</tt> header value for the given
* {@link DiadocCredentials}.
*
* @param credentials The credentials to encode.
* @return a Diadoc authorization header
*/
public static Header authenticate(final DiadocCredentials credentials) {
if (credentials == null) {
throw new IllegalArgumentException("Credentials may not be null");
}
StringBuilder sb = new StringBuilder();
sb.append("ddauth_api_client_id=");
sb.append(credentials.getApiClientId());
if (credentials.getAuthToken() != null) {
sb.append(",ddauth_token=");
sb.append(credentials.getAuthToken());
}
CharArrayBuffer buffer = new CharArrayBuffer(128);
buffer.append(AUTH.WWW_AUTH_RESP);
buffer.append(": DiadocAuth ");
buffer.append(sb.toString());
return new BufferedHeader(buffer);
}
示例15: 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;
}