本文整理汇总了Java中org.apache.http.util.ByteArrayBuffer.append方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayBuffer.append方法的具体用法?Java ByteArrayBuffer.append怎么用?Java ByteArrayBuffer.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.ByteArrayBuffer
的用法示例。
在下文中一共展示了ByteArrayBuffer.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractResponseBytes
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
private byte[] extractResponseBytes(InputStream is) throws IOException {
BufferedInputStream bis = null;
BufferedReader br = null;
try {
ByteArrayBuffer baf = new ByteArrayBuffer(1024);
bis = new BufferedInputStream(is);
int b = 0;
while ((b = bis.read()) != -1)
baf.append((byte) b);
byte[] bytes = baf.toByteArray();
return bytes;
}
finally {
if (bis != null)
bis.close();
if (br != null)
br.close();
}
}
示例2: getResponse
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
public static String getResponse(String reqUrl) throws Exception {
final URL url = new URL(reqUrl);
final URLConnection ucon = url.openConnection();
/* Define InputStreams to read
* from the URLConnection. */
final InputStream is = ucon.getInputStream();
final BufferedInputStream bis = new BufferedInputStream(is);
/* Read bytes to the Buffer until
* there is nothing more to read(-1). */
final ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
return new String(baf.toByteArray());
}
示例3: getLogoImage
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
private byte[] getLogoImage(String url) {
try {
URL imageUrl = new URL(url);
URLConnection ucon = imageUrl.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return baf.toByteArray();
} catch (Exception e) {
Log.d("ImageManager", "Error: " + e.toString());
return null;
}
}
示例4: getHtmlString
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
public static String getHtmlString(String urlString) {
try {
URL url = new URL(urlString);
URLConnection ucon = url.openConnection();
InputStream instr = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(instr);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return EncodingUtils.getString(baf.toByteArray(), "utf-8");
} catch (Exception e) {
Log.d("win","lllll"+e.toString());
return "";
}
}
示例5: externalize
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
@Override
public byte [] externalize(){
//TODO use byte buffer
ByteArrayBuffer bb1 = new ByteArrayBuffer(100);
bb1.append('C');
byte [] cr = String.valueOf(getCreateTime()).getBytes();
bb1.append(cr, 0 , cr.length);
bb1.append(SsTableReader.END_COLUMN_PART);
cr = String.valueOf(getTime()).getBytes();
bb1.append(cr, 0 , cr.length);
bb1.append(SsTableReader.END_COLUMN_PART);
cr = String.valueOf(getTtl()).getBytes();
bb1.append(cr,0,cr.length);
bb1.append(SsTableReader.END_COLUMN_PART);
cr = String.valueOf(getValue()).getBytes();
bb1.append(SsTableReader.END_COLUMN_PART);
bb1.append(cr,0,cr.length);
return bb1.toByteArray();
}
示例6: downloadFromUrl
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
public String downloadFromUrl(String urlStr) {
try {
URL url = new URL(urlStr);
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
ByteArrayBuffer byteArrayBuffer = new ByteArrayBuffer(50);
int current;
while ((current = bufferedInputStream.read()) != -1) {
byteArrayBuffer.append((byte) current);
}
return new String(byteArrayBuffer.toByteArray());
} catch (IOException e) {
Log.d("DataDownloader", "Error: " + e);
}
return "";
}
示例7: hexToBytes
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
public static byte[] hexToBytes(String hex) {
ByteArrayBuffer bytes = new ByteArrayBuffer(hex.length() / 2);
for (int i = 0; i < hex.length(); i++) {
if (hex.charAt(i) == ' ') {
continue;
}
String hexByte;
if (i + 1 < hex.length()) {
hexByte = hex.substring(i, i + 2).trim();
i++;
} else {
hexByte = hex.substring(i, i + 1);
}
bytes.append(Integer.parseInt(hexByte, 16));
}
return bytes.buffer();
}
示例8: readStream
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
/**
* @param in
* @throws IOException
*/
private String readStream(InputStream in) throws IOException {
// prepare the input buffer
BufferedInputStream bis = new BufferedInputStream(in);
ByteArrayBuffer baf = new ByteArrayBuffer(1000);
int read = 0;
int bufSize = 1024;
byte[] buffer = new byte[bufSize];
// read the stream
while (true) {
read = bis.read(buffer);
if (read == -1) {
break;
}
baf.append(buffer, 0, read);
}
String queryResult = new String(baf.toByteArray());
// return result
return queryResult;
}
示例9: encode
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
private static ByteArrayBuffer encode(
final Charset charset, final String string) {
ByteBuffer encoded = charset.encode(CharBuffer.wrap(string));
ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining());
bab.append(encoded.array(), encoded.position(), encoded.remaining());
return bab;
}
示例10: getResponseData
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
byte[] getResponseData(HttpEntity entity) throws IOException {
byte[] responseBody = null;
if (entity != null) {
InputStream instream = entity.getContent();
if (instream != null) {
long contentLength = entity.getContentLength();
if (contentLength > 2147483647L) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in " +
"memory");
}
if (contentLength < 0) {
contentLength = PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;
}
try {
ByteArrayBuffer buffer = new ByteArrayBuffer((int) contentLength);
byte[] tmp = new byte[4096];
while (true) {
int l = instream.read(tmp);
if (l == -1 || Thread.currentThread().isInterrupted()) {
break;
}
buffer.append(tmp, 0, l);
sendProgressDataMessage(copyOfRange(tmp, 0, l));
sendProgressMessage((long) 0, contentLength);
}
AsyncHttpClient.silentCloseInputStream(instream);
responseBody = buffer.toByteArray();
} catch (OutOfMemoryError e) {
System.gc();
throw new IOException("File too large to fit into available memory");
} catch (Throwable th) {
AsyncHttpClient.silentCloseInputStream(instream);
}
}
}
return responseBody;
}
示例11: getResponseData
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
byte[] getResponseData(HttpEntity entity) throws IOException {
byte[] responseBody = null;
if (entity != null) {
InputStream instream = entity.getContent();
if (instream != null) {
long contentLength = entity.getContentLength();
if (contentLength > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
if (contentLength < 0) {
contentLength = BUFFER_SIZE;
}
try {
ByteArrayBuffer buffer = new ByteArrayBuffer((int) contentLength);
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l, count = 0;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
count += l;
buffer.append(tmp, 0, l);
sendProgressMessage(count, (int) contentLength);
}
} finally {
instream.close();
}
responseBody = buffer.toByteArray();
} catch (OutOfMemoryError e) {
System.gc();
throw new IOException("File too large to fit into available memory");
}
}
}
return responseBody;
}
示例12: getResponseData
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
/**
* Returns byte array of response HttpEntity contents
*
* @param entity can be null
* @return response entity body or null
* @throws java.io.IOException if reading entity or creating byte array failed
*/
byte[] getResponseData(HttpEntity entity) throws IOException {
byte[] responseBody = null;
if (entity != null) {
InputStream instream = entity.getContent();
if (instream != null) {
long contentLength = entity.getContentLength();
if (contentLength > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
int buffersize = (contentLength <= 0) ? BUFFER_SIZE : (int) contentLength;
try {
ByteArrayBuffer buffer = new ByteArrayBuffer(buffersize);
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l, count = 0;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
count += l;
buffer.append(tmp, 0, l);
sendProgressMessage(count, (int) (contentLength <= 0 ? 1 : contentLength));
}
} finally {
AsyncHttpClient.silentCloseInputStream(instream);
AsyncHttpClient.endEntityViaReflection(entity);
}
responseBody = buffer.toByteArray();
} catch (OutOfMemoryError e) {
System.gc();
throw new IOException("File too large to fit into available memory");
}
}
}
return responseBody;
}
示例13: getResponseData
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
/**
* Returns byte array of response HttpEntity contents
*
* @param entity can be null
* @return response entity body or null
* @throws java.io.IOException if reading entity or creating byte array failed
*/
@Override
byte[] getResponseData(HttpEntity entity) throws IOException {
byte[] responseBody = null;
if (entity != null) {
InputStream instream = entity.getContent();
if (instream != null) {
long contentLength = entity.getContentLength();
if (contentLength > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
if (contentLength < 0) {
contentLength = BUFFER_SIZE;
}
try {
ByteArrayBuffer buffer = new ByteArrayBuffer((int) contentLength);
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
buffer.append(tmp, 0, l);
sendProgressDataMessage(copyOfRange(tmp, 0, l));
}
} finally {
AsyncHttpClient.silentCloseInputStream(instream);
}
responseBody = buffer.toByteArray();
} catch (OutOfMemoryError e) {
System.gc();
throw new IOException("File too large to fit into available memory");
}
}
}
return responseBody;
}
示例14: getResponseData
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
/**
* Returns byte array of response HttpEntity contents
*
* @param entity can be null
* @return response entity body or null
* @throws IOException if reading entity or creating byte array failed
*/
byte[] getResponseData(HttpEntity entity) throws IOException {
byte[] responseBody = null;
if (entity != null) {
InputStream instream = entity.getContent();
if (instream != null) {
long contentLength = entity.getContentLength();
if (contentLength > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
int buffersize = (contentLength <= 0) ? BUFFER_SIZE : (int) contentLength;
try {
ByteArrayBuffer buffer = new ByteArrayBuffer(buffersize);
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l, count = 0;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
count += l;
buffer.append(tmp, 0, l);
sendProgressMessage(count, (int) (contentLength <= 0 ? 1 : contentLength));
}
} finally {
AsyncHttpClient.silentCloseInputStream(instream);
AsyncHttpClient.endEntityViaReflection(entity);
}
responseBody = buffer.toByteArray();
} catch (OutOfMemoryError e) {
System.gc();
throw new IOException("File too large to fit into available memory");
}
}
}
return responseBody;
}
示例15: getResponseData
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
/**
* Returns byte array of response HttpEntity contents
*
* @param entity can be null
* @return response entity body or null
* @throws IOException if reading entity or creating byte array failed
*/
@Override
byte[] getResponseData(HttpEntity entity) throws IOException {
byte[] responseBody = null;
if (entity != null) {
InputStream instream = entity.getContent();
if (instream != null) {
long contentLength = entity.getContentLength();
if (contentLength > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
if (contentLength < 0) {
contentLength = BUFFER_SIZE;
}
try {
ByteArrayBuffer buffer = new ByteArrayBuffer((int) contentLength);
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
buffer.append(tmp, 0, l);
sendProgressDataMessage(copyOfRange(tmp, 0, l));
}
} finally {
AsyncHttpClient.silentCloseInputStream(instream);
}
responseBody = buffer.toByteArray();
} catch (OutOfMemoryError e) {
System.gc();
throw new IOException("File too large to fit into available memory");
}
}
}
return responseBody;
}