home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / PrintStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.5 KB  |  280 lines

  1. package java.io;
  2.  
  3. public class PrintStream extends FilterOutputStream {
  4.    private boolean autoFlush;
  5.    private boolean trouble;
  6.    private BufferedWriter textOut;
  7.    private OutputStreamWriter charOut;
  8.    private boolean closing;
  9.  
  10.    public PrintStream(OutputStream var1) {
  11.       this(var1, false);
  12.    }
  13.  
  14.    public PrintStream(OutputStream var1, boolean var2) {
  15.       super(var1);
  16.       this.autoFlush = false;
  17.       this.trouble = false;
  18.       this.closing = false;
  19.       if (var1 == null) {
  20.          throw new NullPointerException("Null output stream");
  21.       } else {
  22.          this.autoFlush = var2;
  23.          this.charOut = new OutputStreamWriter(this);
  24.          this.textOut = new BufferedWriter(this.charOut);
  25.       }
  26.    }
  27.  
  28.    private void ensureOpen() throws IOException {
  29.       if (super.out == null) {
  30.          throw new IOException("Stream closed");
  31.       }
  32.    }
  33.  
  34.    public void flush() {
  35.       synchronized(this) {
  36.          try {
  37.             this.ensureOpen();
  38.             super.out.flush();
  39.          } catch (IOException var4) {
  40.             this.trouble = true;
  41.          }
  42.  
  43.       }
  44.    }
  45.  
  46.    public void close() {
  47.       synchronized(this) {
  48.          if (!this.closing) {
  49.             this.closing = true;
  50.  
  51.             try {
  52.                this.textOut.close();
  53.                super.out.close();
  54.             } catch (IOException var4) {
  55.                this.trouble = true;
  56.             }
  57.  
  58.             this.textOut = null;
  59.             this.charOut = null;
  60.             super.out = null;
  61.          }
  62.  
  63.       }
  64.    }
  65.  
  66.    public boolean checkError() {
  67.       if (super.out != null) {
  68.          this.flush();
  69.       }
  70.  
  71.       return this.trouble;
  72.    }
  73.  
  74.    protected void setError() {
  75.       this.trouble = true;
  76.    }
  77.  
  78.    public void write(int var1) {
  79.       try {
  80.          synchronized(this) {
  81.             this.ensureOpen();
  82.             super.out.write(var1);
  83.             if (var1 == 10 && this.autoFlush) {
  84.                super.out.flush();
  85.             }
  86.          }
  87.       } catch (InterruptedIOException var5) {
  88.          Thread.currentThread().interrupt();
  89.       } catch (IOException var6) {
  90.          this.trouble = true;
  91.       }
  92.  
  93.    }
  94.  
  95.    public void write(byte[] var1, int var2, int var3) {
  96.       try {
  97.          synchronized(this) {
  98.             this.ensureOpen();
  99.             super.out.write(var1, var2, var3);
  100.             if (this.autoFlush) {
  101.                super.out.flush();
  102.             }
  103.          }
  104.       } catch (InterruptedIOException var7) {
  105.          Thread.currentThread().interrupt();
  106.       } catch (IOException var8) {
  107.          this.trouble = true;
  108.       }
  109.  
  110.    }
  111.  
  112.    private void write(char[] var1) {
  113.       try {
  114.          synchronized(this) {
  115.             this.ensureOpen();
  116.             this.textOut.write(var1);
  117.             this.textOut.flushBuffer();
  118.             this.charOut.flushBuffer();
  119.             if (this.autoFlush) {
  120.                for(int var3 = 0; var3 < var1.length; ++var3) {
  121.                   if (var1[var3] == '\n') {
  122.                      super.out.flush();
  123.                   }
  124.                }
  125.             }
  126.          }
  127.       } catch (InterruptedIOException var6) {
  128.          Thread.currentThread().interrupt();
  129.       } catch (IOException var7) {
  130.          this.trouble = true;
  131.       }
  132.  
  133.    }
  134.  
  135.    private void write(String var1) {
  136.       try {
  137.          synchronized(this) {
  138.             this.ensureOpen();
  139.             this.textOut.write(var1);
  140.             this.textOut.flushBuffer();
  141.             this.charOut.flushBuffer();
  142.             if (this.autoFlush && var1.indexOf(10) >= 0) {
  143.                super.out.flush();
  144.             }
  145.          }
  146.       } catch (InterruptedIOException var5) {
  147.          Thread.currentThread().interrupt();
  148.       } catch (IOException var6) {
  149.          this.trouble = true;
  150.       }
  151.  
  152.    }
  153.  
  154.    private void newLine() {
  155.       try {
  156.          synchronized(this) {
  157.             this.ensureOpen();
  158.             this.textOut.newLine();
  159.             this.textOut.flushBuffer();
  160.             this.charOut.flushBuffer();
  161.             if (this.autoFlush) {
  162.                super.out.flush();
  163.             }
  164.          }
  165.       } catch (InterruptedIOException var4) {
  166.          Thread.currentThread().interrupt();
  167.       } catch (IOException var5) {
  168.          this.trouble = true;
  169.       }
  170.  
  171.    }
  172.  
  173.    public void print(boolean var1) {
  174.       this.write(var1 ? "true" : "false");
  175.    }
  176.  
  177.    public void print(char var1) {
  178.       this.write(String.valueOf(var1));
  179.    }
  180.  
  181.    public void print(int var1) {
  182.       this.write(String.valueOf(var1));
  183.    }
  184.  
  185.    public void print(long var1) {
  186.       this.write(String.valueOf(var1));
  187.    }
  188.  
  189.    public void print(float var1) {
  190.       this.write(String.valueOf(var1));
  191.    }
  192.  
  193.    public void print(double var1) {
  194.       this.write(String.valueOf(var1));
  195.    }
  196.  
  197.    public void print(char[] var1) {
  198.       this.write(var1);
  199.    }
  200.  
  201.    public void print(String var1) {
  202.       if (var1 == null) {
  203.          var1 = "null";
  204.       }
  205.  
  206.       this.write(var1);
  207.    }
  208.  
  209.    public void print(Object var1) {
  210.       this.write(String.valueOf(var1));
  211.    }
  212.  
  213.    public void println() {
  214.       this.newLine();
  215.    }
  216.  
  217.    public void println(boolean var1) {
  218.       synchronized(this) {
  219.          this.print(var1);
  220.          this.newLine();
  221.       }
  222.    }
  223.  
  224.    public void println(char var1) {
  225.       synchronized(this) {
  226.          this.print(var1);
  227.          this.newLine();
  228.       }
  229.    }
  230.  
  231.    public void println(int var1) {
  232.       synchronized(this) {
  233.          this.print(var1);
  234.          this.newLine();
  235.       }
  236.    }
  237.  
  238.    public void println(long var1) {
  239.       synchronized(this) {
  240.          this.print(var1);
  241.          this.newLine();
  242.       }
  243.    }
  244.  
  245.    public void println(float var1) {
  246.       synchronized(this) {
  247.          this.print(var1);
  248.          this.newLine();
  249.       }
  250.    }
  251.  
  252.    public void println(double var1) {
  253.       synchronized(this) {
  254.          this.print(var1);
  255.          this.newLine();
  256.       }
  257.    }
  258.  
  259.    public void println(char[] var1) {
  260.       synchronized(this) {
  261.          this.print(var1);
  262.          this.newLine();
  263.       }
  264.    }
  265.  
  266.    public void println(String var1) {
  267.       synchronized(this) {
  268.          this.print(var1);
  269.          this.newLine();
  270.       }
  271.    }
  272.  
  273.    public void println(Object var1) {
  274.       synchronized(this) {
  275.          this.print(var1);
  276.          this.newLine();
  277.       }
  278.    }
  279. }
  280.