• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extend OutputStream

 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure to use set encoding on StreamHandler.setEncoding(...) and then use the same encoding to decode bytes in your OutputStream.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic