Change AdbFilterInputStream.read not to wait for more data

The previous AdbFilterInputStream.read function was always waiting for
buffer to fill, even if this meant to block for a long time. Now it checks
if the next read will block. The one case it still could block, when
reading a 0xd (carriage return) is not expected to occur for interactive
output (at least as the last character of some input).
This removes the need for a separate executeShellRaw method.
This commit is contained in:
Daniel Friederich 2016-11-06 20:43:11 -06:00 committed by Samuel Carlsson
parent f8c9098a7e
commit b4f5083d00
2 changed files with 10 additions and 23 deletions

View File

@ -31,6 +31,11 @@ public class AdbFilterInputStream extends FilterInputStream {
if (b == -1) return n == 0 ? -1 : n;
buffer[offset + n] = (byte) b;
n++;
// Return as soon as no more data is available (and at least one byte was read)
if (in.available() <= 0) {
return n;
}
}
return n;
}

View File

@ -71,20 +71,15 @@ public class JadbDevice {
return state;
}
/** Execute a shell command with raw output.
/** Execute a shell command.
*
* This function differs from executeShell in that no buffering and newline filtering is performed.
*
* Especially the buffering may be an issue if the output of an ongoing command should be displayed,
* e.g. the output of running logcat.
*
* @param command main command.
* @param args arguments to the commands
* @param command main command to run. E.g. "ls"
* @param args arguments to the command.
* @return combined stdout/stderr stream.
* @throws IOException
* @throws JadbException
*/
public InputStream executeShellRaw(String command, String... args) throws IOException, JadbException {
public InputStream executeShell(String command, String... args) throws IOException, JadbException {
Transport transport = getTransport();
StringBuilder shellLine = new StringBuilder(command);
for (String arg : args) {
@ -92,20 +87,7 @@ public class JadbDevice {
shellLine.append(Bash.quote(arg));
}
send(transport, "shell:" + shellLine.toString());
return transport.getInputStream();
}
/** Execute a shell command.
*
* @param command main command.
* @param args arguments to the commands
* @return combined stdout/stderr stream.
* @throws IOException
* @throws JadbException
*/
public InputStream executeShell(String command, String... args) throws IOException, JadbException {
InputStream inputStream = executeShellRaw(command, args);
return new AdbFilterInputStream(new BufferedInputStream(inputStream));
return new AdbFilterInputStream(new BufferedInputStream(transport.getInputStream()));
}
/**