Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2015-04-02 11:52:50 +0000
committerMarkus Tiede2015-04-02 11:52:50 +0000
commit898efafabae5bf9875cbf89119891f6f534df934 (patch)
tree54e68681b11384cee6a6a5f6f0a04b206fef094a /org.eclipse.jubula.client.api
parente522f209d7391ac8c13d540d1eef0540117e77aa (diff)
downloadorg.eclipse.jubula.core-898efafabae5bf9875cbf89119891f6f534df934.tar.gz
org.eclipse.jubula.core-898efafabae5bf9875cbf89119891f6f534df934.tar.xz
org.eclipse.jubula.core-898efafabae5bf9875cbf89119891f6f534df934.zip
Non-sprint task - avoid resource leaks when reading and writing OM identifier.
Diffstat (limited to 'org.eclipse.jubula.client.api')
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/utils/SerilizationUtils.java53
1 files changed, 36 insertions, 17 deletions
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/utils/SerilizationUtils.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/utils/SerilizationUtils.java
index 24c81a4ea..d780f6842 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/utils/SerilizationUtils.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/utils/SerilizationUtils.java
@@ -33,33 +33,52 @@ public class SerilizationUtils {
}
- /**
+ /**
* Encodes a serializable object to a Base64 string.
- * @param serializableObject the serializable object
+ *
+ * @param serializableObject
+ * the serializable object
* @return a String representation of the serializable
*/
public static String encode(Serializable serializableObject)
- throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(serializableObject);
- oos.close();
- return new String(
- Base64.encodeBase64(baos.toByteArray()));
+ throws IOException {
+ ByteArrayOutputStream baos = null;
+ ObjectOutputStream oos = null;
+ String encoded = null;
+
+ try {
+ baos = new ByteArrayOutputStream();
+ oos = new ObjectOutputStream(baos);
+ oos.writeObject(serializableObject);
+ encoded = new String(Base64.encodeBase64(baos.toByteArray()));
+ } finally {
+ if (oos != null) {
+ oos.close();
+ }
+ }
+ return encoded;
}
- /**
+ /**
* Decodes a serializable from a base64 encoded string.
- * @param encodedString Base64 encoded String
+ *
+ * @param encodedString
+ * Base64 encoded String
* @return the translated object
*/
public static Object decode(String encodedString) throws IOException,
ClassNotFoundException {
- byte [] data = Base64.decodeBase64(encodedString);
- ObjectInputStream ois = new ObjectInputStream(
- new ByteArrayInputStream(data));
- Object decodedObject = ois.readObject();
- ois.close();
+ byte[] data = Base64.decodeBase64(encodedString);
+ ObjectInputStream ois = null;
+ Object decodedObject = null;
+ try {
+ ois = new ObjectInputStream(new ByteArrayInputStream(data));
+ decodedObject = ois.readObject();
+ } finally {
+ if (ois != null) {
+ ois.close();
+ }
+ }
return decodedObject;
- }
+ }
} \ No newline at end of file

Back to the top