* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
} finally {
- if (request != null && request instanceof HttpServletRequest) {
+ if (request instanceof HttpServletRequest) {
t1 = System.currentTimeMillis();
private String decompressGZIPByteArray(byte[] bytes) {
- BufferedReader in = null;
- InputStreamReader inR = null;
- ByteArrayInputStream byteS = null;
- GZIPInputStream gzS = null;
StringBuilder str = new StringBuilder();
- try {
- byteS = new ByteArrayInputStream(bytes);
- gzS = new GZIPInputStream(byteS);
- inR = new InputStreamReader(gzS);
- in = new BufferedReader(inR);
-
- if (in != null) {
+ try (ByteArrayInputStream byteS = new ByteArrayInputStream(bytes);
+ GZIPInputStream gzS = new GZIPInputStream(byteS);
+ InputStreamReader inR = new InputStreamReader(gzS);
+ BufferedReader in = new BufferedReader(inR);) {
- String content;
+ String content;
- while ((content = in.readLine()) != null) {
- str.append(content);
- }
+ while ((content = in.readLine()) != null) {
+ str.append(content);
}
} catch (Exception e) {
log.error("Failed get read GZIPInputStream", e);
- } finally {
-
- if (byteS != null)
- try {
- byteS.close();
- } catch (IOException e1) {
- log.error("Failed to close ByteStream", e1);
- }
- if (gzS != null)
- try {
- gzS.close();
- } catch (IOException e2) {
- log.error("Failed to close GZStream", e2);
- }
- if (inR != null)
- try {
- inR.close();
- } catch (IOException e3) {
- log.error("Failed to close InputReader", e3);
- }
- if (in != null)
- try {
- in.close();
- } catch (IOException e) {
- log.error("Failed to close BufferedReader", e);
- }
}
+
return str.toString();
}
}
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* @throws SvcLogicException thrown if file cannot be created or if parameters are missing
*/
public static void printContext(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- if (parameters == null || parameters.keySet().size() < 1) {
+ if (parameters == null || parameters.isEmpty()) {
throw new SvcLogicException("no parameters passed");
}
String fileName = parameters.get("filename");
- PrintStream pstr = null;
- try {
- pstr = new PrintStream(new FileOutputStream(new File(fileName), true));
+ try (FileOutputStream fstr = new FileOutputStream(new File(fileName));
+ PrintStream pstr = new PrintStream(fstr, true);)
+ {
+ pstr.println("#######################################");
+ for (String attr : ctx.getAttributeKeySet()) {
+ pstr.println(attr + " = " + ctx.getAttribute(attr));
+ }
} catch (Exception e) {
- throw new SvcLogicException("Cannot open file " + fileName, e);
+ throw new SvcLogicException("Cannot write context to file " + fileName, e);
}
- pstr.println("#######################################");
- for (String attr : ctx.getAttributeKeySet()) {
- pstr.println(attr + " = " + ctx.getAttribute(attr));
- }
- pstr.flush();
- pstr.close();
+
+
}
/**