mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-19 08:17:35 +01:00
aapt2: new method to execAndReturn to collect stdout from a process
This commit is contained in:
parent
f5caccbc2e
commit
574de8db71
@ -19,6 +19,8 @@ package brut.util;
|
|||||||
import brut.common.BrutException;
|
import brut.common.BrutException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -100,6 +102,23 @@ public class OS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String execAndReturn(String[] cmd) {
|
||||||
|
ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
try {
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||||
|
builder.redirectErrorStream(true);
|
||||||
|
|
||||||
|
Process process = builder.start();
|
||||||
|
StreamCollector collector = new StreamCollector(process.getInputStream());
|
||||||
|
executor.execute(collector);
|
||||||
|
|
||||||
|
process.waitFor();
|
||||||
|
return collector.get();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static File createTempDirectory() throws BrutException {
|
public static File createTempDirectory() throws BrutException {
|
||||||
try {
|
try {
|
||||||
File tmp = File.createTempFile("BRUT", null);
|
File tmp = File.createTempFile("BRUT", null);
|
||||||
@ -142,4 +161,37 @@ public class OS {
|
|||||||
private final InputStream mIn;
|
private final InputStream mIn;
|
||||||
private final String mType;
|
private final String mType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class StreamCollector implements Runnable {
|
||||||
|
private final StringBuffer buffer = new StringBuffer();
|
||||||
|
private final InputStream inputStream;
|
||||||
|
|
||||||
|
public StreamCollector(InputStream inputStream) {
|
||||||
|
super();
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
String line;
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
buffer.append(line).append('\n');
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println(e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get() {
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user