einars/js-beautify — Issue #86: JSbeautifier will break the file content
Author: freewind
Created: 2011-12-24 04:13:48+00:00
State: open

JSBeautifier.java

private String getFileContents(InputStream stream) {

StringBuffer contents = new StringBuffer("");
try {
byte[] readBytes = new byte[1024];
int i = 0;
while ((i = stream.read(readBytes)) > 0) {
contents.append(new String(readBytes, 0, i));
}
} catch (Exception e) {
e.printStackTrace();
}
return contents.toString();
}

This line:

contents.append(new String(readBytes, 0, i));

May break the original content. If the content has Chinese characters, `stream.read(readBytes)` may read a half word.

JSLint.java has the same issue