summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/io
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-01-17 18:09:40 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-01-17 18:09:40 +0000
commit2d8cf20d0d5ca6b1fbdefc22229d4b7cf1497ede (patch)
treec976ca91e3ef0bda3b34b37c0195145638d8d08e /libjava/classpath/java/io
parenta3ef37ddfeddcc5b0f1c5068d8fdeb25a302d5cd (diff)
downloadgcc-2d8cf20d0d5ca6b1fbdefc22229d4b7cf1497ede.tar.gz
Imported GNU Classpath 0.20
* Makefile.am (AM_CPPFLAGS): Add classpath/include. * java/nio/charset/spi/CharsetProvider.java: New override file. * java/security/Security.java: Likewise. * sources.am: Regenerated. * Makefile.in: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109831 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/io')
-rw-r--r--libjava/classpath/java/io/File.java9
-rw-r--r--libjava/classpath/java/io/InputStreamReader.java4
-rw-r--r--libjava/classpath/java/io/ObjectInputStream.java1
-rw-r--r--libjava/classpath/java/io/ObjectOutputStream.java5
-rw-r--r--libjava/classpath/java/io/ObjectStreamClass.java31
-rw-r--r--libjava/classpath/java/io/OutputStreamWriter.java4
-rw-r--r--libjava/classpath/java/io/PrintStream.java9
-rw-r--r--libjava/classpath/java/io/RandomAccessFile.java47
-rw-r--r--libjava/classpath/java/io/StreamTokenizer.java6
9 files changed, 109 insertions, 7 deletions
diff --git a/libjava/classpath/java/io/File.java b/libjava/classpath/java/io/File.java
index 3c7ac21301c..43e8e5ded6c 100644
--- a/libjava/classpath/java/io/File.java
+++ b/libjava/classpath/java/io/File.java
@@ -396,7 +396,8 @@ public class File implements Serializable, Comparable
* This method initializes a new <code>File</code> object to represent
* a file corresponding to the specified <code>file:</code> protocol URI.
*
- * @param uri The uri.
+ * @param uri The URI
+ * @throws IllegalArgumentException if the URI is not hierarchical
*/
public File(URI uri)
{
@@ -406,7 +407,11 @@ public class File implements Serializable, Comparable
if (!uri.getScheme().equals("file"))
throw new IllegalArgumentException("invalid uri protocol");
- path = normalizePath(uri.getPath());
+ String name = uri.getPath();
+ if (name == null)
+ throw new IllegalArgumentException("URI \"" + uri
+ + "\" is not hierarchical");
+ path = normalizePath(name);
}
/**
diff --git a/libjava/classpath/java/io/InputStreamReader.java b/libjava/classpath/java/io/InputStreamReader.java
index 57cdc53ed22..ef8fd4542db 100644
--- a/libjava/classpath/java/io/InputStreamReader.java
+++ b/libjava/classpath/java/io/InputStreamReader.java
@@ -230,6 +230,8 @@ public class InputStreamReader extends Reader
* Creates an InputStreamReader that uses a decoder of the given
* charset to decode the bytes in the InputStream into
* characters.
+ *
+ * @since 1.5
*/
public InputStreamReader(InputStream in, Charset charset) {
this.in = in;
@@ -244,6 +246,8 @@ public class InputStreamReader extends Reader
/**
* Creates an InputStreamReader that uses the given charset decoder
* to decode the bytes in the InputStream into characters.
+ *
+ * @since 1.5
*/
public InputStreamReader(InputStream in, CharsetDecoder decoder) {
this.in = in;
diff --git a/libjava/classpath/java/io/ObjectInputStream.java b/libjava/classpath/java/io/ObjectInputStream.java
index 98a11dae3e1..750c6989f25 100644
--- a/libjava/classpath/java/io/ObjectInputStream.java
+++ b/libjava/classpath/java/io/ObjectInputStream.java
@@ -50,7 +50,6 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.Arrays;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.TreeSet;
diff --git a/libjava/classpath/java/io/ObjectOutputStream.java b/libjava/classpath/java/io/ObjectOutputStream.java
index 573b9cfa1de..961d5e3099f 100644
--- a/libjava/classpath/java/io/ObjectOutputStream.java
+++ b/libjava/classpath/java/io/ObjectOutputStream.java
@@ -442,6 +442,11 @@ public class ObjectOutputStream extends OutputStream
realOutput.writeByte(flags);
ObjectStreamField[] fields = osc.fields;
+
+ if (fields == ObjectStreamClass.INVALID_FIELDS)
+ throw new InvalidClassException
+ (osc.getName(), "serialPersistentFields is invalid");
+
realOutput.writeShort(fields.length);
ObjectStreamField field;
diff --git a/libjava/classpath/java/io/ObjectStreamClass.java b/libjava/classpath/java/io/ObjectStreamClass.java
index 975dbfc66d0..203e4a5abaa 100644
--- a/libjava/classpath/java/io/ObjectStreamClass.java
+++ b/libjava/classpath/java/io/ObjectStreamClass.java
@@ -63,6 +63,8 @@ import java.util.Vector;
public class ObjectStreamClass implements Serializable
{
+ static final ObjectStreamField[] INVALID_FIELDS = new ObjectStreamField[0];
+
/**
* Returns the <code>ObjectStreamClass</code> for <code>cl</code>.
* If <code>cl</code> is null, or is not <code>Serializable</code>,
@@ -71,6 +73,11 @@ public class ObjectStreamClass implements Serializable
* same <code>ObjectStreamClass</code> object and no recalculation
* will be done.
*
+ * Warning: If this class contains an invalid serialPersistentField arrays
+ * lookup will not throw anything. However {@link #getFields()} will return
+ * an empty array and {@link java.io.ObjectOutputStream#writeObject} will throw an
+ * {@link java.io.InvalidClassException}.
+ *
* @see java.io.Serializable
*/
public static ObjectStreamClass lookup(Class cl)
@@ -148,6 +155,8 @@ public class ObjectStreamClass implements Serializable
* Returns the serializable (non-static and non-transient) Fields
* of the class represented by this ObjectStreamClass. The Fields
* are sorted by name.
+ * If fields were obtained using serialPersistentFields and this array
+ * is faulty then the returned array of this method will be empty.
*
* @return the fields.
*/
@@ -608,6 +617,28 @@ outer:
fields = getSerialPersistentFields(cl);
if (fields != null)
{
+ ObjectStreamField[] fieldsName = new ObjectStreamField[fields.length];
+ System.arraycopy(fields, 0, fieldsName, 0, fields.length);
+
+ Arrays.sort (fieldsName, new Comparator() {
+ public int compare(Object o1, Object o2)
+ {
+ ObjectStreamField f1 = (ObjectStreamField)o1;
+ ObjectStreamField f2 = (ObjectStreamField)o2;
+
+ return f1.getName().compareTo(f2.getName());
+ }
+ });
+
+ for (int i=1; i < fields.length; i++)
+ {
+ if (fieldsName[i-1].getName().equals(fieldsName[i].getName()))
+ {
+ fields = INVALID_FIELDS;
+ return;
+ }
+ }
+
Arrays.sort (fields);
// Retrieve field reference.
for (int i=0; i < fields.length; i++)
diff --git a/libjava/classpath/java/io/OutputStreamWriter.java b/libjava/classpath/java/io/OutputStreamWriter.java
index 29fb631faf4..572683834be 100644
--- a/libjava/classpath/java/io/OutputStreamWriter.java
+++ b/libjava/classpath/java/io/OutputStreamWriter.java
@@ -213,6 +213,8 @@ public class OutputStreamWriter extends Writer
*
* @param out The <code>OutputStream</code> to write to
* @param cs The <code>Charset</code> of the encoding to use
+ *
+ * @since 1.5
*/
public OutputStreamWriter(OutputStream out, Charset cs)
{
@@ -230,6 +232,8 @@ public class OutputStreamWriter extends Writer
*
* @param out The <code>OutputStream</code> to write to
* @param enc The <code>CharsetEncoder</code> to encode the output with
+ *
+ * @since 1.5
*/
public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
{
diff --git a/libjava/classpath/java/io/PrintStream.java b/libjava/classpath/java/io/PrintStream.java
index 8e50559b310..99af25583b0 100644
--- a/libjava/classpath/java/io/PrintStream.java
+++ b/libjava/classpath/java/io/PrintStream.java
@@ -1,5 +1,6 @@
/* PrintStream.java -- OutputStream for printing output
- Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +39,8 @@ exception statement from your version. */
package java.io;
+import gnu.classpath.SystemProperties;
+
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1
* Status: Believed complete and correct to 1.3
@@ -64,7 +67,7 @@ public class PrintStream extends FilterOutputStream
// Line separator string.
private static final char[] line_separator
- = System.getProperty("line.separator").toCharArray();
+ = SystemProperties.getProperty("line.separator").toCharArray();
/**
* Encoding name
@@ -112,7 +115,7 @@ public class PrintStream extends FilterOutputStream
super (out);
try {
- this.encoding = System.getProperty("file.encoding");
+ this.encoding = SystemProperties.getProperty("file.encoding");
} catch (SecurityException e){
this.encoding = "ISO8859_1";
} catch (IllegalArgumentException e){
diff --git a/libjava/classpath/java/io/RandomAccessFile.java b/libjava/classpath/java/io/RandomAccessFile.java
index 23be5a31947..84ee5dec01e 100644
--- a/libjava/classpath/java/io/RandomAccessFile.java
+++ b/libjava/classpath/java/io/RandomAccessFile.java
@@ -124,7 +124,10 @@ public class RandomAccessFile implements DataOutput, DataInput
ch = FileChannelImpl.create(file, fdmode);
fd = new FileDescriptor(ch);
- out = new DataOutputStream (new FileOutputStream (fd));
+ if ((fdmode & FileChannelImpl.WRITE) != 0)
+ out = new DataOutputStream (new FileOutputStream (fd));
+ else
+ out = null;
in = new DataInputStream (new FileInputStream (fd));
}
@@ -766,6 +769,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public void write (int oneByte) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.write(oneByte);
}
@@ -777,6 +783,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public void write (byte[] buffer) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.write(buffer);
}
@@ -792,6 +801,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public void write (byte[] buffer, int offset, int len) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.write (buffer, offset, len);
}
@@ -806,6 +818,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeBoolean (boolean val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeBoolean(val);
}
@@ -820,6 +835,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeByte (int val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeByte(val);
}
@@ -834,6 +852,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeShort (int val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeShort(val);
}
@@ -848,6 +869,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeChar (int val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeChar(val);
}
@@ -861,6 +885,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeInt (int val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeInt(val);
}
@@ -874,6 +901,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeLong (long val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeLong(val);
}
@@ -893,6 +923,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeFloat (float val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeFloat(val);
}
@@ -913,6 +946,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeDouble (double val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeDouble(val);
}
@@ -927,6 +963,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeBytes (String val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeBytes(val);
}
@@ -941,6 +980,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeChars (String val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeChars(val);
}
@@ -975,6 +1017,9 @@ public class RandomAccessFile implements DataOutput, DataInput
*/
public final void writeUTF (String val) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+
out.writeUTF(val);
}
diff --git a/libjava/classpath/java/io/StreamTokenizer.java b/libjava/classpath/java/io/StreamTokenizer.java
index bd7773b1990..b4695ab3d09 100644
--- a/libjava/classpath/java/io/StreamTokenizer.java
+++ b/libjava/classpath/java/io/StreamTokenizer.java
@@ -550,6 +550,12 @@ public class StreamTokenizer
/**
* This method sets the numeric attribute on the characters '0' - '9' and
* the characters '.' and '-'.
+ * When this method is used, the result of giving other attributes
+ * (whitespace, quote, or comment) to the numeric characters may
+ * vary depending on the implementation. For example, if
+ * parseNumbers() and then whitespaceChars('1', '1') are called,
+ * this implementation reads "121" as 2, while some other implementation
+ * will read it as 21.
*/
public void parseNumbers()
{