Author: koen.aers(a)jboss.com
Date: 2011-07-28 03:53:13 -0400 (Thu, 28 Jul 2011)
New Revision: 33297
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeHiddenOutputFilter.java
Log:
Hidden output is now marked with "^[%" at beginning and end.
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeHiddenOutputFilter.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeHiddenOutputFilter.java 2011-07-28
07:51:54 UTC (rev 33296)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeHiddenOutputFilter.java 2011-07-28
07:53:13 UTC (rev 33297)
@@ -2,44 +2,98 @@
public class ForgeHiddenOutputFilter implements ForgeOutputListener {
- private static final String ESCAPE_SEQUENCE = new String(new char[] { 27, '[',
'%' });
-
private ForgeOutputListener target = null;
private boolean hidden = false;
- private StringBuffer hiddenOutput = new StringBuffer();
+ private StringBuffer hiddenBuffer = new StringBuffer();
+ private StringBuffer targetBuffer = new StringBuffer();
+ private StringBuffer escapeSequence = new StringBuffer();
public ForgeHiddenOutputFilter(ForgeOutputListener target) {
this.target = target;
}
-
+
@Override
public void outputAvailable(String output) {
- System.out.println("ForgeHiddenOutputListener->outputAvailable: " +
output);
- int i = output.indexOf(ESCAPE_SEQUENCE);
- if (i != -1) {
- if (hidden) {
- hiddenOutput.append(output.substring(0, i));
- handleHiddenOutput(hiddenOutput);
+ for (int i = 0; i < output.length(); i++) {
+ char c = output.charAt(i);
+ if (c == 27) {
+ if (escapeSequence.length() == 0) {
+ escapeSequence.append(c);
+ } else {
+ escapeSequence.append(c);
+ if (hidden) {
+ hiddenBuffer.append(escapeSequence);
+ } else {
+ targetBuffer.append(escapeSequence);
+ }
+ escapeSequence.setLength(0);
+ }
+ } else if (c == '[') {
+ if (escapeSequence.length() == 1) {
+ escapeSequence.append(c);
+ } else {
+ escapeSequence.append(c);
+ if (hidden) {
+ hiddenBuffer.append(escapeSequence);
+ } else {
+ targetBuffer.append(escapeSequence);
+ }
+ escapeSequence.setLength(0);
+ }
+ } else if (c == '%') {
+ if (escapeSequence.length() == 2) {
+ if (hidden) {
+ handleHiddenOutput(hiddenBuffer);
+ hiddenBuffer.setLength(0);
+ } else {
+ String out = targetBuffer.toString();
+ targetBuffer.setLength(0);
+ target.outputAvailable(out);
+ }
+ escapeSequence.setLength(0);
+ hidden = !hidden;
+ } else {
+ escapeSequence.append(c);
+ if (hidden) {
+// appendToHiddenBuffer(escapeSequence);
+ hiddenBuffer.append(escapeSequence);
+ } else {
+// appendToTargetBuffer(escapeSequence);
+ targetBuffer.append(escapeSequence);
+ }
+ escapeSequence.setLength(0);
+ }
} else {
- target.outputAvailable(output.substring(0, i));
- hidden = true;
+ escapeSequence.append(c);
+ if (hidden) {
+// appendToHiddenBuffer(escapeSequence);
+ hiddenBuffer.append(escapeSequence);
+ } else {
+// appendToTargetBuffer(escapeSequence);
+ targetBuffer.append(escapeSequence);
+ }
+ escapeSequence.setLength(0);
}
- if (output.length() > i + 3) {
- outputAvailable(output.substring(i + 3));
- }
- } else {
- if (hidden) {
- hiddenOutput.append(output);
- } else {
- target.outputAvailable(output);
- }
}
+ if (hiddenBuffer.length() == 0 && targetBuffer.length() != 0) {
+ String out = targetBuffer.toString();
+ targetBuffer.setLength(0);
+ target.outputAvailable(out);
+ }
+
}
private void handleHiddenOutput(StringBuffer output) {
- System.out.println(output.toString());
- output.setLength(0);
- hidden = false;
+ System.out.println("handleHiddenOutput : " + output.toString());
}
+
+ private void appendToTargetBuffer(StringBuffer buffer) {
+ System.out.println("appendToTargetBuffer : " + buffer);
+ targetBuffer.append(buffer);
+ }
+
+ private void appendToHiddenBuffer(StringBuffer buffer) {
+ System.out.println("appendToHiddenBuffer : " + buffer);
+ }
}
Show replies by date