aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Extend OutputStream" Watch "Extend OutputStream" New topic
Author

Extend OutputStream

chubi shuki
Greenhorn

Joined: May 30, 2008
Posts: 9
Hello,

About to extend java.io.OutputStream
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
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
chubi shuki
Greenhorn

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="http://www.newsinjector.com" target="_blank" rel="nofollow">NewsInjector</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extend OutputStream
 
Similar Threads
instanceof operator
Need Help With This java Problem(Review for a test)
Queston about Inheritance
Can an array be used as a HashMap Key?
Programming Puzzle