CacheEntryUpdater() { this(new HeapResourceFactory()); }
private Resource createResource(HttpRequest request, HttpResponse response) throws IOException { HttpEntity entity = response.getEntity(); if (entity == null) { return null; } String uri = request.getRequestLine().getUri(); InputStream instream = entity.getContent(); return new HeapResourceFactory().generate(uri, instream, null); }
public Resource generate( final String requestId, final InputStream instream, final InputLimit limit) throws IOException { final ByteArrayOutputStream outstream = new ByteArrayOutputStream(); final byte[] buf = new byte[2048]; long total = 0; int l; while ((l = instream.read(buf)) != -1) { outstream.write(buf, 0, l); total += l; if (limit != null && total > limit.getValue()) { limit.reached(); break; } } return createResource(outstream.toByteArray()); }
public Resource copy( final String requestId, final Resource resource) throws IOException { byte[] body; if (resource instanceof HeapResource) { body = ((HeapResource) resource).getByteArray(); } else { final ByteArrayOutputStream outstream = new ByteArrayOutputStream(); IOUtils.copyAndClose(resource.getInputStream(), outstream); body = outstream.toByteArray(); } return createResource(body); }
CacheEntryUpdater() { this(new HeapResourceFactory()); }
public BasicHttpCache(final CacheConfig config) { this(new HeapResourceFactory(), new BasicHttpCacheStorage(config), config); }
public BasicHttpCache(CacheConfig config) { this(new HeapResourceFactory(), new BasicHttpCacheStorage(config), config); }
CachingHttpClient( final HttpClient backend, final CacheValidityPolicy validityPolicy, final ResponseCachingPolicy responseCachingPolicy, final HttpCache responseCache, final CachedHttpResponseGenerator responseGenerator, final CacheableRequestPolicy cacheableRequestPolicy, final CachedResponseSuitabilityChecker suitabilityChecker, final ConditionalRequestBuilder conditionalRequestBuilder, final ResponseProtocolCompliance responseCompliance, final RequestProtocolCompliance requestCompliance) { final CacheConfig config = new CacheConfig(); this.maxObjectSizeBytes = config.getMaxObjectSize(); this.sharedCache = config.isSharedCache(); this.backend = backend; this.validityPolicy = validityPolicy; this.responseCachingPolicy = responseCachingPolicy; this.responseCache = responseCache; this.responseGenerator = responseGenerator; this.cacheableRequestPolicy = cacheableRequestPolicy; this.suitabilityChecker = suitabilityChecker; this.conditionalRequestBuilder = conditionalRequestBuilder; this.responseCompliance = responseCompliance; this.requestCompliance = requestCompliance; this.asynchRevalidator = makeAsynchronousValidator(config); }
CachingHttpClient( HttpClient backend, CacheValidityPolicy validityPolicy, ResponseCachingPolicy responseCachingPolicy, HttpCache responseCache, CachedHttpResponseGenerator responseGenerator, CacheableRequestPolicy cacheableRequestPolicy, CachedResponseSuitabilityChecker suitabilityChecker, ConditionalRequestBuilder conditionalRequestBuilder, ResponseProtocolCompliance responseCompliance, RequestProtocolCompliance requestCompliance) { CacheConfig config = new CacheConfig(); this.maxObjectSizeBytes = config.getMaxObjectSize(); this.sharedCache = config.isSharedCache(); this.backend = backend; this.validityPolicy = validityPolicy; this.responseCachingPolicy = responseCachingPolicy; this.responseCache = responseCache; this.responseGenerator = responseGenerator; this.cacheableRequestPolicy = cacheableRequestPolicy; this.suitabilityChecker = suitabilityChecker; this.conditionalRequestBuilder = conditionalRequestBuilder; this.responseCompliance = responseCompliance; this.requestCompliance = requestCompliance; this.asynchRevalidator = makeAsynchronousValidator(config); }
if (resourceFactory == null) { if (this.cacheDir == null) { resourceFactory = new HeapResourceFactory(); } else { resourceFactory = new FileResourceFactory(cacheDir);