Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
buf.clear(); while (in.read(buf) >= 0 || buf.position != 0) { buf.flip(); out.write(buf); buf.compact(); } // vs. int offset = 0; int length = 0; do { int read = in.read(buf, offset, length); if ( read == -1 && offset == 0 ) break; else if ( read != -1 ) offset += read; length = offset; offset = 0; int write = out.write(buf, offset, length); // Normal java.io doesn't actually provide a partial write, so we're just pretending it does offset += write; if ( offset < length ) { System.arraycopy(buf, offset, buf, 0, length - offset); offset = length - offset; length = buf.length; } else { offset = 0; length = 0; } }
This paste will be private.
From the Design Piracy series on my blog: