本文整理汇总了Java中org.apache.http.util.ByteArrayBuffer类的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayBuffer类的具体用法?Java ByteArrayBuffer怎么用?Java ByteArrayBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteArrayBuffer类属于org.apache.http.util包,在下文中一共展示了ByteArrayBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
/**
* Initializes this session input buffer.
*
* @param instream the source input stream.
* @param buffersize the size of the internal buffer.
* @param params HTTP parameters.
*/
protected void init(final InputStream instream, int buffersize, final HttpParams params) {
if (instream == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
if (buffersize <= 0) {
throw new IllegalArgumentException("Buffer size may not be negative or zero");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.instream = instream;
this.buffer = new byte[buffersize];
this.bufferpos = 0;
this.bufferlen = 0;
this.linebuffer = new ByteArrayBuffer(buffersize);
this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params));
this.ascii = this.charset.equals(ASCII);
this.decoder = null;
this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
this.metrics = createTransportMetrics();
this.onMalformedInputAction = HttpProtocolParams.getMalformedInputAction(params);
this.onUnMappableInputAction = HttpProtocolParams.getUnmappableInputAction(params);
}
示例2: init
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
/**
* Initializes this session output buffer.
*
* @param outstream the destination output stream.
* @param buffersize the size of the internal buffer.
* @param params HTTP parameters.
*/
protected void init(final OutputStream outstream, int buffersize, final HttpParams params) {
if (outstream == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
if (buffersize <= 0) {
throw new IllegalArgumentException("Buffer size may not be negative or zero");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.outstream = outstream;
this.buffer = new ByteArrayBuffer(buffersize);
this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params));
this.ascii = this.charset.equals(ASCII);
this.encoder = null;
this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
this.metrics = createTransportMetrics();
this.onMalformedInputAction = HttpProtocolParams.getMalformedInputAction(params);
this.onUnMappableInputAction = HttpProtocolParams.getUnmappableInputAction(params);
}
示例3: SessionInputBufferImpl
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
/**
* Creates new instance of SessionInputBufferImpl.
*
* @param metrics HTTP transport metrics.
* @param buffersize buffer size. Must be a positive number.
* @param minChunkLimit size limit below which data chunks should be buffered in memory
* in order to minimize native method invocations on the underlying network socket.
* The optimal value of this parameter can be platform specific and defines a trade-off
* between performance of memory copy operations and that of native method invocation.
* If negative default chunk limited will be used.
* @param constraints Message constraints. If <code>null</code>
* {@link MessageConstraints#DEFAULT} will be used.
* @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
* If <code>null</code> simple type cast will be used for byte to char conversion.
*/
public SessionInputBufferImpl(
final HttpTransportMetricsImpl metrics,
final int buffersize,
final int minChunkLimit,
final MessageConstraints constraints,
final CharsetDecoder chardecoder) {
Args.notNull(metrics, "HTTP transport metrcis");
Args.positive(buffersize, "Buffer size");
this.metrics = metrics;
this.buffer = new byte[buffersize];
this.bufferpos = 0;
this.bufferlen = 0;
this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
this.linebuffer = new ByteArrayBuffer(buffersize);
this.decoder = chardecoder;
}
示例4: 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();
}
}
示例5: doWriteTo
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
void doWriteTo(
final OutputStream out,
final boolean writeContent) throws IOException {
final ByteArrayBuffer boundaryEncoded = encode(this.charset, this.boundary);
for (final FormBodyPart part: getBodyParts()) {
writeBytes(TWO_DASHES, out);
writeBytes(boundaryEncoded, out);
writeBytes(CR_LF, out);
formatMultipartHeader(part, out);
writeBytes(CR_LF, out);
if (writeContent) {
part.getBody().writeTo(out);
}
writeBytes(CR_LF, out);
}
writeBytes(TWO_DASHES, out);
writeBytes(boundaryEncoded, out);
writeBytes(TWO_DASHES, out);
writeBytes(CR_LF, out);
}
示例6: 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());
}
示例7: 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;
}
}
示例8: 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;
}
示例9: 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();
}
示例10: 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());
}
示例11: 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 "";
}
}
示例12: HttpGet
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
public static ByteArrayBuffer ʻ(String paramString)
{
HttpGet localHttpGet = new HttpGet(paramString);
DefaultHttpClient localDefaultHttpClient = ˊ();
BufferedHttpEntity localBufferedHttpEntity = new BufferedHttpEntity(localDefaultHttpClient.execute(localHttpGet).getEntity());
BufferedInputStream localBufferedInputStream = new BufferedInputStream(localBufferedHttpEntity.getContent());
ByteArrayBuffer localByteArrayBuffer = new ByteArrayBuffer(50);
while (true)
{
int i = localBufferedInputStream.read();
if (i == -1)
break;
localByteArrayBuffer.append((byte)i);
}
localBufferedInputStream.close();
localBufferedHttpEntity.consumeContent();
localDefaultHttpClient.getConnectionManager().shutdown();
return localByteArrayBuffer;
}
示例13: downloadIconFromUrl
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
@ィ(ˊ="DOWNLOAD_ICON_ASSET")
public final void downloadIconFromUrl(String paramString, File paramFile)
{
int i = paramString.hashCode();
if (!this.ˎ.contains(Integer.valueOf(i)))
{
this.ˎ.add(Integer.valueOf(i));
try
{
ByteArrayBuffer localByteArrayBuffer = 〳.ʻ(paramString);
paramFile.getParentFile().mkdirs();
FileOutputStream localFileOutputStream = new FileOutputStream(paramFile);
localFileOutputStream.write(localByteArrayBuffer.toByteArray());
localFileOutputStream.close();
}
catch (IOException localIOException)
{
}
this.ˎ.remove(Integer.valueOf(i));
}
}
示例14: File
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
public static void ˊ(Context paramContext, ByteArrayBuffer paramByteArrayBuffer, String paramString1, String paramString2)
{
File localFile = new File(paramContext.getCacheDir(), String.valueOf((paramString1 + paramString2).hashCode()));
try
{
FileOutputStream localFileOutputStream = new FileOutputStream(localFile);
localFileOutputStream.write(paramByteArrayBuffer.toByteArray());
localFileOutputStream.close();
return;
}
catch (FileNotFoundException localFileNotFoundException)
{
localFileNotFoundException.printStackTrace();
return;
}
catch (IOException localIOException)
{
localIOException.printStackTrace();
}
}
示例15: catch
import org.apache.http.util.ByteArrayBuffer; //导入依赖的package包/类
private static ByteArrayBuffer ˊ(String[] paramArrayOfString)
{
try
{
ByteArrayBuffer localByteArrayBuffer = 〳.ʻ(paramArrayOfString[0]);
return localByteArrayBuffer;
}
catch (IOException localIOException)
{
localIOException.printStackTrace();
return null;
}
catch (Exception localException)
{
localException.printStackTrace();
}
return null;
}