home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / netscape / applet / ConsoleOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  2.0 KB  |  47 lines

  1. package netscape.applet;
  2.  
  3. import java.io.OutputStream;
  4.  
  5. class ConsoleOutputStream extends OutputStream {
  6.    Console console;
  7.    byte[] doh = new byte[1];
  8.    public static int MAXIMUM_CHARACTERS_IN_CONSOLE;
  9.    public static final int CONSOLE_TRIM_SIZE = 2048;
  10.  
  11.    ConsoleOutputStream(Console console) {
  12.       this.console = console;
  13.    }
  14.  
  15.    public void limitConsoleText(int newCharacterCount) {
  16.       int currentTextLength = this.console.frame.text.getText().length();
  17.       if (MAXIMUM_CHARACTERS_IN_CONSOLE == 0) {
  18.          String consoleMaxCharString = System.getProperty("console.bufferlength", "32768");
  19.          MAXIMUM_CHARACTERS_IN_CONSOLE = Integer.parseInt(consoleMaxCharString);
  20.       }
  21.  
  22.       if (currentTextLength + newCharacterCount > MAXIMUM_CHARACTERS_IN_CONSOLE) {
  23.          this.console.frame.text.replaceText("", 0, 2048);
  24.       }
  25.  
  26.    }
  27.  
  28.    public void write(int b) {
  29.       this.doh[0] = (byte)b;
  30.       String s = new String(this.doh, 0, 0, 1);
  31.       this.limitConsoleText(1);
  32.       this.console.frame.text.insertText(s, 99999);
  33.    }
  34.  
  35.    public void write(byte[] b) {
  36.       String s = new String(b, 0, 0, b.length);
  37.       this.limitConsoleText(b.length);
  38.       this.console.frame.text.insertText(s, 99999);
  39.    }
  40.  
  41.    public void write(byte[] b, int off, int len) {
  42.       String s = new String(b, 0, off, len);
  43.       this.limitConsoleText(len);
  44.       this.console.frame.text.insertText(s, 99999);
  45.    }
  46. }
  47.