• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding System.out.format(), doesnt work

 
Paul dearrt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how i can override method PrintStream format(format, args)?

I made
and System.setOut(ps);

but method format doesnt work, any idea?
 
Paul Clapham
Sheriff
Posts: 20996
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by finding out what "doesn't work" means. Have a look at our FAQ entry ItDoesntWorkIsUseless for tips on how to do that.

Also, I wrapped your posted code in the "Code" tags for you. See how much easier it is to read now? To do that, just select your code after you paste it into the posting box and click the "Code" button you'll see above the box.
 
Paul dearrt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I would start by finding out what "doesn't work" means. Have a look at our FAQ entry ItDoesntWorkIsUseless for tips on how to do that.

Also, I wrapped your posted code in the "Code" tags for you. See how much easier it is to read now? To do that, just select your code after you paste it into the posting box and click the "Code" button you'll see above the box.


Im sorry, I was in hurry.
Doesnt work in this case means: dont formatting text; it only print to PrintStream, without formatting.

 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think that format uses println or print? It's not documented anywhere.

I've checked the source code of PrintStream (just check the src.zip file in your JDK folder), and format treats the PrintStream as an Appender. That means that you would need to override all of the append methods:
That still doesn't mean all methods work. You need to override all of the other print and println methods as well, as these each call a private method called write (and the println methods also a private method called newLine()) which you cannot override. In other words, you'll probably have to override every single method...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic