Skip to content

Commit

Permalink
Make AnsiOutputStream#write methods synchronized, fixes #116
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 25, 2017
1 parent 7c9e5ba commit 4bda4a1
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,22 @@ public AnsiOutputStream(OutputStream os) {
private static final int BEL = 7;
private static final int SECOND_ST_CHAR = '\\';

// TODO: implement to get perf boost: public void write(byte[] b, int off, int len)
@Override
public synchronized void write(byte[] b, int off, int len) throws IOException {
if ((off | len | (b.length - (len + off)) | (off + len)) < 0) {
throw new IndexOutOfBoundsException();
}
for (int i = 0 ; i < len ; i++) {
doWrite(b[off + i]);
}
}

@Override
public synchronized void write(int data) throws IOException {
doWrite(data);
}

public void write(int data) throws IOException {
private void doWrite(int data) throws IOException {
switch (state) {
case LOOKING_FOR_FIRST_ESC_CHAR:
if (data == FIRST_ESC_CHAR) {
Expand Down

0 comments on commit 4bda4a1

Please # to comment.