All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tangosol.io.WriterPrintStream Maven / Gradle / Ivy

There is a newer version: 24.09
Show newest version
/*
 * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */

package com.tangosol.io;


import com.tangosol.util.NullImplementation;

import java.io.PrintStream;
import java.io.PrintWriter;

import java.lang.Double;
import java.lang.Float;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Object;


/**
* Overrides PrintStream to delegate to a PrintWriter.
*
* @author cp  2000.11.01
*/
public class WriterPrintStream
        extends PrintStream
        implements OutputStreaming
    {
    // ------ constructors --------------------------------------------------

    public WriterPrintStream(PrintWriter out)
        {
        super(NullImplementation.getOutputStream(), true);
        m_out = out;
        }


    // ----- PrintStream methods --------------------------------------------

    /**
    * Flush 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()
        {
        m_out.flush();
        }

    /**
    * Close the stream.  This is done by flushing the stream and then closing
    * the underlying output stream.
    *
    * @see        java.io.OutputStream#close()
    */
    public void close()
        {
        m_out.close();
        }

    /**
    * Flush the stream and check its error state.  The internal error state
    * is set to true when the underlying output stream throws an
    * IOException other than InterruptedIOException,
    * and when the setError method is invoked.  If an operation
    * on the underlying output stream throws an
    * InterruptedIOException, then the PrintStream
    * converts the exception back into an interrupt by doing:
    * 
    *     Thread.currentThread().interrupt();
    * 
* or the equivalent. * * @return True if and only if this stream has encountered an * IOException other than * InterruptedIOException, or the * setError method has been invoked */ public boolean checkError() { return m_out.checkError(); } /** * Set the error state of the stream to true. * * @since JDK1.1 */ protected void setError() { throw new UnsupportedOperationException(); } /** * Write the specified byte to this stream. If the byte is a newline and * automatic flushing is enabled then the flush method will be * invoked. * *

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 print(char) or println(char) * methods. * * @param b The byte to be written * @see #print(char) * @see #println(char) */ public void write(int b) { m_out.write(b); } /** * Write len bytes from the specified byte array starting at * offset off to this stream. If automatic flushing is * enabled then the flush method will be invoked. * *

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 print(char) or println(char) * methods. * * @param ab A byte array * @param of Offset from which to start taking bytes * @param cb Number of bytes to write */ public void write(byte ab[], int of, int cb) { while (of < cb) { write(ab[of++]); } } /** * Print a boolean value. The string produced by {@link * java.lang.String#valueOf(boolean)} is translated into bytes * according to the platform's default character encoding, and these bytes * are written in exactly the manner of the * {@link #write(int)} method. * * @param f The boolean to be printed */ public void print(boolean f) { m_out.print(f); } /** * Print 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 * {@link #write(int)} method. * * @param ch The char to be printed */ public void print(char ch) { m_out.print(ch); } /** * Print an integer. The string produced by {@link * java.lang.String#valueOf(int)} is translated into bytes * according to the platform's default character encoding, and these bytes * are written in exactly the manner of the * {@link #write(int)} method. * * @param i The int to be printed * @see Integer#toString(int) */ public void print(int i) { m_out.print(i); } /** * Print a long integer. The string produced by {@link * java.lang.String#valueOf(long)} is translated into bytes * according to the platform's default character encoding, and these bytes * are written in exactly the manner of the * {@link #write(int)} method. * * @param l The long to be printed * @see Long#toString(long) */ public void print(long l) { m_out.print(l); } /** * Print a floating-point number. The string produced by {@link * java.lang.String#valueOf(float)} is translated into bytes * according to the platform's default character encoding, and these bytes * are written in exactly the manner of the * {@link #write(int)} method. * * @param fl The float to be printed * @see Float#toString(float) */ public void print(float fl) { m_out.print(fl); } /** * Print a double-precision floating-point number. The string produced by * {@link java.lang.String#valueOf(double)} is translated into * bytes according to the platform's default character encoding, and these * bytes are written in exactly the manner of the {@link * #write(int)} method. * * @param dfl The double to be printed * @see Double#toString(double) */ public void print(double dfl) { m_out.print(dfl); } /** * Print an array of characters. The characters are converted into bytes * according to the platform's default character encoding, and these bytes * are written in exactly the manner of the * {@link #write(int)} method. * * @param ach The array of chars to be printed * * @throws NullPointerException If s is null */ public void print(char[] ach) { m_out.print(ach); } /** * Print a string. If the argument is null then the string * "null" is printed. Otherwise, the string's characters are * converted into bytes according to the platform's default character * encoding, and these bytes are written in exactly the manner of the * {@link #write(int)} method. * * @param s The String to be printed */ public void print(String s) { m_out.print(s); } /** * Print an object. The string produced by the {@link * java.lang.String#valueOf(Object)} method is translated into bytes * according to the platform's default character encoding, and these bytes * are written in exactly the manner of the * {@link #write(int)} method. * * @param o The Object to be printed * @see Object#toString() */ public void print(Object o) { m_out.print(o); } /** * Terminate the current line by writing the line separator string. The * line separator string is defined by the system property * line.separator, and is not necessarily a single newline * character ('\n'). */ public void println() { m_out.println(); } /** * Print a boolean and then terminate the line. This method behaves as * though it invokes {@link #print(boolean)} and then * {@link #println()}. * * @param f The boolean to be printed */ public void println(boolean f) { m_out.println(f); } /** * Print a character and then terminate the line. This method behaves as * though it invokes {@link #print(char)} and then * {@link #println()}. * * @param ch The char to be printed. */ public void println(char ch) { m_out.println(ch); } /** * Print an integer and then terminate the line. This method behaves as * though it invokes {@link #print(int)} and then * {@link #println()}. * * @param i The int to be printed. */ public void println(int i) { m_out.println(i); } /** * Print a long and then terminate the line. This method behaves as * though it invokes {@link #print(long)} and then * {@link #println()}. * * @param l a The long to be printed. */ public void println(long l) { m_out.println(l); } /** * Print a float and then terminate the line. This method behaves as * though it invokes {@link #print(float)} and then * {@link #println()}. * * @param fl The float to be printed. */ public void println(float fl) { m_out.println(fl); } /** * Print a double and then terminate the line. This method behaves as * though it invokes {@link #print(double)} and then * {@link #println()}. * * @param dfl The double to be printed. */ public void println(double dfl) { m_out.println(dfl); } /** * Print an array of characters and then terminate the line. This method * behaves as though it invokes {@link #print(char[])} and * then {@link #println()}. * * @param ach an array of chars to print. */ public void println(char[] ach) { m_out.println(ach); } /** * Print a String and then terminate the line. This method behaves as * though it invokes {@link #print(String)} and then * {@link #println()}. * * @param s The String to be printed. */ public void println(String s) { m_out.println(s); } /** * Print an Object and then terminate the line. This method behaves as * though it invokes {@link #print(Object)} and then * {@link #println()}. * * @param o The Object to be printed. */ public void println(Object o) { m_out.println(o); } // ----- data members --------------------------------------------------- private PrintWriter m_out; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy