From 63dc579b45ded75b59330e5db9e55b4040d9ad5e Mon Sep 17 00:00:00 2001 From: jruesga Date: Fri, 12 Oct 2012 02:19:52 +0200 Subject: New command: ExecCommand (for execute commands) --- .../commands/shell/AsyncResultProgram.java | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/com/cyanogenmod/explorer/commands/shell/AsyncResultProgram.java') diff --git a/src/com/cyanogenmod/explorer/commands/shell/AsyncResultProgram.java b/src/com/cyanogenmod/explorer/commands/shell/AsyncResultProgram.java index e765369a..480f7f14 100644 --- a/src/com/cyanogenmod/explorer/commands/shell/AsyncResultProgram.java +++ b/src/com/cyanogenmod/explorer/commands/shell/AsyncResultProgram.java @@ -31,12 +31,25 @@ import java.util.List; public abstract class AsyncResultProgram extends Program implements AsyncResultExecutable, AsyncResultProgramListener { + /** + * @hide + */ + static final Byte STDIN = new Byte((byte)0); + /** + * @hide + */ + static final Byte STDERR = new Byte((byte)1); + private final AsyncResultListener mAsyncResultListener; private AsyncResultProgramThread mWorkerThread; /** * @hide */ final List mPartialData; + /** + * @hide + */ + final List mPartialDataType; private final Object mSync = new Object(); /** * @hide @@ -79,6 +92,7 @@ public abstract class AsyncResultProgram super(id, prepare, args); this.mAsyncResultListener = asyncResultListener; this.mPartialData = Collections.synchronizedList(new ArrayList()); + this.mPartialDataType = Collections.synchronizedList(new ArrayList()); this.mTempBuffer = new StringBuffer(); this.mOnCancelListener = null; this.mCanceled = false; @@ -158,6 +172,35 @@ public abstract class AsyncResultProgram data = this.mTempBuffer.append(partialIn.substring(0, pos + 1)).toString(); } + this.mPartialDataType.add(STDIN); + this.mPartialData.add(data); + this.mTempBuffer = new StringBuffer(); + this.mSync.notify(); + } + } + + /** + * Method that parse the error result of a program invocation. + * + * @param partialErr A partial standard err buffer (incremental buffer) + * @hide + */ + public final void parsePartialErrResult(String partialErr) { + synchronized (this.mSync) { + String data = partialErr; + if (parseOnlyCompleteLines()) { + int pos = partialErr.lastIndexOf(FileHelper.NEWLINE); + if (pos == -1) { + //Save partial data + this.mTempBuffer.append(partialErr); + return; + } + + //Retrieve the data + data = this.mTempBuffer.append(partialErr.substring(0, pos + 1)).toString(); + } + + this.mPartialDataType.add(STDERR); this.mPartialData.add(data); this.mTempBuffer = new StringBuffer(); this.mSync.notify(); @@ -265,9 +308,14 @@ public abstract class AsyncResultProgram if (!this.mAlive) { return; } + Byte type = AsyncResultProgram.this.mPartialDataType.remove(0); String data = AsyncResultProgram.this.mPartialData.remove(0); try { - AsyncResultProgram.this.onParsePartialResult(data); + if (type.compareTo(STDIN) == 0) { + AsyncResultProgram.this.onParsePartialResult(data); + } else { + AsyncResultProgram.this.onParseErrorPartialResult(data); + } } catch (Throwable ex) { /**NON BLOCK**/ } -- cgit v1.2.3