aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce McKinlay <bryce@albatross.co.nz>2001-01-27 06:04:29 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2001-01-27 06:04:29 +0000
commit60b7365f52d635016272d4622b0c8a3df30205c8 (patch)
treec15526d29fdc612fde34a407401f6e18edca8b69
parent31e1e0a6528b84e40f8eb97552e4bbe1070e5513 (diff)
downloadgcc-60b7365f52d635016272d4622b0c8a3df30205c8.zip
gcc-60b7365f52d635016272d4622b0c8a3df30205c8.tar.gz
gcc-60b7365f52d635016272d4622b0c8a3df30205c8.tar.bz2
ObjectInputStream.java (read): AND byte with 0xff to make result unsigned.
* java/io/ObjectInputStream.java (read): AND byte with 0xff to make result unsigned. (read (byte[], int, int)): Only call readNextBlock() if the block buffer would actually be overrun. Increment blockDataPosition. (callReadMethod): Propagate exceptions from invocation target. * java/io/ObjectOutputStream.java (callWriteMethod): Propagate exceptions from invocation target. From-SVN: r39293
-rw-r--r--libjava/ChangeLog10
-rw-r--r--libjava/java/io/ObjectInputStream.java29
-rw-r--r--libjava/java/io/ObjectOutputStream.java29
3 files changed, 53 insertions, 15 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 55fb358..b491605 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,13 @@
+2001-01-27 Bryce McKinlay <bryce@albatross.co.nz>
+
+ * java/io/ObjectInputStream.java (read): AND byte with 0xff to make
+ result unsigned.
+ (read (byte[], int, int)): Only call readNextBlock() if the block
+ buffer would actually be overrun. Increment blockDataPosition.
+ (callReadMethod): Propagate exceptions from invocation target.
+ * java/io/ObjectOutputStream.java (callWriteMethod): Propagate
+ exceptions from invocation target.
+
2001-01-26 Tom Tromey <tromey@redhat.com>
* jni.cc (_Jv_JNI_GetAnyMethodID): Rewrite signature from external
diff --git a/libjava/java/io/ObjectInputStream.java b/libjava/java/io/ObjectInputStream.java
index 595e9de..9c10d58 100644
--- a/libjava/java/io/ObjectInputStream.java
+++ b/libjava/java/io/ObjectInputStream.java
@@ -577,21 +577,23 @@ public class ObjectInputStream extends InputStream
{
if (this.blockDataPosition >= this.blockDataBytes)
readNextBlock ();
- return this.blockData[this.blockDataPosition++];
+ return (this.blockData[this.blockDataPosition++] & 0xff);
}
else
return this.realInputStream.read ();
}
- public int read (byte data[], int offset, int length) throws IOException
+ public int read (byte[] data, int offset, int length) throws IOException
{
if (this.readDataFromBlock)
{
- if (this.blockDataPosition + length >= this.blockDataBytes)
+ if (this.blockDataPosition + length > this.blockDataBytes)
readNextBlock ();
System.arraycopy (this.blockData, this.blockDataPosition,
data, offset, length);
+ blockDataPosition += length;
+
return length;
}
else
@@ -1359,16 +1361,29 @@ public class ObjectInputStream extends InputStream
{
try
{
- Class classArgs[] = {Class.forName ("java.io.ObjectInputStream")};
+ Class classArgs[] = {ObjectInputStream.class};
Method m = getMethod (klass, "readObject", classArgs);
if (m == null)
return;
Object args[] = {this};
- m.invoke (obj, args);
+ m.invoke (obj, args);
}
- catch (Exception _)
+ catch (InvocationTargetException x)
+ {
+ /* Rethrow if possible. */
+ Throwable exception = x.getTargetException();
+ if (exception instanceof RuntimeException)
+ throw (RuntimeException) exception;
+ if (exception instanceof IOException)
+ throw (IOException) exception;
+
+ throw new IOException ("Exception thrown from readObject() on " +
+ klass + ": " + exception.getClass().getName());
+ }
+ catch (Exception x)
{
- throw new IOException ();
+ throw new IOException ("Failure invoking readObject() on " +
+ klass + ": " + x.getClass().getName());
}
}
diff --git a/libjava/java/io/ObjectOutputStream.java b/libjava/java/io/ObjectOutputStream.java
index cd6202e..faf7ea1 100644
--- a/libjava/java/io/ObjectOutputStream.java
+++ b/libjava/java/io/ObjectOutputStream.java
@@ -633,7 +633,7 @@ public class ObjectOutputStream extends OutputStream
/**
@see java.io.DataOutputStream#write (byte[])
*/
- public void write (byte b[]) throws IOException
+ public void write (byte[] b) throws IOException
{
write (b, 0, b.length);
}
@@ -642,7 +642,7 @@ public class ObjectOutputStream extends OutputStream
/**
@see java.io.DataOutputStream#write (byte[],int,int)
*/
- public void write (byte b[], int off, int len) throws IOException
+ public void write (byte[] b, int off, int len) throws IOException
{
if (writeDataAsBlocks)
{
@@ -1175,22 +1175,35 @@ public class ObjectOutputStream extends OutputStream
private void callWriteMethod (Object obj) throws IOException
{
+ Class klass = obj.getClass ();
try
{
- Class classArgs[] = {Class.forName ("java.io.ObjectOutputStream")};
- Class klass = obj.getClass ();
+ Class classArgs[] = {ObjectOutputStream.class};
Method m = getMethod (klass, "writeObject", classArgs);
if (m == null)
return;
Object args[] = {this};
m.invoke (obj, args);
}
- catch (Exception _)
+ catch (InvocationTargetException x)
{
- throw new IOException ();
+ /* Rethrow if possible. */
+ Throwable exception = x.getTargetException();
+ if (exception instanceof RuntimeException)
+ throw (RuntimeException) exception;
+ if (exception instanceof IOException)
+ throw (IOException) exception;
+
+ throw new IOException ("Exception thrown from writeObject() on " +
+ klass + ": " + exception.getClass().getName());
+ }
+ catch (Exception x)
+ {
+ throw new IOException ("Failure invoking writeObject() on " +
+ klass + ": " + x.getClass().getName());
}
}
-
+
private boolean getBooleanField (Object obj, String field_name) throws IOException
{
try
@@ -1331,7 +1344,7 @@ public class ObjectOutputStream extends OutputStream
private static native Field getField (Class klass, String name)
throws java.lang.NoSuchFieldException;
- private static native Method getMethod (Class klass, String name, Class args[])
+ private static native Method getMethod (Class klass, String name, Class[] args)
throws java.lang.NoSuchMethodException;
// this value comes from 1.2 spec, but is used in 1.1 as well