Example usage for org.apache.commons.io LineIterator nextLine

List of usage examples for org.apache.commons.io LineIterator nextLine

Introduction

In this page you can find the example usage for org.apache.commons.io LineIterator nextLine.

Prototype

public String nextLine() 

Source Link

Document

Returns the next line in the wrapped Reader.

Usage

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static StringBuilder readDump(String serial, String dumpPath, StringBuilder hierarchy) {
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_cat", new String[] { dumpPath }), false, 3 * 1000);

    if (executorMap.isEmpty()) {
        return new StringBuilder();
    }//from w ww.j a va 2s  .  co m
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    while (li != null && li.hasNext()) {
        hierarchy.append(li.nextLine().trim());
    }

    Utils.destoryExecutor(executorMap.get("executor"));
    return hierarchy;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static String startActivity(List<String> serial, String activity, int timeoutSecond) {
    String rtnStr = "";
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        cmdList.add(AdbShellCommand.cmd(s, "cmd_start_activity", new String[] { activity }));
    }/*from   ww  w. j a v a 2 s. c om*/
    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            rtnStr = li.nextLine();
        }
    }
    return rtnStr;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static String getTopActivity(String serial) {
    String rtnValue = "";
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_dumpsys_activity_top"), false, Settings.EXECUTOR_TIMEOUT);

    if (executorMap.isEmpty()) {
        return rtnValue;
    }//from   w ww  .ja v  a2s . c  om
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    while (li != null && li.hasNext()) {
        String output = li.nextLine();
        if (output.contains("ACTIVITY")) {
            rtnValue = output.trim().split(" ")[1];
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return rtnValue;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static String clearAppData(List<String> serial, String pkgName, int timeoutSecond) {
    String rtnStr = "";
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        cmdList.add(AdbShellCommand.cmd(s, "cmd_clear_app_data", new String[] { pkgName }));
    }//from   w  w w. j  a v a  2s . c  om
    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            String device = li.nextLine();
            if (device.contains("Success")) {
                rtnStr = pkgName + " is cleared on " + serial + " device";
            }
        }
    }
    return rtnStr;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static String installApp(List<String> serial, boolean isReinstall, String apkPath, int timeoutSecond) {
    String rtnStr = "";
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        if (isReinstall) {
            cmdList.add(AdbShellCommand.cmd(s, "cmd_reinstall_app", new String[] { apkPath }));
        } else {/*from www  . jav  a  2s  .  c o  m*/
            cmdList.add(AdbShellCommand.cmd(s, "cmd_install_app", new String[] { apkPath }));
        }
    }
    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            String output = li.nextLine();
            if (output.contains("Success")) {
                rtnStr = (new File(apkPath).getName() + " is successfully installed on " + serial + " device");
            }
            if (output.contains("Failure")) {
                rtnStr = ("Fail to install on " + serial + " device (" + output + ")");
            }
        }
    }
    return rtnStr;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static List<String> unInstallApp(List<String> serial, boolean keepData, String pkgName,
        int timeoutSecond) {
    List<String> rtnStr = new ArrayList<String>();
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        if (keepData) {
            cmdList.add(AdbShellCommand.cmd(s, "cmd_uninstall_app_keep_data", new String[] { pkgName }));
        } else {/*from  ww  w  .ja va  2 s.c  o m*/
            cmdList.add(AdbShellCommand.cmd(s, "cmd_uninstall_app", new String[] { pkgName }));
        }
    }

    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            String device = li.nextLine();
            if (device.contains("Success")) {
                rtnStr.add(pkgName + " is successfully uninstalled on " + serial + " device");
            }
            if (device.contains("Failure")) {
                rtnStr.add("Fail to uninstalled on " + serial + " device");
            }
        }
    }
    return rtnStr;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

/**
 * Leader ?? 3rd party? package? ? ? MainActivity ??
 * /*from  w  w w . j a  v a 2  s .co  m*/
 * @param serial
 * @param pkgName
 * @return
 */
public static String getMainActivity(String serial, String pkgName) {
    String laucherActivity = "";
    Map<String, Object> executorMap = new AdbShellExecutor().execute(
            AdbShellCommand.cmd(serial, "cmd_dumpsys_package", new String[] { pkgName }), false,
            Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return "";
    }
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    boolean flag = false;
    while (li != null && li.hasNext()) {
        String str = li.nextLine().trim();
        if (str.contains("android.intent.action.MAIN:"))
            flag = true;
        // if(flag && str.contains("filter")){
        if (flag && (!str.isEmpty() && str.split(" ").length > 1)) {
            laucherActivity = str.split(" ")[1];
            flag = false;
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return laucherActivity;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static Map<String, String> getCurrentActivity(String serial) {
    Map<String, String> currentActivity = new HashMap<String, String>();
    String activityName = "";
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_dumpsys_activity_top"), false, Settings.EXECUTOR_TIMEOUT);

    if (executorMap.isEmpty()) {
        return currentActivity;
    }/*from  w  w  w.  j  a  v  a2s. com*/
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    boolean isHierarchyInfo = false;
    StringBuilder sb = new StringBuilder();

    while (li != null && li.hasNext()) {
        String output = li.nextLine();
        if (output.contains("ACTIVITY")) {
            activityName = output.trim().split(" ")[1];
        }
        if (output.contains("Looper"))
            isHierarchyInfo = false;
        if (isHierarchyInfo) {
            output = output.split("\\{")[0].trim();
            if (!output.isEmpty())
                sb.append(output + "\n");
        }
        if (output.contains("View Hierarchy"))
            isHierarchyInfo = true;
    }
    currentActivity.put(activityName, sb.toString());
    Utils.destoryExecutor(executorMap.get("executor"));
    return currentActivity;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

/**
 * Dumpsys Input Diagnostics  ? ? ?? ??   . 1) Touch Screen?
 * width height 2) Touch Screen? Scaling Factors - XScale, YScale 3)
 * SurfaceOrientation? ?  ? Orientation  4) FocusedWindow? ? 
 * ? Activity /*from  w ww . j  av a2s  . co  m*/
 * 
 * @see <a href="https://source.android.com/devices/input/diagnostics.html">
 *      Dumpsys Input Diagnostics</a>
 * @param serial
 * @return
 */

public static Map<String, Object> getInputManager(String serial) {
    Map<String, Object> rtnValue = new HashMap<String, Object>();
    final String activity_regex = "((\\S+)/(\\S+))[\\s|\\}]";
    final String dispaly_regex = "[X|Y]: min=\\d, max=(\\d+),";
    final String orientation_regex = "(\\d)";
    final String scaling_regex = "[X|Y]Scale:\\s(.*)";
    //final String touchscreen_regex = "Device\\s\\d+:\\s(\\S+)";
    final String touchscreen_regex = "DeviceType: touchScreen";
    final String pointerVelocityControlParameters_regex = "PointerVelocityControlParameters:\\s(.*)";
    final String tabInterval_regex = "TapInterval:\\s(.*)ms";
    final String tapDragInterval_regex = "TapDragInterval:\\s(.*)ms";
    final String multitouchSettleInterval_regex = "MultitouchSettleInterval:\\s(.*)ms";
    final String swipeMaxWidthRatio_regex = "SwipeMaxWidthRatio:\\s(.*)";
    final String movementSpeedRatio_regex = "MovementSpeedRatio:\\s(.*)";
    final String zoomSpeedRatio_regex = "ZoomSpeedRatio:\\s(.*)";
    final String velocity_scale_regex = "scale=(.*), lowThreshold";
    final String velocity_lowThreshold_regex = "lowThreshold=(.*), highThreshold";
    final String velocity_highThreshold_regex = "highThreshold=(.*), acceleration";
    final String velocity_acceleration_regex = "acceleration=(.*)";

    boolean isTouchScreen = false;

    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_dumpsys_input"), false, Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return null;
    }
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    while (li.hasNext()) {
        String output = li.nextLine().trim();
        if (output.contains(touchscreen_regex)) {
            isTouchScreen = true;
        }
        if (isTouchScreen && output.contains("Last Cooked Touch")) {
            isTouchScreen = false;
        }
        if (isTouchScreen && output.contains("X: min=0, max=")) {
            if (!rtnValue.containsKey("width"))
                rtnValue.put("width", (Integer.valueOf(Utils.convertRegex(dispaly_regex, output, 1)) + 1) + "");
        }
        if (isTouchScreen && output.contains("Y: min=0, max=")) {
            if (!rtnValue.containsKey("height"))
                rtnValue.put("height",
                        (Integer.valueOf(Utils.convertRegex(dispaly_regex, output, 1)) + 1) + "");
        }
        if (isTouchScreen && output.contains("XScale:") && !output.contains("TiltXScale")) {
            if (!rtnValue.containsKey("xScale"))
                rtnValue.put("xScale", Utils.convertRegex(scaling_regex, output, 1));
        }
        if (isTouchScreen && output.contains("YScale:") && !output.contains("TiltYScale")) {
            if (!rtnValue.containsKey("yScale"))
                rtnValue.put("yScale", Utils.convertRegex(scaling_regex, output, 1));
        }
        if (output.contains("SwipeMaxWidthRatio")) {
            if (!rtnValue.containsKey("SwipeMaxWidthRatio")) {
                log.info("width  : " + String.valueOf(rtnValue.get("width")) + " height : "
                        + String.valueOf(rtnValue.get("height")));
                String swipeMaxWidthRatio = Utils.convertRegex(swipeMaxWidthRatio_regex, output, 1);
                Integer width = Integer.valueOf((String) rtnValue.get("width"));
                Integer height = Integer.valueOf((String) rtnValue.get("height"));
                //Double swipe_distance = (Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) * Double.valueOf(swipeMaxWidthRatio));
                Double swipe_distance = (Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2))
                        * Double.valueOf(swipeMaxWidthRatio));
                Settings.SWIPE_AREA_THRESHOLD = swipe_distance.intValue();
            }
        }
        if (output.contains("SurfaceOrientation:"))
            DataQueue.CURRENT_ORIENTATION = Integer.valueOf(Utils.convertRegex(orientation_regex, output, 1));
        /*         
         *          String output = li.nextLine().trim();
                 if (output.contains("TOUCH_MAJOR"))
                    isTouchScreen = true;
                 if (isTouchScreen && output.contains("Input Dispatcher State:"))
                    isTouchScreen = false;
                 if (isTouchScreen && output.contains("X: min=0, max=")) {
                    if (!rtnValue.containsKey("width"))
                       rtnValue.put("width", (Integer.valueOf(Utils.convertRegex(dispaly_regex, output, 1)) + 1) + "");
                 }
                 if (isTouchScreen && output.contains("Y: min=0, max=")) {
                    if (!rtnValue.containsKey("height"))
                       rtnValue.put("height", (Integer.valueOf(Utils.convertRegex(dispaly_regex, output, 1)) + 1) + "");
                 }
                 if (isTouchScreen && output.contains("XScale:") && !output.contains("TiltXScale")) {
                    if (!rtnValue.containsKey("xScale"))
                       rtnValue.put("xScale", Utils.convertRegex(scaling_regex, output, 1));
                 }
                 if (isTouchScreen && output.contains("YScale:") && !output.contains("TiltYScale")) {
                    if (!rtnValue.containsKey("yScale"))
                       rtnValue.put("yScale", Utils.convertRegex(scaling_regex, output, 1));
                 }
                
                 if (isTouchScreen && output.contains("PointerVelocityControlParameters")) {
                    if (!rtnValue.containsKey("pointerVelocityControlParameters")){
                
                       String velocityInfo = Utils.convertRegex(pointerVelocityControlParameters_regex, output, 1);
                       Map<String,String> detailInfo = new HashMap<String,String>();
                       detailInfo.put("scale", Utils.convertRegex(velocity_scale_regex, velocityInfo, 1));
                       detailInfo.put("lowThreshold", Utils.convertRegex(velocity_lowThreshold_regex, velocityInfo, 1));
                       detailInfo.put("highThreshold", Utils.convertRegex(velocity_highThreshold_regex, velocityInfo, 1));
                       detailInfo.put("acceleration", Utils.convertRegex(velocity_acceleration_regex, velocityInfo, 1));
                       rtnValue.put("pointerVelocityControlParameters",detailInfo);
                    }
                 }
                 if (isTouchScreen && output.contains("TapInterval")) {
                    if (!rtnValue.containsKey("tapInterval"))
                       rtnValue.put("tapInterval", Utils.convertRegex(tabInterval_regex, output, 1));
                
                 }
                 if (isTouchScreen && output.contains("TapDragInterval")) {
                    if (!rtnValue.containsKey("tapDragInterval"))
                       rtnValue.put("tapDragInterval", Utils.convertRegex(tapDragInterval_regex, output, 1));
                
                 }
                 if (isTouchScreen && output.contains("MultitouchSettleInterval")) {
                    if (!rtnValue.containsKey("multitouchSettleInterval"))
                       rtnValue.put("multitouchSettleInterval",
             Utils.convertRegex(multitouchSettleInterval_regex, output, 1));
                 }
                 if (isTouchScreen && output.contains("SwipeMaxWidthRatio")) {
                    if (!rtnValue.containsKey("swipeMaxWidthRatio"))
                       rtnValue.put("swipeMaxWidthRatio", Utils.convertRegex(swipeMaxWidthRatio_regex, output, 1));
                 }
                 if (isTouchScreen && output.contains("MovementSpeedRatio")) {
                    if (!rtnValue.containsKey("movementSpeedRatio"))
                       rtnValue.put("movementSpeedRatio", Utils.convertRegex(movementSpeedRatio_regex, output, 1));
                 }
                 if (isTouchScreen && output.contains("ZoomSpeedRatio")) {
                    if (!rtnValue.containsKey("zoomSpeedRatio"))
                       rtnValue.put("zoomSpeedRatio", Utils.convertRegex(zoomSpeedRatio_regex, output, 1));
                 }*/

        if (output.contains("SurfaceOrientation:"))
            DataQueue.CURRENT_ORIENTATION = Integer.valueOf(Utils.convertRegex(orientation_regex, output, 1));
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return rtnValue;
}

From source file:io.hops.hopsworks.common.util.HopsUtils.java

/**
 * Read blacklisted Spark properties from file
 * @return Blacklisted Spark properties/*from w w  w. ja  v  a2s  . c  om*/
 * @throws IOException
 */
private static Set<String> readBlacklistedSparkProperties(String sparkDir) throws IOException {
    File sparkBlacklistFile = Paths.get(sparkDir, Settings.SPARK_BLACKLISTED_PROPS).toFile();
    LineIterator lineIterator = FileUtils.lineIterator(sparkBlacklistFile);
    Set<String> blacklistedProps = new HashSet<>();
    try {
        while (lineIterator.hasNext()) {
            String line = lineIterator.nextLine();
            if (!line.startsWith("#")) {
                blacklistedProps.add(line);
            }
        }
        return blacklistedProps;
    } finally {
        LineIterator.closeQuietly(lineIterator);
    }
}