FileDocCategorySizeDatePackage
SafePrintWriter.javaAPI DocExample4791Sat Sep 09 19:52:12 BST 2000com.macfaq.io

SafePrintWriter

public class SafePrintWriter extends Writer
version
1.0, 99/07/10
author
Elliotte Rusty Harold
since
Java Network Programming, 2nd edition

Fields Summary
protected Writer
out
private boolean
autoFlush
private String
lineSeparator
private boolean
closed
Constructors Summary
public SafePrintWriter(Writer out, String lineSeparator)


       
    this(out, false, lineSeparator);
  
public SafePrintWriter(Writer out, char lineSeparator)

    this(out, false, String.valueOf(lineSeparator));
  
public SafePrintWriter(Writer out, boolean autoFlush, String lineSeparator)

    super(out);
    this.out = out;
    this.autoFlush = autoFlush;
    this.lineSeparator = lineSeparator;
  
public SafePrintWriter(OutputStream out, boolean autoFlush, String encoding, String lineSeparator)

    this(new OutputStreamWriter(out, encoding), autoFlush, lineSeparator);
  
Methods Summary
public voidclose()

  
    try {
      this.flush();
    }
    catch (IOException e) {
    }
    
    synchronized (lock) {
      out.close();
      this.closed = true;
    }
    
  
public voidflush()

  
    synchronized (lock) {
      if (closed) throw new IOException("Stream closed");
      out.flush();
    }
    
  
public voidprint(boolean b)

    if (b) this.write("true");
    else this.write("false");
  
public voidprint(char c)

    this.write(String.valueOf(c));
  
public voidprint(int i)

    this.write(String.valueOf(i));
  
public voidprint(long l)

    this.write(String.valueOf(l));
  
public voidprint(float f)

    this.write(String.valueOf(f));
  
public voidprint(double d)

    this.write(String.valueOf(d));
  
public voidprint(char[] text)

    this.write(text);
  
public voidprint(java.lang.String s)

    if (s == null) this.write("null");
    else this.write(s);
  
public voidprint(java.lang.Object o)

    if (o == null) this.write("null");
    else this.write(o.toString());
  
public voidprintln(boolean b)

    if (b) this.write("true");
    else this.write("false");
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(char c)

    this.write(String.valueOf(c));
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(int i)

    this.write(String.valueOf(i));
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(long l)

    this.write(String.valueOf(l));
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(float f)

    this.write(String.valueOf(f));
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(double d)

    this.write(String.valueOf(d));
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(char[] text)

    this.write(text);
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(java.lang.String s)

    if (s == null) this.write("null");
    else this.write(s);
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln(java.lang.Object o)

    if (o == null) this.write("null");
    else this.write(o.toString());
    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidprintln()

    this.write(lineSeparator);
    if (autoFlush) out.flush();
  
public voidwrite(java.lang.String s, int offset, int length)


    synchronized (lock) {
      if (closed) throw new IOException("Stream closed");
      out.write(s, offset, length);
    }

  
public voidwrite(int c)

    synchronized (lock) {
      if (closed) throw new IOException("Stream closed");
      out.write(c);
    }    
  
public voidwrite(char[] text, int offset, int length)

    synchronized (lock) {
      if (closed) throw new IOException("Stream closed");
      out.write(text, offset, length);
    }    
  
public voidwrite(char[] text)

    synchronized (lock) {
      if (closed) throw new IOException("Stream closed");
      out.write(text, 0, text.length);
    }