Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14218979 authored by Roman Birg's avatar Roman Birg Committed by Matt Garnes
Browse files

Update ShellConsole to pass original bytes of output.

- Use byte buffers to back ShellConsole instead of StringBuffers.
- Allows the encoding of the output of commands to be preserved.

Change-Id: I85fa567ef589a82f1c8604f1f215647376c31c9a
(cherry picked from commit 55c55835)
(cherry picked from commit 1ba3bdce)
parent d7f0314d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1139,7 +1139,8 @@ public class EditorActivity extends Activity implements TextWatcher {
                        };

                        // Execute the command (read the file)
                        CommandHelper.read(activity, fso.getFullPath(), this.mReader, null);
                        CommandHelper.read(activity, fso.getFullPath(), this.mReader,
                                           null);

                        // Wait for
                        synchronized (this.mReader.mSync) {
+8 −9
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public abstract class AsyncResultProgram
    /**
     * @hide
     */
    final List<String> mPartialData;
    final List<byte[]> mPartialData;
    /**
     * @hide
     */
@@ -97,7 +97,7 @@ public abstract class AsyncResultProgram
        if (mAsyncResultListener instanceof ConcurrentAsyncResultListener) {
            ((ConcurrentAsyncResultListener) mAsyncResultListener).onRegister();
        }
        this.mPartialData = Collections.synchronizedList(new ArrayList<String>());
        this.mPartialData = Collections.synchronizedList(new ArrayList<byte[]>());
        this.mPartialDataType = Collections.synchronizedList(new ArrayList<Byte>());
        this.mTempBuffer = new StringBuffer();
        this.mOnCancelListener = null;
@@ -169,12 +169,12 @@ public abstract class AsyncResultProgram
    /**
     * Method that parse the result of a program invocation.
     *
     * @param partialIn A partial standard input buffer (incremental buffer)
     * @param input A partial standard input buffer (incremental buffer)
     * @hide
     */
    public final void onRequestParsePartialResult(String partialIn) {
    public final void onRequestParsePartialResult(byte[] input) {
        String partialIn = new String(input);
        synchronized (this.mSync) {
            String data = partialIn;
            String rest = ""; //$NON-NLS-1$
            if (parseOnlyCompleteLines()) {
                int pos = partialIn.lastIndexOf(FileHelper.NEWLINE);
@@ -185,12 +185,11 @@ public abstract class AsyncResultProgram
                }

                //Retrieve the data
                data = this.mTempBuffer.append(partialIn.substring(0, pos + 1)).toString();
                rest = partialIn.substring(pos + 1);
            }

            this.mPartialDataType.add(STDIN);
            this.mPartialData.add(data);
            this.mPartialData.add(input);
            this.mTempBuffer = new StringBuffer(rest);
            this.mSync.notify();
        }
@@ -220,7 +219,7 @@ public abstract class AsyncResultProgram
            }

            this.mPartialDataType.add(STDERR);
            this.mPartialData.add(data);
            this.mPartialData.add(data.getBytes());
            this.mTempBuffer = new StringBuffer(rest);
            this.mSync.notify();
        }
@@ -381,7 +380,7 @@ public abstract class AsyncResultProgram
                       AsyncResultProgram.this.mSync.wait();
                       while (AsyncResultProgram.this.mPartialData.size() > 0) {
                           Byte type = AsyncResultProgram.this.mPartialDataType.remove(0);
                           String data = AsyncResultProgram.this.mPartialData.remove(0);
                           byte[] data = AsyncResultProgram.this.mPartialData.remove(0);
                           try {
                               if (type.compareTo(STDIN) == 0) {
                                   AsyncResultProgram.this.onParsePartialResult(data);
+2 −2
Original line number Diff line number Diff line
@@ -48,12 +48,12 @@ public interface AsyncResultProgramListener {
     *
     * @param partialIn A partial standard input buffer (incremental buffer)
     */
    void onParsePartialResult(String partialIn);
    void onParsePartialResult(byte[] partialIn);

    /**
     * Method invoked when a parse of new error results are needed.
     *
     * @param partialErr A partial standard err buffer (incremental buffer)
     */
    void onParseErrorPartialResult(String partialErr);
    void onParseErrorPartialResult(byte[] partialErr);
}
+7 −6
Original line number Diff line number Diff line
@@ -89,7 +89,8 @@ public class ChecksumCommand extends AsyncResultProgram implements ChecksumExecu
     * {@inheritDoc}
     */
    @Override
    public void onParsePartialResult(final String partialIn) {
    public void onParsePartialResult(final byte[] in) {
        String partialIn = new String(in);
        if (partialIn == null || partialIn.length() == 0) return;
        boolean endsWithNewLine = partialIn.endsWith("\n"); //$NON-NLS-1$
        String[] lines = partialIn.split("\n"); //$NON-NLS-1$
@@ -126,7 +127,7 @@ public class ChecksumCommand extends AsyncResultProgram implements ChecksumExecu
     * {@inheritDoc}
     */
    @Override
    public void onParseErrorPartialResult(String partialErr) {/**NON BLOCK**/}
    public void onParseErrorPartialResult(byte[] partialErr) {/**NON BLOCK**/}

    /**
     * {@inheritDoc}
+3 −2
Original line number Diff line number Diff line
@@ -202,7 +202,8 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
     * {@inheritDoc}
     */
    @Override
    public void onParsePartialResult(final String partialIn) {
    public void onParsePartialResult(final byte[] in) {
        String partialIn = new String(in);
        if (partialIn == null || partialIn.length() ==0) return;
        boolean endsWithNewLine = partialIn.endsWith("\n"); //$NON-NLS-1$
        String[] lines = partialIn.split("\n"); //$NON-NLS-1$
@@ -240,7 +241,7 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
     * {@inheritDoc}
     */
    @Override
    public void onParseErrorPartialResult(String partialErr) {/**NON BLOCK**/}
    public void onParseErrorPartialResult(byte[] partialErr) {/**NON BLOCK**/}

    /**
     * {@inheritDoc}
Loading