use of brut.common.BrutException in project Apktool by iBotPeaches.
the class TestUtils method parseStringsXml.
public static Map<String, String> parseStringsXml(File file) throws BrutException {
try {
XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
xpp.setInput(new FileReader(file));
int eventType;
String key = null;
Map<String, String> map = new HashMap<String, String>();
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
switch(eventType) {
case XmlPullParser.START_TAG:
if ("string".equals(xpp.getName())) {
int attrCount = xpp.getAttributeCount();
for (int i = 0; i < attrCount; i++) {
if ("name".equals(xpp.getAttributeName(i))) {
key = xpp.getAttributeValue(i);
break;
}
}
}
break;
case XmlPullParser.END_TAG:
if ("string".equals(xpp.getName())) {
key = null;
}
break;
case XmlPullParser.TEXT:
if (key != null) {
map.put(key, xpp.getText());
}
break;
}
}
return map;
} catch (IOException ex) {
throw new BrutException(ex);
} catch (XmlPullParserException ex) {
throw new BrutException(ex);
}
}
use of brut.common.BrutException in project Apktool by iBotPeaches.
the class OS method cpdir.
public static void cpdir(File src, File dest) throws BrutException {
dest.mkdirs();
File[] files = src.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
File destFile = new File(dest.getPath() + File.separatorChar + file.getName());
if (file.isDirectory()) {
cpdir(file, destFile);
continue;
}
try {
InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFile);
IOUtils.copy(in, out);
in.close();
out.close();
} catch (IOException ex) {
throw new BrutException("Could not copy file: " + file, ex);
}
}
}
use of brut.common.BrutException in project Apktool by iBotPeaches.
the class OS method exec.
public static void exec(String[] cmd) throws BrutException {
Process ps = null;
int exitValue = -99;
try {
ProcessBuilder builder = new ProcessBuilder(cmd);
ps = builder.start();
new StreamForwarder(ps.getErrorStream(), "ERROR").start();
new StreamForwarder(ps.getInputStream(), "OUTPUT").start();
exitValue = ps.waitFor();
if (exitValue != 0)
throw new BrutException("could not exec (exit code = " + exitValue + "): " + Arrays.toString(cmd));
} catch (IOException ex) {
throw new BrutException("could not exec: " + Arrays.toString(cmd), ex);
} catch (InterruptedException ex) {
throw new BrutException("could not exec : " + Arrays.toString(cmd), ex);
}
}
Aggregations