Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printwriter

 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i posted this in multiple forums but this just drives me crazy right now. I can't figure out why i can't get an output. Sorry again for post many times. here is the query.
hi i have this method in my code that i wrote to send a message to clients. Now if i change the code to use PrintWriter it says that print writer with every println() method is flushing the buffer it doesn't WORK . i tried everything nothing happends. Now i try to use BufferedWriter same story. I use flush method to flush it nothing happends. I used to specify a buffer size trying to limit it to the length of the string and then flush it again nothing happends. What do i do wrong ? Code is below. The only way it flushes is only when the buffer get's overloaded.
 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If this is the code in your servlet,then try passing the PrintWriter out as parameter toy uor method.If it is a standalone class I think you will have to import Servlet pacage and use the PrinWriter object as parameter to your method.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THis is a standalonne class which i start it by command line. Servlets access it and it sends back the data to them well it should. But it doesn't flush it when data arrives.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well it drove me nuts but i got it solved. Not that it was something hard to do but just overlooked HttpServletResponse object which has bufferFlush method. When dealing with more then one Stream it gets tied. I tried to flush on my stream that i get from one of the Server classes which ofcouse didnt' do anything instead must have used HttpServletResponse object. So i post this message just incase someone runs into this.
Thanks and bye
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic