Class FileResourceFactory
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.FileResourceFactory
-
- All Implemented Interfaces:
ResourceFactory
@Contract(threading=STATELESS) public class FileResourceFactory extends java.lang.Object implements ResourceFactory
GeneratesResource
instances whose body is stored in a temporary file.- Since:
- 4.1
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
cacheDir
private BasicIdGenerator
idgen
-
Constructor Summary
Constructors Constructor Description FileResourceFactory(java.io.File cacheDir)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource
copy(java.lang.String requestId, Resource resource)
Clones an existingResource
.Resource
generate(java.lang.String requestId, byte[] content)
Creates aResource
from a given response body.Resource
generate(java.lang.String requestId, byte[] content, int off, int len)
Creates aResource
from a given response body.private java.io.File
generateUniqueCacheFile(java.lang.String requestId)
-
-
-
Field Detail
-
cacheDir
private final java.io.File cacheDir
-
idgen
private final BasicIdGenerator idgen
-
-
Method Detail
-
generateUniqueCacheFile
private java.io.File generateUniqueCacheFile(java.lang.String requestId)
-
generate
public Resource generate(java.lang.String requestId, byte[] content, int off, int len) throws ResourceIOException
Description copied from interface:ResourceFactory
Creates aResource
from a given response body.- Specified by:
generate
in interfaceResourceFactory
- Parameters:
requestId
- a unique identifier for this particular response body.content
- byte array that represents the origin HTTP response body.off
- the start offset in the array.len
- the number of bytes to read from the array.- Returns:
- a
Resource
containing however much of the response body was successfully read. - Throws:
ResourceIOException
-
generate
public Resource generate(java.lang.String requestId, byte[] content) throws ResourceIOException
Description copied from interface:ResourceFactory
Creates aResource
from a given response body.- Specified by:
generate
in interfaceResourceFactory
- Parameters:
requestId
- a unique identifier for this particular response body.content
- byte array that represents the origin HTTP response body.- Returns:
- a
Resource
containing however much of the response body was successfully read. - Throws:
ResourceIOException
-
copy
public Resource copy(java.lang.String requestId, Resource resource) throws ResourceIOException
Description copied from interface:ResourceFactory
Clones an existingResource
.- Specified by:
copy
in interfaceResourceFactory
- Parameters:
requestId
- unique identifier provided to associate with the cloned response body.resource
- the original response body to clone.- Returns:
- the
Resource
copy - Throws:
ResourceIOException
-
-