diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-01-11 23:19:44 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-01-11 23:19:44 +0000 |
commit | 0947834ac950fb4dd59b719cbdddc1726e68674b (patch) | |
tree | dbd0be38df31a000ee178a60dac3557de0f1ad58 /src/main/java/com/amazon/carbonado/lob | |
parent | 1ce80a9798cc52b12074fcdf1acf32b0fdfe0569 (diff) |
Fixes for bugs found using FindBugs.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/lob')
-rw-r--r-- | src/main/java/com/amazon/carbonado/lob/AbstractBlob.java | 58 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/lob/AbstractClob.java | 34 |
2 files changed, 54 insertions, 38 deletions
diff --git a/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java b/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java index 3da80e9..6440978 100644 --- a/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java +++ b/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java @@ -90,30 +90,34 @@ public abstract class AbstractBlob implements Blob { char[] buffer = new char[(int) charLength];
- Reader r = new InputStreamReader(openInputStream(), decoder);
-
try {
- int offset = 0;
- int amt;
- while ((amt = r.read(buffer, offset, buffer.length - offset)) >= 0) {
- offset += amt;
- if (amt == 0 && offset >= buffer.length) {
- // Expand capacity.
- charLength *= 2;
- if (charLength >= Integer.MAX_VALUE) {
- charLength = Integer.MAX_VALUE;
- }
- if (charLength <= buffer.length) {
- throw new IllegalArgumentException
- ("Blob is too long to fit in a String");
+ Reader r = new InputStreamReader(openInputStream(), decoder);
+
+ try {
+ int offset = 0;
+ int amt;
+ while ((amt = r.read(buffer, offset, buffer.length - offset)) >= 0) {
+ offset += amt;
+ if (amt == 0 && offset >= buffer.length) {
+ // Expand capacity.
+ charLength *= 2;
+ if (charLength >= Integer.MAX_VALUE) {
+ charLength = Integer.MAX_VALUE;
+ }
+ if (charLength <= buffer.length) {
+ throw new IllegalArgumentException
+ ("Blob is too long to fit in a String");
+ }
+ char[] newBuffer = new char[(int) charLength];
+ System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
+ buffer = newBuffer;
}
- char[] newBuffer = new char[(int) charLength];
- System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
- buffer = newBuffer;
}
- }
- return new String(buffer, 0, offset);
+ return new String(buffer, 0, offset);
+ } finally {
+ r.close();
+ }
} catch (IOException e) {
throw AbstractClob.toFetchException(e);
}
@@ -145,8 +149,11 @@ public abstract class AbstractBlob implements Blob { setLength(0);
try {
Writer w = new OutputStreamWriter(openOutputStream(), charset);
- w.write(value);
- w.close();
+ try {
+ w.write(value);
+ } finally {
+ w.close();
+ }
} catch (IOException e) {
throw AbstractClob.toPersistException(e);
}
@@ -159,8 +166,11 @@ public abstract class AbstractBlob implements Blob { try {
DataOutputStream out = new DataOutputStream(openOutputStream());
Writer w = new OutputStreamWriter(out, charset);
- w.write(value);
- w.close();
+ try {
+ w.write(value);
+ } finally {
+ w.close();
+ }
newLength = out.size();
} catch (IOException e) {
throw AbstractClob.toPersistException(e);
diff --git a/src/main/java/com/amazon/carbonado/lob/AbstractClob.java b/src/main/java/com/amazon/carbonado/lob/AbstractClob.java index 3ccb0f7..6e4e273 100644 --- a/src/main/java/com/amazon/carbonado/lob/AbstractClob.java +++ b/src/main/java/com/amazon/carbonado/lob/AbstractClob.java @@ -91,19 +91,22 @@ public abstract class AbstractClob implements Clob { try {
Reader r = openReader();
- char[] buf = new char[iLen];
- int offset = 0;
- int amt;
- while ((amt = r.read(buf, offset, iLen - offset)) > 0) {
- offset += amt;
- }
- r.close();
-
- if (offset <= 0) {
- return "";
+ try {
+ char[] buf = new char[iLen];
+ int offset = 0;
+ int amt;
+ while ((amt = r.read(buf, offset, iLen - offset)) > 0) {
+ offset += amt;
+ }
+
+ if (offset <= 0) {
+ return "";
+ }
+
+ return new String(buf, 0, offset);
+ } finally {
+ r.close();
}
-
- return new String(buf, 0, offset);
} catch (IOException e) {
throw toFetchException(e);
}
@@ -140,8 +143,11 @@ public abstract class AbstractClob implements Clob { try {
Writer w = openWriter();
- w.write(value);
- w.close();
+ try {
+ w.write(value);
+ } finally {
+ w.close();
+ }
} catch (IOException e) {
throw toPersistException(e);
}
|