Mp3dings 
20100427

de.mospace.swing.text
Class DocumentOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by de.mospace.swing.text.DocumentOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class DocumentOutputStream
extends OutputStream

An OutputStream that writes to the Document of a Swing text component.

Version:
$Revision: 69 $ ($Date: 2007-10-24 23:57:43 +0200 (Mi, 24 Okt 2007) $)
Author:
Moritz Ringler

Constructor Summary
DocumentOutputStream(Document d)
          Constructs a new DocumentOutputStream that uses the default system charset for decoding bytes passed to its write methods.
DocumentOutputStream(Document d, Charset c)
          Creates a new DocumentOutputStream that uses the specified charset for decoding bytes passed to its write methods.
DocumentOutputStream(Document d, String charsetName)
          Creates a new DocumentOutputStream that uses the charset with the specified name for decoding bytes passed to its write methods.
 
Method Summary
 void close()
          Closes the output stream.
 Charset getCharset()
          Returns the character set that this DocumentOutputStream uses to write bytes to its document.
 String getCharsetName()
          Returns the character set that this DocumentOutputStream uses to write bytes to its document.
 Document getDocument()
          Returns the document that this OutputStream writes to.
 void setCharset(Charset c)
          Sets the character set used for decoding bytes passed to the write methods of this DocumentOutputStream.
 void setCharset(String name)
          Sets the character set used for decoding bytes passed to the write methods of this DocumentOutputStream.
 void setColor(Color c)
          Sets the foreground color for new output.
 void setDocument(Document d)
          Sets the document that this OutputStream writes to.
 void write(byte[] b)
          Inserts the specified bytes at the end of the current document of this DocumentOutputStream.
 void write(byte[] b, int off, int len)
          Inserts the specified bytes at the end of the current document of this DocumentOutputStream.
 void write(int b)
          Inserts the specified byte at the end of the current document of this DocumentOutputStream.
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentOutputStream

public DocumentOutputStream(Document d)
Constructs a new DocumentOutputStream that uses the default system charset for decoding bytes passed to its write methods.

Parameters:
d - the document that this output stream will write to
Throws:
NullPointerException - if d is null

DocumentOutputStream

public DocumentOutputStream(Document d,
                            Charset c)
Creates a new DocumentOutputStream that uses the specified charset for decoding bytes passed to its write methods.

Parameters:
d - the document that this output stream will write to
c - charset for decoding bytes passed to one of the write methods
Throws:
NullPointerException - if one of the parameters is null

DocumentOutputStream

public DocumentOutputStream(Document d,
                            String charsetName)
Creates a new DocumentOutputStream that uses the charset with the specified name for decoding bytes passed to its write methods.

Parameters:
d - the document that this output stream will write to
charsetName - the name of a charset to use
Throws:
NullPointerException - if one of the parameters is null
UnsupportedCharsetException - if the JVM does not support the charset with the specified name
Method Detail

setColor

public void setColor(Color c)
Sets the foreground color for new output.

Parameters:
c - the new text color

setCharset

public void setCharset(String name)
Sets the character set used for decoding bytes passed to the write methods of this DocumentOutputStream. Has no effect when this OutputStream has been closed.

Parameters:
name - charset for decoding bytes
Throws:
NullPointerException - if name is null
UnsupportedCharsetException - if the JVM does not support the charset with the specified name

setCharset

public void setCharset(Charset c)
Sets the character set used for decoding bytes passed to the write methods of this DocumentOutputStream. Has no effect when this OutputStream has been closed.

Parameters:
c - charset for decoding bytes
Throws:
NullPointerException - if c is null

getCharset

public Charset getCharset()
Returns the character set that this DocumentOutputStream uses to write bytes to its document.

Returns:
the character set used by this DocumentOutputStream or null if this stream has been closed

getCharsetName

public String getCharsetName()
Returns the character set that this DocumentOutputStream uses to write bytes to its document.

Returns:
the character set used by this DocumentOutputStream or null if this stream has been closed

setDocument

public void setDocument(Document d)
Sets the document that this OutputStream writes to. Has no effect when this OutputStream has been closed.

Parameters:
d - the document that this output stream will write to
Throws:
NullPointerException - if d is null

getDocument

public Document getDocument()
Returns the document that this OutputStream writes to.

Returns:
the document that this output stream writes to or null if this stream has been closed

close

public void close()
Closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream

write

public void write(int b)
           throws IOException
Inserts the specified byte at the end of the current document of this DocumentOutputStream. b is converted to a unicode character by calling the decode method of the current charset of this DocumentOutputStream.

Specified by:
write in class OutputStream
Parameters:
b - the byte to write
Throws:
IOException - if the output stream has been closed

write

public void write(byte[] b)
           throws IOException
Inserts the specified bytes at the end of the current document of this DocumentOutputStream. b is converted to a unicode string by calling the decode method of the current charset of this DocumentOutputStream.

write(b) has exactly the same effect as the call write(b, 0, b.length).

Overrides:
write in class OutputStream
Parameters:
b - the byte to write
Throws:
IOException - if the output stream has been closed
See Also:
write(byte[], int, int)

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Inserts the specified bytes at the end of the current document of this DocumentOutputStream. b is converted to a unicode string by calling the decode method of the current charset of this DocumentOutputStream.

Overrides:
write in class OutputStream
Parameters:
b - the data
off - the start offset in the data
len - the number of bytes to write
Throws:
IOException - if the output stream has been closed
NullPointerException - if b is null
IndexOutOfBoundsException - if the preconditions on the off and len parameters do not hold

Mp3dings 
20100427