diff options
Diffstat (limited to 'libjava/java/io')
57 files changed, 512 insertions, 430 deletions
diff --git a/libjava/java/io/BufferedInputStream.java b/libjava/java/io/BufferedInputStream.java index 5343f0762b6..ce166b337f4 100644 --- a/libjava/java/io/BufferedInputStream.java +++ b/libjava/java/io/BufferedInputStream.java @@ -65,6 +65,7 @@ package java.io; */ public class BufferedInputStream extends FilterInputStream { + /** * This is the default buffer size */ @@ -103,17 +104,11 @@ public class BufferedInputStream extends FilterInputStream protected int marklimit; /** - * This is the maximum size we have to allocate for the mark buffer. - * This number may be huge (Integer.MAX_VALUE). The class will continue - * to allocate new chunks (specified by <code>CHUNKSIZE</code>) until the - * the size specified by this field is achieved. - */ - private int marktarget = 0; - - /** - * This is the number of bytes to allocate to reach marktarget. + * This is the initial buffer size. When the buffer is grown because + * of marking requirements, it will be grown by bufferSize increments. + * The underlying stream will be read in chunks of bufferSize. */ - static final private int CHUNKSIZE = 1024; + private final int bufferSize; /** * This method initializes a new <code>BufferedInputStream</code> that will @@ -143,6 +138,9 @@ public class BufferedInputStream extends FilterInputStream if (size <= 0) throw new IllegalArgumentException(); buf = new byte[size]; + // initialize pos & count to bufferSize, to prevent refill from + // allocating a new buffer (if the caller starts out by calling mark()). + pos = count = bufferSize = size; } /** @@ -160,7 +158,7 @@ public class BufferedInputStream extends FilterInputStream */ public synchronized int available() throws IOException { - return count - pos + super.available(); + return count - pos + in.available(); } /** @@ -173,7 +171,9 @@ public class BufferedInputStream extends FilterInputStream { // Free up the array memory. buf = null; - super.close(); + pos = count = 0; + markpos = -1; + in.close(); } /** @@ -196,9 +196,7 @@ public class BufferedInputStream extends FilterInputStream */ public synchronized void mark(int readlimit) { - marktarget = marklimit = readlimit; - if (marklimit > CHUNKSIZE) - marklimit = CHUNKSIZE; + marklimit = readlimit; markpos = pos; } @@ -231,9 +229,6 @@ public class BufferedInputStream extends FilterInputStream if (pos >= count && !refill()) return -1; // EOF - if (markpos >= 0 && pos - markpos > marktarget) - markpos = -1; - return buf[pos++] & 0xFF; } @@ -278,10 +273,7 @@ public class BufferedInputStream extends FilterInputStream off += totalBytesRead; len -= totalBytesRead; - if (markpos >= 0 && pos - markpos > marktarget) - markpos = -1; - - while (len > 0 && super.available() > 0 && refill()) + while (len > 0 && in.available() > 0 && refill()) { int remain = Math.min(count - pos, len); System.arraycopy(buf, pos, b, off, remain); @@ -289,9 +281,6 @@ public class BufferedInputStream extends FilterInputStream off += remain; len -= remain; totalBytesRead += remain; - - if (markpos >= 0 && pos - markpos > marktarget) - markpos = -1; } return totalBytesRead; @@ -338,23 +327,28 @@ public class BufferedInputStream extends FilterInputStream while (n > 0L) { - if (pos >= count && !refill()) - if (n < origN) - break; - else - return 0; // No bytes were read before EOF. + if (pos >= count) + { + if (markpos == -1) + { + // Buffer is empty and no mark is set, skip on the + // underlying stream. + n -= in.skip(n); + break; + } + else if (!refill()) + break; + } int numread = (int) Math.min((long) (count - pos), n); pos += numread; n -= numread; - - if (markpos >= 0 && pos - markpos > marktarget) - markpos = -1; } return origN - n; } + // GCJ LOCAL: package-private for use by InputStreamReader /** * Called to refill the buffer (when count is equal to pos). * @@ -366,39 +360,31 @@ public class BufferedInputStream extends FilterInputStream if (buf == null) throw new IOException("Stream closed."); - if (markpos < 0) - count = pos = 0; - else if (markpos > 0) + if (markpos == -1 || count - markpos >= marklimit) { - // Shift the marked bytes (if any) to the beginning of the array - // but don't grow it. This saves space in case a reset is done - // before we reach the max capacity of this array. - System.arraycopy(buf, markpos, buf, 0, count - markpos); - count -= markpos; - pos -= markpos; - markpos = 0; + markpos = -1; + pos = count = 0; } - else if (count >= buf.length && count < marktarget) // BTW, markpos == 0 + else { - // Need to grow the buffer now to have room for marklimit bytes. - // Note that the new buffer is one greater than marklimit. - // This is so that there will be one byte past marklimit to be read - // before having to call refill again, thus allowing marklimit to be - // invalidated. That way refill doesn't have to check marklimit. - marklimit += CHUNKSIZE; - if (marklimit >= marktarget) - marklimit = marktarget; - byte[] newbuf = new byte[marklimit + 1]; - System.arraycopy(buf, 0, newbuf, 0, count); + byte[] newbuf = buf; + if (markpos < bufferSize) + { + newbuf = new byte[count - markpos + bufferSize]; + } + System.arraycopy(buf, markpos, newbuf, 0, count - markpos); buf = newbuf; + count -= markpos; + pos -= markpos; + markpos = 0; } - int numread = super.read(buf, count, buf.length - count); + int numread = in.read(buf, count, bufferSize); - if (numread < 0) // EOF + if (numread <= 0) // EOF return false; count += numread; - return numread > 0; + return true; } } diff --git a/libjava/java/io/BufferedReader.java b/libjava/java/io/BufferedReader.java index 19074703938..ab597884828 100644 --- a/libjava/java/io/BufferedReader.java +++ b/libjava/java/io/BufferedReader.java @@ -1,5 +1,5 @@ /* BufferedReader.java - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,8 +55,8 @@ package java.io; * of remembering any number of input chars, to the limits of * system memory or the size of <code>Integer.MAX_VALUE</code> * - * @author Per Bothner <bothner@cygnus.com> - * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Per Bothner (bothner@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) */ public class BufferedReader extends Reader { diff --git a/libjava/java/io/ByteArrayInputStream.java b/libjava/java/io/ByteArrayInputStream.java index 45a09a77b5d..906e71a0d94 100644 --- a/libjava/java/io/ByteArrayInputStream.java +++ b/libjava/java/io/ByteArrayInputStream.java @@ -1,5 +1,5 @@ /* ByteArrayInputStream.java -- Read an array as a stream - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,7 +41,7 @@ package java.io; /** * This class permits an array of bytes to be read as an input stream. * - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) * @author Aaron M. Renn (arenn@urbanophile.com) */ public class ByteArrayInputStream extends InputStream diff --git a/libjava/java/io/ByteArrayOutputStream.java b/libjava/java/io/ByteArrayOutputStream.java index 2e89cf5ee0a..095debefa7b 100644 --- a/libjava/java/io/ByteArrayOutputStream.java +++ b/libjava/java/io/ByteArrayOutputStream.java @@ -1,5 +1,5 @@ /* BufferedReader.java - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -66,7 +66,7 @@ package java.io; * multibyte character encodings. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * @date September 24, 1998 */ public class ByteArrayOutputStream extends OutputStream diff --git a/libjava/java/io/CharArrayReader.java b/libjava/java/io/CharArrayReader.java index 9d5382bef1e..d0d5a28399c 100644 --- a/libjava/java/io/CharArrayReader.java +++ b/libjava/java/io/CharArrayReader.java @@ -1,5 +1,5 @@ /* CharArrayReader.java -- Read an array of characters as a stream - Copyright (C) 1998, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,7 +42,7 @@ package java.io; * This class permits an array of chars to be read as an input stream. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class CharArrayReader extends Reader { diff --git a/libjava/java/io/CharArrayWriter.java b/libjava/java/io/CharArrayWriter.java index 7453996c346..4593f15c784 100644 --- a/libjava/java/io/CharArrayWriter.java +++ b/libjava/java/io/CharArrayWriter.java @@ -1,5 +1,5 @@ /* CharArrayWriter.java -- Write chars to a buffer - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,7 +60,7 @@ package java.io; * <p> * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) */ public class CharArrayWriter extends Writer { diff --git a/libjava/java/io/CharConversionException.java b/libjava/java/io/CharConversionException.java index 0cb83d2d020..6f2afb53f7b 100644 --- a/libjava/java/io/CharConversionException.java +++ b/libjava/java/io/CharConversionException.java @@ -1,5 +1,5 @@ /* CharConversionException.java -- Character conversion exceptions - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,7 +43,7 @@ package java.io; * an attempted character conversion. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * @since 1.1 * @status updated to 1.4 */ diff --git a/libjava/java/io/DataInput.java b/libjava/java/io/DataInput.java index 52cd246110d..0aa172b17a0 100644 --- a/libjava/java/io/DataInput.java +++ b/libjava/java/io/DataInput.java @@ -1,5 +1,5 @@ /* DataInput.java -- Interface for reading data from a stream - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,7 +48,7 @@ package java.io; * into Java primitive types. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public interface DataInput { diff --git a/libjava/java/io/DataInputStream.java b/libjava/java/io/DataInputStream.java index d6068828c89..9cdbc695506 100644 --- a/libjava/java/io/DataInputStream.java +++ b/libjava/java/io/DataInputStream.java @@ -50,8 +50,8 @@ package java.io; * * @see DataInput * - * @author Warren Levy <warrenl@cygnus.com> - * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) * @date October 20, 1998. */ public class DataInputStream extends FilterInputStream implements DataInput diff --git a/libjava/java/io/DataOutput.java b/libjava/java/io/DataOutput.java index e07eb628969..70fb7d48c69 100644 --- a/libjava/java/io/DataOutput.java +++ b/libjava/java/io/DataOutput.java @@ -1,5 +1,5 @@ /* DataOutput.java -- Interface for writing data from a stream - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -49,7 +49,7 @@ package java.io; * by classes implementing the <code>DataInput</code> interface. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * * @see DataInput */ diff --git a/libjava/java/io/DataOutputStream.java b/libjava/java/io/DataOutputStream.java index ab2db95df99..9a2d172ac46 100644 --- a/libjava/java/io/DataOutputStream.java +++ b/libjava/java/io/DataOutputStream.java @@ -1,5 +1,5 @@ /* DataOutputStream.java -- Writes primitive Java datatypes to streams - Copyright (C) 1998, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,8 +51,8 @@ package java.io; * * @see DataInputStream * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Tom Tromey <tromey@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) */ public class DataOutputStream extends FilterOutputStream implements DataOutput { diff --git a/libjava/java/io/EOFException.java b/libjava/java/io/EOFException.java index d129cd69249..2ec28c6c8ee 100644 --- a/libjava/java/io/EOFException.java +++ b/libjava/java/io/EOFException.java @@ -1,5 +1,5 @@ /* EOFException.java -- unexpected end of file exception - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,7 +47,7 @@ package java.io; * thus throw this exception. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * @status updated to 1.4 */ public class EOFException extends IOException diff --git a/libjava/java/io/Externalizable.java b/libjava/java/io/Externalizable.java index 09080a05831..71304e24abf 100644 --- a/libjava/java/io/Externalizable.java +++ b/libjava/java/io/Externalizable.java @@ -60,8 +60,6 @@ package java.io; */ public interface Externalizable extends Serializable { - long serialVersionUID = -282491828744381764L; - /** * This method restores an object's state by reading in the instance data * for the object from the passed in stream. Note that this stream is not diff --git a/libjava/java/io/FileDescriptor.java b/libjava/java/io/FileDescriptor.java index e3c1a18bd9f..1e44a60bb99 100644 --- a/libjava/java/io/FileDescriptor.java +++ b/libjava/java/io/FileDescriptor.java @@ -120,7 +120,7 @@ public final class FileDescriptor if (ex instanceof SyncFailedException) throw (SyncFailedException) ex; else - throw new SyncFailedException(ex.getMessage()); + throw new SyncFailedException(ex.toString()); } } } diff --git a/libjava/java/io/FileInputStream.java b/libjava/java/io/FileInputStream.java index 908c00a19b9..17aaf799be0 100644 --- a/libjava/java/io/FileInputStream.java +++ b/libjava/java/io/FileInputStream.java @@ -1,5 +1,5 @@ /* FileInputStream.java -- An input stream that reads from disk files. - Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,8 +51,8 @@ import java.nio.channels.FileChannel; /** * This class is a stream that reads its bytes from a file. * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Warren Levy <warrenl@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Warren Levy (warrenl@cygnus.com) */ public class FileInputStream extends InputStream { diff --git a/libjava/java/io/FileNotFoundException.java b/libjava/java/io/FileNotFoundException.java index 7877aba150d..66809f5e7bb 100644 --- a/libjava/java/io/FileNotFoundException.java +++ b/libjava/java/io/FileNotFoundException.java @@ -1,5 +1,5 @@ /* FileNotFoundException.java -- the requested file could not be found - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,8 +43,8 @@ package java.io; * does not exist, or is inaccessible for some other reason (such as writing * a read-only file). * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Tom Tromey <tromey@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) * @status updated to 1.4 */ public class FileNotFoundException extends IOException diff --git a/libjava/java/io/FileOutputStream.java b/libjava/java/io/FileOutputStream.java index 1702ffe8f54..34b06cbf151 100644 --- a/libjava/java/io/FileOutputStream.java +++ b/libjava/java/io/FileOutputStream.java @@ -1,5 +1,5 @@ /* FileOutputStream.java -- Writes to a file on disk. - Copyright (C) 1998, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,8 +51,8 @@ import java.nio.channels.FileChannel; * This classes allows a stream of data to be written to a disk file or * any open <code>FileDescriptor</code>. * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Tom Tromey <tromey@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) */ public class FileOutputStream extends OutputStream { diff --git a/libjava/java/io/FilenameFilter.java b/libjava/java/io/FilenameFilter.java index e3b004d5499..dad3ccf28af 100644 --- a/libjava/java/io/FilenameFilter.java +++ b/libjava/java/io/FilenameFilter.java @@ -1,5 +1,5 @@ /* FilenameFilter.java -- Filter a list of filenames - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -53,7 +53,7 @@ package java.io; * or should not be included in the file listing. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * * @see File#listFiles(java.io.FilenameFilter) * @see java.awt.FileDialog#setFilenameFilter(java.io.FilenameFilter) diff --git a/libjava/java/io/FilterInputStream.java b/libjava/java/io/FilterInputStream.java index c81259bd25b..477521aa816 100644 --- a/libjava/java/io/FilterInputStream.java +++ b/libjava/java/io/FilterInputStream.java @@ -1,5 +1,5 @@ /* FilterInputStream.java -- Base class for classes that filter input - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -65,7 +65,7 @@ package java.io; * <code>InputStream read(byte[])</code> method. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class FilterInputStream extends InputStream { diff --git a/libjava/java/io/FilterOutputStream.java b/libjava/java/io/FilterOutputStream.java index 2144213f0e1..98db4ac12c9 100644 --- a/libjava/java/io/FilterOutputStream.java +++ b/libjava/java/io/FilterOutputStream.java @@ -1,5 +1,5 @@ /* FilterOutputStream.java -- Parent class for output streams that filter - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,7 +52,7 @@ package java.io; * underlying stream. Subclasses provide actual filtering. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) */ public class FilterOutputStream extends OutputStream { diff --git a/libjava/java/io/FilterReader.java b/libjava/java/io/FilterReader.java index caf102b082a..4cc6940c518 100644 --- a/libjava/java/io/FilterReader.java +++ b/libjava/java/io/FilterReader.java @@ -1,5 +1,5 @@ /* FilterReader.java -- Base class for char stream classes that filter input - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -59,7 +59,7 @@ package java.io; * <code>Reader} read(yte[])</code> method. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public abstract class FilterReader extends Reader { diff --git a/libjava/java/io/FilterWriter.java b/libjava/java/io/FilterWriter.java index a717092d859..5a8ede572db 100644 --- a/libjava/java/io/FilterWriter.java +++ b/libjava/java/io/FilterWriter.java @@ -1,5 +1,5 @@ /* FilterWriter.java -- Parent class for output streams that filter - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,7 +52,7 @@ package java.io; * underlying stream. Subclasses provide actual filtering. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) */ public abstract class FilterWriter extends Writer { diff --git a/libjava/java/io/IOException.java b/libjava/java/io/IOException.java index 8baf593c9c2..f1e3848da4a 100644 --- a/libjava/java/io/IOException.java +++ b/libjava/java/io/IOException.java @@ -1,5 +1,5 @@ /* IOException.java -- Generic input/output exception - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,7 +45,7 @@ package java.io; * detailed indication of what happened. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * @status updated to 1.4 */ public class IOException extends Exception diff --git a/libjava/java/io/InputStream.java b/libjava/java/io/InputStream.java index 610ccf1f177..1d942446711 100644 --- a/libjava/java/io/InputStream.java +++ b/libjava/java/io/InputStream.java @@ -1,5 +1,5 @@ /* InputStream.java -- Base class for input - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,7 +46,7 @@ package java.io; * or network connection. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public abstract class InputStream { diff --git a/libjava/java/io/InputStreamReader.java b/libjava/java/io/InputStreamReader.java index 3ebbb4ec9e4..b3f65368ce3 100644 --- a/libjava/java/io/InputStreamReader.java +++ b/libjava/java/io/InputStreamReader.java @@ -1,5 +1,5 @@ /* InputStreamReader.java -- Reader than transforms bytes to chars - Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -82,7 +82,7 @@ import gnu.gcj.convert.*; * @see InputStream * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner <bothner@cygnus.com> + * @author Per Bothner (bothner@cygnus.com) * @date April 22, 1998. */ public class InputStreamReader extends Reader @@ -282,11 +282,9 @@ public class InputStreamReader extends Reader { // We have knowledge of the internals of BufferedInputStream // here. Eww. - in.mark (0); // BufferedInputStream.refill() can only be called when // `pos>=count'. boolean r = in.pos < in.count || in.refill (); - in.reset (); if (! r) return -1; converter.setInput(in.buf, in.pos, in.count); diff --git a/libjava/java/io/InterruptedIOException.java b/libjava/java/io/InterruptedIOException.java index 321c2697b43..614fb3b8947 100644 --- a/libjava/java/io/InterruptedIOException.java +++ b/libjava/java/io/InterruptedIOException.java @@ -1,5 +1,5 @@ /* InterruptedIOException.java -- an I/O operation was interrupted - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,8 +43,8 @@ package java.io; * for some reason. The field bytesTransferred will contain the number of * bytes that were read/written prior to the interruption. * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Tom Tromey <tromey@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) * @see Thread#interrupt() * @status updated to 1.4 */ diff --git a/libjava/java/io/LineNumberInputStream.java b/libjava/java/io/LineNumberInputStream.java index ee0ce2c799e..ae6292e9284 100644 --- a/libjava/java/io/LineNumberInputStream.java +++ b/libjava/java/io/LineNumberInputStream.java @@ -1,5 +1,5 @@ /* LineNumberInputStream.java -- An input stream which counts line numbers - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -67,7 +67,7 @@ package java.io; * compatibility only and should not be used in new applications. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class LineNumberInputStream extends FilterInputStream { diff --git a/libjava/java/io/LineNumberReader.java b/libjava/java/io/LineNumberReader.java index b3cb5826930..0a4797bd6c1 100644 --- a/libjava/java/io/LineNumberReader.java +++ b/libjava/java/io/LineNumberReader.java @@ -1,5 +1,5 @@ /* LineNumberReader.java -- A character input stream which counts line numbers - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,9 +52,9 @@ package java.io; * read from the stream does not end in a line termination sequence, it * will not be counted as a line. * - * @author Per Bothner <bothner@cygnus.com> + * @author Per Bothner (bothner@cygnus.com) * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Guilhem Lavaux <guilhem@kaffe.org> + * @author Guilhem Lavaux (guilhem@kaffe.org) * @date December 28, 2003. */ /* Written using "Java Class Libraries", 2nd edition, plus online diff --git a/libjava/java/io/ObjectInputStream.java b/libjava/java/io/ObjectInputStream.java index 0c79d332700..2cfe4c99419 100644 --- a/libjava/java/io/ObjectInputStream.java +++ b/libjava/java/io/ObjectInputStream.java @@ -1,5 +1,6 @@ /* ObjectInputStream.java -- Class used to read serialized objects - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,13 +43,14 @@ import gnu.classpath.Configuration; import gnu.java.io.ObjectIdentityWrapper; import java.lang.reflect.Array; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; -import java.security.PrivilegedAction; import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Arrays; import java.util.Hashtable; import java.util.Vector; @@ -121,15 +123,6 @@ public class ObjectInputStream extends InputStream */ public final Object readObject() throws ClassNotFoundException, IOException { - if (callersClassLoader == null) - { - callersClassLoader = getCallersClassLoader (); - if (Configuration.DEBUG && dump) - { - dumpElementln ("CallersClassLoader = " + callersClassLoader); - } - } - if (this.useSubclassMethod) return readObjectOverride(); @@ -271,7 +264,7 @@ public class ObjectInputStream extends InputStream readArrayElements(array, componentType); if(dump) for (int i = 0, len = Array.getLength(array); i < len; i++) - dumpElementln(" ELEMENT[" + i + "]=" + Array.get(array, i)); + dumpElementln(" ELEMENT[" + i + "]=" + Array.get(array, i)); ret_val = processResolution(null, array, handle); break; } @@ -301,13 +294,18 @@ public class ObjectInputStream extends InputStream obj.readExternal(this); if (read_from_blocks) - setBlockDataMode(oldmode); + { + setBlockDataMode(oldmode); + if (!oldmode) + if (this.realInputStream.readByte() != TC_ENDBLOCKDATA) + throw new IOException("No end of block data seen for class with readExternal (ObjectInputStream) method."); + } ret_val = processResolution(osc, obj, handle); break; } // end if (osc.realClassIsExternalizable) - Object obj = newObject(clazz, osc.firstNonSerializableParent); + Object obj = newObject(clazz, osc.firstNonSerializableParentConstructor); int handle = assignNewHandle(obj); Object prevObject = this.currentObject; @@ -398,8 +396,6 @@ public class ObjectInputStream extends InputStream setBlockDataMode(old_mode); this.isDeserializing = was_deserializing; - - depth -= 2; depth -= 2; @@ -505,7 +501,8 @@ public class ObjectInputStream extends InputStream flags, fields); assignNewHandle(osc); - ClassLoader currentLoader = currentLoader(); + if (callersClassLoader == null) + callersClassLoader = currentLoader(); for (int i = 0; i < field_count; i++) { @@ -526,12 +523,40 @@ public class ObjectInputStream extends InputStream class_name = String.valueOf(type_code); fields[i] = - new ObjectStreamField(field_name, class_name, currentLoader); + new ObjectStreamField(field_name, class_name, callersClassLoader); } /* Now that fields have been read we may resolve the class * (and read annotation if needed). */ - Class clazz = resolveClass(osc); + Class clazz; + try + { + clazz = resolveClass(osc); + } + catch (ClassNotFoundException cnfe) + { + // Maybe it was an primitive class? + if (name.equals("void")) + clazz = Void.TYPE; + else if (name.equals("boolean")) + clazz = Boolean.TYPE; + else if (name.equals("byte")) + clazz = Byte.TYPE; + else if (name.equals("short")) + clazz = Short.TYPE; + else if (name.equals("char")) + clazz = Character.TYPE; + else if (name.equals("int")) + clazz = Integer.TYPE; + else if (name.equals("long")) + clazz = Long.TYPE; + else if (name.equals("float")) + clazz = Float.TYPE; + else if (name.equals("double")) + clazz = Double.TYPE; + else + throw cnfe; + } boolean oldmode = setBlockDataMode(true); osc.setClass(clazz, lookupClass(clazz.getSuperclass())); @@ -541,16 +566,45 @@ public class ObjectInputStream extends InputStream // find the first non-serializable, non-abstract // class in clazz's inheritance hierarchy Class first_nonserial = clazz.getSuperclass(); - while (Serializable.class.isAssignableFrom(first_nonserial) - || Modifier.isAbstract(first_nonserial.getModifiers())) + // Maybe it is a primitive class, those don't have a super class, + // or Object itself. Otherwise we can keep getting the superclass + // till we hit the Object class, or some other non-serializable class. + + if (first_nonserial == null) + first_nonserial = clazz; + else + while (Serializable.class.isAssignableFrom(first_nonserial) + || Modifier.isAbstract(first_nonserial.getModifiers())) first_nonserial = first_nonserial.getSuperclass(); - osc.firstNonSerializableParent = first_nonserial; + final Class local_constructor_class = first_nonserial; + + osc.firstNonSerializableParentConstructor = + (Constructor)AccessController.doPrivileged(new PrivilegedAction() + { + public Object run() + { + try + { + Constructor c = local_constructor_class. + getDeclaredConstructor(new Class[0]); + if (Modifier.isPrivate(c.getModifiers())) + return null; + return c; + } + catch (NoSuchMethodException e) + { + // error will be reported later, in newObject() + return null; + } + } + }); + osc.realClassIsSerializable = Serializable.class.isAssignableFrom(clazz); osc.realClassIsExternalizable = Externalizable.class.isAssignableFrom(clazz); ObjectStreamField[] stream_fields = osc.fields; - ObjectStreamField[] real_fields = ObjectStreamClass.lookup(clazz).fields; + ObjectStreamField[] real_fields = ObjectStreamClass.lookupForClassObject(clazz).fields; ObjectStreamField[] fieldmapping = new ObjectStreamField[2 * Math.max(stream_fields.length, real_fields.length)]; int stream_idx = 0; @@ -716,6 +770,15 @@ public class ObjectInputStream extends InputStream protected Class resolveClass(ObjectStreamClass osc) throws ClassNotFoundException, IOException { + if (callersClassLoader == null) + { + callersClassLoader = currentLoader (); + if (Configuration.DEBUG && dump) + { + dumpElementln ("CallersClassLoader = " + callersClassLoader); + } + } + return Class.forName(osc.getName(), true, callersClassLoader); } @@ -749,8 +812,10 @@ public class ObjectInputStream extends InputStream */ private ObjectStreamClass lookupClass(Class clazz) { - ObjectStreamClass oclazz; + if (clazz == null) + return null; + ObjectStreamClass oclazz; oclazz = (ObjectStreamClass)classLookupTable.get(clazz); if (oclazz == null) return ObjectStreamClass.lookup(clazz); @@ -1766,14 +1831,14 @@ public class ObjectInputStream extends InputStream // returns a new instance of REAL_CLASS that has been constructed // only to the level of CONSTRUCTOR_CLASS (a super class of REAL_CLASS) - private Object newObject (Class real_class, Class constructor_class) - throws ClassNotFoundException + private Object newObject (Class real_class, Constructor constructor) + throws ClassNotFoundException, IOException { + if (constructor == null) + throw new InvalidClassException("Missing accessible no-arg base class constructor for " + real_class.getName()); try { - Object obj = allocateObject (real_class); - callConstructor (constructor_class, obj); - return obj; + return allocateObject(real_class, constructor.getDeclaringClass(), constructor); } catch (InstantiationException e) { @@ -1808,10 +1873,7 @@ public class ObjectInputStream extends InputStream * @param sm SecurityManager instance which should be called. * @return The current class loader in the calling stack. */ - private static native ClassLoader currentClassLoader (SecurityManager sm); - - private native ClassLoader getCallersClassLoader(); private void callReadMethod (Method readObject, Class klass, Object obj) throws ClassNotFoundException, IOException @@ -1844,11 +1906,9 @@ public class ObjectInputStream extends InputStream prereadFields = null; } - private native Object allocateObject (Class clazz) + private native Object allocateObject(Class clazz, Class constr_clazz, Constructor constructor) throws InstantiationException; - private native void callConstructor (Class clazz, Object obj); - private static final int BUFFER_SIZE = 1024; private DataInputStream realInputStream; @@ -1870,15 +1930,14 @@ public class ObjectInputStream extends InputStream private Hashtable classLookupTable; private GetField prereadFields; - private static boolean dump = false && Configuration.DEBUG; - private ClassLoader callersClassLoader; + private static boolean dump; // The nesting depth for debugging output private int depth = 0; private void dumpElement (String msg) - { + { System.out.print(msg); } @@ -1897,24 +1956,24 @@ public class ObjectInputStream extends InputStream System.loadLibrary ("javaio"); } } -} - - -// used to keep a prioritized list of object validators -class ValidatorAndPriority implements Comparable -{ - int priority; - ObjectInputValidation validator; - - ValidatorAndPriority (ObjectInputValidation validator, int priority) - { - this.priority = priority; - this.validator = validator; - } - public int compareTo (Object o) + // used to keep a prioritized list of object validators + private static final class ValidatorAndPriority implements Comparable { - ValidatorAndPriority vap = (ValidatorAndPriority)o; - return this.priority - vap.priority; + int priority; + ObjectInputValidation validator; + + ValidatorAndPriority (ObjectInputValidation validator, int priority) + { + this.priority = priority; + this.validator = validator; + } + + public int compareTo (Object o) + { + ValidatorAndPriority vap = (ValidatorAndPriority)o; + return this.priority - vap.priority; + } } } + diff --git a/libjava/java/io/ObjectOutputStream.java b/libjava/java/io/ObjectOutputStream.java index 3482225232a..55763eeddfe 100644 --- a/libjava/java/io/ObjectOutputStream.java +++ b/libjava/java/io/ObjectOutputStream.java @@ -250,6 +250,11 @@ public class ObjectOutputStream extends OutputStream break; } + Class clazz = obj.getClass(); + ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); + if (osc == null) + throw new NotSerializableException(clazz.getName()); + if ((replacementEnabled || obj instanceof Serializable) && ! replaceDone) { @@ -257,19 +262,11 @@ public class ObjectOutputStream extends OutputStream if (obj instanceof Serializable) { - Method m = null; try { - Class classArgs[] = {}; - m = getMethod(obj.getClass(), "writeReplace", - classArgs); - // m can't be null by definition since an - // exception would have been thrown so a check - // for null is not needed. - obj = m.invoke(obj, new Object[] {}); - } - catch (NoSuchMethodException ignore) - { + Method m = osc.writeReplaceMethod; + if (m != null) + obj = m.invoke(obj, new Object[0]); } catch (IllegalAccessException ignore) { @@ -294,11 +291,6 @@ public class ObjectOutputStream extends OutputStream break; } - Class clazz = obj.getClass(); - ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); - if (osc == null) - throw new NotSerializableException(clazz.getName()); - if (clazz.isArray ()) { realOutput.writeByte(TC_ARRAY); @@ -347,8 +339,8 @@ public class ObjectOutputStream extends OutputStream fieldsAlreadyWritten = false; if (currentObjectStreamClass.hasWriteMethod()) { - if (dump) - dumpElementln ("WRITE METHOD CALLED FOR: " + obj); + if (dump) + dumpElementln ("WRITE METHOD CALLED FOR: " + obj); setBlockDataMode(true); callWriteMethod(obj, currentObjectStreamClass); setBlockDataMode(false); @@ -358,10 +350,10 @@ public class ObjectOutputStream extends OutputStream } else { - if (dump) - dumpElementln ("WRITE FIELDS CALLED FOR: " + obj); - writeFields(obj, currentObjectStreamClass); - } + if (dump) + dumpElementln ("WRITE FIELDS CALLED FOR: " + obj); + writeFields(obj, currentObjectStreamClass); + } } this.currentObject = prevObject; @@ -1261,18 +1253,11 @@ public class ObjectOutputStream extends OutputStream private void callWriteMethod(Object obj, ObjectStreamClass osc) throws IOException { - Class klass = osc.forClass(); currentPutField = null; try { - Class classArgs[] = {ObjectOutputStream.class}; - Method m = getMethod(klass, "writeObject", classArgs); - Object args[] = {this}; - m.invoke(obj, args); - } - catch (NoSuchMethodException nsme) - { - // Nothing. + Object args[] = {this}; + osc.writeObjectMethod.invoke(obj, args); } catch (InvocationTargetException x) { @@ -1285,7 +1270,8 @@ public class ObjectOutputStream extends OutputStream IOException ioe = new IOException("Exception thrown from writeObject() on " + - klass + ": " + exception.getClass().getName()); + osc.forClass().getName() + ": " + + exception.getClass().getName()); ioe.initCause(exception); throw ioe; } @@ -1293,7 +1279,8 @@ public class ObjectOutputStream extends OutputStream { IOException ioe = new IOException("Failure invoking writeObject() on " + - klass + ": " + x.getClass().getName()); + osc.forClass().getName() + ": " + + x.getClass().getName()); ioe.initCause(x); throw ioe; } @@ -1535,15 +1522,6 @@ public class ObjectOutputStream extends OutputStream } } - private Method getMethod (Class klass, String name, Class[] args) - throws java.lang.NoSuchMethodException - { - final Method m = klass.getDeclaredMethod(name, args); - setAccessible.setMember(m); - AccessController.doPrivileged(setAccessible); - return m; - } - private void dumpElementln (String msg) { for (int i = 0; i < depth; i++) diff --git a/libjava/java/io/ObjectStreamClass.java b/libjava/java/io/ObjectStreamClass.java index d133afc08f9..a5f6ea0be5e 100644 --- a/libjava/java/io/ObjectStreamClass.java +++ b/libjava/java/io/ObjectStreamClass.java @@ -452,27 +452,33 @@ public class ObjectStreamClass implements Serializable } private Method findMethod(Method[] methods, String name, Class[] params, - Class returnType) + Class returnType, boolean mustBePrivate) { outer: - for(int i = 0; i < methods.length; i++) + for (int i = 0; i < methods.length; i++) { - if(methods[i].getName().equals(name) && - methods[i].getReturnType() == returnType) + final Method m = methods[i]; + int mods = m.getModifiers(); + if (Modifier.isStatic(mods) + || (mustBePrivate && !Modifier.isPrivate(mods))) + { + continue; + } + + if (m.getName().equals(name) + && m.getReturnType() == returnType) { - Class[] mp = methods[i].getParameterTypes(); - if(mp.length == params.length) + Class[] mp = m.getParameterTypes(); + if (mp.length == params.length) { - for(int j = 0; j < mp.length; j++) + for (int j = 0; j < mp.length; j++) { - if(mp[j] != params[j]) + if (mp[j] != params[j]) { continue outer; } } - final Method m = methods[i]; - SetAccessibleAction setAccessible = new SetAccessibleAction(m); - AccessController.doPrivileged(setAccessible); + AccessController.doPrivileged(new SetAccessibleAction(m)); return m; } } @@ -485,9 +491,14 @@ outer: Method[] methods = forClass().getDeclaredMethods(); readObjectMethod = findMethod(methods, "readObject", new Class[] { ObjectInputStream.class }, - Void.TYPE); + Void.TYPE, true); + writeObjectMethod = findMethod(methods, "writeObject", + new Class[] { ObjectOutputStream.class }, + Void.TYPE, true); readResolveMethod = findMethod(methods, "readResolve", - new Class[0], Object.class); + new Class[0], Object.class, false); + writeReplaceMethod = findMethod(methods, "writeReplace", + new Class[0], Object.class, false); } private ObjectStreamClass(Class cl) @@ -517,20 +528,8 @@ outer: // only set this bit if CL is NOT Externalizable flags |= ObjectStreamConstants.SC_SERIALIZABLE; - try - { - Method writeMethod = cl.getDeclaredMethod("writeObject", - writeMethodArgTypes); - int modifiers = writeMethod.getModifiers(); - - if (writeMethod.getReturnType() == Void.TYPE - && Modifier.isPrivate(modifiers) - && !Modifier.isStatic(modifiers)) - flags |= ObjectStreamConstants.SC_WRITE_METHOD; - } - catch(NoSuchMethodException oh_well) - { - } + if (writeObjectMethod != null) + flags |= ObjectStreamConstants.SC_WRITE_METHOD; } @@ -851,11 +850,11 @@ outer: { return (Externalizable)constructor.newInstance(null); } - catch(Throwable t) + catch(Exception x) { throw (InvalidClassException) new InvalidClassException(clazz.getName(), - "Unable to instantiate").initCause(t); + "Unable to instantiate").initCause(x); } } @@ -884,10 +883,12 @@ outer: Method readObjectMethod; Method readResolveMethod; + Method writeReplaceMethod; + Method writeObjectMethod; boolean realClassIsSerializable; boolean realClassIsExternalizable; ObjectStreamField[] fieldMapping; - Class firstNonSerializableParent; + Constructor firstNonSerializableParentConstructor; private Constructor constructor; // default constructor for Externalizable boolean isProxyClass = false; @@ -896,34 +897,33 @@ outer: // but it will avoid showing up as a discrepancy when comparing SUIDs. private static final long serialVersionUID = -6120832682080437368L; -} - -// interfaces are compared only by name -class InterfaceComparator implements Comparator -{ - public int compare(Object o1, Object o2) + // interfaces are compared only by name + private static final class InterfaceComparator implements Comparator { - return ((Class) o1).getName().compareTo(((Class) o2).getName()); + public int compare(Object o1, Object o2) + { + return ((Class) o1).getName().compareTo(((Class) o2).getName()); + } } -} -// Members (Methods and Constructors) are compared first by name, -// conflicts are resolved by comparing type signatures -class MemberComparator implements Comparator -{ - public int compare(Object o1, Object o2) + // Members (Methods and Constructors) are compared first by name, + // conflicts are resolved by comparing type signatures + private static final class MemberComparator implements Comparator { - Member m1 = (Member) o1; - Member m2 = (Member) o2; + public int compare(Object o1, Object o2) + { + Member m1 = (Member) o1; + Member m2 = (Member) o2; - int comp = m1.getName().compareTo(m2.getName()); + int comp = m1.getName().compareTo(m2.getName()); - if (comp == 0) - return TypeSignature.getEncodingOfMember(m1). - compareTo(TypeSignature.getEncodingOfMember(m2)); - else - return comp; + if (comp == 0) + return TypeSignature.getEncodingOfMember(m1). + compareTo(TypeSignature.getEncodingOfMember(m2)); + else + return comp; + } } } diff --git a/libjava/java/io/ObjectStreamException.java b/libjava/java/io/ObjectStreamException.java index da1ca46e662..fa2c78021c2 100644 --- a/libjava/java/io/ObjectStreamException.java +++ b/libjava/java/io/ObjectStreamException.java @@ -1,5 +1,5 @@ /* ObjectStreamException.java -- Superclass of all serialization exceptions - Copyright (C) 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,7 +44,7 @@ package java.io; * indications of the precise failure. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) * @since 1.1 * @status updated to 1.4 */ diff --git a/libjava/java/io/ObjectStreamField.java b/libjava/java/io/ObjectStreamField.java index 93a121cd762..8c1a5db7b59 100644 --- a/libjava/java/io/ObjectStreamField.java +++ b/libjava/java/io/ObjectStreamField.java @@ -367,109 +367,46 @@ public class ObjectStreamField implements Comparable final void setBooleanField(Object obj, boolean val) { - try - { - field.setBoolean(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setBooleanNative(field, obj, val); } final void setByteField(Object obj, byte val) { - try - { - field.setByte(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setByteNative(field, obj, val); } final void setCharField(Object obj, char val) { - try - { - field.setChar(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setCharNative(field, obj, val); } final void setShortField(Object obj, short val) { - try - { - field.setShort(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setShortNative(field, obj, val); } final void setIntField(Object obj, int val) { - try - { - field.setInt(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setIntNative(field, obj, val); } final void setLongField(Object obj, long val) { - try - { - field.setLong(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setLongNative(field, obj, val); } final void setFloatField(Object obj, float val) { - try - { - field.setFloat(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setFloatNative(field, obj, val); } final void setDoubleField(Object obj, double val) { - try - { - field.setDouble(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setDoubleNative(field, obj, val); } final void setObjectField(Object obj, Object val) { - try - { - field.set(obj, val); - } - catch(IllegalAccessException x) - { - throw new InternalError(x.getMessage()); - } + VMObjectStreamClass.setObjectNative(field, obj, val); } } diff --git a/libjava/java/io/OptionalDataException.java b/libjava/java/io/OptionalDataException.java index 919c2bf0f4d..858302c0486 100644 --- a/libjava/java/io/OptionalDataException.java +++ b/libjava/java/io/OptionalDataException.java @@ -1,5 +1,5 @@ /* OptionalDataException.java -- indicates unexpected data in serialized stream - Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -50,7 +50,7 @@ package java.io; * </ul> * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) * @since 1.1 * @status updated to 1.4 */ diff --git a/libjava/java/io/OutputStream.java b/libjava/java/io/OutputStream.java index cee98644b0f..2b1a90a7508 100644 --- a/libjava/java/io/OutputStream.java +++ b/libjava/java/io/OutputStream.java @@ -1,5 +1,5 @@ /* OutputStream.java -- Base class for byte output streams - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,7 +46,7 @@ package java.io; * destination such as a file on disk or network connection. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) */ public abstract class OutputStream { diff --git a/libjava/java/io/OutputStreamWriter.java b/libjava/java/io/OutputStreamWriter.java index a07470a7291..07050415aba 100644 --- a/libjava/java/io/OutputStreamWriter.java +++ b/libjava/java/io/OutputStreamWriter.java @@ -1,5 +1,5 @@ /* OutputStreamWriter.java -- Writer that converts chars to bytes - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -70,7 +70,7 @@ import gnu.gcj.convert.UnicodeToBytes; * </ul> * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner <bothner@cygnus.com> + * @author Per Bothner (bothner@cygnus.com) * @date April 17, 1998. */ public class OutputStreamWriter extends Writer diff --git a/libjava/java/io/PipedInputStream.java b/libjava/java/io/PipedInputStream.java index 906ef10fa9f..d424587889a 100644 --- a/libjava/java/io/PipedInputStream.java +++ b/libjava/java/io/PipedInputStream.java @@ -1,5 +1,5 @@ /* PipedInputStream.java -- Read portion of piped streams. - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -226,18 +226,17 @@ public class PipedInputStream extends InputStream } /** - * This method reads bytes from the stream into a caller supplied buffer. - * It starts storing bytes at position <code>offset</code> into the - * buffer and - * reads a maximum of <code>len</code> bytes. Note that this method - * can actually - * read fewer than <code>len</code> bytes. The actual number of bytes - * read is - * returned. A -1 is returned to indicated that no bytes can be read + * This method reads one byte from the stream. + * -1 is returned to indicated that no bytes can be read * because the end of the stream was reached. If the stream is already * closed, a -1 will again be returned to indicate the end of the stream. - * <p> - * This method will block if no byte is available to be read. + * + * <p>This method will block if no byte is available to be read.</p> + * + * @return the value of the read byte value, or -1 of the end of the stream + * was reached + * + * @throws IOException if an error occured */ public int read() throws IOException { @@ -248,7 +247,7 @@ public class PipedInputStream extends InputStream // if this method is never called. int r = read(read_buf, 0, 1); - return r != -1 ? read_buf[0] : -1; + return r != -1 ? (read_buf[0] & 0xff) : -1; } /** diff --git a/libjava/java/io/PrintStream.java b/libjava/java/io/PrintStream.java index 3526473a4fd..02a126b000f 100644 --- a/libjava/java/io/PrintStream.java +++ b/libjava/java/io/PrintStream.java @@ -1,5 +1,5 @@ /* PrintStream.java -- OutputStream for printing output - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,8 +55,8 @@ import gnu.gcj.convert.UnicodeToBytes; * <p> * This class converts char's into byte's using the system default encoding. * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Tom Tromey <tromey@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) */ public class PrintStream extends FilterOutputStream { diff --git a/libjava/java/io/PrintWriter.java b/libjava/java/io/PrintWriter.java index 376b3c44e7b..e03f2f85a87 100644 --- a/libjava/java/io/PrintWriter.java +++ b/libjava/java/io/PrintWriter.java @@ -54,8 +54,8 @@ package java.io; * class which also auto-flushes when it encounters a newline character * in the chars written). * - * @author Per Bothner <bothner@cygnus.com> - * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Per Bothner (bothner@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) * @date April 17, 1998. */ public class PrintWriter extends Writer diff --git a/libjava/java/io/PushbackInputStream.java b/libjava/java/io/PushbackInputStream.java index c07714ec61c..aedd7eb65ee 100644 --- a/libjava/java/io/PushbackInputStream.java +++ b/libjava/java/io/PushbackInputStream.java @@ -1,5 +1,5 @@ /* PushbackInputStream.java -- An input stream that can unread bytes - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -49,7 +49,7 @@ package java.io; * <p> * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class PushbackInputStream extends FilterInputStream { diff --git a/libjava/java/io/PushbackReader.java b/libjava/java/io/PushbackReader.java index cc2473a6c34..05f343ed9aa 100644 --- a/libjava/java/io/PushbackReader.java +++ b/libjava/java/io/PushbackReader.java @@ -1,5 +1,5 @@ /* PushbackReader.java -- An character stream that can unread chars - Copyright (C) 1998, 2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -49,7 +49,7 @@ package java.io; * by the creator of the stream. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class PushbackReader extends FilterReader { diff --git a/libjava/java/io/RandomAccessFile.java b/libjava/java/io/RandomAccessFile.java index 2b1e08599e8..c23ca3adf2e 100644 --- a/libjava/java/io/RandomAccessFile.java +++ b/libjava/java/io/RandomAccessFile.java @@ -1,5 +1,5 @@ /* RandomAccessFile.java -- Class supporting random file I/O - Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,8 +55,8 @@ import java.nio.channels.FileChannel; * <code>DataInput</code> and <code>DataOutput</code> interfaces to allow * the reading and writing of Java primitives. * - * @author Aaron M. Renn <arenn@urbanophile.com> - * @author Tom Tromey <tromey@cygnus.com> + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) */ public class RandomAccessFile implements DataOutput, DataInput { diff --git a/libjava/java/io/Reader.java b/libjava/java/io/Reader.java index 18481ac697b..bb4494b431a 100644 --- a/libjava/java/io/Reader.java +++ b/libjava/java/io/Reader.java @@ -49,7 +49,7 @@ package java.io; * methods to read characters from a particular input source such as a file * or network connection. * - * @author Per Bothner <bothner@cygnus.com> + * @author Per Bothner (bothner@cygnus.com) * @date April 21, 1998. * @author Aaron M. Renn (arenn@urbanophile.com) */ diff --git a/libjava/java/io/SequenceInputStream.java b/libjava/java/io/SequenceInputStream.java index e7b2f494c2a..a46b11d56aa 100644 --- a/libjava/java/io/SequenceInputStream.java +++ b/libjava/java/io/SequenceInputStream.java @@ -1,5 +1,5 @@ /* SequenceInputStream.java -- Reads multiple input streams in sequence - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -61,7 +61,7 @@ import java.util.Enumeration; * to completion, all subordinate streams are closed. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class SequenceInputStream extends InputStream { diff --git a/libjava/java/io/Serializable.java b/libjava/java/io/Serializable.java index b6c47c4ccbd..1ca6638c874 100644 --- a/libjava/java/io/Serializable.java +++ b/libjava/java/io/Serializable.java @@ -1,5 +1,5 @@ /* Serializable.java -- Interface to indicate a class may be serialized - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,9 +47,8 @@ package java.io; * the implementing class may be serialized. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public interface Serializable { - long serialVersionUID = 1196656838076753133L; } // interface Serializable diff --git a/libjava/java/io/StreamCorruptedException.java b/libjava/java/io/StreamCorruptedException.java index 004047fb654..86002cbe8a6 100644 --- a/libjava/java/io/StreamCorruptedException.java +++ b/libjava/java/io/StreamCorruptedException.java @@ -1,5 +1,5 @@ /* StreamCorruptedException.java -- Error in stream during serialization - Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,7 +43,7 @@ package java.io; * read from a stream during de-serialization. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) * @since 1.1 * @status updated to 1.4 */ diff --git a/libjava/java/io/StreamTokenizer.java b/libjava/java/io/StreamTokenizer.java index dd6acb3fd36..b5bd38f2d78 100644 --- a/libjava/java/io/StreamTokenizer.java +++ b/libjava/java/io/StreamTokenizer.java @@ -42,7 +42,7 @@ package java.io; * million-zillion flags that can be set to control the parsing, as * described under the various method headings. * - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) * @date October 25, 1998. */ /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 diff --git a/libjava/java/io/StringBufferInputStream.java b/libjava/java/io/StringBufferInputStream.java index 96dc4a382f3..4ed9a9f7190 100644 --- a/libjava/java/io/StringBufferInputStream.java +++ b/libjava/java/io/StringBufferInputStream.java @@ -1,5 +1,5 @@ /* StringBufferInputStream.java -- Read an String as a stream - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -65,7 +65,7 @@ package java.io; * @deprecated * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy <warrenl@cygnus.com> + * @author Warren Levy (warrenl@cygnus.com) */ public class StringBufferInputStream extends InputStream { diff --git a/libjava/java/io/StringWriter.java b/libjava/java/io/StringWriter.java index c5aab8d157c..7b6e14193cd 100644 --- a/libjava/java/io/StringWriter.java +++ b/libjava/java/io/StringWriter.java @@ -1,5 +1,5 @@ /* StringWriter.java -- Writes bytes to a StringBuffer - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,7 +47,7 @@ package java.io; * can then be used to retrieve a <code>String</code>. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) */ public class StringWriter extends Writer { diff --git a/libjava/java/io/SyncFailedException.java b/libjava/java/io/SyncFailedException.java index a896ffb5e43..5563268ffd5 100644 --- a/libjava/java/io/SyncFailedException.java +++ b/libjava/java/io/SyncFailedException.java @@ -1,5 +1,5 @@ /* SyncFailedException.java -- a file sync failed - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,7 +42,7 @@ package java.io; * Thrown when a file synchronization fails. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * @see FileDescriptor#sync() * @since 1.1 * @status updated to 1.4 diff --git a/libjava/java/io/UTFDataFormatException.java b/libjava/java/io/UTFDataFormatException.java index a38e25179f5..d4f2df253e4 100644 --- a/libjava/java/io/UTFDataFormatException.java +++ b/libjava/java/io/UTFDataFormatException.java @@ -1,5 +1,5 @@ /* UTFDataFormatException.java -- thrown on bad format in UTF data - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,7 +43,7 @@ package java.io; * to indicate that the data read is invalid. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey <tromey@cygnus.com> + * @author Tom Tromey (tromey@cygnus.com) * @see DataInput * @see DataInputStream#readUTF(DataInput) * @status updated to 1.4 diff --git a/libjava/java/io/UnsupportedEncodingException.java b/libjava/java/io/UnsupportedEncodingException.java index 8ee686bde03..5159fb2b246 100644 --- a/libjava/java/io/UnsupportedEncodingException.java +++ b/libjava/java/io/UnsupportedEncodingException.java @@ -1,5 +1,5 @@ /* UnsupportedEncodingException.java -- the requested encoding isn't supported - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,7 +43,7 @@ package java.io; * not supported. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner <bothner@cygnus.com> + * @author Per Bothner (bothner@cygnus.com) * @since 1.1 * @status updated to 1.4 */ diff --git a/libjava/java/io/VMObjectStreamClass.java b/libjava/java/io/VMObjectStreamClass.java index fd4023e402b..d21de72a130 100644 --- a/libjava/java/io/VMObjectStreamClass.java +++ b/libjava/java/io/VMObjectStreamClass.java @@ -38,7 +38,7 @@ exception statement from your version. */ package java.io; -import java.lang.reflect.Method; +import java.lang.reflect.Field; final class VMObjectStreamClass { @@ -47,4 +47,94 @@ final class VMObjectStreamClass * (a.k.a. <clinit>). */ static native boolean hasClassInitializer (Class clazz); + + /** + * Sets the value of the specified "double" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setDoubleNative(Field field, Object obj, double val); + + /** + * Sets the value of the specified "float" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setFloatNative(Field field, Object obj, float val); + + /** + * Sets the value of the specified "long" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setLongNative(Field field, Object obj, long val); + + /** + * Sets the value of the specified "int" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setIntNative(Field field, Object obj, int val); + + /** + * Sets the value of the specified "short" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setShortNative(Field field, Object obj, short val); + + /** + * Sets the value of the specified "char" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setCharNative(Field field, Object obj, char val); + + /** + * Sets the value of the specified "byte" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setByteNative(Field field, Object obj, byte val); + + /** + * Sets the value of the specified "boolean" field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setBooleanNative(Field field, Object obj, boolean val); + + /** + * Sets the value of the specified object field, allowing final values + * to be assigned. + * + * @param field Field to set the value. + * @param obj Instance which will have its field set. + * @param val Value to put in the field. + */ + static native void setObjectNative(Field field, Object obj, Object val); } diff --git a/libjava/java/io/WriteAbortedException.java b/libjava/java/io/WriteAbortedException.java index 7b683854d3d..a7787805f30 100644 --- a/libjava/java/io/WriteAbortedException.java +++ b/libjava/java/io/WriteAbortedException.java @@ -1,5 +1,5 @@ /* WriteAbortedException.java -- wraps an exception thrown while writing - Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,7 +44,7 @@ package java.io; * objects are discarded. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake <ebb9@email.byu.edu> + * @author Eric Blake (ebb9@email.byu.edu) * @since 1.1 * @status updated to 1.4 */ diff --git a/libjava/java/io/Writer.java b/libjava/java/io/Writer.java index 49b6315231e..4a69030a5e2 100644 --- a/libjava/java/io/Writer.java +++ b/libjava/java/io/Writer.java @@ -1,5 +1,5 @@ /* Writer.java -- Base class for character output streams - Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,7 +51,7 @@ package java.io; * destination such as a file on disk or network connection. * * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner <bothner@cygnus.com> + * @author Per Bothner (bothner@cygnus.com) */ public abstract class Writer { diff --git a/libjava/java/io/natObjectInputStream.cc b/libjava/java/io/natObjectInputStream.cc index 9da4910aa06..0e0d5a719cc 100644 --- a/libjava/java/io/natObjectInputStream.cc +++ b/libjava/java/io/natObjectInputStream.cc @@ -12,6 +12,7 @@ details. */ #include <gcj/cni.h> #include <jvm.h> +#include <gcj/method.h> #include <java/io/ObjectInputStream$GetField.h> #include <java/io/ObjectInputStream.h> @@ -21,6 +22,8 @@ details. */ #include <java/lang/reflect/Method.h> #include <java/lang/ArrayIndexOutOfBoundsException.h> #include <java/lang/SecurityManager.h> +#include <java/lang/reflect/Constructor.h> +#include <java/lang/reflect/Method.h> #ifdef DEBUG #include <java/lang/System.h> @@ -28,7 +31,8 @@ details. */ #endif jobject -java::io::ObjectInputStream::allocateObject (jclass klass) +java::io::ObjectInputStream::allocateObject (jclass klass, jclass, + ::java::lang::reflect::Constructor *ctr) { jobject obj = NULL; using namespace java::lang::reflect; @@ -41,21 +45,15 @@ java::io::ObjectInputStream::allocateObject (jclass klass) else { obj = _Jv_AllocObject (klass); - } + } } catch (jthrowable t) { return NULL; } - return obj; -} - + jmethodID meth = _Jv_FromReflectedConstructor (ctr); -void -java::io::ObjectInputStream::callConstructor (jclass klass, jobject obj) -{ - jstring init_name = JvNewStringLatin1 ("<init>"); // This is a bit inefficient, and a bit of a hack, since we don't // actually use the Method and since what is returned isn't // technically a Method. We can't use Method.invoke as it looks up @@ -63,36 +61,12 @@ java::io::ObjectInputStream::callConstructor (jclass klass, jobject obj) JArray<jclass> *arg_types = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, NULL); - java::lang::reflect::Method *m = klass->getPrivateMethod (init_name, - arg_types); + // We lie about this being a constructor. If we put `true' here // then _Jv_CallAnyMethodA would try to allocate the object for us. - jmethodID meth = (jmethodID) ((char *) (klass->methods) - + m->offset); _Jv_CallAnyMethodA (obj, JvPrimClass (void), meth, false, arg_types, NULL); -} -java::lang::ClassLoader* -java::io::ObjectInputStream::getCallersClassLoader () -{ - java::lang::ClassLoader *loader = NULL; - gnu::gcj::runtime::StackTrace *t - = new gnu::gcj::runtime::StackTrace(4); - java::lang::Class *klass = NULL; - try - { - for (int i = 2; !klass; i++) - { - klass = t->classAt (i); - } - loader = klass->getClassLoaderInternal(); - } - catch (::java::lang::ArrayIndexOutOfBoundsException *e) - { - // FIXME: RuntimeError - } - - return loader; + return obj; } java::lang::ClassLoader* diff --git a/libjava/java/io/natVMObjectStreamClass.cc b/libjava/java/io/natVMObjectStreamClass.cc index b7a056c457f..847b540f0be 100644 --- a/libjava/java/io/natVMObjectStreamClass.cc +++ b/libjava/java/io/natVMObjectStreamClass.cc @@ -13,11 +13,75 @@ details. */ #include <java/io/VMObjectStreamClass.h> #include <java/lang/Class.h> +#include <java/lang/reflect/Field.h> + +using namespace java::lang::reflect; jboolean java::io::VMObjectStreamClass::hasClassInitializer (jclass klass) { + if (klass->isPrimitive()) + return false; _Jv_Method *meth = _Jv_GetMethodLocal(klass, gcj::clinit_name, gcj::void_signature); return (meth != NULL); } + +void +java::io::VMObjectStreamClass::setDoubleNative (Field *f, jobject obj, + jdouble val) +{ + f->setDouble (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setFloatNative (Field *f, jobject obj, + jfloat val) +{ + f->setFloat (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setLongNative (Field *f, jobject obj, jlong val) +{ + f->setLong (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setIntNative (Field *f, jobject obj, jint val) +{ + f->setInt (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setShortNative (Field *f, jobject obj, + jshort val) +{ + f->setShort (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setCharNative (Field *f, jobject obj, jchar val) +{ + f->setChar (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setByteNative (Field *f, jobject obj, jbyte val) +{ + f->setByte (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setBooleanNative (Field *f, jobject obj, + jboolean val) +{ + f->setBoolean (NULL, obj, val, false); +} + +void +java::io::VMObjectStreamClass::setObjectNative (Field *f, jobject obj, + jobject val) +{ + f->set (NULL, obj, val, f->getType(), false); +} |