Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] Problems reading from an InputStream into a StringBuffer

Anders Viklund

2010-03-16

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,

I am having problems reading from an InputStream into a StringBuffer.

For some reason the content of the StringBuffer gets truncated.

Any ideas how to solve this?

Thanks!

...
    final int BLOCKSIZE = 1024
    InputStream input
    OutputStream output
    StringBuffer content = new StringBuffer()
...
    byte[] block = new byte[BLOCKSIZE]
    boolean done = false
    while(!done) {
        try {
            int size = input.read(block)
            println "size: "+size
            if(size >0) {
                content.append(new String(block))
            }
            if(size == -1) {
                done = true
            }
        } catch (IOException e) {
            System.err.println(e.getMessage())
            done = true
        }
    }        
...

Hotmail: Free, trusted and rich email service. Get it now.
©2008 gg3721.com - Jax Systems, LLC, U.S.A.