File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Extend OutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Extend OutputStream" Watch "Extend OutputStream" New topic

Extend OutputStream

chubi shuki

Joined: May 30, 2008
Posts: 9

About to extend
But I need to override the method write(int b)
Actually the implementatino should print the value in a textArea
like textArea.append(new String(...))
It is about the 'int b'
How can I leverage this parameter and print it out.

Thank you for support
Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

I think in this case it's better to override the other write methods as well. These are mostly linked to each other, with one calling the other; usually, write(int[]) calls write(int[], int, int) and that one calls write(int).

In your case it would best to focus on write(int[], int, int):

I have one other suggestion for you though: don't overwrite OutputStream but Writer instead. OutputStream is not really built for handling text. For the writer you'd only need to override the write(char[], int, int) method, which can be done as I did above.

How To Ask Questions How To Answer Questions
chubi shuki

Joined: May 30, 2008
Posts: 9
I would like to extend Writer instead,

but the java.util.logging.logger would accept on StreamHandler as a Handler, the latter only accepts OutputStream

Thank you for reply
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
Make sure to use set encoding on StreamHandler.setEncoding(...) and then use the same encoding to decode bytes in your OutputStream.

Author of <a href="" target="_blank" rel="nofollow">NewsInjector</a>
I agree. Here's the link:
subject: Extend OutputStream
jQuery in Action, 3rd edition