当前位置: 首页>>代码示例>>Java>>正文


Java ByteArrayBuffer.toByteArray方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:20,代码来源:HttpAltConnection.java

示例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());
}
 
开发者ID:sunnygoyal,项目名称:neon-clock-gl,代码行数:20,代码来源:WeatherService.java

示例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;
    }

}
 
开发者ID:tranquang9a1,项目名称:ECRM,代码行数:23,代码来源:LoginActivity.java

示例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;
}
 
开发者ID:balscit,项目名称:Padio,代码行数:20,代码来源:Settings.java

示例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());
}
 
开发者ID:tincent,项目名称:libtincent,代码行数:24,代码来源:TXStringUtils.java

示例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 "";
}
 
开发者ID:Wearlabs,项目名称:gps-mock-android,代码行数:20,代码来源:SendMockLocationService.java

示例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;
}
 
开发者ID:dbalaouras,项目名称:greece-phonebook-android,代码行数:28,代码来源:JavaWebServiceClient.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:DataAsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:36,代码来源:AsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:42,代码来源:AsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:44,代码来源:DataAsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:42,代码来源:AsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:44,代码来源:DataAsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:hcq0618,项目名称:AndroidWear-OpenWear,代码行数:43,代码来源:AsyncHttpResponseHandler.java

示例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();
}
 
开发者ID:GeoThings,项目名称:Clickers,代码行数:10,代码来源:SocialSharing.java


注:本文中的org.apache.http.util.ByteArrayBuffer.toByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。