Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Extend OutputStream  RSS feed

 
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
Posts: 21048
85
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!