Deprecated #copy method in FileResourceFactory
This commit is contained in:
parent
4adaa20be6
commit
5ecd396f60
|
@ -61,13 +61,9 @@ public interface ResourceFactory {
|
|||
Resource generate(String requestId, byte[] content, int off, int len) throws ResourceIOException;
|
||||
|
||||
/**
|
||||
* Clones an existing {@link Resource}.
|
||||
* @param requestId unique identifier provided to associate
|
||||
* with the cloned response body.
|
||||
* @param resource the original response body to clone.
|
||||
* @return the {@code Resource} copy
|
||||
* @throws ResourceIOException
|
||||
* @deprecated Do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
Resource copy(String requestId, Resource resource) throws ResourceIOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -29,9 +29,6 @@ package org.apache.hc.client5.http.impl.cache;
|
|||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import org.apache.hc.client5.http.cache.Resource;
|
||||
import org.apache.hc.client5.http.cache.ResourceFactory;
|
||||
|
@ -95,33 +92,15 @@ public class FileResourceFactory implements ResourceFactory {
|
|||
return generate(requestId, content, 0, content.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public Resource copy(
|
||||
final String requestId,
|
||||
final Resource resource) throws ResourceIOException {
|
||||
final File file = generateUniqueCacheFile(requestId);
|
||||
try {
|
||||
if (resource instanceof FileResource) {
|
||||
try (final RandomAccessFile srcFile = new RandomAccessFile(((FileResource) resource).getFile(), "r");
|
||||
final RandomAccessFile dstFile = new RandomAccessFile(file, "rw");
|
||||
final FileChannel src = srcFile.getChannel();
|
||||
final FileChannel dst = dstFile.getChannel()) {
|
||||
src.transferTo(0, srcFile.length(), dst);
|
||||
}
|
||||
} else {
|
||||
try (final FileOutputStream out = new FileOutputStream(file);
|
||||
final InputStream in = resource.getInputStream()) {
|
||||
final byte[] buf = new byte[2048];
|
||||
int len;
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
throw new ResourceIOException(ex.getMessage(), ex);
|
||||
}
|
||||
return new FileResource(file);
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,12 +57,16 @@ public class HeapResourceFactory implements ResourceFactory {
|
|||
return new HeapResource(content != null ? content.clone() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public Resource copy(
|
||||
final String requestId,
|
||||
final Resource resource) throws ResourceIOException {
|
||||
Args.notNull(resource, "Resource");
|
||||
return new HeapResource(resource.get());
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue