diff options
Diffstat (limited to 'libjava/classpath/java/io')
-rw-r--r-- | libjava/classpath/java/io/CharArrayWriter.java | 78 | ||||
-rw-r--r-- | libjava/classpath/java/io/DataOutputStream.java | 105 | ||||
-rw-r--r-- | libjava/classpath/java/io/FilePermission.java | 22 | ||||
-rw-r--r-- | libjava/classpath/java/io/InputStream.java | 4 | ||||
-rw-r--r-- | libjava/classpath/java/io/ObjectOutputStream.java | 60 | ||||
-rw-r--r-- | libjava/classpath/java/io/ObjectStreamConstants.java | 20 | ||||
-rw-r--r-- | libjava/classpath/java/io/class-dependencies.conf | 100 |
7 files changed, 205 insertions, 184 deletions
diff --git a/libjava/classpath/java/io/CharArrayWriter.java b/libjava/classpath/java/io/CharArrayWriter.java index f9b338f..68e693b 100644 --- a/libjava/classpath/java/io/CharArrayWriter.java +++ b/libjava/classpath/java/io/CharArrayWriter.java @@ -242,6 +242,84 @@ public class CharArrayWriter extends Writer } } + /** + * Appends the Unicode character, <code>c</code>, to the output stream + * underlying this writer. This is equivalent to <code>write(c)</code>. + * + * @param c the character to append. + * @return a reference to this object. + * @since 1.5 + */ + public CharArrayWriter append(char c) + { + write(c); + return this; + } + + /** + * Appends the specified sequence of Unicode characters to the + * output stream underlying this writer. This is equivalent to + * appending the results of calling <code>toString()</code> on the + * character sequence. As a result, the entire sequence may not be + * appended, as it depends on the implementation of + * <code>toString()</code> provided by the + * <code>CharSequence</code>. For example, if the character + * sequence is wrapped around an input buffer, the results will + * depend on the current position and length of that buffer. + * + * @param cs the character sequence to append. If cs is null, + * then the string "null" (the string representation of null) + * is appended. + * @return a reference to this object. + * @since 1.5 + */ + public CharArrayWriter append(CharSequence cs) + { + try + { + write(cs == null ? "null" : cs.toString()); + } + catch (IOException _) + { + // Can't happen. + } + return this; + } + + /** + * Appends the specified subsequence of Unicode characters to the + * output stream underlying this writer, starting and ending at the + * specified positions within the sequence. The behaviour of this + * method matches the behaviour of writing the result of + * <code>append(cs.subSequence(start,end))</code> when the sequence + * is not null. + * + * @param cs the character sequence to append. If cs is null, + * then the string "null" (the string representation of null) + * is appended. + * @param start the index of the first Unicode character to use from + * the sequence. + * @param end the index of the last Unicode character to use from the + * sequence. + * @return a reference to this object. + * @throws IndexOutOfBoundsException if either of the indices are negative, + * the start index occurs after the end index, or the end index is + * beyond the end of the sequence. + * @since 1.5 + */ + public CharArrayWriter append(CharSequence cs, int start, int end) + { + try + { + write(cs == null ? "null" : cs.subSequence(start, end).toString()); + } + catch (IOException _) + { + // Can't happen. + } + return this; + } + /** * This private method makes the buffer bigger when we run out of room * by allocating a larger buffer and copying the valid chars from the diff --git a/libjava/classpath/java/io/DataOutputStream.java b/libjava/classpath/java/io/DataOutputStream.java index 2517816..6670c2d 100644 --- a/libjava/classpath/java/io/DataOutputStream.java +++ b/libjava/classpath/java/io/DataOutputStream.java @@ -63,6 +63,11 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput protected int written; /** + * Utf8 byte buffer, used by writeUTF() + */ + private byte[] buf; + + /** * This method initializes an instance of <code>DataOutputStream</code> to * write its data to the specified underlying <code>OutputStream</code> * @@ -373,6 +378,37 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput } /** + * Calculate the length, in bytes, of a <code>String</code> in Utf8 format. + * + * @param value The <code>String</code> to measure + * @param start String index at which to begin count + * @param sum Starting Utf8 byte count + * + * @throws UTFDataFormatException if result would exceed 65535 + */ + private int getUTFlength(String value, int start, int sum) + throws IOException + { + int len = value.length(); + + for (int i = start; i < len && sum <= 65535; ++i) + { + char c = value.charAt(i); + if (c >= '\u0001' && c <= '\u007f') + sum += 1; + else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) + sum += 2; + else + sum += 3; + } + + if (sum > 65535) + throw new UTFDataFormatException (); + + return sum; + } + + /** * This method writes a Java <code>String</code> to the stream in a modified * UTF-8 format. First, two bytes are written to the stream indicating the * number of bytes to follow. Note that this is the number of bytes in the @@ -407,48 +443,47 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput public final synchronized void writeUTF(String value) throws IOException { int len = value.length(); - int sum = 0; - - for (int i = 0; i < len && sum <= 65535; ++i) - { - char c = value.charAt(i); - if (c >= '\u0001' && c <= '\u007f') - sum += 1; - else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) - sum += 2; - else - sum += 3; - } - - if (sum > 65535) - throw new UTFDataFormatException (); - + int i = 0; int pos = 0; - byte[] buf = new byte[sum]; + boolean lengthWritten = false; - for (int i = 0; i < len; ++i) + if (buf == null) + buf = new byte[512]; + + do { - char c = value.charAt(i); - if (c >= '\u0001' && c <= '\u007f') - buf[pos++] = (byte) c; - else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) + while (i < len && pos < buf.length - 3) { - buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6))); - buf[pos++] = (byte) (0x80 | (0x3f & c)); + char c = value.charAt(i++); + if (c >= '\u0001' && c <= '\u007f') + buf[pos++] = (byte) c; + else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) + { + buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6))); + buf[pos++] = (byte) (0x80 | (0x3f & c)); + } + else + { + // JSL says the first byte should be or'd with 0xc0, but + // that is a typo. Unicode says 0xe0, and that is what is + // consistent with DataInputStream. + buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12))); + buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6))); + buf[pos++] = (byte) (0x80 | (0x3f & c)); + } } - else + if (! lengthWritten) { - // JSL says the first byte should be or'd with 0xc0, but - // that is a typo. Unicode says 0xe0, and that is what is - // consistent with DataInputStream. - buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12))); - buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6))); - buf[pos++] = (byte) (0x80 | (0x3f & c)); + if (i == len) + writeShort(pos); + else + writeShort(getUTFlength(value, i, pos)); + lengthWritten = true; } - } - - writeShort (sum); - write(buf, 0, sum); + write(buf, 0, pos); + pos = 0; + } + while (i < len); } } // class DataOutputStream diff --git a/libjava/classpath/java/io/FilePermission.java b/libjava/classpath/java/io/FilePermission.java index 31802c6..9a83efb 100644 --- a/libjava/classpath/java/io/FilePermission.java +++ b/libjava/classpath/java/io/FilePermission.java @@ -1,5 +1,6 @@ /* FilePermission.java -- - Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,9 +45,6 @@ public final class FilePermission extends Permission implements Serializable { private static final long serialVersionUID = 7930732926638008763L; - private static final String CURRENT_DIRECTORY = - System.getProperty("user.dir"); - private static final String ALL_FILES = "<<ALL FILES>>"; private boolean readPerm = false; @@ -213,10 +211,18 @@ public final class FilePermission extends Permission implements Serializable FilePermission fp = (FilePermission) p; String f2 = fp.getName(); - if (f1.charAt(0) != File.separatorChar) - f1 = CURRENT_DIRECTORY + f1; - if (f2.charAt(0) != File.separatorChar) - f2 = CURRENT_DIRECTORY + f2; + if (f2.equals(ALL_FILES)) + return false; + + try + { + f1 = new File(f1).getCanonicalPath(); + f2 = new File(f2).getCanonicalPath(); + } + catch (IOException ioe) + { + return false; + } String sub1; diff --git a/libjava/classpath/java/io/InputStream.java b/libjava/classpath/java/io/InputStream.java index e56197a..2934f00 100644 --- a/libjava/classpath/java/io/InputStream.java +++ b/libjava/classpath/java/io/InputStream.java @@ -1,5 +1,5 @@ /* InputStream.java -- Base class for input - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,7 +48,7 @@ package java.io; * @author Aaron M. Renn (arenn@urbanophile.com) * @author Warren Levy (warrenl@cygnus.com) */ -public abstract class InputStream +public abstract class InputStream implements Closeable { /** * Default, no-arg, public constructor diff --git a/libjava/classpath/java/io/ObjectOutputStream.java b/libjava/classpath/java/io/ObjectOutputStream.java index 55a12e4..61f07bc 100644 --- a/libjava/classpath/java/io/ObjectOutputStream.java +++ b/libjava/classpath/java/io/ObjectOutputStream.java @@ -549,53 +549,37 @@ public class ObjectOutputStream extends OutputStream * different protocols, specified by <code>PROTOCOL_VERSION_1</code> * and <code>PROTOCOL_VERSION_2</code>. This implementation writes * data using <code>PROTOCOL_VERSION_2</code> by default, as is done - * by the JDK 1.2. - * - * A non-portable method, <code>setDefaultProtocolVersion (int - * version)</code> is provided to change the default protocol - * version. - * + * since the JDK 1.2. + * <p> * For an explanation of the differences between the two protocols - * see XXX: the Java ObjectSerialization Specification. - * - * @exception IOException if <code>version</code> is not a valid - * protocol - * - * @see #setDefaultProtocolVersion(int) + * see the Java Object Serialization Specification. + * </p> + * + * @param version the version to use. + * + * @throws IllegalArgumentException if <code>version</code> is not a valid + * protocol. + * @throws IllegalStateException if called after the first the first object + * was serialized. + * @throws IOException if an I/O error occurs. + * + * @see ObjectStreamConstants#PROTOCOL_VERSION_1 + * @see ObjectStreamConstants#PROTOCOL_VERSION_2 + * + * @since 1.2 */ public void useProtocolVersion(int version) throws IOException { if (version != PROTOCOL_VERSION_1 && version != PROTOCOL_VERSION_2) - throw new IOException("Invalid protocol version requested."); + throw new IllegalArgumentException("Invalid protocol version requested."); + + if (nextOID != baseWireHandle) + throw new IllegalStateException("Protocol version cannot be changed " + + "after serialization started."); protocolVersion = version; } - - /** - * <em>GNU $classpath specific</em> - * - * Changes the default stream protocol used by all - * <code>ObjectOutputStream</code>s. There are currently two - * different protocols, specified by <code>PROTOCOL_VERSION_1</code> - * and <code>PROTOCOL_VERSION_2</code>. The default default is - * <code>PROTOCOL_VERSION_1</code>. - * - * @exception IOException if <code>version</code> is not a valid - * protocol - * - * @see #useProtocolVersion(int) - */ - public static void setDefaultProtocolVersion(int version) - throws IOException - { - if (version != PROTOCOL_VERSION_1 && version != PROTOCOL_VERSION_2) - throw new IOException("Invalid protocol version requested."); - - defaultProtocolVersion = version; - } - - /** * An empty hook that allows subclasses to write extra information * about classes to the stream. This method is called the first diff --git a/libjava/classpath/java/io/ObjectStreamConstants.java b/libjava/classpath/java/io/ObjectStreamConstants.java index f1a4af7..04cf79b 100644 --- a/libjava/classpath/java/io/ObjectStreamConstants.java +++ b/libjava/classpath/java/io/ObjectStreamConstants.java @@ -1,6 +1,6 @@ /* ObjectStreamConstants.java -- Interface containing constant values used in reading and writing serialized objects - Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2003, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,11 +45,29 @@ package java.io; * <code>ObjectInputStream</code>, and <code>ObjectStreamClass</code>. * The values for these constants are specified by the Java library * specification. + * + * @since 1.1 */ public interface ObjectStreamConstants { // FIXME: Javadoc comment these values. + + /** + * The serialization stream protocol version 1. This version was + * the default serialization protocol before JDK 1.2. + * + * @see ObjectOutputStream#useProtocolVersion(int) + * @since 1.2 + */ int PROTOCOL_VERSION_1 = 1; + + /** + * The serialization stream protocol version 2. This version is + * used as the default serialization protocol since JDK 1.2. + * + * @see ObjectOutputStream#useProtocolVersion(int) + * @since 1.2 + */ int PROTOCOL_VERSION_2 = 2; short STREAM_MAGIC = (short)0xaced; diff --git a/libjava/classpath/java/io/class-dependencies.conf b/libjava/classpath/java/io/class-dependencies.conf deleted file mode 100644 index 633bb17..0000000 --- a/libjava/classpath/java/io/class-dependencies.conf +++ /dev/null @@ -1,100 +0,0 @@ -# This property file contains dependencies of classes, methods, and -# field on other methods or classes. -# -# Syntax: -# -# <used>: <needed 1> [... <needed N>] -# -# means that when <used> is included, <needed 1> (... <needed N>) must -# be included as well. -# -# <needed X> and <used> are of the form -# -# <class.methodOrField(signature)> -# -# or just -# -# <class> -# -# Within dependencies, variables can be used. A variable is defined as -# follows: -# -# {variable}: value1 value2 ... value<n> -# -# variables can be used on the right side of dependencies as follows: -# -# <used>: com.bla.blu.{variable}.Class.m()V -# -# The use of the variable will expand to <n> dependencies of the form -# -# <used>: com.bla.blu.value1.Class.m()V -# <used>: com.bla.blu.value2.Class.m()V -# ... -# <used>: com.bla.blu.value<n>.Class.m()V -# -# Variables can be redefined when building a system to select the -# required support for features like encodings, protocols, etc. -# -# Hints: -# -# - For methods and fields, the signature is mandatory. For -# specification, please see the Java Virtual Machine Specification by -# SUN. Unlike in the spec, field signatures (types) are in brackets. -# -# - Package names must be separated by '/' (and not '.'). E.g., -# java/lang/Class (this is necessary, because the '.' is used to -# separate method or field names from classes) -# -# - In case <needed> refers to a class, only the class itself will be -# included in the resulting binary, NOT necessarily all its methods -# and fields. If you want to refer to all methods and fields, you can -# write class.* as an abbreviation. -# -# - Abbreviations for packages are also possible: my/package/* means all -# methods and fields of all classes in my/package. -# -# - A line with a trailing '\' continues in the next line. - -java/io/File: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V \ - java/lang/IllegalArgumentException.<init>(Ljava/lang/String;)V - -java/io/FileDescriptor: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/lang/IllegalArgumentException.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V - -java/io/FileInputStream: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V \ - java/io/FileNotFoundException.<init>(Ljava/lang/String;)V - -java/io/FileOutputStream: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/io/FileNotFoundException.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V - -java/io/ObjectInputStream: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/lang/SecurityManager.currentClassLoader()Ljava/lang/ClassLoader; \ - java/lang/IllegalArgumentException.<init>(Ljava/lang/String;)V - -java/io/ObjectOutputStream: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/lang/SecurityManager.currentClassLoader()Ljava/lang/ClassLoader; \ - java/lang/IllegalArgumentException.<init>(Ljava/lang/String;)V - -java/io/RandomAccessFile: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/io/FileNotFoundException.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V - -# end of file |