mirror of
https://github.com/revanced/jadb.git
synced 2025-04-30 06:34:39 +02:00
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:
parent
f8c9098a7e
commit
b4f5083d00
@ -31,6 +31,11 @@ public class AdbFilterInputStream extends FilterInputStream {
|
|||||||
if (b == -1) return n == 0 ? -1 : n;
|
if (b == -1) return n == 0 ? -1 : n;
|
||||||
buffer[offset + n] = (byte) b;
|
buffer[offset + n] = (byte) b;
|
||||||
n++;
|
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;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -71,20 +71,15 @@ public class JadbDevice {
|
|||||||
return state;
|
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.
|
* @param command main command to run. E.g. "ls"
|
||||||
*
|
* @param args arguments to the command.
|
||||||
* 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
|
|
||||||
* @return combined stdout/stderr stream.
|
* @return combined stdout/stderr stream.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws JadbException
|
* @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();
|
Transport transport = getTransport();
|
||||||
StringBuilder shellLine = new StringBuilder(command);
|
StringBuilder shellLine = new StringBuilder(command);
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
@ -92,20 +87,7 @@ public class JadbDevice {
|
|||||||
shellLine.append(Bash.quote(arg));
|
shellLine.append(Bash.quote(arg));
|
||||||
}
|
}
|
||||||
send(transport, "shell:" + shellLine.toString());
|
send(transport, "shell:" + shellLine.toString());
|
||||||
return transport.getInputStream();
|
return new AdbFilterInputStream(new BufferedInputStream(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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user