本文整理匯總了Java中org.apache.http.util.CharArrayBuffer.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java CharArrayBuffer.toString方法的具體用法?Java CharArrayBuffer.toString怎麽用?Java CharArrayBuffer.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.util.CharArrayBuffer
的用法示例。
在下文中一共展示了CharArrayBuffer.toString方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
}
示例2: BufferedHeader
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Creates a new header from a buffer.
* The name of the header will be parsed immediately,
* the value only if it is accessed.
*
* @param buffer the buffer containing the header to represent
*
* @throws ParseException in case of a parse error
*/
public BufferedHeader(final CharArrayBuffer buffer)
throws ParseException {
super();
if (buffer == null) {
throw new IllegalArgumentException
("Char array buffer may not be null");
}
int colon = buffer.indexOf(':');
if (colon == -1) {
throw new ParseException
("Invalid header: " + buffer.toString());
}
String s = buffer.substringTrimmed(0, colon);
if (s.length() == 0) {
throw new ParseException
("Invalid header: " + buffer.toString());
}
this.buffer = buffer;
this.name = s;
this.valuePos = colon + 1;
}
示例3: readLine
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
public String readLine() throws IOException {
CharArrayBuffer charbuffer = new CharArrayBuffer(64);
int l = readLine(charbuffer);
if (l != -1) {
return charbuffer.toString();
} else {
return null;
}
}
示例4: gzipToString
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
public static String gzipToString(final HttpEntity entity, final String defaultCharset) throws IOException, ParseException {
if (entity == null) {
throw new IllegalArgumentException("HTTP entity may not be null");
}
InputStream instream = entity.getContent();
if (instream == null) {
return "";
}
// gzip logic start
if (entity.getContentEncoding().getValue().contains("gzip")) {
instream = new GZIPInputStream(instream);
}
// gzip logic end
if (entity.getContentLength() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
int i = (int)entity.getContentLength();
if (i < 0) {
i = 4096;
}
String charset = EntityUtils.getContentCharSet(entity);
if (charset == null) {
charset = defaultCharset;
}
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
Reader reader = new InputStreamReader(instream, charset);
CharArrayBuffer buffer = new CharArrayBuffer(i);
try {
char[] tmp = new char[1024];
int l;
while((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
} finally {
reader.close();
}
return buffer.toString();
}
示例5: toString
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
/**
* Generates textual representation of this content type which can be used as the value
* of a <code>Content-Type</code> header.
*/
@Override
public String toString() {
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.append(this.mimeType);
if (this.params != null) {
buf.append("; ");
BasicHeaderValueFormatterHC4.INSTANCE.formatParameters(buf, this.params, false);
} else if (this.charset != null) {
buf.append("; charset=");
buf.append(this.charset.name());
}
return buf.toString();
}
示例6: readLine
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
public String readLine() throws IOException {
final CharArrayBuffer charbuffer = new CharArrayBuffer(64);
final int l = readLine(charbuffer);
if (l != -1) {
return charbuffer.toString();
} else {
return null;
}
}
示例7: doSendResponse
import org.apache.http.util.CharArrayBuffer; //導入方法依賴的package包/類
@Override
public void doSendResponse(RestResponse response) {
status = response.status().getStatus();
byte[] bytes = response.content().toBytes();
long length = bytes.length;
Args.check(length <= Integer.MAX_VALUE, "HTTP entity too large to be buffered in memory");
if(length < 0) {
length = 4096;
}
InputStream instream = new ByteArrayInputStream(bytes);
InputStreamReader reader = new InputStreamReader(instream, Consts.UTF_8);
CharArrayBuffer buffer = new CharArrayBuffer((int)length);
char[] tmp = new char[1024];
int l;
try {
while ((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
content = buffer.toString();
} catch (IOException e) {
status = RestStatus.INTERNAL_SERVER_ERROR.getStatus();
content = "IOException: " + e.getMessage();
} finally {
try {
reader.close();
instream.close();
} catch (IOException e1) {
content = "IOException: " + e1.getMessage();
} finally {
count.countDown();
}
}
}