All pastes #634866 Raw Edit

Stuff

public text v1 · immutable
#634866 ·published 2007-07-26 18:29 UTC
rendered paste body
            int byte1;
            String pageData = "";
            ByteBuffer buf = ByteBuffer.allocateDirect(1024);
            InputStream in = uconn.getInputStream();

            synchronized(buf) {
                while((byte1 = in.read()) >= 0) {
                    try {
                        buf.put((byte) byte1);
                    } catch (BufferOverflowException e) {
                        buf.flip();
                        byte[] bytes = new byte[buf.remaining()];
                        buf.get(bytes);
                        pageData += new String(bytes);
                        buf.clear();
                        buf.put((byte) byte1);
                    }
                }

                buf.flip();
                byte[] bytes = new byte[buf.remaining()];
                buf.get(bytes);
                pageData += new String(bytes);
                buf.clear();
            }

            System.out.println(pageData);