/** Reads the contents of HttpEntity into a byte[]. */ public static byte[] entityToBytes(InputStream inputStream, long contentLength, int bufferSize) throws IOException, ServerError { ByteArrayPool bytePool = new ByteArrayPool(bufferSize); PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(bytePool, (int)contentLength); byte[] buffer = null; try { if (inputStream == null) { throw new ServerError(); } buffer = bytePool.getBuf(1024); int count; while ((count = inputStream.read(buffer)) != -1) { bytes.write(buffer, 0, count); } return bytes.toByteArray(); } finally { try { // Close the InputStream and release the resources by "consuming the content". inputStream.close(); } catch (IOException e) { // This can happen if there was an exception above that left the entity in // an invalid state. VolleyLog.v("Error occured when calling consumingContent"); } bytePool.returnBuf(buffer); bytes.close(); } }
public CastWebServer(Context context, String host, int port) { super(host, port); mContext = context; // get the lock mWifiLock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "CastServer"); mWifiLock.setReferenceCounted(false); // arbitrary size might increase as needed; mEtagCache = new LruCache<>(20); mBytePool = new ByteArrayPool(2*1024*1024); }
/** * @param httpStack * HTTP stack to be used */ public QMusicNetwork(HttpStack httpStack) { // If a pool isn't passed in, then build a small default pool that will // give us a lot of // benefit and not use too much memory. this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE)); }
/** * @param httpStack HTTP stack to be used */ public BaseNetwork(HttpStack httpStack) { // If a pool isn't passed in, then build a small default pool that will give us a lot of // benefit and not use too much memory. this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE)); }
/** * @param httpStack HTTP stack to be used * @param pool a buffer pool that improves GC performance in copy operations */ public BaseNetwork(HttpStack httpStack, ByteArrayPool pool) { mHttpStack = httpStack; mPool = pool; }
/** * @param httpStack HTTP stack to be used */ public DrBasicNetwork(HttpStack httpStack) { // If a pool isn't passed in, then build a small default pool that will give us a lot of // benefit and not use too much memory. this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE)); }
/** * @param httpStack HTTP stack to be used * @param pool a buffer pool that improves GC performance in copy operations */ public DrBasicNetwork(HttpStack httpStack, ByteArrayPool pool) { mHttpStack = httpStack; mPool = pool; }
public SBaseNetWork(HttpStack httpStack, ByteArrayPool pool) { super(httpStack, pool); }
/** * @param httpStack HTTP stack to be used */ public RVNetwork(HttpStack httpStack) { // If a pool isn't passed in, then build a small default pool that will give us a lot of // benefit and not use too much memory. this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE)); }
/** * @param httpStack HTTP stack to be used * @param pool a buffer pool that improves GC performance in copy operations */ public RVNetwork(HttpStack httpStack, ByteArrayPool pool) { mHttpStack = httpStack; mPool = pool; }
private Network createNetwork() { if (Utils.isBackgroundDataEnabled(this)) { FinskyExperiments localFinskyExperiments = getExperiments(); boolean bool = localFinskyExperiments.isEnabled(12603642L); int i; if ((localFinskyExperiments.isEnabled(12602748L)) || (localFinskyExperiments.isEnabled(12604235L)) || (localFinskyExperiments.isEnabled(12604236L))) { i = 1; } OkHttpClient localOkHttpClient; while ((GooglePlayServicesUtil.isSidewinderDevice(this)) || (((bool) || (i != 0)) && (((Boolean)G.enableOkHttp.get()).booleanValue()))) { Protocol[] arrayOfProtocol = new Protocol[1]; arrayOfProtocol[0] = Protocol.HTTP_1_1; ArrayList localArrayList = Lists.newArrayList(arrayOfProtocol); if (!bool) { localArrayList.add(Protocol.SPDY_3); } localOkHttpClient = new OkHttpClient(); List localList = Util.immutableList(localArrayList); if (!localList.contains(Protocol.HTTP_1_1)) { throw new IllegalArgumentException("protocols doesn't contain http/1.1: " + localList); i = 0; } else { if (localList.contains(Protocol.HTTP_1_0)) { throw new IllegalArgumentException("protocols must not contain http/1.0: " + localList); } if (localList.contains(null)) { throw new IllegalArgumentException("protocols must not contain null"); } localOkHttpClient.protocols = Util.immutableList(localList); localOkHttpClient.followRedirects = false; } } for (Object localObject = new GoogleOkHttpStack(this, localOkHttpClient, new GoogleUrlRewriter(this), null, ((Boolean)G.enableSensitiveLogging.get()).booleanValue());; localObject = new GoogleHttpClientStack(this, ((Boolean)G.enableSensitiveLogging.get()).booleanValue())) { return new BasicNetwork((HttpStack)localObject, new ByteArrayPool(1024 * ((Integer)G.volleyBufferPoolSizeKb.get()).intValue())); } } return new DenyAllNetwork(); }
public VolleyDiskCacheWrapper(DiskCache diskCache) { this.diskCache = diskCache; this.byteArrayPool = new ByteArrayPool(BYTE_POOL_SIZE); }
/** * @param httpStack HTTP stack to be used */ public OkNetwork(OkStack httpStack) { // If a pool isn't passed in, then build a small default pool that will give us a lot of // benefit and not use too much memory. this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE)); }
/** * @param httpStack HTTP stack to be used * @param pool a buffer pool that improves GC performance in copy operations */ public OkNetwork(OkStack httpStack, ByteArrayPool pool) { mHttpStack = httpStack; mPool = pool; }
public BasicNetworkOOM(HttpStack httpStack, ByteArrayPool pool) { super(httpStack, pool); }
public void setByteArrayPool(ByteArrayPool byteArrayPool) { this.byteArrayPool = byteArrayPool; }
/** * @param httpStack The HTTP stack that requests are performed with. * @param poolSize The size of the pool buffer used for cached requests. NOTE: caching * requests will have a significant adverse affect on parsing speed! */ public JacksonNetwork(HttpStack httpStack, int poolSize) { mHttpStack = httpStack; mPool = new ByteArrayPool(poolSize); }
/** * @param httpStack * HTTP stack to be used * @param pool * a buffer pool that improves GC performance in copy operations */ public QMusicNetwork(HttpStack httpStack, ByteArrayPool pool) { mHttpStack = httpStack; mPool = pool; }