/**
* Download from given URL.
- *
+ *
* @param url String
* @return
*/
/**
* Download from given URL to given file location.
- *
+ *
* @param url String
* @param filepath String
* @return
*/
public static String download(String url, String filepath) {
String status = "";
- try {
- CloseableHttpClient client = HttpClients.createDefault();
+ try (CloseableHttpClient client = HttpClients.createDefault()){
HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = client.execute(httpget);
HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- if(filepath == null) {
- filepath = getFilePath(response); // NOSONAR
- }
+ try(InputStream is = entity.getContent()) {
+ if(filepath == null) {
+ filepath = getFilePath(response); // NOSONAR
+ }
- File file = new File(filepath);
- file.getParentFile().mkdirs();
- FileOutputStream fileout = new FileOutputStream(file);
+ File file = new File(filepath);
+ file.getParentFile().mkdirs();
+ try(FileOutputStream fileout = new FileOutputStream(file)){
- byte[] buffer = new byte[CACHE];
- int ch;
- while((ch = is.read(buffer)) != -1) {
- fileout.write(buffer, 0, ch);
+ byte[] buffer = new byte[CACHE];
+ int ch;
+ while((ch = is.read(buffer)) != -1) {
+ fileout.write(buffer, 0, ch);
+ }
+ fileout.flush();
+ status = Constant.DOWNLOADCSAR_SUCCESS;
+ } catch(Exception e) {
+ status = Constant.DOWNLOADCSAR_FAIL;
+ LOG.error("Download csar file failed! " + e.getMessage(), e);
+ }
+ } catch(Exception e) {
+ status = Constant.DOWNLOADCSAR_FAIL;
+ LOG.error("Download csar file failed! " + e.getMessage(), e);
}
- is.close();
- fileout.flush();
- fileout.close();
- client.close();
- status = Constant.DOWNLOADCSAR_SUCCESS;
-
} catch(Exception e) {
status = Constant.DOWNLOADCSAR_FAIL;
LOG.error("Download csar file failed! " + e.getMessage(), e);
}
+
return status;
}
/**
* Retrieve file path from given response.
- *
+ *
* @param response HttpResponse
* @return
*/
/**
* Retrieve file name from given response.
- *
+ *
* @param response HttpResponse
* @return
*/
/**
* Provides random file name.
- *
+ *
* @return
*/
public static String getRandomFileName() {
/**
* unzip CSAR packge
- *
+ *
* @param fileName filePath
* @return
* @throws IOException
* The base class for all common exception.<br/>
* <p>
* </p>
- *
+ *
* @author
* @version 28-May-2016
*/
*/
private String id = DEFAULT_ID;
- private Object[] args = null;
+ private Object[] args = null; // NOSONAR
private int httpCode = 500;
* <p>
* This method is only used as deserialized, in other cases, use parameterized constructor.
* </p>
- *
+ *
* @since
*/
public ServiceException() {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: details.
* @param cause: reason.
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param message: details.
*/
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param httpCode: http status code.
* <p>
* the exception include the httpcode and message.
* </p>
- *
+ *
* @since
* @param httpCode http code.
* @param message details.
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param httpCode: http code.
* <p>
* Have a placeholder exception, use args formatted message.
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
* <p>
* Have a placeholder exception, use args formatted message
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param cause: reason.
*/
/**
* Get exceptoin id.<br/>
- *
+ *
* @return
* @since
*/
/**
* Obtain the ROA exception handling framework parameters<br/>
- *
+ *
* @return exception args.
* @since
*/
/**
* Gets the parameter information<br/>
- *
+ *
* @return parameter list.
* @since
*/