本文整理汇总了Java中org.apache.http.util.ByteArrayBuffer.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayBuffer.toByteArray方法的具体用法?Java ByteArrayBuffer.toByteArray怎么用?Java ByteArrayBuffer.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.ByteArrayBuffer
的用法示例。
在下文中一共展示了ByteArrayBuffer.toByteArray方法的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: DownloadFromUrl
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
public static String DownloadFromUrl(String u) {
try {
URL url = new URL(u);
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return new String(baf.toByteArray());
} catch (Exception e) {
Log.e(TAG, "Error: " + e);
}
return null;
}
示例5: inputStreamToString
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
/**
* 将inputStream 以系统默认编码转换为字符串
*
* @param 字节流
*
*/
public String inputStreamToString(InputStream is) throws IOException {
byte arr[] = new byte[1024];
ByteArrayBuffer byteArrayBuffer = new ByteArrayBuffer(1024);
int len = 0;
try {
while ((len = is.read(arr)) != -1) {
byteArrayBuffer.append(arr, 0, len);
}
} finally {
try {
is.close();
} catch (IOException e) {
// do nothing
}
}
return new String(byteArrayBuffer.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: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例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 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 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];
long count = 0;
int l;
// 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, (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: getBytes
import org.apache.http.util.ByteArrayBuffer; //导入方法依赖的package包/类
private byte[] getBytes(InputStream is) throws IOException {
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(5000);
int current;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return baf.toByteArray();
}