Skip to content

Commit

Permalink
Override PrintStream.write as well as print
Browse files Browse the repository at this point in the history
args4j inconsistently uses both methods for output.  Workaround for
kohsuke/args4j#149.
  • Loading branch information
gaul committed May 8, 2017
1 parent 84ec8e2 commit 525c6e2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/gaul/s3proxy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,27 @@ public static void main(String[] args) throws Exception {

private static PrintStream createLoggerErrorPrintStream() {
return new PrintStream(System.err) {
private final StringBuilder builder = new StringBuilder();

@Override
public void print(final String string) {
logger.error(string);
}

@Override
public void write(byte[] buf, int off, int len) {
for (int i = off; i < len; ++i) {
char ch = (char) buf[i];
if (ch == '\n') {
if (builder.length() != 0) {
print(builder.toString());
builder.setLength(0);
}
} else {
builder.append(ch);
}
}
}
};
}

Expand Down

0 comments on commit 525c6e2

Please sign in to comment.