home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / io / PrintStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  3.3 KB  |  349 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.       this.autoFlush = var2;
  20.       this.charOut = new OutputStreamWriter(this);
  21.       this.textOut = new BufferedWriter(this.charOut);
  22.    }
  23.  
  24.    private void ensureOpen() throws IOException {
  25.       if (super.out == null) {
  26.          throw new IOException("Stream closed");
  27.       }
  28.    }
  29.  
  30.    public void flush() {
  31.       synchronized(this){}
  32.  
  33.       try {
  34.          try {
  35.             this.ensureOpen();
  36.             super.out.flush();
  37.          } catch (IOException var4) {
  38.             this.trouble = true;
  39.          }
  40.       } catch (Throwable var5) {
  41.          throw var5;
  42.       }
  43.  
  44.    }
  45.  
  46.    public void close() {
  47.       synchronized(this){}
  48.  
  49.       try {
  50.          if (!this.closing) {
  51.             this.closing = true;
  52.  
  53.             try {
  54.                this.textOut.close();
  55.                super.out.close();
  56.             } catch (IOException var4) {
  57.                this.trouble = true;
  58.             }
  59.  
  60.             this.textOut = null;
  61.             this.charOut = null;
  62.             super.out = null;
  63.          }
  64.       } catch (Throwable var5) {
  65.          throw var5;
  66.       }
  67.  
  68.    }
  69.  
  70.    public boolean checkError() {
  71.       if (super.out != null) {
  72.          this.flush();
  73.       }
  74.  
  75.       return this.trouble;
  76.    }
  77.  
  78.    protected void setError() {
  79.       this.trouble = true;
  80.    }
  81.  
  82.    public void write(int var1) {
  83.       try {
  84.          synchronized(this){}
  85.  
  86.          try {
  87.             this.ensureOpen();
  88.             super.out.write(var1);
  89.             if (var1 == 10 && this.autoFlush) {
  90.                super.out.flush();
  91.             }
  92.          } catch (Throwable var6) {
  93.             throw var6;
  94.          }
  95.  
  96.       } catch (InterruptedIOException var7) {
  97.          Thread.currentThread().interrupt();
  98.       } catch (IOException var8) {
  99.          this.trouble = true;
  100.       }
  101.    }
  102.  
  103.    public void write(byte[] var1, int var2, int var3) {
  104.       try {
  105.          synchronized(this){}
  106.  
  107.          try {
  108.             this.ensureOpen();
  109.             super.out.write(var1, var2, var3);
  110.             if (this.autoFlush) {
  111.                super.out.flush();
  112.             }
  113.          } catch (Throwable var8) {
  114.             throw var8;
  115.          }
  116.  
  117.       } catch (InterruptedIOException var9) {
  118.          Thread.currentThread().interrupt();
  119.       } catch (IOException var10) {
  120.          this.trouble = true;
  121.       }
  122.    }
  123.  
  124.    private void write(char[] var1) {
  125.       try {
  126.          synchronized(this){}
  127.  
  128.          try {
  129.             this.ensureOpen();
  130.             this.textOut.write(var1);
  131.             this.textOut.flushBuffer();
  132.             this.charOut.flushBuffer();
  133.             if (this.autoFlush) {
  134.                for(int var4 = 0; var4 < var1.length; ++var4) {
  135.                   if (var1[var4] == '\n') {
  136.                      super.out.flush();
  137.                   }
  138.                }
  139.             }
  140.          } catch (Throwable var8) {
  141.             throw var8;
  142.          }
  143.  
  144.       } catch (InterruptedIOException var9) {
  145.          Thread.currentThread().interrupt();
  146.       } catch (IOException var10) {
  147.          this.trouble = true;
  148.       }
  149.    }
  150.  
  151.    private void write(String var1) {
  152.       try {
  153.          synchronized(this){}
  154.  
  155.          try {
  156.             this.ensureOpen();
  157.             this.textOut.write(var1);
  158.             this.textOut.flushBuffer();
  159.             this.charOut.flushBuffer();
  160.             if (this.autoFlush && var1.indexOf(10) >= 0) {
  161.                super.out.flush();
  162.             }
  163.          } catch (Throwable var6) {
  164.             throw var6;
  165.          }
  166.  
  167.       } catch (InterruptedIOException var7) {
  168.          Thread.currentThread().interrupt();
  169.       } catch (IOException var8) {
  170.          this.trouble = true;
  171.       }
  172.    }
  173.  
  174.    private void newLine() {
  175.       try {
  176.          synchronized(this){}
  177.  
  178.          try {
  179.             this.ensureOpen();
  180.             this.textOut.newLine();
  181.             this.textOut.flushBuffer();
  182.             this.charOut.flushBuffer();
  183.             if (this.autoFlush) {
  184.                super.out.flush();
  185.             }
  186.          } catch (Throwable var5) {
  187.             throw var5;
  188.          }
  189.  
  190.       } catch (InterruptedIOException var6) {
  191.          Thread.currentThread().interrupt();
  192.       } catch (IOException var7) {
  193.          this.trouble = true;
  194.       }
  195.    }
  196.  
  197.    public void print(boolean var1) {
  198.       this.write(var1 ? "true" : "false");
  199.    }
  200.  
  201.    public void print(char var1) {
  202.       this.write(String.valueOf(var1));
  203.    }
  204.  
  205.    public void print(int var1) {
  206.       this.write(String.valueOf(var1));
  207.    }
  208.  
  209.    public void print(long var1) {
  210.       this.write(String.valueOf(var1));
  211.    }
  212.  
  213.    public void print(float var1) {
  214.       this.write(String.valueOf(var1));
  215.    }
  216.  
  217.    public void print(double var1) {
  218.       this.write(String.valueOf(var1));
  219.    }
  220.  
  221.    public void print(char[] var1) {
  222.       this.write(var1);
  223.    }
  224.  
  225.    public void print(String var1) {
  226.       if (var1 == null) {
  227.          var1 = "null";
  228.       }
  229.  
  230.       this.write(var1);
  231.    }
  232.  
  233.    public void print(Object var1) {
  234.       this.write(String.valueOf(var1));
  235.    }
  236.  
  237.    public void println() {
  238.       this.newLine();
  239.    }
  240.  
  241.    public void println(boolean var1) {
  242.       synchronized(this){}
  243.  
  244.       try {
  245.          this.print(var1);
  246.          this.newLine();
  247.       } catch (Throwable var4) {
  248.          throw var4;
  249.       }
  250.  
  251.    }
  252.  
  253.    public void println(char var1) {
  254.       synchronized(this){}
  255.  
  256.       try {
  257.          this.print(var1);
  258.          this.newLine();
  259.       } catch (Throwable var4) {
  260.          throw var4;
  261.       }
  262.  
  263.    }
  264.  
  265.    public void println(int var1) {
  266.       synchronized(this){}
  267.  
  268.       try {
  269.          this.print(var1);
  270.          this.newLine();
  271.       } catch (Throwable var4) {
  272.          throw var4;
  273.       }
  274.  
  275.    }
  276.  
  277.    public void println(long var1) {
  278.       synchronized(this){}
  279.  
  280.       try {
  281.          this.print(var1);
  282.          this.newLine();
  283.       } catch (Throwable var5) {
  284.          throw var5;
  285.       }
  286.  
  287.    }
  288.  
  289.    public void println(float var1) {
  290.       synchronized(this){}
  291.  
  292.       try {
  293.          this.print(var1);
  294.          this.newLine();
  295.       } catch (Throwable var4) {
  296.          throw var4;
  297.       }
  298.  
  299.    }
  300.  
  301.    public void println(double var1) {
  302.       synchronized(this){}
  303.  
  304.       try {
  305.          this.print(var1);
  306.          this.newLine();
  307.       } catch (Throwable var5) {
  308.          throw var5;
  309.       }
  310.  
  311.    }
  312.  
  313.    public void println(char[] var1) {
  314.       synchronized(this){}
  315.  
  316.       try {
  317.          this.print(var1);
  318.          this.newLine();
  319.       } catch (Throwable var4) {
  320.          throw var4;
  321.       }
  322.  
  323.    }
  324.  
  325.    public void println(String var1) {
  326.       synchronized(this){}
  327.  
  328.       try {
  329.          this.print(var1);
  330.          this.newLine();
  331.       } catch (Throwable var4) {
  332.          throw var4;
  333.       }
  334.  
  335.    }
  336.  
  337.    public void println(Object var1) {
  338.       synchronized(this){}
  339.  
  340.       try {
  341.          this.print(var1);
  342.          this.newLine();
  343.       } catch (Throwable var4) {
  344.          throw var4;
  345.       }
  346.  
  347.    }
  348. }
  349.