Skip to content

Commit

Permalink
ControlSequenceOutputStream inherits from OutputStream and defines tw…
Browse files Browse the repository at this point in the history
…o abstract methods: 'onOutput' and 'onControlSequence'
  • Loading branch information
koentsje committed Mar 7, 2014
1 parent a8d97f8 commit 607231c
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package org.jboss.tools.aesh.core.internal.io;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.jboss.tools.aesh.core.ansi.ControlSequence;
import org.jboss.tools.aesh.core.internal.ansi.ControlSequenceFactory;
import org.jboss.tools.aesh.core.internal.ansi.DefaultControlSequenceFactory;

public abstract class ControlSequenceOutputStream extends FilterOutputStream {
public abstract class ControlSequenceOutputStream extends OutputStream {

private OutputStream target = null;
private StringBuffer escapeSequence = new StringBuffer();
private StringBuffer targetBuffer = new StringBuffer();

private ControlSequenceFactory controlSequenceFactory = DefaultControlSequenceFactory.INSTANCE;

public ControlSequenceOutputStream(OutputStream out) {
super(out);
this.target = out;
}

public abstract void onControlSequence(ControlSequence controlSequence);
public abstract void onOutput(String string);

@Override
public void write(int i) throws IOException {
Expand All @@ -40,7 +34,7 @@ private void outputAvailable(String output) throws IOException {
if (targetBuffer.length() > 0) {
String targetString = targetBuffer.toString();
targetBuffer.setLength(0);
target.write(targetString.getBytes());
onOutput(targetString);
}
}

Expand All @@ -49,7 +43,7 @@ private void charAppended(char c) throws IOException {
if (targetBuffer.length() > 0) {
String targetString = targetBuffer.toString();
targetBuffer.setLength(0);
target.write(targetString.getBytes());
onOutput(targetString);
}
escapeSequence.append(c);
} else if (c == '[' && escapeSequence.length() == 1) {
Expand Down

0 comments on commit 607231c

Please sign in to comment.