SK.gnome.dwarf.utils.io
Class SafePrintWriter

java.lang.Object
  extended byjava.io.Writer
      extended bySK.gnome.dwarf.utils.io.SafePrintWriter

public class SafePrintWriter
extends java.io.Writer

Provides network-safe Writer implementation.

It can be used instead of the java.io.PrintWriter class, but it differs from it in two ways:

  • a custom line separator can be provided to the class contructors so the println methods can behave independently of the platform-default line separator. This is useful mainly for implementing some network protocols, which define a strict rules for the line-separating sequence.
  • all methods throw java.io.IOException in the case of an I/O error

    Thread-safety note:
    The access to the underlying output stream is not synchronized.

    This class is based on an example from The Java Network Programming, 2nd edition, written by Elliotte Rusty Harold.


    Field Summary
    protected  java.io.Writer out
               
     
    Fields inherited from class java.io.Writer
    lock
     
    Constructor Summary
    SafePrintWriter(java.io.OutputStream out, boolean autoFlush, java.lang.String encoding)
               
    SafePrintWriter(java.io.OutputStream out, boolean autoFlush, java.lang.String encoding, java.lang.String lineSeparator)
               
    SafePrintWriter(java.io.Writer out, boolean autoFlush)
               
    SafePrintWriter(java.io.Writer out, boolean autoFlush, java.lang.String lineSeparator)
               
    SafePrintWriter(java.io.Writer out, java.lang.String lineSeparator)
               
     
    Method Summary
     void close()
               
     void flush()
               
     void print(boolean b)
               
     void print(double d)
               
     void print(float f)
               
     void print(char c)
               
     void print(char[] text)
               
     void print(int i)
               
     void print(long l)
               
     void print(java.lang.Object o)
               
     void print(java.lang.String s)
               
     void println()
               
     void println(boolean b)
               
     void println(double d)
               
     void println(float f)
               
     void println(char c)
               
     void println(char[] text)
               
     void println(int i)
               
     void println(long l)
               
     void println(java.lang.Object o)
               
     void println(java.lang.String s)
               
     void write(char[] text)
               
     void write(char[] text, int off, int len)
               
     void write(int c)
               
     void write(java.lang.String s)
               
     void write(java.lang.String s, int off, int len)
               
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    out

    protected java.io.Writer out
    Constructor Detail

    SafePrintWriter

    public SafePrintWriter(java.io.Writer out,
                           java.lang.String lineSeparator)

    SafePrintWriter

    public SafePrintWriter(java.io.Writer out,
                           boolean autoFlush)

    SafePrintWriter

    public SafePrintWriter(java.io.Writer out,
                           boolean autoFlush,
                           java.lang.String lineSeparator)

    SafePrintWriter

    public SafePrintWriter(java.io.OutputStream out,
                           boolean autoFlush,
                           java.lang.String encoding)
                    throws java.io.UnsupportedEncodingException

    SafePrintWriter

    public SafePrintWriter(java.io.OutputStream out,
                           boolean autoFlush,
                           java.lang.String encoding,
                           java.lang.String lineSeparator)
                    throws java.io.UnsupportedEncodingException
    Method Detail

    flush

    public void flush()
               throws java.io.IOException
    Throws:
    java.io.IOException

    close

    public void close()
               throws java.io.IOException
    Throws:
    java.io.IOException

    write

    public void write(int c)
               throws java.io.IOException
    Throws:
    java.io.IOException

    write

    public void write(char[] text,
                      int off,
                      int len)
               throws java.io.IOException
    Throws:
    java.io.IOException

    write

    public void write(char[] text)
               throws java.io.IOException
    Throws:
    java.io.IOException

    write

    public void write(java.lang.String s,
                      int off,
                      int len)
               throws java.io.IOException
    Throws:
    java.io.IOException

    write

    public void write(java.lang.String s)
               throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(boolean b)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(boolean b)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(char c)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(char c)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(int i)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(int i)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(long l)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(long l)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(float f)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(float f)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(double d)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(double d)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(char[] text)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(char[] text)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(java.lang.String s)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(java.lang.String s)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    print

    public void print(java.lang.Object o)
               throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println(java.lang.Object o)
                 throws java.io.IOException
    Throws:
    java.io.IOException

    println

    public void println()
                 throws java.io.IOException
    Throws:
    java.io.IOException


    Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.