diff options
Diffstat (limited to 'libjava/classpath/java/io')
-rw-r--r-- | libjava/classpath/java/io/Console.java | 122 | ||||
-rw-r--r-- | libjava/classpath/java/io/File.java | 4 | ||||
-rw-r--r-- | libjava/classpath/java/io/IOError.java | 58 | ||||
-rw-r--r-- | libjava/classpath/java/io/ObjectOutputStream.java | 46 | ||||
-rw-r--r-- | libjava/classpath/java/io/PrintStream.java | 12 |
5 files changed, 241 insertions, 1 deletions
diff --git a/libjava/classpath/java/io/Console.java b/libjava/classpath/java/io/Console.java new file mode 100644 index 0000000..5434b02 --- /dev/null +++ b/libjava/classpath/java/io/Console.java @@ -0,0 +1,122 @@ +/* Console.java -- A character-based console device + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.io; + +/** + * @since 1.6 + */ +public final class Console implements Flushable +{ + private static Console console = new Console(); + + public static Console console() + { + return console; + } + + private Console() + { + } + + public PrintWriter writer() + { + return new PrintWriter(new OutputStreamWriter(System.out)); + } + + public Reader reader() + { + return new InputStreamReader(System.in); + } + + public Console format(String fmt, Object... args) + { + System.out.printf(fmt, args); + + return this; + } + + public Console printf(String fmt, Object... args) + { + return format(fmt, args); + } + + public String readLine(String fmt, Object... args) + { + format(fmt, args); + return readLine(); + } + + public String readLine() + { + String result = null; + try + { + result = new BufferedReader(reader()).readLine(); + } + catch (IOException e) + { + throw new IOError(e); + } + return result; + } + + public char[] readPassword(String fmt, Object... args) + { + format(fmt, args); + return readPassword(); + } + + public char[] readPassword() + { + String s = VMConsole.readPassword(this); + + System.out.println(); + + if (s == null) + { + return null; + } + return s.toCharArray(); + } + + public void flush() throws IOException + { + System.out.flush(); + } +} diff --git a/libjava/classpath/java/io/File.java b/libjava/classpath/java/io/File.java index 4f670e1..080b52f 100644 --- a/libjava/classpath/java/io/File.java +++ b/libjava/classpath/java/io/File.java @@ -700,11 +700,13 @@ public class File implements Serializable, Comparable<File> * * @return <code>true</code> if the file is hidden, <code>false</code> * otherwise. - * + * @throws SecurityException if a security manager exists and denies + * read access to this file. * @since 1.2 */ public boolean isHidden() { + checkRead(); return VMFile.isHidden(path); } diff --git a/libjava/classpath/java/io/IOError.java b/libjava/classpath/java/io/IOError.java new file mode 100644 index 0000000..52acb38 --- /dev/null +++ b/libjava/classpath/java/io/IOError.java @@ -0,0 +1,58 @@ +/* IOError.java -- Throw when unrecoverable I/O error happens. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.io; + +/** + * Throw when unrecoverable I/O error happens. + * + * @since 1.6 + */ +public class IOError extends Error +{ + private static final long serialVersionUID = 67100927991680413L; + + /** + * Create a new instance with a cause. + * @param cause the cause + */ + public IOError(Throwable cause) + { + super(cause); + } +} diff --git a/libjava/classpath/java/io/ObjectOutputStream.java b/libjava/classpath/java/io/ObjectOutputStream.java index 71d2e0b..8abf7f5 100644 --- a/libjava/classpath/java/io/ObjectOutputStream.java +++ b/libjava/classpath/java/io/ObjectOutputStream.java @@ -48,6 +48,8 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * An <code>ObjectOutputStream</code> can be used to write objects @@ -136,6 +138,10 @@ public class ObjectOutputStream extends OutputStream */ public ObjectOutputStream (OutputStream out) throws IOException { + SecurityManager secMan = System.getSecurityManager(); + if (secMan != null && overridesMethods(getClass())) + secMan.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION); + realOutput = new DataOutputStream(out); blockData = new byte[ BUFFER_SIZE ]; blockDataCount = 0; @@ -1487,4 +1493,44 @@ public class ObjectOutputStream extends OutputStream private boolean dump = false; private static final boolean DEBUG = false; + + /** + * Returns true if the given class overrides either of the + * methods <code>putFields</code> or <code>writeUnshared</code>. + * + * @param clazz the class to check. + * @return true if the class overrides one of the methods. + */ + private static boolean overridesMethods(final Class<?> clazz) + { + if (clazz == ObjectOutputStream.class) + return false; + + return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { + public Boolean run() + { + Method[] methods = clazz.getDeclaredMethods(); + for (int a = 0; a < methods.length; ++a) + { + String name = methods[a].getName(); + if (name.equals("writeUnshared")) + { + Class<?>[] paramTypes = methods[a].getParameterTypes(); + if (paramTypes.length == 1 && + paramTypes[0] == Object.class && + methods[a].getReturnType() == Void.class) + return true; + } + else if (name.equals("putFields")) + { + if (methods[a].getParameterTypes().length == 0 && + methods[a].getReturnType() == PutField.class) + return true; + } + } + return false; + } + }); + } + } diff --git a/libjava/classpath/java/io/PrintStream.java b/libjava/classpath/java/io/PrintStream.java index eaab7c3..caa6035 100644 --- a/libjava/classpath/java/io/PrintStream.java +++ b/libjava/classpath/java/io/PrintStream.java @@ -181,10 +181,15 @@ public class PrintStream extends FilterOutputStream implements Appendable * @param out The <code>OutputStream</code> to write to. * @param auto_flush <code>true</code> to flush the stream after every * line, <code>false</code> otherwise + * @exception NullPointerException If out is null. */ public PrintStream (OutputStream out, boolean auto_flush) { super (out); + + if (out == null) + throw new NullPointerException("out is null"); + String encoding; try { encoding = SystemProperties.getProperty("file.encoding"); @@ -213,12 +218,19 @@ public class PrintStream extends FilterOutputStream implements Appendable * line, <code>false</code> otherwise * @param encoding The name of the character encoding to use for this * object. + * @exception NullPointerException If out or encoding is null. */ public PrintStream (OutputStream out, boolean auto_flush, String encoding) throws UnsupportedEncodingException { super (out); + if (out == null) + throw new NullPointerException("out is null"); + + if (encoding == null) + throw new NullPointerException("encoding is null"); + new String(new byte[]{0}, encoding); // check if encoding is supported this.encoding = encoding; this.auto_flush = auto_flush; |