com.android.volley.ResponseDelivery Java Examples

The following examples show how to use com.android.volley.ResponseDelivery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestQueueTest.java    From volley with Apache License 2.0 6 votes vote down vote up
@Test
public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(
            RequestQueue.class.getConstructor(
                    Cache.class, Network.class, int.class, ResponseDelivery.class));
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class));
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class));

    assertNotNull(RequestQueue.class.getMethod("start"));
    assertNotNull(RequestQueue.class.getMethod("stop"));
    assertNotNull(RequestQueue.class.getMethod("getSequenceNumber"));
    assertNotNull(RequestQueue.class.getMethod("getCache"));
    assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class));
    assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class));
    assertNotNull(RequestQueue.class.getMethod("add", Request.class));
    assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class));
}
 
Example #2
Source File: RequestQueueTest.java    From SaveVolley with Apache License 2.0 6 votes vote down vote up
@Test public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class,
            ResponseDelivery.class));
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class));
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class));

    assertNotNull(RequestQueue.class.getMethod("start"));
    assertNotNull(RequestQueue.class.getMethod("stop"));
    assertNotNull(RequestQueue.class.getMethod("getSequenceNumber"));
    assertNotNull(RequestQueue.class.getMethod("getCache"));
    assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class));
    assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class));
    assertNotNull(RequestQueue.class.getMethod("add", Request.class));
    assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class));
}
 
Example #3
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("OpenAPI-Generator/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
  // TODO: comment out below as OAuth does not exist
  //INSTANCE.authentications.put("petstore_auth", new OAuth());
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
 
Example #4
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("OpenAPI-Generator/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("jenkins_auth", new HttpBasicAuth());
  INSTANCE.authentications.put("jwt_auth", new ApiKeyAuth("header", "Authorization"));
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
 
Example #5
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("OpenAPI-Generator/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("aemAuth", new HttpBasicAuth());
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
 
Example #6
Source File: WaspTest.java    From wasp with Apache License 2.0 5 votes vote down vote up
public WaspTest() throws Exception {
  File cacheDir = new File(context.getCacheDir(), "volley");
  Network network = new BasicNetwork(new OkHttpStack(new OkHttpClient()));
  ResponseDelivery delivery = new ExecutorDelivery(executor);
  requestQueue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, delivery);
  requestQueue.start();

  server.start();
}
 
Example #7
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
private void initConnectionRequest(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) {
  mRequestQueue = new RequestQueue(cache, network, threadPoolSize, delivery);
  mRequestQueue.start();
}
 
Example #8
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 4 votes vote down vote up
private void initConnectionRequest(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) {
  mRequestQueue = new RequestQueue(cache, network, threadPoolSize, delivery);
  mRequestQueue.start();
}
 
Example #9
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 4 votes vote down vote up
private void initConnectionRequest(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) {
  mRequestQueue = new RequestQueue(cache, network, threadPoolSize, delivery);
  mRequestQueue.start();
}
 
Example #10
Source File: BasicNetwork.java    From volley with Apache License 2.0 4 votes vote down vote up
/** Reads the contents of HttpEntity into a byte[]. */
private byte[] entityToBytes(ResponseDelivery delivery, Request<?> request, HttpEntity entity) throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes =
            new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
    byte[] buffer = null;
    long time = SystemClock.uptimeMillis();
    try {
        InputStream in = entity.getContent();
        if (in == null) {
            throw new ServerError();
        }
        buffer = mPool.getBuf(1024);
        long length = entity.getContentLength();
        long current = 0;
        int count = -1;
        LoadingListener listener = request.getLoadingListener();
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
            current += count;
            if (listener != null) {
                long thisTime = SystemClock.uptimeMillis();
                if(thisTime - time >= request.getRate()) {
                    time = thisTime;
                    delivery.postLoading(request, length == -1 ? current * 2 : length, current);
                }
            }
        }
        if (listener != null) {
            delivery.postLoading(request, length == -1 ? current : length, current);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            entity.consumeContent();
        } 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");
        }
        mPool.returnBuf(buffer);
        bytes.close();
    }
}