Skip to content

Instantly share code, notes, and snippets.

@presci
Created May 11, 2012 18:31
Show Gist options
  • Save presci/2661552 to your computer and use it in GitHub Desktop.
Save presci/2661552 to your computer and use it in GitHub Desktop.
Buffered Writer in java
package com.etrade.neo.util;
import java.io.StringWriter;
public class TestWriter {
public static void main(String[] args) {
String source = "Now is the time for all good men\\n"
+ " to come to the aid of their country\\n"
+ " and pay their due taxes.";
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
StringWriter writer = new StringWriter();
int off = 0;
int len = 4;
while (true) {
if (buffer.length > (off + len)) {
writer.write(buffer, off, len);
} else {
len = buffer.length - off;
writer.write(buffer, off, len);
break;
}
off = off + 4;
}
System.out.println(writer.getBuffer().toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment