Example usage for org.apache.commons.lang3 StringUtils substringBefore

List of usage examples for org.apache.commons.lang3 StringUtils substringBefore

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringBefore.

Prototype

public static String substringBefore(final String str, final String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:com.utdallas.s3lab.smvhunter.monkey.MonkeyMe.java

/**
 * @param args//from  w ww .j a  v  a2  s. co m
 */
public static void main(String[] args) throws Exception {

    logger.info("start time ==== " + System.currentTimeMillis());

    try {
        //load the adb location from the props file
        Properties props = new Properties();
        props.load(new FileInputStream(new File("adb.props")));

        //set the adb location
        WindowUpdate.adbLocation = props.getProperty("adb_location");
        adbLocation = props.getProperty("adb_location");
        //set root dir
        ROOT_DIRECTORY = props.getProperty("root_dir");
        //completed txt
        completedFile = new File(ROOT_DIRECTORY + "tested.txt");
        //db location for static analysis
        dbLocation = props.getProperty("db_location");
        //location for smart input generation output
        smartInputLocation = props.getProperty("smart_input_location");

        //udp dump location
        udpDumpLocation = props.getProperty("udp_dump_location");
        //logcat dump location
        logCatLocation = props.getProperty("log_cat_location");
        //strace output location
        straceOutputLocation = props.getProperty("strace_output_location");
        //strace dump location
        straceDumpLocation = props.getProperty("strace_output_location");

        //set x and y coords
        UIEnumerator.screenX = props.getProperty("x");
        UIEnumerator.screenY = props.getProperty("y");

        DeviceOfflineMonitor.START_EMULATOR = props.getProperty("restart");

        //read output of static analysis
        readFromStaticAnalysisText();
        logger.info("Read static analysis output");

        readFromSmartInputText();
        logger.info("Read smart input generation output");

        //populate the queue with apps which are only present in the static analysis
        @SuppressWarnings("unchecked")
        final Set<? extends String> sslApps = new HashSet<String>(
                CollectionUtils.collect(FileUtils.readLines(new File(dbLocation)), new Transformer() {
                    @Override
                    public Object transform(Object input) {
                        //get app file name
                        String temp = StringUtils.substringBefore(input.toString(), " ");
                        return StringUtils.substringAfterLast(temp, "/");
                    }
                }));
        Collection<File> fileList = FileUtils.listFiles(new File(ROOT_DIRECTORY), new String[] { "apk" },
                false);
        CollectionUtils.filter(fileList, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                return sslApps.contains(StringUtils.substringAfterLast(object.toString(), "/"));
            }
        });
        apkQueue = new LinkedBlockingDeque<File>(fileList);

        logger.info("finished listing files from the root directory");

        try {
            //populate the tested apk list
            completedApps.addAll(FileUtils.readLines(completedFile));
        } catch (Exception e) {
            //pass except
            logger.info("No tested.txt file found");

            //create new file
            if (completedFile.createNewFile()) {
                logger.info("tested.txt created in root directory");
            } else {
                logger.info("tested.txt file could not be created");
            }

        }

        //get the executors for managing the emulators
        executors = Executors.newCachedThreadPool();

        //set the devicemonitor exec
        DeviceOfflineMonitor.exec = executors;

        final List<Future<?>> futureList = new ArrayList<Future<?>>();

        //start the offline device monitor (emulator management thread)
        logger.info("Starting Device Offline Monitor Thread");
        executors.submit(new DeviceOfflineMonitor());

        //get ADB backend object for device change listener
        AdbBackend adb = new AdbBackend();

        //register for device change and wait for events
        //once event is received, start the MonkeyMe thread
        MonkeyDeviceChangeListener deviceChangeListener = new MonkeyDeviceChangeListener(executors, futureList);
        AndroidDebugBridge.addDeviceChangeListener(deviceChangeListener);
        logger.info("Listening to changes in devices (emulators)");

        //wait for the latch to come down
        //this means that all the apks have been processed
        cdl.await();

        logger.info("Finished testing all apps waiting for threads to join");

        //now wait for every thread to finish
        for (Future<?> future : futureList) {
            future.get();
        }

        logger.info("All threads terminated");

        //stop listening for device update
        AndroidDebugBridge.removeDeviceChangeListener(deviceChangeListener);

        //stop the debug bridge
        AndroidDebugBridge.terminate();

        //stop offline device monitor
        DeviceOfflineMonitor.stop = true;

        logger.info("adb and listeners terminated");

    } finally {
        logger.info("Executing this finally");
        executors.shutdownNow();
    }

    logger.info("THE END!!");
}

From source file:com.google.dart.ui.test.matchers.HasTextWidgetMatcher.java

/**
 * Normalizes given {@link String} by removing special characters.
 */// w  ww  . j a v a  2 s.co  m
private static String normalizeWidgetText(String s) {
    s = s.trim();
    s = StringUtils.remove(s, '&');
    s = StringUtils.substringBefore(s, "\t");
    return s;
}

From source file:com.thinkbiganalytics.support.FeedNameUtil.java

/**
 * Parse the category name from a full feed name  (category.feed)
 *//*from  ww  w  .java2  s  .com*/
public static String category(String name) {
    return StringUtils.trim(StringUtils.substringBefore(name, "."));
}

From source file:com.neatresults.mgnltweaks.NeatUtil.java

public static String templateIdToPath(String templateId) {
    if (StringUtils.contains(templateId, ":")) {
        return "/modules/" + StringUtils.substringBefore(templateId, ":") + "/templates/"
                + StringUtils.substringAfter(templateId, ":");
    }//w ww  .j av a2s .c om
    return null;
}

From source file:keepinchecker.network.PacketParser.java

public static String parse(String keyword, String packet) {
    String value = "";

    if (!StringUtils.contains(packet, keyword)) {
        return value;
    }/*  w  w  w .  j ava2 s  .  c  om*/

    String[] packetSplitOnNewline = packet.split("\n");
    for (String line : packetSplitOnNewline) {
        if (StringUtils.equals(keyword, GET) && StringUtils.contains(line, keyword)) {
            value = StringUtils.substringBefore(line.split(keyword)[1], "HTTP");
            break;
        } else if ((StringUtils.contains(line, HOST) || StringUtils.contains(line, REFERER))
                && StringUtils.contains(line, keyword)) {
            value = line.split(keyword + ":")[1];
            break;
        }
    }

    return value.trim();
}

From source file:io.cloudslang.lang.compiler.modeller.TransformersHandler.java

public static String keyToTransform(Transformer transformer) {
    String key;//  w ww  .  j  av  a 2 s.  c  o m
    if (transformer.keyToTransform() != null) {
        key = transformer.keyToTransform();
    } else {
        String simpleClassName = transformer.getClass().getSimpleName();
        key = StringUtils.substringBefore(simpleClassName, Transformer.class.getSimpleName());
    }
    return key.toLowerCase();
}

From source file:com.threewks.thundr.gae.GaeEnvironment.java

/**
 * @return The application version deployed to. In dev server, returns an empty string
 *///from w ww. j a  va 2 s .c om
public static String applicationVersion() {
    // The version identifier for the current application version.
    // Result is of the form <major>.<minor> where <major> is the version name supplied at deploy time
    // and <minor> is a timestamp value maintained by App Engine
    String fullApplicationVersion = SystemProperty.applicationVersion.get();
    return isProduction() ? StringUtils.substringBefore(fullApplicationVersion, ".") : StringPool.EMPTY;
}

From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java

/**
 * Parse a timer string to a Joda time period
 *
 * @param timer      a string indicating a time unit (i.e. 5 sec)
 * @param periodType the Period unit to use.
 */// ww  w  .  java 2s. c o  m
public static Period timerStringToPeriod(String timer, PeriodType periodType) {
    String cronString = null;
    Integer time = Integer.parseInt(StringUtils.substringBefore(timer, " "));
    String units = StringUtils.substringAfter(timer, " ").toLowerCase();
    //time to years,days,months,hours,min, sec
    Integer days = 0;
    Integer hours = 0;
    Integer min = 0;
    Integer sec = 0;
    Period p = null;
    if (units.startsWith("sec")) {
        p = Period.seconds(time);
    } else if (units.startsWith("min")) {
        p = Period.minutes(time);
    } else if (units.startsWith("hr") || units.startsWith("hour")) {
        p = Period.hours(time);
    } else if (units.startsWith("day")) {
        p = Period.days(time);
    }
    if (periodType != null) {
        p = p.normalizedStandard(periodType);
    } else {
    }
    return p;
}

From source file:io.wcm.devops.conga.model.util.MapExpander.java

/**
 * Get object from map with "deep" access resolving dots in the key as nested map keys.
 * @param map Map/*from   w w w .ja  v  a 2  s. c o m*/
 * @param key Key with dots
 * @return Value or null
 */
@SuppressWarnings("unchecked")
public static Object getDeep(Map<String, Object> map, String key) {
    if (map.containsKey(key)) {
        return ObjectUtils.defaultIfNull(map.get(key), "");
    }
    if (StringUtils.contains(key, ".")) {
        String keyPart = StringUtils.substringBefore(key, ".");
        String keySuffix = StringUtils.substringAfter(key, ".");
        Object resultKeyPart = map.get(keyPart);
        if (resultKeyPart != null && resultKeyPart instanceof Map) {
            return getDeep((Map<String, Object>) resultKeyPart, keySuffix);
        }
    }
    return null;
}

From source file:com.thinkbiganalytics.servicemonitor.support.ServiceMonitorCheckUtil.java

/**
 * get all the services names as a list/* w w w  . j  a va 2 s.c  om*/
 */
public static List<String> getServiceNames(String services) {
    List<String> list = new ArrayList<>();
    for (String service : StringUtils.split(services, ",")) {
        String serviceName = service;
        if (service.contains("/")) {
            serviceName = StringUtils.substringBefore(serviceName, "/");
        }
        list.add(serviceName);
    }
    return list;
}