summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-05-07 06:15:29 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-05-07 06:15:29 +0000
commite41ab77a6299ae147832f0f22a21a0c2b3665ee3 (patch)
tree0bdbf184dad1fdf9a61d1df1b4797fa49bedb8ce /src/main/java/com
parent8ca1c356bec65f45b235ea95edb92f07b461b1e4 (diff)
Return -1 when end of stream reached instead of 0.
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java28
-rw-r--r--src/main/java/com/amazon/carbonado/lob/CharArrayClob.java28
2 files changed, 34 insertions, 22 deletions
diff --git a/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java b/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java
index 028f575..9ef522e 100644
--- a/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java
+++ b/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java
@@ -138,9 +138,12 @@ public class ByteArrayBlob extends AbstractBlob {
length = mLength - ipos;
}
- System.arraycopy(mData, ipos, bytes, 0, length);
-
- return length;
+ if (length > 0) {
+ System.arraycopy(mData, ipos, bytes, 0, length);
+ return length;
+ } else {
+ return -1;
+ }
}
synchronized int read(long pos, byte[] bytes, int offset, int length) {
@@ -170,16 +173,19 @@ public class ByteArrayBlob extends AbstractBlob {
length = mLength - ipos;
}
- try {
- System.arraycopy(mData, ipos, bytes, offset, length);
- } catch (IndexOutOfBoundsException e) {
- if (offset >= bytes.length && length > 0) {
- throw new IllegalArgumentException("Offset is too large: " + offset);
+ if (length > 0) {
+ try {
+ System.arraycopy(mData, ipos, bytes, offset, length);
+ } catch (IndexOutOfBoundsException e) {
+ if (offset >= bytes.length && length > 0) {
+ throw new IllegalArgumentException("Offset is too large: " + offset);
+ }
+ throw e;
}
- throw e;
+ return length;
+ } else {
+ return -1;
}
-
- return length;
}
public OutputStream openOutputStream() {
diff --git a/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java b/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java
index ddba889..369eeaf 100644
--- a/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java
+++ b/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java
@@ -144,9 +144,12 @@ public class CharArrayClob extends AbstractClob {
length = mLength - ipos;
}
- System.arraycopy(mData, ipos, chars, 0, length);
-
- return length;
+ if (length > 0) {
+ System.arraycopy(mData, ipos, chars, 0, length);
+ return length;
+ } else {
+ return -1;
+ }
}
synchronized int read(long pos, char[] chars, int offset, int length) {
@@ -176,16 +179,19 @@ public class CharArrayClob extends AbstractClob {
length = mLength - ipos;
}
- try {
- System.arraycopy(mData, ipos, chars, offset, length);
- } catch (IndexOutOfBoundsException e) {
- if (offset >= chars.length && length > 0) {
- throw new IllegalArgumentException("Offset is too large: " + offset);
+ if (length > 0) {
+ try {
+ System.arraycopy(mData, ipos, chars, offset, length);
+ } catch (IndexOutOfBoundsException e) {
+ if (offset >= chars.length && length > 0) {
+ throw new IllegalArgumentException("Offset is too large: " + offset);
+ }
+ throw e;
}
- throw e;
+ return length;
+ } else {
+ return -1;
}
-
- return length;
}
public Writer openWriter() {