public void buildNonDefaultSources(ExtFile appDir) throws AndrolibException {
    try {
      Map<String, Directory> dirs = appDir.getDirectory().getDirs();
      for (Map.Entry<String, Directory> directory : dirs.entrySet()) {
        String name = directory.getKey();
        if (name.startsWith("smali_")) {
          String filename = name.substring(name.indexOf("_") + 1) + ".dex";

          if (!buildSourcesRaw(appDir, filename)
              && !buildSourcesSmali(appDir, name, filename)
              && !buildSourcesJava(appDir)) {
            LOGGER.warning("Could not find sources");
          }
        }
      }
    } catch (DirectoryException ex) {
      throw new AndrolibException(ex);
    }
  }
  public void buildUnknownFiles(File appDir, File outFile, Map<String, Object> meta)
      throws AndrolibException {
    File file;
    Path globalPath = Paths.get(appDir.getPath() + File.separatorChar + UNK_DIRNAME);

    if (meta.containsKey("unknownFiles")) {
      LOGGER.info("Copying unknown files/dir...");

      Map<String, String> files = (Map<String, String>) meta.get("unknownFiles");

      try {
        // set our filesystem options
        Map<String, String> zip_properties = new HashMap<>();
        zip_properties.put("create", "false");
        zip_properties.put("encoding", "UTF-8");

        // create filesystem
        Path path = Paths.get(outFile.getAbsolutePath());

        // loop through files inside
        for (Map.Entry<String, String> entry : files.entrySet()) {

          file = new File(globalPath.toFile(), entry.getKey());
          if (file.isFile() && file.exists()) {
            insertFolder(
                path,
                zip_properties,
                file.getParentFile(),
                entry.getValue(),
                globalPath.toAbsolutePath());

            insertFile(path, zip_properties, file, entry.getValue(), globalPath.toAbsolutePath());
          }
        }
      } catch (IOException ex) {
        throw new AndrolibException(ex);
      }
    }
  }
示例#3
0
  public static String doPost(String urlString, Map<Object, Object> nameValuePairs)
      throws IOException {
    URL url = new URL(urlString);
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    String encoding = connection.getContentEncoding();
    if (encoding == null) encoding = "ISO-8859-1";

    try (PrintWriter out = new PrintWriter(connection.getOutputStream())) {
      boolean first = true;
      for (Map.Entry<Object, Object> pair : nameValuePairs.entrySet()) {
        if (first) first = false;
        else out.print('&');
        String name = pair.getKey().toString();
        String value = pair.getValue().toString();
        out.print(name);
        out.print('=');
        out.print(URLEncoder.encode(value, encoding));
      }
    }

    StringBuilder response = new StringBuilder();
    try (Scanner in = new Scanner(connection.getInputStream(), encoding)) {
      while (in.hasNextLine()) {
        response.append(in.nextLine());
        response.append("\n");
      }
    } catch (IOException e) {
      if (!(connection instanceof HttpURLConnection)) throw e;
      InputStream err = ((HttpURLConnection) connection).getErrorStream();
      if (err == null) throw e;
      Scanner in = new Scanner(err);
      response.append(in.nextLine());
      response.append("\n");
    }

    return response.toString();
  }