From e41ab77a6299ae147832f0f22a21a0c2b3665ee3 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 7 May 2008 06:15:29 +0000 Subject: Return -1 when end of stream reached instead of 0. --- .../com/amazon/carbonado/lob/ByteArrayBlob.java | 28 +++++++++++++--------- .../com/amazon/carbonado/lob/CharArrayClob.java | 28 +++++++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) (limited to 'src/main/java/com') 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() { -- cgit v1.2.3