Search in sources :

Example 11 with BrutException

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);
    }
}
Also used : BrutException(brut.common.BrutException) HashMap(java.util.HashMap)

Example 12 with BrutException

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);
        }
    }
}
Also used : BrutException(brut.common.BrutException)

Example 13 with BrutException

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);
    }
}
Also used : BrutException(brut.common.BrutException)

Aggregations

BrutException (brut.common.BrutException)13 ExtFile (brut.directory.ExtFile)8 ZipFile (java.util.zip.ZipFile)5 AndrolibException (brut.androlib.AndrolibException)2 File (java.io.File)2 SAXException (org.xml.sax.SAXException)2 InFileNotFoundException (brut.androlib.err.InFileNotFoundException)1 OutDirExistsException (brut.androlib.err.OutDirExistsException)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1