1 33 34 package edu.rice.cs.util.swing; 35 36 import java.io.OutputStream ; 37 import javax.swing.text.Document ; 38 import javax.swing.text.BadLocationException ; 39 import javax.swing.text.AttributeSet ; 40 41 47 public class DocumentOutputStream extends OutputStream { 48 private Document _doc; 49 private AttributeSet _attributes; 50 51 60 public DocumentOutputStream(Document doc) { 61 this(doc, null); 62 } 63 64 72 public DocumentOutputStream(Document doc, AttributeSet attributes) { 73 _doc = doc; 74 _attributes = attributes; 75 } 76 77 81 public void write(int c) { 82 try { 83 _doc.insertString(_doc.getLength(), String.valueOf((char)c), _attributes); 84 } catch (BadLocationException canNeverHappen) { 85 throw new RuntimeException ("Internal error: bad location in OutputWindowStream"); 86 } 87 } 88 89 95 public void write(byte[] b, int off, int len) { 96 try { 97 _doc.insertString(_doc.getLength(), new String (b, off, len), _attributes); 98 } catch (BadLocationException canNevenHappen) { 99 throw new RuntimeException ("Internal error: bad location in OutputWindowStream"); 100 } 101 } 102 } 103 | Popular Tags |