|
From: <ls...@us...> - 2009-03-20 19:22:32
|
Revision: 5131
http://jnode.svn.sourceforge.net/jnode/?rev=5131&view=rev
Author: lsantha
Date: 2009-03-20 19:22:25 +0000 (Fri, 20 Mar 2009)
Log Message:
-----------
Integrated java.io.PrintStream from OpenJDK.
Modified Paths:
--------------
trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java
trunk/core/descriptors/org.classpath.core.xml
trunk/core/src/core/org/jnode/vm/VmSystem.java
Added Paths:
-----------
trunk/core/src/openjdk/java/java/io/PrintStream.java
trunk/core/src/openjdk/java/java/nio/
trunk/core/src/openjdk/java/java/nio/charset/
trunk/core/src/openjdk/java/java/nio/charset/Charset.java
Removed Paths:
-------------
trunk/core/src/classpath/java/java/io/PrintStream.java
trunk/core/src/classpath/java/java/nio/charset/Charset.java
Modified: trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java
===================================================================
--- trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2009-03-20 18:59:22 UTC (rev 5130)
+++ trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2009-03-20 19:22:25 UTC (rev 5131)
@@ -1319,6 +1319,9 @@
addCompileHighOptLevel("java.nio.ByteBuffer*");
addCompileHighOptLevel("java.nio.DirectByteBuffer*");
addCompileHighOptLevel("java.nio.ByteOrder");
+ addCompileHighOptLevel("java.nio.Char*");
+ addCompileHighOptLevel("java.nio.charset.spi");
+ addCompileHighOptLevel("java.nio.charset");
addCompileHighOptLevel("java.security.ProtectionDomain");
addCompileHighOptLevel("java.security.AccessController");
@@ -1404,7 +1407,21 @@
// addCompileHighOptLevel("sun.reflect.generics.tree");
// addCompileHighOptLevel("sun.reflect.generics.visitor");
// addCompileHighOptLevel("sun.reflect.misc");
+ addCompileHighOptLevel("sun.misc.VM");
addCompileHighOptLevel("sun.nio");
+ addCompileHighOptLevel("sun.nio.cs.US_ASCII");
+ addCompileHighOptLevel("sun.nio.cs.ISO_8859_1*");
+ addCompileHighOptLevel("sun.nio.cs.Surrogate*");
+ addCompileHighOptLevel("sun.nio.cs.StreamEncoder");
+ addCompileHighOptLevel("sun.nio.cs.SingleByteDecoder");
+ addCompileHighOptLevel("sun.nio.cs.SingleByteEncoder");
+ addCompileHighOptLevel("sun.nio.cs.FastCharsetProvider");
+ addCompileHighOptLevel("sun.nio.cs.StandardCharsets");
+ addCompileHighOptLevel("sun.nio.cs.HistoricallyNamedCharset");
+ addCompileHighOptLevel("sun.nio.cs.StreamDecoder");
+ addCompileHighOptLevel("sun.nio.cs.ThreadLocalCoders");
+ addCompileHighOptLevel("sun.nio.cs.Unicode*");
+ addCompileHighOptLevel("sun.nio.cs.UTF*");
if (false) {
addCompileHighOptLevel("org.mmtk.plan");
Modified: trunk/core/descriptors/org.classpath.core.xml
===================================================================
--- trunk/core/descriptors/org.classpath.core.xml 2009-03-20 18:59:22 UTC (rev 5130)
+++ trunk/core/descriptors/org.classpath.core.xml 2009-03-20 19:22:25 UTC (rev 5131)
@@ -49,11 +49,9 @@
<export name="sun.misc.Service"/>
<export name="sun.misc.ServiceConfigurationError"/>
+ <export name="sun.misc.VM"/>
- <export name="sun.nio.cs.StreamEncoder"/>
- <export name="sun.nio.cs.StreamDecoder"/>
- <export name="sun.nio.cs.HistoricallyNamedCharset"/>
- <export name="sun.nio.cs.ThreadLocalCoders"/>
+ <export name="sun.nio.cs.*"/>
<export name="sun.text.*"/>
<export name="sun.text.normalizer.*"/>
Deleted: trunk/core/src/classpath/java/java/io/PrintStream.java
===================================================================
--- trunk/core/src/classpath/java/java/io/PrintStream.java 2009-03-20 18:59:22 UTC (rev 5130)
+++ trunk/core/src/classpath/java/java/io/PrintStream.java 2009-03-20 19:22:25 UTC (rev 5131)
@@ -1,688 +0,0 @@
-/* PrintStream.java -- OutputStream for printing output
- Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006
- 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;
-
-import java.util.Locale;
-import java.util.Formatter;
-
-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
- */
-
-/**
- * This class prints Java primitive values and object to a stream as
- * text. None of the methods in this class throw an exception. However,
- * errors can be detected by calling the <code>checkError()</code> method.
- * Additionally, this stream can be designated as "autoflush" when
- * created so that any writes are automatically flushed to the underlying
- * output sink when the current line is terminated.
- * <p>
- * This class converts char's into byte's using the system default encoding.
- *
- * @author Aaron M. Renn (ar...@ur...)
- * @author Tom Tromey (tr...@cy...)
- * @author Andrew John Hughes (gnu...@me...)
- */
-public class PrintStream extends FilterOutputStream implements Appendable
-{
- /* Notice the implementation is quite similar to OutputStreamWriter.
- * This leads to some minor duplication, because neither inherits
- * from the other, and we want to maximize performance. */
-
- // Line separator string.
- private static final char[] line_separator
- = SystemProperties.getProperty("line.separator", "\n").toCharArray();
-
- /**
- * Encoding name
- */
- private String encoding;
-
- /**
- * This boolean indicates whether or not an error has ever occurred
- * on this stream.
- */
- private boolean error_occurred = false;
-
- /**
- * This is <code>true</code> if auto-flush is enabled,
- * <code>false</code> otherwise
- */
- private boolean auto_flush;
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output File. Doesn't autoflush.
- *
- * @param file The <code>File</code> to write to.
- * @throws FileNotFoundException if an error occurs while opening the file.
- *
- * @since 1.5
- */
- public PrintStream (File file)
- throws FileNotFoundException
- {
- this (new FileOutputStream(file), false);
- }
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output File. Doesn't autoflush.
- *
- * @param file The <code>File</code> to write to.
- * @param encoding The name of the character encoding to use for this
- * object.
- * @throws FileNotFoundException If an error occurs while opening the file.
- * @throws UnsupportedEncodingException If the charset specified by
- * <code>encoding</code> is invalid.
- *
- * @since 1.5
- */
- public PrintStream (File file, String encoding)
- throws FileNotFoundException,UnsupportedEncodingException
- {
- this (new FileOutputStream(file), false, encoding);
- }
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output File. Doesn't autoflush.
- *
- * @param fileName The name of the <code>File</code> to write to.
- * @throws FileNotFoundException if an error occurs while opening the file,
- *
- * @since 1.5
- */
- public PrintStream (String fileName)
- throws FileNotFoundException
- {
- this (new FileOutputStream(new File(fileName)), false);
- }
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output File. Doesn't autoflush.
- *
- * @param fileName The name of the <code>File</code> to write to.
- * @param encoding The name of the character encoding to use for this
- * object.
- * @throws FileNotFoundException if an error occurs while opening the file.
- * @throws UnsupportedEncodingException If the charset specified by
- * <code>encoding</code> is invalid.
- *
- * @since 1.5
- */
- public PrintStream (String fileName, String encoding)
- throws FileNotFoundException,UnsupportedEncodingException
- {
- this (new FileOutputStream(new File(fileName)), false, encoding);
- }
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output sink. Doesn't autoflush.
- *
- * @param out The <code>OutputStream</code> to write to.
- */
- public PrintStream (OutputStream out)
- {
- this (out, false);
- }
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output sink. This constructor also allows "auto-flush"
- * functionality to be specified where the stream will be flushed after
- * every <code>print</code> or <code>println</code> call, when the
- * <code>write</code> methods with array arguments are called, or when a
- * single new-line character is written.
- * <p>
- *
- * @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
- */
- public PrintStream (OutputStream out, boolean auto_flush)
- {
- super (out);
-
- try {
- this.encoding = SystemProperties.getProperty("file.encoding");
- } catch (SecurityException e){
- this.encoding = "ISO8859_1";
- } catch (IllegalArgumentException e){
- this.encoding = "ISO8859_1";
- } catch (NullPointerException e){
- this.encoding = "ISO8859_1";
- }
- this.auto_flush = auto_flush;
- }
-
- /**
- * This method initializes a new <code>PrintStream</code> object to write
- * to the specified output sink. This constructor also allows "auto-flush"
- * functionality to be specified where the stream will be flushed after
- * every <code>print</code> or <code>println</code> call, when the
- * <code>write</code> methods with array arguments are called, or when a
- * single new-line character is written.
- * <p>
- *
- * @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
- * @param encoding The name of the character encoding to use for this
- * object.
- */
- public PrintStream (OutputStream out, boolean auto_flush, String encoding)
- throws UnsupportedEncodingException
- {
- super (out);
-
- new String(new byte[]{0}, encoding); // check if encoding is supported
- this.encoding = encoding;
- this.auto_flush = auto_flush;
- }
-
- /**
- * This method checks to see if an error has occurred on this stream. Note
- * that once an error has occurred, this method will continue to report
- * <code>true</code> forever for this stream. Before checking for an
- * error condition, this method flushes the stream.
- *
- * @return <code>true</code> if an error has occurred,
- * <code>false</code> otherwise
- */
- public boolean checkError ()
- {
- flush ();
- return error_occurred;
- }
-
- /**
- * This method can be called by subclasses to indicate that an error
- * has occurred and should be reported by <code>checkError</code>.
- */
- protected void setError ()
- {
- error_occurred = true;
- }
-
- /**
- * This method closes this stream and all underlying streams.
- */
- public void close ()
- {
- try
- {
- flush();
- out.close();
- }
- catch (InterruptedIOException iioe)
- {
- Thread.currentThread().interrupt();
- }
- catch (IOException e)
- {
- setError ();
- }
- }
-
- /**
- * This method flushes any buffered bytes to the underlying stream and
- * then flushes that stream as well.
- */
- public void flush ()
- {
- try
- {
- out.flush();
- }
- catch (InterruptedIOException iioe)
- {
- Thread.currentThread().interrupt();
- }
- catch (IOException e)
- {
- setError ();
- }
- }
-
- private synchronized void print (String str, boolean println)
- {
- try
- {
- writeChars(str, 0, str.length());
- if (println)
- writeChars(line_separator, 0, line_separator.length);
- if (auto_flush)
- flush();
- }
- catch (InterruptedIOException iioe)
- {
- Thread.currentThread().interrupt();
- }
- catch (IOException e)
- {
- setError ();
- }
- }
-
- private synchronized void print (char[] chars, int pos, int len,
- boolean println)
- {
- try
- {
- writeChars(chars, pos, len);
- if (println)
- writeChars(line_separator, 0, line_separator.length);
- if (auto_flush)
- flush();
- }
- catch (InterruptedIOException iioe)
- {
- Thread.currentThread().interrupt();
- }
- catch (IOException e)
- {
- setError ();
- }
- }
-
- private void writeChars(char[] buf, int offset, int count)
- throws IOException
- {
- byte[] bytes = (new String(buf, offset, count)).getBytes(encoding);
- out.write(bytes, 0, bytes.length);
- }
-
- private void writeChars(String str, int offset, int count)
- throws IOException
- {
- byte[] bytes = str.substring(offset, offset+count).getBytes(encoding);
- out.write(bytes, 0, bytes.length);
- }
-
- /**
- * This methods prints a boolean value to the stream. <code>true</code>
- * values are printed as "true" and <code>false</code> values are printed
- * as "false".
- *
- * @param bool The <code>boolean</code> value to print
- */
- public void print (boolean bool)
- {
- print(String.valueOf(bool), false);
- }
-
- /**
- * This method prints an integer to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- *
- * @param inum The <code>int</code> value to be printed
- */
- public void print (int inum)
- {
- print(String.valueOf(inum), false);
- }
-
- /**
- * This method prints a long to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- *
- * @param lnum The <code>long</code> value to be printed
- */
- public void print (long lnum)
- {
- print(String.valueOf(lnum), false);
- }
-
- /**
- * This method prints a float to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- *
- * @param fnum The <code>float</code> value to be printed
- */
- public void print (float fnum)
- {
- print(String.valueOf(fnum), false);
- }
-
- /**
- * This method prints a double to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- *
- * @param dnum The <code>double</code> value to be printed
- */
- public void print (double dnum)
- {
- print(String.valueOf(dnum), false);
- }
-
- /**
- * This method prints an <code>Object</code> to the stream. The actual
- * value printed is determined by calling the <code>String.valueOf()</code>
- * method.
- *
- * @param obj The <code>Object</code> to print.
- */
- public void print (Object obj)
- {
- print(obj == null ? "null" : obj.toString(), false);
- }
-
- /**
- * This method prints a <code>String</code> to the stream. The actual
- * value printed depends on the system default encoding.
- *
- * @param str The <code>String</code> to print.
- */
- public void print (String str)
- {
- print(str == null ? "null" : str, false);
- }
-
- /**
- * This method prints a char to the stream. The actual value printed is
- * determined by the character encoding in use.
- *
- * @param ch The <code>char</code> value to be printed
- */
- public synchronized void print (char ch)
- {
- print(new char[]{ch}, 0, 1, false);
- }
-
- /**
- * This method prints an array of characters to the stream. The actual
- * value printed depends on the system default encoding.
- *
- * @param charArray The array of characters to print.
- */
- public void print (char[] charArray)
- {
- print(charArray, 0, charArray.length, false);
- }
-
- /**
- * This method prints a line separator sequence to the stream. The value
- * printed is determined by the system property <xmp>line.separator</xmp>
- * and is not necessarily the Unix '\n' newline character.
- */
- public void println ()
- {
- print(line_separator, 0, line_separator.length, false);
- }
-
- /**
- * This methods prints a boolean value to the stream. <code>true</code>
- * values are printed as "true" and <code>false</code> values are printed
- * as "false".
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param bool The <code>boolean</code> value to print
- */
- public void println (boolean bool)
- {
- print(String.valueOf(bool), true);
- }
-
- /**
- * This method prints an integer to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param inum The <code>int</code> value to be printed
- */
- public void println (int inum)
- {
- print(String.valueOf(inum), true);
- }
-
- /**
- * This method prints a long to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param lnum The <code>long</code> value to be printed
- */
- public void println (long lnum)
- {
- print(String.valueOf(lnum), true);
- }
-
- /**
- * This method prints a float to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param fnum The <code>float</code> value to be printed
- */
- public void println (float fnum)
- {
- print(String.valueOf(fnum), true);
- }
-
- /**
- * This method prints a double to the stream. The value printed is
- * determined using the <code>String.valueOf()</code> method.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param dnum The <code>double</code> value to be printed
- */
- public void println (double dnum)
- {
- print(String.valueOf(dnum), true);
- }
-
- /**
- * This method prints an <code>Object</code> to the stream. The actual
- * value printed is determined by calling the <code>String.valueOf()</code>
- * method.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param obj The <code>Object</code> to print.
- */
- public void println (Object obj)
- {
- print(obj == null ? "null" : obj.toString(), true);
- }
-
- /**
- * This method prints a <code>String</code> to the stream. The actual
- * value printed depends on the system default encoding.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param str The <code>String</code> to print.
- */
- public void println (String str)
- {
- print (str == null ? "null" : str, true);
- }
-
- /**
- * This method prints a char to the stream. The actual value printed is
- * determined by the character encoding in use.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param ch The <code>char</code> value to be printed
- */
- public synchronized void println (char ch)
- {
- print(new char[]{ch}, 0, 1, true);
- }
-
- /**
- * This method prints an array of characters to the stream. The actual
- * value printed depends on the system default encoding.
- * <p>
- * This method prints a line termination sequence after printing the value.
- *
- * @param charArray The array of characters to print.
- */
- public void println (char[] charArray)
- {
- print(charArray, 0, charArray.length, true);
- }
-
- /**
- * This method writes a byte of data to the stream. If auto-flush is
- * enabled, printing a newline character will cause the stream to be
- * flushed after the character is written.
- *
- * @param oneByte The byte to be written
- */
- public void write (int oneByte)
- {
- try
- {
- out.write (oneByte & 0xff);
-
- if (auto_flush && (oneByte == '\n'))
- flush ();
- }
- catch (InterruptedIOException iioe)
- {
- Thread.currentThread ().interrupt ();
- }
- catch (IOException e)
- {
- setError ();
- }
- }
-
- /**
- * This method writes <code>len</code> bytes from the specified array
- * starting at index <code>offset</code> into the array.
- *
- * @param buffer The array of bytes to write
- * @param offset The index into the array to start writing from
- * @param len The number of bytes to write
- */
- public void write (byte[] buffer, int offset, int len)
- {
- try
- {
- out.write (buffer, offset, len);
-
- if (auto_flush)
- flush ();
- }
- catch (InterruptedIOException iioe)
- {
- Thread.currentThread ().interrupt ();
- }
- catch (IOException e)
- {
- setError ();
- }
- }
-
- /** @since 1.5 */
- public PrintStream append(char c)
- {
- print(c);
- return this;
- }
-
- /** @since 1.5 */
- public PrintStream append(CharSequence cs)
- {
- print(cs == null ? "null" : cs.toString());
- return this;
- }
-
- /** @since 1.5 */
- public PrintStream append(CharSequence cs, int start, int end)
- {
- print(cs == null ? "null" : cs.subSequence(start, end).toString());
- return this;
- }
-
- /** @since 1.5 */
- public PrintStream printf(String format, Object... args)
- {
- return format(format, args);
- }
-
- /** @since 1.5 */
- public PrintStream printf(Locale locale, String format, Object... args)
- {
- return format(locale, format, args);
- }
-
- /** @since 1.5 */
- public PrintStream format(String format, Object... args)
- {
- return format(Locale.getDefault(), format, args);
- }
-
- /** @since 1.5 */
- public PrintStream format(Locale locale, String format, Object... args)
- {
- Formatter f = new Formatter(this, locale);
- f.format(format, args);
- return this;
- }
-
- //jnode + opnjdk
- /**
- * Clears the internal error state of this stream.
- *
- * <p> This method will cause subsequent invocations of {@link
- * #checkError()} to return <tt>false</tt> until another write
- * operation fails and invokes {@link #setError()}.
- *
- * @since 1.6
- */
- protected void clearError() {
- error_occurred = false;
- }
-} // class PrintStream
Deleted: trunk/core/src/classpath/java/java/nio/charset/Charset.java
===================================================================
--- trunk/core/src/classpath/java/java/nio/charset/Charset.java 2009-03-20 18:59:22 UTC (rev 5130)
+++ trunk/core/src/classpath/java/java/nio/charset/Charset.java 2009-03-20 19:22:25 UTC (rev 5131)
@@ -1,395 +0,0 @@
-/* Charset.java --
- Copyright (C) 2002, 2004, 2005 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.nio.charset;
-
-import gnu.classpath.ServiceFactory;
-import gnu.classpath.SystemProperties;
-import gnu.java.nio.charset.Provider;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.spi.CharsetProvider;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Locale;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-/**
- * @author Jesse Rosenstock
- * @since 1.4
- * @status updated to 1.5
- */
-public abstract class Charset implements Comparable<Charset>
-{
- private CharsetEncoder cachedEncoder;
- private CharsetDecoder cachedDecoder;
-
- /**
- * Extra Charset providers.
- */
- private static CharsetProvider[] providers;
-
- private final String canonicalName;
- private final String[] aliases;
-
- protected Charset (String canonicalName, String[] aliases)
- {
- checkName (canonicalName);
- if (aliases != null)
- {
- int n = aliases.length;
- for (int i = 0; i < n; ++i)
- checkName (aliases[i]);
- }
-
- cachedEncoder = null;
- cachedDecoder = null;
- this.canonicalName = canonicalName;
- this.aliases = aliases;
- }
-
- /**
- * @throws IllegalCharsetNameException if the name is illegal
- */
- private static void checkName (String name)
- {
- int n = name.length ();
-
- if (n == 0)
- throw new IllegalCharsetNameException (name);
-
- char ch = name.charAt (0);
- if (!(('A' <= ch && ch <= 'Z')
- || ('a' <= ch && ch <= 'z')
- || ('0' <= ch && ch <= '9')))
- throw new IllegalCharsetNameException (name);
-
- for (int i = 1; i < n; ++i)
- {
- ch = name.charAt (i);
- if (!(('A' <= ch && ch <= 'Z')
- || ('a' <= ch && ch <= 'z')
- || ('0' <= ch && ch <= '9')
- || ch == '-' || ch == '.' || ch == ':' || ch == '_'))
- throw new IllegalCharsetNameException (name);
- }
- }
-
- /**
- * Returns the system default charset.
- *
- * This may be set by the user or VM with the file.encoding
- * property.
- *
- * @since 1.5
- */
- public static Charset defaultCharset()
- {
- String encoding;
-
- try
- {
- encoding = SystemProperties.getProperty("file.encoding");
- }
- catch(SecurityException e)
- {
- // Use fallback.
- encoding = "ISO-8859-1";
- }
- catch(IllegalArgumentException e)
- {
- // Use fallback.
- encoding = "ISO-8859-1";
- }
-
- try
- {
- return forName(encoding);
- }
- catch(UnsupportedCharsetException e)
- {
- // Ignore.
- }
- catch(IllegalCharsetNameException e)
- {
- // Ignore.
- }
- catch(IllegalArgumentException e)
- {
- // Ignore.
- }
-
- throw new IllegalStateException("Can't get default charset!");
- }
-
- public static boolean isSupported (String charsetName)
- {
- return charsetForName (charsetName) != null;
- }
-
- /**
- * Returns the Charset instance for the charset of the given name.
- *
- * @param charsetName
- * @return the Charset instance for the indicated charset
- * @throws UnsupportedCharsetException if this VM does not support
- * the charset of the given name.
- * @throws IllegalCharsetNameException if the given charset name is
- * legal.
- * @throws IllegalArgumentException if <code>charsetName</code> is null.
- */
- public static Charset forName (String charsetName)
- {
- // Throws IllegalArgumentException as the JDK does.
- if(charsetName == null)
- throw new IllegalArgumentException("Charset name must not be null.");
-
- Charset cs = charsetForName (charsetName);
- if (cs == null)
- throw new UnsupportedCharsetException (charsetName);
- return cs;
- }
-
- /**
- * Retrieves a charset for the given charset name.
- *
- * @return A charset object for the charset with the specified name, or
- * <code>null</code> if no such charset exists.
- *
- * @throws IllegalCharsetNameException if the name is illegal
- */
- private static Charset charsetForName(String charsetName)
- {
- checkName (charsetName);
- // Try the default provider first
- // (so we don't need to load external providers unless really necessary)
- // if it is an exotic charset try loading the external providers.
- Charset cs = provider().charsetForName(charsetName);
- if (cs == null)
- {
- CharsetProvider[] providers = providers2();
- for (int i = 0; i < providers.length; i++)
- {
- cs = providers[i].charsetForName(charsetName);
- if (cs != null)
- break;
- }
- }
- return cs;
- }
-
- public static SortedMap<String, Charset> availableCharsets()
- {
- TreeMap<String, Charset> charsets
- = new TreeMap(String.CASE_INSENSITIVE_ORDER);
- for (Iterator<Charset> i = provider().charsets(); i.hasNext(); )
- {
- Charset cs = i.next();
- charsets.put(cs.name(), cs);
- }
-
- CharsetProvider[] providers = providers2();
- for (int j = 0; j < providers.length; j++)
- {
- for (Iterator<Charset> i = providers[j].charsets(); i.hasNext(); )
- {
- Charset cs = (Charset) i.next();
- charsets.put(cs.name(), cs);
- }
- }
-
- return Collections.unmodifiableSortedMap(charsets);
- }
-
- private static CharsetProvider provider()
- {
- return Provider.provider();
- }
-
- /**
- * We need to support multiple providers, reading them from
- * java.nio.charset.spi.CharsetProvider in the resource directory
- * META-INF/services. This returns the "extra" charset providers.
- */
- private static CharsetProvider[] providers2()
- {
- if (providers == null)
- {
- try
- {
- Iterator i = ServiceFactory.lookupProviders(CharsetProvider.class);
- LinkedHashSet set = new LinkedHashSet();
- while (i.hasNext())
- set.add(i.next());
-
- providers = new CharsetProvider[set.size()];
- set.toArray(providers);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
- return providers;
- }
-
- public final String name ()
- {
- return canonicalName;
- }
-
- public final Set<String> aliases ()
- {
- if (aliases == null)
- return Collections.<String>emptySet();
-
- // should we cache the aliasSet instead?
- int n = aliases.length;
- HashSet<String> aliasSet = new HashSet<String> (n);
- for (int i = 0; i < n; ++i)
- aliasSet.add (aliases[i]);
- return Collections.unmodifiableSet (aliasSet);
- }
-
- public String displayName ()
- {
- return canonicalName;
- }
-
- public String displayName (Locale locale)
- {
- return canonicalName;
- }
-
- public final boolean isRegistered ()
- {
- return (!canonicalName.startsWith ("x-")
- && !canonicalName.startsWith ("X-"));
- }
-
- public abstract boolean contains (Charset cs);
-
- public abstract CharsetDecoder newDecoder ();
-
- public abstract CharsetEncoder newEncoder ();
-
- public boolean canEncode ()
- {
- return true;
- }
-
- // NB: This implementation serializes different threads calling
- // Charset.encode(), a potential performance problem. It might
- // be better to remove the cache, or use ThreadLocal to cache on
- // a per-thread basis.
- public final synchronized ByteBuffer encode (CharBuffer cb)
- {
- try
- {
- if (cachedEncoder == null)
- {
- cachedEncoder = newEncoder ()
- .onMalformedInput (CodingErrorAction.REPLACE)
- .onUnmappableCharacter (CodingErrorAction.REPLACE);
- } else
- cachedEncoder.reset();
- return cachedEncoder.encode (cb);
- }
- catch (CharacterCodingException e)
- {
- throw new AssertionError (e);
- }
- }
-
- public final ByteBuffer encode (String str)
- {
- return encode (CharBuffer.wrap (str));
- }
-
- // NB: This implementation serializes different threads calling
- // Charset.decode(), a potential performance problem. It might
- // be better to remove the cache, or use ThreadLocal to cache on
- // a per-thread basis.
- public final synchronized CharBuffer decode (ByteBuffer bb)
- {
- try
- {
- if (cachedDecoder == null)
- {
- cachedDecoder = newDecoder ()
- .onMalformedInput (CodingErrorAction.REPLACE)
- .onUnmappableCharacter (CodingErrorAction.REPLACE);
- } else
- cachedDecoder.reset();
-
- return cachedDecoder.decode (bb);
- }
- catch (CharacterCodingException e)
- {
- throw new AssertionError (e);
- }
- }
-
- public final int compareTo (Charset other)
- {
- return canonicalName.compareToIgnoreCase (other.canonicalName);
- }
-
- public final int hashCode ()
- {
- return canonicalName.hashCode ();
- }
-
- public final boolean equals (Object ob)
- {
- if (ob instanceof Charset)
- return canonicalName.equalsIgnoreCase (((Charset) ob).canonicalName);
- else
- return false;
- }
-
- public final String toString ()
- {
- return canonicalName;
- }
-}
Modified: trunk/core/src/core/org/jnode/vm/VmSystem.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/VmSystem.java 2009-03-20 18:59:22 UTC (rev 5130)
+++ trunk/core/src/core/org/jnode/vm/VmSystem.java 2009-03-20 19:22:25 UTC (rev 5131)
@@ -123,13 +123,13 @@
// Initialize resource manager
final ResourceManager rm = ResourceManagerImpl.initialize();
- VmSystem.out = getSystemOut();
-
/* Initialize the system classloader */
VmSystemClassLoader loader = (VmSystemClassLoader) (getVmClass(VmProcessor.current()).getLoader());
systemLoader = loader;
loader.initialize();
+ VmSystem.out = getSystemOut();
+
// Initialize VmThread
VmThread.initialize();
@@ -226,6 +226,8 @@
bootOutStream = new PrintStream(bootOut, true);
VmIOContext.setGlobalOutStream(bootOutStream);
VmIOContext.setGlobalErrStream(bootOutStream);
+ setOut(bootOutStream);
+ setErr(bootOutStream);
return bootOutStream;
} else if (VmIsolate.isRoot()) {
return bootOutStream;
@@ -278,6 +280,7 @@
// Standard Java properties
res.put("file.separator", "/");
+// res.put("file.encoding", "ISO-8859-1");
res.put("java.awt.graphicsenv", "org.jnode.awt.JNodeGraphicsEnvironment");
//todo
// res.put("java.awt.printerjob", "");
@@ -944,7 +947,7 @@
static class SystemOutputStream extends OutputStream {
- private final StringBuffer data = new StringBuffer();
+ private StringBuffer data;
/**
* @see java.io.OutputStream#write(int)
@@ -952,6 +955,11 @@
public void write(int b) throws IOException {
final char ch = (char) (b & 0xFF);
Unsafe.debug(ch);
+ if(data == null) {
+ synchronized (this) {
+ data = new StringBuffer();
+ }
+ }
data.append(ch);
}
@@ -961,6 +969,8 @@
* @return data written to the system output stream
*/
public String getData() {
+ if(data == null)
+ return "";
return data.toString();
}
}
Added: trunk/core/src/openjdk/java/java/io/PrintStream.java
===================================================================
--- trunk/core/src/openjdk/java/java/io/PrintStream.java (rev 0)
+++ trunk/core/src/openjdk/java/java/io/PrintStream.java 2009-03-20 19:22:25 UTC (rev 5131)
@@ -0,0 +1,1096 @@
+/*
+ * Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.io;
+
+import java.util.Formatter;
+import java.util.Locale;
+
+
+/**
+ * A <code>PrintStream</code> adds functionality to another output stream,
+ * namely the ability to print representations of various data values
+ * conveniently. Two other features are provided as well. Unlike other output
+ * streams, a <code>PrintStream</code> never throws an
+ * <code>IOException</code>; instead, exceptional situations merely set an
+ * internal flag that can be tested via the <code>checkError</code> method.
+ * Optionally, a <code>PrintStream</code> can be created so as to flush
+ * automatically; this means that the <code>flush</code> method is
+ * automatically invoked after a byte array is written, one of the
+ * <code>println</code> methods is invoked, or a newline character or byte
+ * (<code>'\n'</code>) is written.
+ *
+ * <p> All characters printed by a <code>PrintStream</code> are converted into
+ * bytes using the platform's default character encoding. The <code>{@link
+ * PrintWriter}</code> class should be used in situations that require writing
+ * characters rather than bytes.
+ *
+ * @author Frank Yellin
+ * @author Mark Reinhold
+ * @since JDK1.0
+ */
+
+public class PrintStream extends FilterOutputStream
+ implements Appendable, Closeable
+{
+
+ private boolean autoFlush = false;
+ private boolean trouble = false;
+ private Formatter formatter;
+
+ /**
+ * Track both the text- and character-output streams, so that their buffers
+ * can be flushed without flushing the entire stream.
+ */
+ private BufferedWriter textOut;
+ private OutputStreamWriter charOut;
+
+ /**
+ * Creates a new print stream. This stream will not flush automatically.
+ *
+ * @param out The output stream to which values and objects will be
+ * printed
+ *
+ * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream)
+ */
+ public PrintStream(OutputStream out) {
+ this(out, false);
+ }
+
+ /* Initialization is factored into a private constructor (note the swapped
+ * parameters so that this one isn't confused with the public one) and a
+ * separate init method so that the following two public constructors can
+ * share code. We use a separate init method so that the constructor that
+ * takes an encoding will throw an NPE for a null stream before it throws
+ * an UnsupportedEncodingException for an unsupported encoding.
+ */
+
+ private PrintStream(boolean autoFlush, OutputStream out)
+ {
+ super(out);
+ if (out == null)
+ throw new NullPointerException("Null output stream");
+ this.autoFlush = autoFlush;
+ }
+
+ private void init(OutputStreamWriter osw) {
+ this.charOut = osw;
+ this.textOut = new BufferedWriter(osw);
+ }
+
+ /**
+ * Creates a new print stream.
+ *
+ * @param out The output stream to which values and objects will be
+ * printed
+ * @param autoFlush A boolean; if true, the output buffer will be flushed
+ * whenever a byte array is written, one of the
+ * <code>println</code> methods is invoked, or a newline
+ * character or byte (<code>'\n'</code>) is written
+ *
+ * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
+ */
+ public PrintStream(OutputStream out, boolean autoFlush) {
+ this(autoFlush, out);
+ init(new OutputStreamWriter(this));
+ }
+
+ /**
+ * Creates a new print stream.
+ *
+ * @param out The output stream to which values and objects will be
+ * printed
+ * @param autoFlush A boolean; if true, the output buffer will be flushed
+ * whenever a byte array is written, one of the
+ * <code>println</code> methods is invoked, or a newline
+ * character or byte (<code>'\n'</code>) is written
+ * @param encoding The name of a supported
+ * <a href="../lang/package-summary.html#charenc">
+ * character encoding</a>
+ *
+ * @throws UnsupportedEncodingException
+ * If the named encoding is not supported
+ *
+ * @since 1.4
+ */
+ public PrintStream(OutputStream out, boolean autoFlush, String encoding)
+ throws UnsupportedEncodingException
+ {
+ this(autoFlush, out);
+ init(new OutputStreamWriter(this, encoding));
+ }
+
+ /**
+ * Creates a new print stream, without automatic line flushing, with the
+ * specified file name. This convenience constructor creates
+ * the necessary intermediate {@link java.io.OutputStreamWriter
+ * OutputStreamWriter}, which will encode characters using the
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
+ * for this instance of the Java virtual machine.
+ *
+ * @param fileName
+ * The name of the file to use as the destination of this print
+ * stream. If the file exists, then it will be truncated to
+ * zero size; otherwise, a new file will be created. The output
+ * will be written to the file and is buffered.
+ *
+ * @throws FileNotFoundException
+ * If the given file object does not denote an existing, writable
+ * regular file and a new regular file of that name cannot be
+ * created, or if some other error occurs while opening or
+ * creating the file
+ *
+ * @throws SecurityException
+ * If a security manager is present and {@link
+ * SecurityManager#checkWrite checkWrite(fileName)} denies write
+ * access to the file
+ *
+ * @since 1.5
+ */
+ public PrintStream(String fileName) throws FileNotFoundException {
+ this(false, new FileOutputStream(fileName));
+ init(new OutputStreamWriter(this));
+ }
+
+ /**
+ * Creates a new print stream, without automatic line flushing, with the
+ * specified file name and charset. This convenience constructor creates
+ * the necessary intermediate {@link java.io.OutputStreamWriter
+ * OutputStreamWriter}, which will encode characters using the provided
+ * charset.
+ *
+ * @param fileName
+ * The name of the file to use as the destination of this print
+ * stream. If the file exists, then it will be truncated to
+ * zero size; otherwise, a new file will be created. The output
+ * will be written to the file and is buffered.
+ *
+ * @param csn
+ * The name of a supported {@linkplain java.nio.charset.Charset
+ * charset}
+ *
+ * @throws FileNotFoundException
+ * If the given file object does not denote an existing, writable
+ * regular file and a new regular file of that name cannot be
+ * created, or if some other error occurs while opening or
+ * creating the file
+ *
+ * @throws SecurityException
+ * If a security manager is present and {@link
+ * SecurityManager#checkWrite checkWrite(fileName)} denies write
+ * access to the file
+ *
+ * @throws UnsupportedEncodingException
+ * If the named charset is not supported
+ *
+ * @since 1.5
+ */
+ public PrintStream(String fileName, String csn)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(false, new FileOutputStream(fileName));
+ init(new OutputStreamWriter(this, csn));
+ }
+
+ /**
+ * Creates a new print stream, without automatic line flushing, with the
+ * specified file. This convenience constructor creates the necessary
+ * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
+ * which will encode characters using the {@linkplain
+ * java.nio.charset.Charset#defaultCharset() default charset} for this
+ * instance of the Java virtual machine.
+ *
+ * @param file
+ * The file to use as the destination of this print stream. If the
+ * file exists, then it will be truncated to zero size; otherwise,
+ * a new file will be created. The output will be written to the
+ * file and is buffered.
+ *
+ * @throws FileNotFoundException
+ * If the given file object does not denote an existing, writable
+ * regular file and a new regular file of that name cannot be
+ * created, or if some other error occurs while opening or
+ * creating the file
+ *
+ * @throws SecurityException
+ * If a security manager is present and {@link
+ * SecurityManager#checkWrite checkWrite(file.getPath())}
+ * denies write access to the file
+ *
+ * @since 1.5
+ */
+ public PrintStream(File file) throws FileNotFoundException {
+ this(false, new FileOutputStream(file));
+ init(new OutputStreamWriter(this));
+ }
+
+ /**
+ * Creates a new print stream, without automatic line flushing, with the
+ * specified file and charset. This convenience constructor creates
+ * the necessary intermediate {@link java.io.OutputStreamWriter
+ * OutputStreamWriter}, which will encode characters using the provided
+ * charset.
+ *
+ * @param file
+ * The file to use as the destination of this print stream. If the
+ * file exists, then it will be truncated to zero size; otherwise,
+ * a new file will be created. The output will be written to the
+ * file and is buffered.
+ *
+ * @param csn
+ * The name of a supported {@linkplain java.nio.charset.Charset
+ * charset}
+ *
+ * @throws FileNotFoundException
+ * If the given file object does not denote an existing, writable
+ * regular file and a new regular file of that name cannot be
+ * created, or if some other error occurs while opening or
+ * creating the file
+ *
+ * @throws SecurityException
+ * If a security manager is presentand {@link
+ * SecurityManager#checkWrite checkWrite(file.getPath())}
+ * denies write access to the file
+ *
+ * @throws UnsupportedEncodingException
+ * If the named charset is not supported
+ *
+ * @since 1.5
+ */
+ public PrintStream(File file, String csn)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(false, new FileOutputStream(file));
+ init(new OutputStreamWriter(this, csn));
+ }
+
+ /** Check to make sure that the stream has not been closed */
+ private void ensureOpen() throws IOException {
+ if (out == null)
+ throw new IOException("Stream closed");
+ }
+
+ /**
+ * Flushes the stream. This is done by writing any buffered output bytes to
+ * the underlying output stream and then flushing that stream.
+ *
+ * @see java.io.OutputStream#flush()
+ */
+ public void flush() {
+ synchronized (this) {
+ try {
+ ensureOpen();
+ out.flush();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+ }
+
+ private boolean closing = false; /* To avoid recursive closing */
+
+ /**
+ * Closes the stream. This is done by flushing the stream and then closing
+ * the underlying output stream.
+ *
+ * @see java.io.OutputStream#close()
+ */
+ public void close() {
+ synchronized (this) {
+ if (! closing) {
+ closing = true;
+ try {
+ textOut.close();
+ out.close();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ textOut = null;
+ charOut = null;
+ out = null;
+ }
+ }
+ }
+
+ /**
+ * Flushes the stream and checks its error state. The internal error state
+ * is set to <code>true</code> when the underlying output stream throws an
+ * <code>IOException</code> other than <code>InterruptedIOException</code>,
+ * and when the <code>setError</code> method is invoked. If an operation
+ * on the underlying output stream throws an
+ * <code>InterruptedIOException</code>, then the <code>PrintStream</code>
+ * converts the exception back into an interrupt by doing:
+ * <pre>
+ * Thread.currentThread().interrupt();
+ * </pre>
+ * or the equivalent.
+ *
+ * @return <code>true</code> if and only if this stream has encountered an
+ * <code>IOException</code> other than
+ * <code>InterruptedIOException</code>, or the
+ * <code>setError</code> method has been invoked
+ */
+ public boolean checkError() {
+ if (out != null)
+ flush();
+ if (out instanceof java.io.PrintStream) {
+ PrintStream ps = (PrintStream) out;
+ return ps.checkError();
+ }
+ return trouble;
+ }
+
+ /**
+ * Sets the error state of the stream to <code>true</code>.
+ *
+ * <p> This method will cause subsequent invocations of {@link
+ * #checkError()} to return <tt>true</tt> until {@link
+ * #clearError()} is invoked.
+ *
+ * @since JDK1.1
+ */
+ protected void setError() {
+ trouble = true;
+ }
+
+ /**
+ * Clears the internal error state of this stream.
+ *
+ * <p> This method will cause subsequent invocations of {@link
+ * #checkError()} to return <tt>false</tt> until another write
+ * operation fails and invokes {@link #setError()}.
+ *
+ * @since 1.6
+ */
+ protected void clearError() {
+ trouble = false;
+ }
+
+ /*
+ * Exception-catching, synchronized output operations,
+ * which also implement the write() methods of OutputStream
+ */
+
+ /**
+ * Writes the specified byte to this stream. If the byte is a newline and
+ * automatic flushing is enabled then the <code>flush</code> method will be
+ * invoked.
+ *
+ * <p> Note that the byte is written as given; to write a character that
+ * will be translated according to the platform's default character
+ * encoding, use the <code>print(char)</code> or <code>println(char)</code>
+ * methods.
+ *
+ * @param b The byte to be written
+ * @see #print(char)
+ * @see #println(char)
+ */
+ public void write(int b) {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ out.write(b);
+ if ((b == '\n') && autoFlush)
+ out.flush();
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
+ /**
+ * Writes <code>len</code> bytes from the specified byte array starting at
+ * offset <code>off</code> to this stream. If automatic flushing is
+ * enabled then the <code>flush</code> method will be invoked.
+ *
+ * <p> Note that the bytes will be written as given; to write characters
+ * that will be translated according to the platform's default character
+ * encoding, use the <code>print(char)</code> or <code>println(char)</code>
+ * methods.
+ *
+ * @param buf A byte array
+ * @param off Offset from which to start taking bytes
+ * @param len Number of bytes to write
+ */
+ public void write(byte buf[], int off, int len) {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ out.write(buf, off, len);
+ if (autoFlush)
+ out.flush();
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
+ /*
+ * The following private methods on the text- and character-output streams
+ * always flush the stream buffers, so that writes to the underlying byte
+ * stream occur as promptly as with the original PrintStream.
+ */
+
+ private void write(char buf[]) {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ textOut.write(buf);
+ textOut.flushBuffer();
+ charOut.flushBuffer();
+ if (autoFlush) {
+ for (int i = 0; i < buf.length; i++)
+ if (buf[i] == '\n')
+ out.flush();
+ }
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
+ private void write(String s) {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ textOut.write(s);
+ textOut.flushBuffer();
+ charOut.flushBuffer();
+ if (autoFlush && (s.indexOf('\n') >= 0))
+ out.flush();
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
+ private void newLine() {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ textOut.newLine();
+ textOut.flushBuffer();
+ charOut.flushBuffer();
+ if (autoFlush)
+ out.flush();
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
+ /* Methods that do not terminate lines */
+
+ /**
+ * Prints a boolean value. The string produced by <code>{@link
+ * java.lang.String#valueOf(boolean)}</code> is translated into bytes
+ * according to the platform's default character encoding, and these bytes
+ * are written in exactly the manner of the
+ * <code>{@link #write(int)}</code> method.
+ *
+ * @param b The <code>boolean</code> to be printed
+ */
+ public void print(boolean b) {
+ write(b ? "true" : "false");
+ }
+
+ /**
+ * Prints a character. The character is translated into one or more bytes
+ * according to the platform's default character encoding, and these bytes
+ * are written in exactly the manner of the
+ * <code>{@link #write(int)}</code> method.
+ *
+ * @param c The <code>char</code> to be printed
+ */
+ public void print(char c) {
+ write(String.valueOf(c));
+ }
+
+ /**
+ * Prints an integer. The string produced by <code>{@link
+ * java.lang.String#valueOf(int)}</code> is translated into bytes
+ * according to the platform's default character encoding, and these bytes
+ * are written in exactly the manner of the
+ * <code>{@link #write(int)}</code> method.
+ *
+ * @param i The <code>int</code> to be printed
+ * @see java.lang.Integer#toString(int)
+ */
+ public void print(int i) {
+ write(String.valueOf(i));
+ }
+
+ /**
+ * Prints a long integer. The string produced by <code>{@link
+ * java.lang.String#valueOf(long)}</code> is translated into bytes
+ * according to the platform's default character encoding, and these bytes
+ * are written in exactly the manner of the
+ * <code>{@link #write(int)}</code> method.
+ *
+ * @param l The <code>long</code> to be printed
+ * @see java.lang.Long#toString(long)
+ */
+ public void print(long l) {
+ write(String.valueOf(l));
+ }
+
+ /**
+ * Prints a floating-point number. The string produced by <code>{@link
+ * java.lang.String#valueOf(float)}</code> is translated into bytes
+ * according to the platform's default character encoding, and these bytes
+ * are written in exactly the manner of the
+ * <code>{@link #write(int)}</code> method.
+ *
+ * @para...
[truncated message content] |