diff options
author | lu xin <luxin7@huawei.com> | 2018-03-30 03:21:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-30 03:21:33 +0000 |
commit | ad01f547af0d866d2b535162b8949615c95875ea (patch) | |
tree | fe2367fc1cfa0efe50c4b0f870e499215466703a /service/src | |
parent | 1266b3e00bec3688c2f40e9132d41f417c56aa15 (diff) | |
parent | 08ff50f0f17135e778475c83c5550cfe81fde059 (diff) |
Merge "Resources handling multivimproxy"
Diffstat (limited to 'service/src')
2 files changed, 10 insertions, 48 deletions
diff --git a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestHttpContentExchange.java b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestHttpContentExchange.java index d6e4643..f5a59cb 100644 --- a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestHttpContentExchange.java +++ b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestHttpContentExchange.java @@ -79,41 +79,16 @@ public class RestHttpContentExchange extends ContentExchange { if(data == null) { return ""; } - ByteArrayInputStream input = null; - GZIPInputStream gzis = null; - InputStreamReader reader = null; final StringBuilder out = new StringBuilder(); - try { - input = new ByteArrayInputStream(data); - gzis = new GZIPInputStream(input); - reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING)); + try ( + ByteArrayInputStream input = new ByteArrayInputStream(data); + GZIPInputStream gzis = new GZIPInputStream(input); + InputStreamReader reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING))){ final char[] buff = new char[1024]; for(int n; (n = reader.read(buff)) != -1;) { out.append(new String(buff, 0, n)); } - } finally { - if(reader != null) { - try { - reader.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip reader exception:", e); - } - } - if(gzis != null) { - try { - gzis.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip exception:", e); - } - } - if(input != null) { - try { - input.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip input exception:", e); - } - } - } + } return out.toString(); } diff --git a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestfulConfigure.java b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestfulConfigure.java index 6bb383f..ad186c9 100644 --- a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestfulConfigure.java +++ b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/RestfulConfigure.java @@ -134,28 +134,15 @@ public class RestfulConfigure { LOG.error(filePath + "isn't exist."); return null; } - BufferedReader reader = null; final StringBuilder jsonstr = new StringBuilder(); - JSONObject jo = null; - try { - reader = new BufferedReader(new FileReader(file)); + try (BufferedReader reader = new BufferedReader(new FileReader(file))){ final ReaderHelper rHelpper = new ReaderHelper(reader); - String tempString = null; - while((tempString = rHelpper.getLine()) != null) { - jsonstr.append(tempString); + while(null != rHelpper.getLine()) { + jsonstr.append(rHelpper.getLine()); } - jo = JSONObject.fromObject(jsonstr.toString()); } catch(final IOException e) { LOG.error("load file exception:" + e); - } finally { - if(reader != null) { - try { - reader.close(); - } catch(final IOException e) { - LOG.error("close error.", e); - } - } - } - return jo; + } + return JSONObject.fromObject(jsonstr.toString()); } } |