Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java Thu Jan 4 09:47:01 2007
@@ -19,7 +19,6 @@
import org.apache.harmony.luni.util.Msg;
-
/**
* PipedWriter is a class which places information on a communications pipe.
* When two threads want to pass data back and forth, one creates a piped writer
@@ -28,179 +27,172 @@
* @see PipedReader
*/
public class PipedWriter extends Writer {
- /**
- * The destination PipedReader
- */
- private PipedReader dest;
-
- private boolean closed;
-
- /**
- * Constructs a new unconnected PipedWriter. The resulting Stream must be
- * connected to a PipedReader before data may be written to it.
- */
- public PipedWriter() {
- super();
- }
-
- /**
- * Constructs a new PipedWriter connected to the PipedReader
- * <code>dest</code>. Any data written to this Writer can be read from
- * the <code>dest</code>.
- *
- * @param dest
- * the PipedReader to connect to.
- *
- * @throws java.io.IOException
- * if <code>dest</code> is already connected.
- */
- public PipedWriter(PipedReader dest) throws IOException {
- super(dest);
- connect(dest);
- }
-
- /**
- * Close this PipedWriter. Any data buffered in the corresponding
- * PipedReader can be read, then -1 will be returned to the reader. If this
- * Writer is not connected, this method does nothing.
- *
- * @throws java.io.IOException
- * If an error occurs attempting to close this PipedWriter.
- */
- @Override
+ /**
+ * The destination PipedReader
+ */
+ private PipedReader dest;
+
+ private boolean closed;
+
+ /**
+ * Constructs a new unconnected PipedWriter. The resulting Stream must be
+ * connected to a PipedReader before data may be written to it.
+ */
+ public PipedWriter() {
+ super();
+ }
+
+ /**
+ * Constructs a new PipedWriter connected to the PipedReader
+ * <code>dest</code>. Any data written to this Writer can be read from
+ * the <code>dest</code>.
+ *
+ * @param dest
+ * the PipedReader to connect to.
+ *
+ * @throws java.io.IOException
+ * if <code>dest</code> is already connected.
+ */
+ public PipedWriter(PipedReader dest) throws IOException {
+ super(dest);
+ connect(dest);
+ }
+
+ /**
+ * Close this PipedWriter. Any data buffered in the corresponding
+ * PipedReader can be read, then -1 will be returned to the reader. If this
+ * Writer is not connected, this method does nothing.
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to close this PipedWriter.
+ */
+ @Override
public void close() throws IOException {
- synchronized (lock) {
- /* Is the pipe connected? */
- if (dest != null) {
- dest.done();
- dest = null;
- }
- closed = true;
- }
- }
-
- /**
- * Connects this PipedWriter to a PipedReader. Any data written to this
- * Writer becomes readable in the Reader.
- *
- * @param stream
- * the destination PipedReader.
- *
- * @throws java.io.IOException
- * If this Writer or the dest is already connected.
- */
- public void connect(PipedReader stream) throws IOException {
- synchronized (lock) {
- if (this.dest == null) {
- if (!closed) {
- stream.establishConnection();
- this.dest = stream;
- } else {
- throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
- }
- } else {
+ synchronized (lock) {
+ /* Is the pipe connected? */
+ if (dest != null) {
+ dest.done();
+ dest = null;
+ }
+ closed = true;
+ }
+ }
+
+ /**
+ * Connects this PipedWriter to a PipedReader. Any data written to this
+ * Writer becomes readable in the Reader.
+ *
+ * @param stream
+ * the destination PipedReader.
+ *
+ * @throws java.io.IOException
+ * If this Writer or the dest is already connected.
+ */
+ public void connect(PipedReader stream) throws IOException {
+ synchronized (lock) {
+ if (this.dest != null) {
throw new IOException(Msg.getString("K0079")); //$NON-NLS-1$
}
- }
- }
+ if (closed) {
+ throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
+ }
+ stream.establishConnection();
+ this.dest = stream;
+ }
+ }
- /**
- * Notifies the readers on the PipedReader that characters can be read. This
- * method does nothing if this Writer is not connected.
- *
- * @throws java.io.IOException
- * If an IO error occurs during the flush.
- */
- @Override
+ /**
+ * Notifies the readers on the PipedReader that characters can be read. This
+ * method does nothing if this Writer is not connected.
+ *
+ * @throws java.io.IOException
+ * If an IO error occurs during the flush.
+ */
+ @Override
public void flush() throws IOException {
- if (dest != null) {
+ if (dest != null) {
dest.flush();
}
- }
+ }
- /**
- * Writes <code>count</code> <code>chars</code> from the char array
- * <code>buffer</code> starting at offset <code>index</code> to this
- * PipedWriter. The written data can now be read from the destination
- * PipedReader. Separate threads should be used for the reader of the
- * PipedReader and the PipedWriter. There may be undesirable results if more
- * than one Thread interacts a input or output pipe.
- *
- * @param buffer
- * the buffer to be written
- * @param offset
- * offset in buffer to get chars
- * @param count
- * number of chars in buffer to write
- *
- * @throws java.io.IOException
- * If the receiving thread was terminated without closing the
- * pipe. This case is not currently handled correctly.
- * @throws java.io.InterruptedIOException
- * If the pipe is full and the current thread is interrupted
- * waiting for space to write data. This case is not currently
- * handled correctly.
- * @throws java.lang.NullPointerException
- * If the receiver has not been connected yet.
- * @throws java.lang.IllegalArgumentException
- * If any of the arguments are out of bounds.
- */
- @Override
+ /**
+ * Writes <code>count</code> <code>chars</code> from the char array
+ * <code>buffer</code> starting at offset <code>index</code> to this
+ * PipedWriter. The written data can now be read from the destination
+ * PipedReader. Separate threads should be used for the reader of the
+ * PipedReader and the PipedWriter. There may be undesirable results if more
+ * than one Thread interacts a input or output pipe.
+ *
+ * @param buffer
+ * the buffer to be written
+ * @param offset
+ * offset in buffer to get chars
+ * @param count
+ * number of chars in buffer to write
+ *
+ * @throws java.io.IOException
+ * If the receiving thread was terminated without closing the
+ * pipe. This case is not currently handled correctly.
+ * @throws java.io.InterruptedIOException
+ * If the pipe is full and the current thread is interrupted
+ * waiting for space to write data. This case is not currently
+ * handled correctly.
+ * @throws java.lang.NullPointerException
+ * If the receiver has not been connected yet.
+ * @throws java.lang.IllegalArgumentException
+ * If any of the arguments are out of bounds.
+ */
+ @Override
public void write(char buffer[], int offset, int count) throws IOException {
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
- // avoid int overflow
- if (0 <= offset && offset <= buffer.length && 0 <= count
- && count <= buffer.length - offset) {
- synchronized (lock) {
- if (!closed) {
- if (dest != null) {
- dest.receive(buffer, offset, count);
- } else {
- throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
- }
- } else {
- throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
- }
- }
- } else {
- throw new IndexOutOfBoundsException();
- }
- }
-
- /**
- * Writes the character <code>c</code> to this PipedWriter. The written
- * data can now be read from the destination PipedReader. Separate threads
- * should be used for the reader of the PipedReader and the PipedWriter.
- * There may be undesirable results if more than one Thread interacts a
- * input or output pipe.
- *
- * @param c
- * the character to be written
- *
- * @throws java.io.IOException
- * If the receiving thread was terminated without closing the
- * pipe. This case is not currently handled correctly.
- * @throws java.io.InterruptedIOException
- * If the pipe is full and the current thread is interrupted
- * waiting for space to write data. This case is not currently
- * handled correctly.
- * @throws java.lang.NullPointerException
- * If the receiver has not been connected yet.
- */
- @Override
+ // avoid int overflow
+ if (offset < 0 || offset > buffer.length || count < 0
+ || count > buffer.length - offset) {
+ throw new IndexOutOfBoundsException();
+ }
+ synchronized (lock) {
+ if (closed) {
+ throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
+ }
+ if (dest == null) {
+ throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
+ }
+ dest.receive(buffer, offset, count);
+ }
+ }
+
+ /**
+ * Writes the character <code>c</code> to this PipedWriter. The written
+ * data can now be read from the destination PipedReader. Separate threads
+ * should be used for the reader of the PipedReader and the PipedWriter.
+ * There may be undesirable results if more than one Thread interacts a
+ * input or output pipe.
+ *
+ * @param c
+ * the character to be written
+ *
+ * @throws java.io.IOException
+ * If the receiving thread was terminated without closing the
+ * pipe. This case is not currently handled correctly.
+ * @throws java.io.InterruptedIOException
+ * If the pipe is full and the current thread is interrupted
+ * waiting for space to write data. This case is not currently
+ * handled correctly.
+ * @throws java.lang.NullPointerException
+ * If the receiver has not been connected yet.
+ */
+ @Override
public void write(int c) throws IOException {
- synchronized (lock) {
- if (!closed) {
- if (dest != null) {
- dest.receive((char) c);
- } else {
- throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
- }
- } else {
+ synchronized (lock) {
+ if (closed) {
throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
}
- }
- }
+ if (dest == null) {
+ throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
+ }
+ dest.receive((char) c);
+ }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java Thu Jan 4 09:47:01 2007
@@ -36,266 +36,267 @@
*
*/
public class PrintStream extends FilterOutputStream implements Appendable,
- Closeable {
+ Closeable {
private static final String TOKEN_NULL = "null"; //$NON-NLS-1$
- /**
- * indicates whether or not this PrintStream has incurred an error.
- */
- private boolean ioError;
-
- /**
- * indicates whether or not this PrintStream should flush its contents after
- * printing a new line.
- */
- private boolean autoflush;
-
- private String encoding;
-
- private final String lineSeparator = AccessController
- .doPrivileged(new PriviAction<String>("line.separator")); //$NON-NLS-1$
-
- // private Formatter formatter;
-
- /**
- * Constructs a new PrintStream on the OutputStream <code>out</code>. All
- * writes to the target can now take place through this PrintStream. By
- * default, the PrintStream is set to not autoflush when a newline is
- * encountered.
- *
- * @param out
- * the OutputStream to provide convenience methods on.
- */
- public PrintStream(OutputStream out) {
- super(out);
- if (out == null) {
+ /**
+ * indicates whether or not this PrintStream has incurred an error.
+ */
+ private boolean ioError;
+
+ /**
+ * indicates whether or not this PrintStream should flush its contents after
+ * printing a new line.
+ */
+ private boolean autoflush;
+
+ private String encoding;
+
+ private final String lineSeparator = AccessController
+ .doPrivileged(new PriviAction<String>("line.separator")); //$NON-NLS-1$
+
+ // private Formatter formatter;
+
+ /**
+ * Constructs a new PrintStream on the OutputStream <code>out</code>. All
+ * writes to the target can now take place through this PrintStream. By
+ * default, the PrintStream is set to not autoflush when a newline is
+ * encountered.
+ *
+ * @param out
+ * the OutputStream to provide convenience methods on.
+ */
+ public PrintStream(OutputStream out) {
+ super(out);
+ if (out == null) {
throw new NullPointerException();
}
- }
+ }
- /**
- * Constructs a new PrintStream on the OutputStream <code>out</code>. All
- * writes to the target can now take place through this PrintStream. The
- * PrintStream is set to not autoflush if <code>autoflush</code> is
- * <code>true</code>.
- *
- * @param out
- * the OutputStream to provide convenience methods on.
- * @param autoflush
- * indicates whether or not to flush contents upon encountering a
- * newline sequence.
- */
- public PrintStream(OutputStream out, boolean autoflush) {
- super(out);
- if (out == null) {
+ /**
+ * Constructs a new PrintStream on the OutputStream <code>out</code>. All
+ * writes to the target can now take place through this PrintStream. The
+ * PrintStream is set to not autoflush if <code>autoflush</code> is
+ * <code>true</code>.
+ *
+ * @param out
+ * the OutputStream to provide convenience methods on.
+ * @param autoflush
+ * indicates whether or not to flush contents upon encountering a
+ * newline sequence.
+ */
+ public PrintStream(OutputStream out, boolean autoflush) {
+ super(out);
+ if (out == null) {
throw new NullPointerException();
}
- this.autoflush = autoflush;
- }
+ this.autoflush = autoflush;
+ }
- /**
- * Constructs a new PrintStream on the OutputStream <code>out</code>. All
- * writes to the target can now take place through this PrintStream. The
- * PrintStream is set to not autoflush if <code>autoflush</code> is
- * <code>true</code>.
- *
- * @param out
- * the OutputStream to provide convenience methods on.
- * @param autoflush
- * indicates whether or not to flush contents upon encountering a
- * newline sequence.
- * @param enc
- * the non-null String describing the desired character encoding.
- *
- * @throws UnsupportedEncodingException
- * If the chosen encoding is not supported
- */
- public PrintStream(OutputStream out, boolean autoflush, String enc)
- throws UnsupportedEncodingException {
- super(out);
- if (out == null || enc == null) {
+ /**
+ * Constructs a new PrintStream on the OutputStream <code>out</code>. All
+ * writes to the target can now take place through this PrintStream. The
+ * PrintStream is set to not autoflush if <code>autoflush</code> is
+ * <code>true</code>.
+ *
+ * @param out
+ * the OutputStream to provide convenience methods on.
+ * @param autoflush
+ * indicates whether or not to flush contents upon encountering a
+ * newline sequence.
+ * @param enc
+ * the non-null String describing the desired character encoding.
+ *
+ * @throws UnsupportedEncodingException
+ * If the chosen encoding is not supported
+ */
+ public PrintStream(OutputStream out, boolean autoflush, String enc)
+ throws UnsupportedEncodingException {
+ super(out);
+ if (out == null || enc == null) {
throw new NullPointerException();
}
- this.autoflush = autoflush;
- if (!Charset.isSupported(enc)) {
+ this.autoflush = autoflush;
+ if (!Charset.isSupported(enc)) {
throw new UnsupportedEncodingException(enc);
}
- encoding = enc;
- }
+ encoding = enc;
+ }
- /**
- * Constructs a new PrintStream on the file <code>file</code>. All writes
- * to the target can now take place through this PrintStream. Its encoding
- * character set is the default charset in the VM.
- *
- * @param file
- * the file to provide convenience methods on.
- * @throws FileNotFoundException
- * if the file does not exist or cannot be opened to write. Or the file cannot be created or any problem when open the file to write.
- * @throws SecurityException
- * if the security manager exists and denies the write to the
- * file.
- */
- public PrintStream(File file) throws FileNotFoundException {
- super(new FileOutputStream(file));
- }
-
- /**
- * Constructs a new PrintStream on the file <code>file</code>. All writes
- * to the target can now take place through this PrintStream. Its encoding
- * character set name is <code>csn</code>.
- *
- * @param file
- * the file to provide convenience methods on.
- * @param csn
- * the character set name
- * @throws FileNotFoundException
- * if the file does not exist or cannot be opened to write. Or
- * the file cannot be created or any problem when open the file
- * to write.
- * @throws SecurityException
- * if the security manager exists and denies the write to the
- * file.
- * @throws UnsupportedEncodingException
- * if the chosen character set is not supported
- */
- public PrintStream(File file, String csn) throws FileNotFoundException,
- UnsupportedEncodingException {
- super(new FileOutputStream(file));
- if (csn == null) {
+ /**
+ * Constructs a new PrintStream on the file <code>file</code>. All writes
+ * to the target can now take place through this PrintStream. Its encoding
+ * character set is the default charset in the VM.
+ *
+ * @param file
+ * the file to provide convenience methods on.
+ * @throws FileNotFoundException
+ * if the file does not exist or cannot be opened to write. Or
+ * the file cannot be created or any problem when open the file
+ * to write.
+ * @throws SecurityException
+ * if the security manager exists and denies the write to the
+ * file.
+ */
+ public PrintStream(File file) throws FileNotFoundException {
+ super(new FileOutputStream(file));
+ }
+
+ /**
+ * Constructs a new PrintStream on the file <code>file</code>. All writes
+ * to the target can now take place through this PrintStream. Its encoding
+ * character set name is <code>csn</code>.
+ *
+ * @param file
+ * the file to provide convenience methods on.
+ * @param csn
+ * the character set name
+ * @throws FileNotFoundException
+ * if the file does not exist or cannot be opened to write. Or
+ * the file cannot be created or any problem when open the file
+ * to write.
+ * @throws SecurityException
+ * if the security manager exists and denies the write to the
+ * file.
+ * @throws UnsupportedEncodingException
+ * if the chosen character set is not supported
+ */
+ public PrintStream(File file, String csn) throws FileNotFoundException,
+ UnsupportedEncodingException {
+ super(new FileOutputStream(file));
+ if (csn == null) {
throw new NullPointerException();
}
- if (!Charset.isSupported(csn)) {
+ if (!Charset.isSupported(csn)) {
throw new UnsupportedEncodingException();
}
- encoding = csn;
- }
+ encoding = csn;
+ }
+
+ /**
+ * Constructs a new PrintStream on the file the name of which is<code>fileName</code>.
+ * All writes to the target can now take place through this PrintStream. Its
+ * encoding character set is the default charset in the VM.
+ *
+ * @param file
+ * the file to provide convenience methods on.
+ * @throws FileNotFoundException
+ * if the file does not exist or cannot be opened to write. Or
+ * the file cannot be created or any problem when open the file
+ * to write.
+ * @throws SecurityException
+ * if the security manager exists and denies the write to the
+ * file.
+ */
+ public PrintStream(String fileName) throws FileNotFoundException {
+ this(new File(fileName));
+ }
+
+ /**
+ * Constructs a new PrintStream on the file the name of which is<code>fileName</code>.
+ * All writes to the target can now take place through this PrintStream. Its
+ * encoding character set name is <code>csn</code>.
+ *
+ * @param file
+ * the file to provide convenience methods on.
+ * @param csn
+ * the character set name
+ * @throws FileNotFoundException
+ * if the file does not exist or cannot be opened to write. Or
+ * the file cannot be created or any problem when open the file
+ * to write.
+ * @throws SecurityException
+ * if the security manager exists and denies the write to the
+ * file.
+ * @throws UnsupportedEncodingException
+ * if the chosen character set is not supported
+ */
+ public PrintStream(String fileName, String csn)
+ throws FileNotFoundException, UnsupportedEncodingException {
+ this(new File(fileName), csn);
+ }
- /**
- * Constructs a new PrintStream on the file the name of which is<code>fileName</code>.
- * All writes to the target can now take place through this PrintStream. Its
- * encoding character set is the default charset in the VM.
- *
- * @param file
- * the file to provide convenience methods on.
- * @throws FileNotFoundException
- * if the file does not exist or cannot be opened to write. Or
- * the file cannot be created or any problem when open the file
- * to write.
- * @throws SecurityException
- * if the security manager exists and denies the write to the
- * file.
- */
- public PrintStream(String fileName) throws FileNotFoundException {
- this(new File(fileName));
- }
-
- /**
- * Constructs a new PrintStream on the file the name of which is<code>fileName</code>.
- * All writes to the target can now take place through this PrintStream. Its
- * encoding character set name is <code>csn</code>.
- *
- * @param file
- * the file to provide convenience methods on.
- * @param csn
- * the character set name
- * @throws FileNotFoundException
- * if the file does not exist or cannot be opened to write. Or
- * the file cannot be created or any problem when open the file
- * to write.
- * @throws SecurityException
- * if the security manager exists and denies the write to the
- * file.
- * @throws UnsupportedEncodingException
- * if the chosen character set is not supported
- */
- public PrintStream(String fileName, String csn)
- throws FileNotFoundException, UnsupportedEncodingException {
- this(new File(fileName), csn);
- }
-
- /**
- * Answers a boolean indicating whether or not this PrintStream has
- * encountered an error. If so, the receiver should probably be closed since
- * further writes will not actually take place. A side effect of calling
- * checkError is that the target OutputStream is flushed.
- *
- * @return <code>true</code> if an error occurred in this PrintStream,
- * <code>false</code> otherwise.
- */
- public boolean checkError() {
- if (out != null) {
+ /**
+ * Answers a boolean indicating whether or not this PrintStream has
+ * encountered an error. If so, the receiver should probably be closed since
+ * further writes will not actually take place. A side effect of calling
+ * checkError is that the target OutputStream is flushed.
+ *
+ * @return <code>true</code> if an error occurred in this PrintStream,
+ * <code>false</code> otherwise.
+ */
+ public boolean checkError() {
+ if (out != null) {
flush();
}
- return ioError;
- }
+ return ioError;
+ }
- /**
- * Close this PrintStream. This implementation flushes and then closes the
- * target stream. If an error occurs, set an error in this PrintStream to
- * <code>true</code>.
- *
- */
- @Override
+ /**
+ * Close this PrintStream. This implementation flushes and then closes the
+ * target stream. If an error occurs, set an error in this PrintStream to
+ * <code>true</code>.
+ */
+ @Override
public synchronized void close() {
- flush();
- if (out != null) {
- try {
- out.close();
- out = null;
- } catch (IOException e) {
- setError();
- }
- }
- }
-
- /**
- * Flush this PrintStream to ensure all pending data is sent out to the
- * target OutputStream. This implementation flushes the target OutputStream.
- * If an error occurs, set an error in this PrintStream to <code>true</code>.
- *
- */
- @Override
+ flush();
+ if (out != null) {
+ try {
+ out.close();
+ out = null;
+ } catch (IOException e) {
+ setError();
+ }
+ }
+ }
+
+ /**
+ * Flush this PrintStream to ensure all pending data is sent out to the
+ * target OutputStream. This implementation flushes the target OutputStream.
+ * If an error occurs, set an error in this PrintStream to <code>true</code>.
+ */
+ @Override
public synchronized void flush() {
- if (out != null) {
- try {
- out.flush();
- return;
- } catch (IOException e) {
- }
- }
- setError();
- }
+ if (out != null) {
+ try {
+ out.flush();
+ return;
+ } catch (IOException e) {
+ // Ignored, fall through to setError
+ }
+ }
+ setError();
+ }
/**
- * Writes a string formatted by an intermediate <code>Formatter</code>
- * to this stream using the given format string and arguments.
+ * Writes a string formatted by an intermediate <code>Formatter</code> to
+ * this stream using the given format string and arguments.
* <p>
- * The method uses the default for the current JVM instance locale, as if
- * it is specified by the <code>Locale.getDefault()</code> call.
+ * The method uses the default for the current JVM instance locale, as if it
+ * is specified by the <code>Locale.getDefault()</code> call.
*
* @param format
* A format string.
* @param args
- * The arguments list. If there are more arguments than those
- * specified by the format string, then the additional
- * arguments are ignored.
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional arguments
+ * are ignored.
* @return This stream.
* @throws IllegalFormatException
- * If the format string is illegal or incompatible with the
- * arguments or the arguments are less than those required by
- * the format string or any other illegal situation.
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
* @throws NullPointerException
- * If the given format is null.
+ * If the given format is null.
*/
public PrintStream format(String format, Object... args) {
return format(Locale.getDefault(), format, args);
}
/**
- * Writes a string formatted by an intermediate <code>Formatter</code>
- * to this stream using the given format string and arguments.
+ * Writes a string formatted by an intermediate <code>Formatter</code> to
+ * this stream using the given format string and arguments.
*
* @param l
* The locale used in the method. If locale is null, then no
@@ -303,16 +304,16 @@
* @param format
* A format string.
* @param args
- * The arguments list. If there are more arguments than those
- * specified by the format string, then the additional
- * arguments are ignored.
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional arguments
+ * are ignored.
* @return This stream.
* @throws IllegalFormatException
- * If the format string is illegal or incompatible with the
- * arguments or the arguments are less than those required by
- * the format string or any other illegal situation.
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
* @throws NullPointerException
- * If the given format is null.
+ * If the given format is null.
*/
public PrintStream format(Locale l, String format, Object... args) {
if (format == null) {
@@ -323,34 +324,34 @@
}
/**
- * Prints a formatted string. The behavior of this method is the same
- * as this stream's <code>format(String format, Object... args)</code>
+ * Prints a formatted string. The behavior of this method is the same as
+ * this stream's <code>format(String format, Object... args)</code>
* method.
* <p>
- * The method uses the default for the current JVM instance locale, as if
- * it is specified by the <code>Locale.getDefault()</code> call.
+ * The method uses the default for the current JVM instance locale, as if it
+ * is specified by the <code>Locale.getDefault()</code> call.
*
* @param format
* A format string.
* @param args
- * The arguments list. If there are more arguments than those
- * specified by the format string, then the additional
- * arguments are ignored.
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional arguments
+ * are ignored.
* @return This stream.
* @throws IllegalFormatException
- * If the format string is illegal or incompatible with the
- * arguments or the arguments are less than those required by
- * the format string or any other illegal situation.
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
* @throws NullPointerException
- * If the given format is null.
+ * If the given format is null.
*/
public PrintStream printf(String format, Object... args) {
return format(format, args);
}
/**
- * Prints a formatted string. The behavior of this method is the same
- * as this writer's
+ * Prints a formatted string. The behavior of this method is the same as
+ * this writer's
* <code>format(Locale l, String format, Object... args)</code> method.
*
* @param l
@@ -359,371 +360,372 @@
* @param format
* A format string.
* @param args
- * The arguments list. If there are more arguments than those
- * specified by the format string, then the additional
- * arguments are ignored.
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional arguments
+ * are ignored.
* @return This stream.
* @throws IllegalFormatException
- * If the format string is illegal or incompatible with the
- * arguments or the arguments are less than those required by
- * the format string or any other illegal situation.
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
* @throws NullPointerException
- * If the given format is null.
+ * If the given format is null.
*/
public PrintStream printf(Locale l, String format, Object... args) {
return format(l, format, args);
}
- private void newline() {
- print(lineSeparator);
- }
-
- /**
- * Prints the String representation of the character array parameter
- * <code>charArray</code> to the target OutputStream.
- *
- * @param charArray
- * the character array to print on this PrintStream.
- */
- public void print(char[] charArray) {
- print(new String(charArray, 0, charArray.length));
- }
-
- /**
- * Prints the String representation of the character parameter
- * <code>ch</code> to the target OutputStream.
- *
- * @param ch
- * the character to print on this PrintStream.
- */
- public void print(char ch) {
- print(String.valueOf(ch));
- }
-
- /**
- * Prints the String representation of the <code>double</code> parameter
- * <code>dnum</code> to the target OutputStream.
- *
- * @param dnum
- * the <code>double</code> to print on this PrintStream.
- */
- public void print(double dnum) {
- print(String.valueOf(dnum));
- }
-
- /**
- * Prints the String representation of the <code>float</code> parameter
- * <code>fnum</code> to the target OutputStream.
- *
- * @param fnum
- * the <code>float</code> to print on this PrintStream.
- */
- public void print(float fnum) {
- print(String.valueOf(fnum));
- }
-
- /**
- * Obtains the <code>int</code> argument as a <code>String</code> and
- * prints it to the target {@link OutputStream}.
- *
- * @param inum
- * the <code>int</code> to print on this PrintStream.
- */
- public void print(int inum) {
- print(String.valueOf(inum));
- }
-
- /**
- * Prints the String representation of the <code>long</code> parameter
- * <code>lnum</code> to the target OutputStream.
- *
- * @param lnum
- * the <code>long</code> to print on this PrintStream.
- */
- public void print(long lnum) {
- print(String.valueOf(lnum));
- }
-
- /**
- * Prints the String representation of the Object parameter <code>obj</code>
- * to the target OutputStream.
- *
- * @param obj
- * the Object to print on this PrintStream.
- */
- public void print(Object obj) {
- print(String.valueOf(obj));
- }
-
- /**
- * Prints the String representation of the <code>String</code> parameter
- * <code>str</code> to the target OutputStream.
- *
- * @param str
- * the <code>String</code> to print on this PrintStream.
- */
- public synchronized void print(String str) {
- if (out == null) {
- setError();
- return;
- }
- if (str == null) {
- print("null"); //$NON-NLS-1$
- return;
- }
+ /**
+ * Put the line separator String onto the print stream.
+ */
+ private void newline() {
+ print(lineSeparator);
+ }
+
+ /**
+ * Prints the String representation of the character array parameter
+ * <code>charArray</code> to the target OutputStream.
+ *
+ * @param charArray
+ * the character array to print on this PrintStream.
+ */
+ public void print(char[] charArray) {
+ print(new String(charArray, 0, charArray.length));
+ }
+
+ /**
+ * Prints the String representation of the character parameter
+ * <code>ch</code> to the target OutputStream.
+ *
+ * @param ch
+ * the character to print on this PrintStream.
+ */
+ public void print(char ch) {
+ print(String.valueOf(ch));
+ }
+
+ /**
+ * Prints the String representation of the <code>double</code> parameter
+ * <code>dnum</code> to the target OutputStream.
+ *
+ * @param dnum
+ * the <code>double</code> to print on this PrintStream.
+ */
+ public void print(double dnum) {
+ print(String.valueOf(dnum));
+ }
+
+ /**
+ * Prints the String representation of the <code>float</code> parameter
+ * <code>fnum</code> to the target OutputStream.
+ *
+ * @param fnum
+ * the <code>float</code> to print on this PrintStream.
+ */
+ public void print(float fnum) {
+ print(String.valueOf(fnum));
+ }
+
+ /**
+ * Obtains the <code>int</code> argument as a <code>String</code> and
+ * prints it to the target {@link OutputStream}.
+ *
+ * @param inum
+ * the <code>int</code> to print on this PrintStream.
+ */
+ public void print(int inum) {
+ print(String.valueOf(inum));
+ }
+
+ /**
+ * Prints the String representation of the <code>long</code> parameter
+ * <code>lnum</code> to the target OutputStream.
+ *
+ * @param lnum
+ * the <code>long</code> to print on this PrintStream.
+ */
+ public void print(long lnum) {
+ print(String.valueOf(lnum));
+ }
+
+ /**
+ * Prints the String representation of the Object parameter <code>obj</code>
+ * to the target OutputStream.
+ *
+ * @param obj
+ * the Object to print on this PrintStream.
+ */
+ public void print(Object obj) {
+ print(String.valueOf(obj));
+ }
+
+ /**
+ * Prints the String representation of the <code>String</code> parameter
+ * <code>str</code> to the target OutputStream.
+ *
+ * @param str
+ * the <code>String</code> to print on this PrintStream.
+ */
+ public synchronized void print(String str) {
+ if (out == null) {
+ setError();
+ return;
+ }
+ if (str == null) {
+ print("null"); //$NON-NLS-1$
+ return;
+ }
- try {
- if (encoding == null) {
+ try {
+ if (encoding == null) {
write(str.getBytes());
} else {
write(str.getBytes(encoding));
}
- } catch (IOException e) {
- setError();
- }
- }
-
- /**
- * Prints the String representation of the <code>boolean</code> parameter
- * <code>bool</code> to the target OutputStream.
- *
- * @param bool
- * the <code>boolean</code> to print on this PrintStream.
- */
- public void print(boolean bool) {
- print(String.valueOf(bool));
- }
-
- /**
- * Prints the String representation of the System property
- * <code>"line.separator"</code> to the target OutputStream.
- *
- */
- public void println() {
- newline();
- }
-
- /**
- * Prints the String representation of the character array parameter
- * <code>charArray</code> to the target OutputStream followed by the
- * System property <code>"line.separator"</code>.
- *
- * @param charArray
- * the character array to print on this PrintStream.
- */
- public void println(char[] charArray) {
- println(new String(charArray, 0, charArray.length));
- }
-
- /**
- * Prints the String representation of the character parameter
- * <code>ch</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param ch
- * the character to print on this PrintStream.
- */
- public void println(char ch) {
- println(String.valueOf(ch));
- }
-
- /**
- * Prints the String representation of the <code>double</code> parameter
- * <code>dnum</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param dnum
- * the double to print on this PrintStream.
- */
- public void println(double dnum) {
- println(String.valueOf(dnum));
- }
-
- /**
- * Prints the String representation of the <code>float</code> parameter
- * <code>fnum</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param fnum
- * the float to print on this PrintStream.
- */
- public void println(float fnum) {
- println(String.valueOf(fnum));
- }
-
- /**
- * Obtains the <code>int</code> argument as a <code>String</code> and
- * prints it to the target {@link OutputStream} followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param inum
- * the int to print on this PrintStream.
- */
- public void println(int inum) {
- println(String.valueOf(inum));
- }
-
- /**
- * Prints the String representation of the <code>long</code> parameter
- * <code>lnum</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param lnum
- * the long to print on this PrintStream.
- */
- public void println(long lnum) {
- println(String.valueOf(lnum));
- }
-
- /**
- * Prints the String representation of the <code>Object</code> parameter
- * <code>obj</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param obj
- * the <code>Object</code> to print on this PrintStream.
- */
- public void println(Object obj) {
- println(String.valueOf(obj));
- }
-
- /**
- * Prints the String representation of the <code>String</code> parameter
- * <code>str</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param str
- * the <code>String</code> to print on this PrintStream.
- */
- public synchronized void println(String str) {
- print(str);
- newline();
- }
-
- /**
- * Prints the String representation of the <code>boolean</code> parameter
- * <code>bool</code> to the target OutputStream followed by the System
- * property <code>"line.separator"</code>.
- *
- * @param bool
- * the boolean to print on this PrintStream.
- */
- public void println(boolean bool) {
- println(String.valueOf(bool));
- }
-
- protected void setError() {
- ioError = true;
- }
-
- /**
- * Writes <code>count</code> <code>bytes</code> from the byte array
- * <code>buffer</code> starting at <code>offset</code> to this
- * PrintStream. This implementation writes the <code>buffer</code> to the
- * target OutputStream and if this PrintStream is set to autoflush, flushes
- * it. If an error occurs, set an error in this PrintStream to
- * <code>true</code>.
- *
- * @param buffer
- * the buffer to be written
- * @param offset
- * offset in buffer to get bytes
- * @param count
- * number of bytes in buffer to write
- *
- * @throws IndexOutOfBoundsException
- * If offset or count are outside of bounds.
- */
- @Override
+ } catch (IOException e) {
+ setError();
+ }
+ }
+
+ /**
+ * Prints the String representation of the <code>boolean</code> parameter
+ * <code>bool</code> to the target OutputStream.
+ *
+ * @param bool
+ * the <code>boolean</code> to print on this PrintStream.
+ */
+ public void print(boolean bool) {
+ print(String.valueOf(bool));
+ }
+
+ /**
+ * Prints the String representation of the System property
+ * <code>"line.separator"</code> to the target OutputStream.
+ *
+ */
+ public void println() {
+ newline();
+ }
+
+ /**
+ * Prints the String representation of the character array parameter
+ * <code>charArray</code> to the target OutputStream followed by the
+ * System property <code>"line.separator"</code>.
+ *
+ * @param charArray
+ * the character array to print on this PrintStream.
+ */
+ public void println(char[] charArray) {
+ println(new String(charArray, 0, charArray.length));
+ }
+
+ /**
+ * Prints the String representation of the character parameter
+ * <code>ch</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param ch
+ * the character to print on this PrintStream.
+ */
+ public void println(char ch) {
+ println(String.valueOf(ch));
+ }
+
+ /**
+ * Prints the String representation of the <code>double</code> parameter
+ * <code>dnum</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param dnum
+ * the double to print on this PrintStream.
+ */
+ public void println(double dnum) {
+ println(String.valueOf(dnum));
+ }
+
+ /**
+ * Prints the String representation of the <code>float</code> parameter
+ * <code>fnum</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param fnum
+ * the float to print on this PrintStream.
+ */
+ public void println(float fnum) {
+ println(String.valueOf(fnum));
+ }
+
+ /**
+ * Obtains the <code>int</code> argument as a <code>String</code> and
+ * prints it to the target {@link OutputStream} followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param inum
+ * the int to print on this PrintStream.
+ */
+ public void println(int inum) {
+ println(String.valueOf(inum));
+ }
+
+ /**
+ * Prints the String representation of the <code>long</code> parameter
+ * <code>lnum</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param lnum
+ * the long to print on this PrintStream.
+ */
+ public void println(long lnum) {
+ println(String.valueOf(lnum));
+ }
+
+ /**
+ * Prints the String representation of the <code>Object</code> parameter
+ * <code>obj</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param obj
+ * the <code>Object</code> to print on this PrintStream.
+ */
+ public void println(Object obj) {
+ println(String.valueOf(obj));
+ }
+
+ /**
+ * Prints the String representation of the <code>String</code> parameter
+ * <code>str</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param str
+ * the <code>String</code> to print on this PrintStream.
+ */
+ public synchronized void println(String str) {
+ print(str);
+ newline();
+ }
+
+ /**
+ * Prints the String representation of the <code>boolean</code> parameter
+ * <code>bool</code> to the target OutputStream followed by the System
+ * property <code>"line.separator"</code>.
+ *
+ * @param bool
+ * the boolean to print on this PrintStream.
+ */
+ public void println(boolean bool) {
+ println(String.valueOf(bool));
+ }
+
+ protected void setError() {
+ ioError = true;
+ }
+
+ /**
+ * Writes <code>count</code> <code>bytes</code> from the byte array
+ * <code>buffer</code> starting at <code>offset</code> to this
+ * PrintStream. This implementation writes the <code>buffer</code> to the
+ * target OutputStream and if this PrintStream is set to autoflush, flushes
+ * it. If an error occurs, set an error in this PrintStream to
+ * <code>true</code>.
+ *
+ * @param buffer
+ * the buffer to be written
+ * @param offset
+ * offset in buffer to get bytes
+ * @param count
+ * number of bytes in buffer to write
+ *
+ * @throws IndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ */
+ @Override
public void write(byte[] buffer, int offset, int count) {
- if (buffer != null) {
- // avoid int overflow
- if (0 <= offset && offset <= buffer.length && 0 <= count
- && count <= buffer.length - offset) {
- synchronized (this) {
- if (out == null) {
- setError();
- return;
- }
- try {
- out.write(buffer, offset, count);
- if (autoflush) {
- flush();
- }
- } catch (IOException e) {
- setError();
- }
- }
- } else {
- throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
- }
- } else {
+ if (buffer == null) {
throw new NullPointerException();
}
- }
+ // avoid int overflow
+ if (offset < 0 || offset > buffer.length || count < 0
+ || count > buffer.length - offset) {
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+ }
+ synchronized (this) {
+ if (out == null) {
+ setError();
+ return;
+ }
+ try {
+ out.write(buffer, offset, count);
+ if (autoflush) {
+ flush();
+ }
+ } catch (IOException e) {
+ setError();
+ }
+ }
+ }
- /**
- * Writes the specified byte <code>oneByte</code> to this PrintStream.
- * Only the low order byte of <code>oneByte</code> is written. This
- * implementation writes <code>oneByte</code> to the target OutputStream.
- * If <code>oneByte</code> is equal to the character <code>'\n'</code>
- * and this PrintSteam is set to autoflush, the target OutputStream is
- * flushed.
- *
- * @param oneByte
- * the byte to be written
- */
- @Override
+ /**
+ * Writes the specified byte <code>oneByte</code> to this PrintStream.
+ * Only the low order byte of <code>oneByte</code> is written. This
+ * implementation writes <code>oneByte</code> to the target OutputStream.
+ * If <code>oneByte</code> is equal to the character <code>'\n'</code>
+ * and this PrintSteam is set to autoflush, the target OutputStream is
+ * flushed.
+ *
+ * @param oneByte
+ * the byte to be written
+ */
+ @Override
public synchronized void write(int oneByte) {
- if (out == null) {
- setError();
- return;
- }
- try {
- out.write(oneByte);
- if (autoflush && (oneByte & 0xFF) == '\n') {
+ if (out == null) {
+ setError();
+ return;
+ }
+ try {
+ out.write(oneByte);
+ if (autoflush && (oneByte & 0xFF) == '\n') {
flush();
}
- } catch (IOException e) {
- setError();
- }
- }
-
- /**
- * Append a char <code>c</code> to the PrintStream. The
- * PrintStream.append(<code>c</code>) works the same way as
- * PrintStream.print(<code>c</code>).
- *
- * @param c
- * The character appended to the PrintStream.
- * @return The PrintStream.
- */
- public PrintStream append(char c) {
- print(c);
- return this;
- }
-
- /**
- * Append a CharSequence <code>csq</code> to the PrintStream. The
- * PrintStream.append(<code>csq</code>) works the same way as
- * PrintStream.print(<code>csq</code>.toString()). If <code>csq</code>
- * is null, then a CharSequence just contains then "null" will be
- * substituted for <code>csq</code>.
- *
- * @param csq
- * The CharSequence appended to the PrintStream.
- * @return The PrintStream.
- */
- public PrintStream append(CharSequence csq) {
- if (null == csq) {
- print(TOKEN_NULL);
- } else {
- print(csq.toString());
- }
- return this;
- }
+ } catch (IOException e) {
+ setError();
+ }
+ }
+
+ /**
+ * Append a char <code>c</code> to the PrintStream. The
+ * PrintStream.append(<code>c</code>) works the same way as
+ * PrintStream.print(<code>c</code>).
+ *
+ * @param c
+ * The character appended to the PrintStream.
+ * @return The PrintStream.
+ */
+ public PrintStream append(char c) {
+ print(c);
+ return this;
+ }
+
+ /**
+ * Append a CharSequence <code>csq</code> to the PrintStream. The
+ * PrintStream.append(<code>csq</code>) works the same way as
+ * PrintStream.print(<code>csq</code>.toString()). If <code>csq</code>
+ * is null, then a CharSequence just contains then "null" will be
+ * substituted for <code>csq</code>.
+ *
+ * @param csq
+ * The CharSequence appended to the PrintStream.
+ * @return The PrintStream.
+ */
+ public PrintStream append(CharSequence csq) {
+ if (null == csq) {
+ print(TOKEN_NULL);
+ } else {
+ print(csq.toString());
+ }
+ return this;
+ }
- /**
+ /**
* Append a subsequence of a CharSequence <code>csq</code> to the
* PrintStream. The first char and the last char of the subsequnce is
* specified by the parameter <code>start</code> and <code>end</code>.
@@ -732,22 +734,25 @@
* <code>end</code>).toString). If <code>csq</code> is null, then
* "null" will be substituted for <code>csq</code>.
*
- * @param csq The CharSequence appended to the PrintStream.
- * @param start The index of the first char in the CharSequence appended to
- * the PrintStream.
- * @param end The index of the char after the last one in the CharSequence
- * appended to the PrintStream.
+ * @param csq
+ * The CharSequence appended to the PrintStream.
+ * @param start
+ * The index of the first char in the CharSequence appended to
+ * the PrintStream.
+ * @param end
+ * The index of the char after the last one in the CharSequence
+ * appended to the PrintStream.
* @return The PrintStream.
- * @throws IndexOutOfBoundsException If start is less than end, end is
- * greater than the length of the CharSequence, or start or end is
- * negative.
- */
- public PrintStream append(CharSequence csq, int start, int end) {
- if (null == csq) {
- print(TOKEN_NULL.substring(start, end));
- } else {
- print(csq.subSequence(start, end).toString());
- }
- return this;
- }
+ * @throws IndexOutOfBoundsException
+ * If start is less than end, end is greater than the length of
+ * the CharSequence, or start or end is negative.
+ */
+ public PrintStream append(CharSequence csq, int start, int end) {
+ if (null == csq) {
+ print(TOKEN_NULL.substring(start, end));
+ } else {
+ print(csq.subSequence(start, end).toString());
+ }
+ return this;
+ }
}
|