throws ResourceNotAvailableException {
// extract ARC filename
String fileName = result.getFile();
if(fileName == null || fileName.length() < 1) {
throw new ResourceNotAvailableException("No ARC/WARC name in search result...", fileName);
}
// If includeFilter is provided, filter out paths that don't contain the include filter
if (includeFilter != null) {
if (!fileName.contains(includeFilter)) {
throw new ResourceNotAvailableException("Resource " + fileName + " not found in this store", fileName);
}
}
final long offset = result.getOffset();
if(!fileName.endsWith(ArcWarcFilenameFilter.ARC_SUFFIX)
&& !fileName.endsWith(ArcWarcFilenameFilter.ARC_GZ_SUFFIX)
&& !fileName.endsWith(ArcWarcFilenameFilter.WARC_SUFFIX)
&& !fileName.endsWith(ArcWarcFilenameFilter.WARC_GZ_SUFFIX)) {
fileName = fileName + ArcWarcFilenameFilter.ARC_GZ_SUFFIX;
}
String fileUrl;
if ( regex != null && replace != null )
{
fileUrl = fileName.replaceAll( regex, replace );
}
else
{
fileUrl = prefix + fileName;
}
Resource r = null;
try {
int attempts = retries;
while(attempts-- > 0) {
try {
r = ResourceFactory.getResource(fileUrl, offset);
break;
} catch (IOException e) {
String message = e.getMessage();
if(attempts > 0
&& message.contains(HTTP_ERROR)
&& message.contains(HTTP_502)) {
LOGGER.info(String.format(
"Failed attempt for (%s) retrying with" +
" (%d) attempts left",fileUrl,attempts));
} else {
throw e;
}
}
}
} catch (IOException e) {
String msg = fileUrl + " - " + e;
LOGGER.info("Unable to retrieve:" + msg);
throw new ResourceNotAvailableException(msg, fileUrl, e);
}
return r;
}