summaryrefslogtreecommitdiffstats
path: root/base/util/test
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2013-03-08 09:29:02 -0500
committerAde Lee <alee@redhat.com>2013-03-08 21:26:30 -0500
commitddc391f574fff16f84cfa485c09ebc495f654340 (patch)
tree11400da443e222716cb68d22b74ba108347e2fed /base/util/test
parentb953c172bf274352c628ffef7d3ef0ef4c9ce59d (diff)
downloadpki-ddc391f574fff16f84cfa485c09ebc495f654340.tar.gz
pki-ddc391f574fff16f84cfa485c09ebc495f654340.tar.xz
pki-ddc391f574fff16f84cfa485c09ebc495f654340.zip
Plug resource leaks
Diffstat (limited to 'base/util/test')
-rw-r--r--base/util/test/com/netscape/security/util/StringTestUtil.java32
1 files changed, 17 insertions, 15 deletions
diff --git a/base/util/test/com/netscape/security/util/StringTestUtil.java b/base/util/test/com/netscape/security/util/StringTestUtil.java
index 16810581c..b25ea5981 100644
--- a/base/util/test/com/netscape/security/util/StringTestUtil.java
+++ b/base/util/test/com/netscape/security/util/StringTestUtil.java
@@ -31,29 +31,31 @@ public class StringTestUtil {
public static byte[] normalizeUnicode(byte[] data) throws Exception {
- DerValue value = new DerValue(data);
- byte[] tmp = value.data.toByteArray();
+ try (DerOutputStream os = new DerOutputStream()) {
+ DerValue value = new DerValue(data);
+ byte[] tmp = value.data.toByteArray();
- if (tmp[0] == -2 && tmp[1] == -1) { // remove optional big-endian byte-order mark
+ if (tmp[0] == -2 && tmp[1] == -1) { // remove optional big-endian byte-order mark
- byte tag = value.tag;
- int length = value.length() - 2;
+ byte tag = value.tag;
+ int length = value.length() - 2;
- DerOutputStream os = new DerOutputStream();
- os.putTag((byte) 0, false, tag);
- os.putLength(length);
- os.write(tmp, 2, length);
+ os.putTag((byte) 0, false, tag);
+ os.putLength(length);
+ os.write(tmp, 2, length);
- return os.toByteArray();
- }
+ return os.toByteArray();
+ }
- return data;
+ return data;
+ }
}
public static byte[] encode(byte tag, String string) throws Exception {
- DerOutputStream os = new DerOutputStream();
- os.putStringType(tag, string);
- return os.toByteArray();
+ try (DerOutputStream os = new DerOutputStream()) {
+ os.putStringType(tag, string);
+ return os.toByteArray();
+ }
}
public static String decode(byte tag, byte[] bytes) throws Exception {