FileWriter writer = null;
try {
int statusCode = client.executeMethod(get);
if (statusCode == HttpStatus.SC_NOT_FOUND) {
throw new SignatureServiceException(
String.format(FILE_NOT_FOUND_404, endpointUrl));
} else if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_NOT_MODIFIED) {
throw new SignatureServiceException(
String.format(ERROR_MESSAGE_PATTERN, endpointUrl, statusCode));
}
int version = getVersion(get);
SignatureFileInfo signatureFileInfo = new SignatureFileInfo(version, false, SignatureType.CONTAINER);
String fileName = String.format(FILENAME_PATTERN, version);
final File targetFile = new File(targetDir, fileName);
writer = new FileWriter(targetFile);
IOUtils.copy(get.getResponseBodyAsStream(), writer);
signatureFileInfo.setFile(targetFile);
return signatureFileInfo;
} catch (UnknownHostException e) {
throw new SignatureServiceException(
String.format(COULD_NOT_FIND_SERVER, endpointUrl));
} catch (IOException e) {
throw new SignatureServiceException(e);
} catch (DateParseException e) {
throw new SignatureServiceException(e);
} finally {
get.releaseConnection();
try {
if (writer != null) {
writer.close();