• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StringBuffer problem

 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add your code
 
Malhar Barai
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the code

tia
malhar
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would there be any difference between calling out.println(sb)
and out.println(sb.toString()) ?
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic