diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-04-24 17:47:00 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-04-24 17:47:00 +0200 |
commit | a118bc79249ba9184ada2315dacf48fd19e444a5 (patch) | |
tree | e38c68efeff03afaba2be1ed625182895e0ab7ab /src | |
parent | 27fd5e477671d74aa1deb169fdc3ea11c37cb442 (diff) | |
parent | 5f276b620901e7b41a213c2a9c2dc252b6b4cfa1 (diff) | |
download | lombok-a118bc79249ba9184ada2315dacf48fd19e444a5.tar.gz lombok-a118bc79249ba9184ada2315dacf48fd19e444a5.tar.bz2 lombok-a118bc79249ba9184ada2315dacf48fd19e444a5.zip |
Merge branch 'master' of git@github.com:rzwitserloot/lombok
Diffstat (limited to 'src')
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 8 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/UnicodeEscapeWriter.java | 47 |
2 files changed, 53 insertions, 2 deletions
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 8d28735a..b38d3ef5 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -323,10 +323,14 @@ public class Delombok { File outFile = new File(base, fileName); outFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(outFile); - return new OutputStreamWriter(out, charset); + return createUnicodeEscapeWriter(out); } private Writer createStandardOutWriter() { - return new OutputStreamWriter(System.out, charset); + return createUnicodeEscapeWriter(System.out); + } + + private Writer createUnicodeEscapeWriter(OutputStream out) { + return new UnicodeEscapeWriter(new OutputStreamWriter(out, charset), charset); } } diff --git a/src/delombok/lombok/delombok/UnicodeEscapeWriter.java b/src/delombok/lombok/delombok/UnicodeEscapeWriter.java new file mode 100644 index 00000000..afb779dd --- /dev/null +++ b/src/delombok/lombok/delombok/UnicodeEscapeWriter.java @@ -0,0 +1,47 @@ +package lombok.delombok; +import java.io.IOException; +import java.io.Writer; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; + +public class UnicodeEscapeWriter extends Writer { + private final Writer writer; + private CharsetEncoder encoder; + + public UnicodeEscapeWriter(Writer writer, Charset charset) { + this.writer = writer; + encoder = charset.newEncoder(); + } + + @Override + public void close() throws IOException { + writer.close(); + } + + @Override + public void flush() throws IOException { + writer.flush(); + } + + @Override + public final void write(char[] cbuf, int off, int len) throws IOException { + int start = off; + int index = start; + int end = off + len; + while (index < end) { + if (!encoder.canEncode(cbuf[index])) { + writer.write(cbuf, start, index - start); + writeUnicodeEscape(cbuf[index]); + start = index + 1; + } + index++; + } + if (start < end) { + writer.write(cbuf, start, end - start); + } + } + + protected void writeUnicodeEscape(char c) throws IOException { + writer.write("\\u" + Integer.toHexString(c)); + } +}
\ No newline at end of file |