This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes StringBuffer problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "StringBuffer problem" Watch "StringBuffer problem" New topic
Author

StringBuffer problem

Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
hi all
is there any limitation to the size of StringBuffer...
I append few thing in StringBuffer, but when i output them, few lines are lost...
hope I am clear
tia
MB
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
add your code


Asher Tarnopolski
SCJP,SCWCD
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
here is the code

tia
malhar
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
As per the specification,
"Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger",
hence it should not give any problem, but you can try printing its capacity (using sb.capacity())
at different places at the end , if it varies. well there mite be some mistake in ur code


- Varun
Linda Jones
Ranch Hand

Joined: Aug 17, 2002
Posts: 57
Would there be any difference between calling out.println(sb)
and out.println(sb.toString()) ?
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
As Linda said send the StringBuffer as a String using sb.toString(); .
But also, don't forget to flush the stream:
with out.flush(); or out.close();
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
Hi Linda, the two lines of code are perfectly the same thing.
regarding your problems I can suggest two things:
1)you can specify the size of the StringBuffer as an int variables so I suppose a StringBuffer can't contains (Integer.MAX_VALUE + 1) chars;
2) You insert in the StringBuffer an HTML page. I suppose you use this in a Servlet. In this case, look at the html code, because if there is a syntax error, the page is printed until the error is reached. This not means the StringBuffer doesn't hold your string, but simply the Browser (IE, NEtscape??) html parser doesn't recongnize the rest of the page.
Hope it helps.


Regards,<br />Andrea<br /> <br /><a href="http://www.linkedin.com/in/andreagazzarini" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID : a.gazzarini@gmail.com<br /><a href="http://www.andreagazzarini.blogspot.com" target="_blank" rel="nofollow">My Blog</a>
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi all,
the first thing i would have done is,
S.o.p(sb.toString()); which should print content to the Server screen (where we started the server) and then copy & pasted to a HTML file and try viewing it in some of the browser.
regards,
maulin
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Andrea Gazzarini:
Hi Linda, the two lines of code are perfectly the same thing.
regarding your problems I can suggest two things:
1)you can specify the size of the StringBuffer as an int variables so I suppose a StringBuffer can't contains (Integer.MAX_VALUE + 1) chars;


2) You insert in the StringBuffer an HTML page. I suppose you use this in a Servlet. In this case, look at the html code, because if there is a syntax error, the page is printed until the error is reached. This not means the StringBuffer doesn't hold your string, but simply the Browser (IE, NEtscape??) html parser doesn't recongnize the rest of the page.
Hope it helps.

well andrea
i dont think there's any problem with HTML code as this is the code supplied to me by Front Page. It is just that i have to get the values printed from database between this HTML tags.
I had to ask abt the size problem just because, if i remove some line that i have put as comments in HTML tag, the same number of line are then appended to the output & as a result i can see more HTML stuff.
hope i m clear
MB
 
Don't get me started about those stupid light bulbs.
 
subject: StringBuffer problem