aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-07-09 08:17:32 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-07-09 08:17:32 +0000
commitabef4b9fb6d0490c8a8f41d976133239228f679e (patch)
tree923a7826f434acdf0d302f0bd4b140532795fa52
parent5a846bbe359bb0ff658d79e31c319276e47da4e9 (diff)
downloadjavassist-abef4b9fb6d0490c8a8f41d976133239228f679e.tar.gz
javassist-abef4b9fb6d0490c8a8f41d976133239228f679e.zip
enforced close() in a finally block.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@28 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r--src/main/javassist/ClassPool.java9
-rw-r--r--src/main/javassist/ClassPoolTail.java10
-rw-r--r--src/main/javassist/URLClassPath.java33
3 files changed, 33 insertions, 19 deletions
diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java
index 83788953..61314777 100644
--- a/src/main/javassist/ClassPool.java
+++ b/src/main/javassist/ClassPool.java
@@ -418,8 +418,13 @@ public class ClassPool {
{
ByteArrayOutputStream barray = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(barray);
- write(classname, out, true);
- out.close();
+ try {
+ write(classname, out, true);
+ }
+ finally {
+ out.close();
+ }
+
return barray.toByteArray();
}
diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java
index 678badd2..0756cf44 100644
--- a/src/main/javassist/ClassPoolTail.java
+++ b/src/main/javassist/ClassPoolTail.java
@@ -256,8 +256,14 @@ final class ClassPoolTail extends ClassPool {
throws NotFoundException, IOException
{
InputStream fin = openClassfile(classname);
- byte[] b = readStream(fin);
- fin.close();
+ byte[] b;
+ try {
+ b = readStream(fin);
+ }
+ finally {
+ fin.close();
+ }
+
return b;
}
diff --git a/src/main/javassist/URLClassPath.java b/src/main/javassist/URLClassPath.java
index 9d56635b..279b20f1 100644
--- a/src/main/javassist/URLClassPath.java
+++ b/src/main/javassist/URLClassPath.java
@@ -98,23 +98,26 @@ public class URLClassPath implements ClassPath {
directory + classname.replace('.', '/') + ".class");
int size = con.getContentLength();
InputStream s = con.getInputStream();
- if (size <= 0)
- b = ClassPoolTail.readStream(s);
- else {
- b = new byte[size];
- int len = 0;
- do {
- int n = s.read(b, len, size - len);
- if (n < 0) {
- s.close();
- throw new IOException("the stream was closed: "
- + classname);
- }
- len += n;
- } while (len < size);
+ try {
+ if (size <= 0)
+ b = ClassPoolTail.readStream(s);
+ else {
+ b = new byte[size];
+ int len = 0;
+ do {
+ int n = s.read(b, len, size - len);
+ if (n < 0)
+ throw new IOException("the stream was closed: "
+ + classname);
+
+ len += n;
+ } while (len < size);
+ }
+ }
+ finally {
+ s.close();
}
- s.close();
return b;
}