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

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

Introduction

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

Prototype

public static String trim(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null .

The String is trimmed using String#trim() .

Usage

From source file:by.lang.StringUtilsTest.java

public static void main(String[] args) {
    System.out.println("?,....");
    System.out.println(StringUtils.abbreviate("The quick brown fox jumps over the lazy dog.", 10));

    System.out.println(".");
    System.out.println(StringUtils.chomp("1,2,3,", ","));

    System.out.println("???.");
    System.out.println(StringUtils.contains("defg", "ef"));
    System.out.println(StringUtils.contains("ef", "defg"));

    System.out.println("??nulltoString().");
    System.out.println(StringUtils.defaultString(null, "defaultIfEmpty"));
    System.out.println(".");
    System.out.println(StringUtils.deleteWhitespace("aa  bb  cc"));

    System.out.println("??.");
    System.out.println(StringUtils.isAlpha("ab"));
    System.out.println(StringUtils.isAlphanumeric("12"));
    System.out.println(StringUtils.isBlank(""));
    System.out.println(StringUtils.isNumeric("123"));

    System.out.println("?Null  \"\"");
    System.out.println(StringUtils.isEmpty(null));
    System.out.println(StringUtils.isNotEmpty(null));
    System.out.println("?null  \"\" ");
    System.out.println(StringUtils.isBlank("  "));
    System.out.println(StringUtils.isNotBlank(null));
    System.out.println(".Nullnull");
    System.out.println(StringUtils.trim(null));
    System.out.println("Null\"\" ?Null");
    System.out.println(StringUtils.trimToNull(""));
    // NULL  "" ?""
    // System.out.println(StringUtils.trimToEmpty(null));
    // ??/*w  ww.j a  va2s  .  c  om*/
    // System.out.println(StringUtils.strip("  \t"));
    // ?""null?Null
    // System.out.println(StringUtils.stripToNull(" \t"));
    // ?""null?""
    // System.out.println(StringUtils.stripToEmpty(null));
    // ""Null ? ""
    // System.out.println(StringUtils.defaultString(null));
    // Null ?(?)
    // System.out.println(StringUtils.defaultString("", "df"));
    // null""?(?)
    // System.out.println(StringUtils.defaultIfEmpty(null, "sos"));
    // .~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?null(?2?)
    // System.out.println(StringUtils.strip("fsfsdf", "f"));
    // ?null???(????)
    // System.out.println(StringUtils.stripStart("ddsuuu ", "d"));
    // ?null???(????)
    // System.out.println(StringUtils.stripEnd("dabads", "das"));
    // 
    // ArrayToList(StringUtils.stripAll(new String[]{" ? ", "  ",
    // " "}));
    // ?null.?(??)
    // ArrayToList(StringUtils.stripAll(new String[]{" ? ", " ", ""},
    // ""));
    // ,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // 2?,Null
    // System.out.println(StringUtils.equals(null, null));
    // ??
    // System.out.println(StringUtils.equalsIgnoreCase("abc", "ABc"));
    // ????~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?null""-1
    // System.out.println(StringUtils.indexOf(null, "a"));
    // ?(?)2k
    // System.out.println(StringUtils.indexOf("akfekcd?", "k", 2));
    // ???
    // System.out.println(StringUtils.ordinalIndexOf("akfekcd?", "k", 2));
    // ,??
    // System.out.println(StringUtils.indexOfIgnoreCase("adfs", "D"));
    // ?(?),??
    // System.out.println(StringUtils.indexOfIgnoreCase("adfs", "a", 3));
    // ??
    // System.out.println(StringUtils.lastIndexOf("adfas", "a"));
    // ?,2
    // System.out.println(StringUtils.lastIndexOf("dabasdafs", "a", 3));
    // ,-1
    // System.out.println(StringUtils.lastOrdinalIndexOf("yksdfdht", "f",
    // 2));
    // ????
    // System.out.println(StringUtils.lastIndexOfIgnoreCase("sdffet", "E"));
    // ,1
    // System.out.println(StringUtils.lastIndexOfIgnoreCase("efefrfs", "F"
    // , 2));
    // ?boolean,null?
    // System.out.println(StringUtils.contains("sdf", "dg"));
    // ?boolean,null?,??
    // System.out.println(StringUtils.containsIgnoreCase("sdf", "D"));
    // ??,boolean
    // System.out.println(StringUtils.containsWhitespace(" d"));
    // ???
    // System.out.println(StringUtils.indexOfAny("absfekf", new
    // String[]{"f", "b"}));
    // (?)
    // System.out.println(StringUtils.indexOfAny("afefes", "e"));
    // ??boolean
    // System.out.println(StringUtils.containsAny("asfsd", new char[]{'k',
    // 'e', 's'}));
    // ?lastIndexOf???boolean
    // System.out.println(StringUtils.containsAny("f", ""));
    // 
    // System.out.println(StringUtils.indexOfAnyBut("seefaff", "af"));
    // ?
    // System.out.println(StringUtils.containsOnly("??", "?"));
    // ?
    // System.out.println(StringUtils.containsOnly("?", new char[]{'',
    // '?'}));
    // ??
    // System.out.println(StringUtils.containsNone("??", ""));
    // ??
    // System.out.println(StringUtils.containsNone("?", new char[]{'',
    // ''}));
    // ????4
    // System.out.println(StringUtils.lastIndexOfAny("", new
    // String[]{"", ""}));
    // ?indexOfAny?? (?)
    // System.out.println(StringUtils.countMatches("", ""));
    // ?CharSequence??Unicode?falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlpha("2"));
    // ???UnicodeCharSequence?''CharSequence?=
    // 0true
    // System.out.println(StringUtils.isAlphaSpace("NBA "));
    // ???UnicodeCharSequence?falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlphanumeric("NBA"));
    // Unicode
    // CharSequence???''falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlphanumericSpace("NBA"));
    // ???ASCII?CharSequencefalseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAsciiPrintable("NBA"));
    // ???
    // System.out.println(StringUtils.isNumeric("NBA"));
    // ???
    // System.out.println(StringUtils.isNumericSpace("33 545"));
    // ??""
    // System.out.println(StringUtils.isWhitespace(" "));
    // ??
    // System.out.println(StringUtils.isAllLowerCase("kjk33"));
    // ?
    // System.out.println(StringUtils.isAllUpperCase("KJKJ"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?2?:
    // System.out.println(StringUtils.difference("", ""));
    // 2
    // System.out.println(StringUtils.indexOfDifference("ww.taobao",
    // "www.taobao.com"));
    // ?
    // System.out.println(StringUtils.indexOfDifference(new String[]
    // {"", "", ""}));
    // ???
    // System.out.println(StringUtils.getCommonPrefix(new String[] {"",
    // "", ""}));
    // ??????
    // System.out.println(StringUtils.getLevenshteinDistance("?",
    // ""));
    // ???
    // System.out.println(StringUtils.startsWith("", ""));
    // ?????
    // System.out.println(StringUtils.startsWithIgnoreCase("",
    // ""));
    // ???
    // System.out.println(StringUtils.startsWithAny("abef", new
    // String[]{"ge", "af", "ab"}));
    // ??
    // System.out.println(StringUtils.endsWith("abcdef", "def"));
    // ????
    // System.out.println(StringUtils.endsWithIgnoreCase("abcdef", "Def"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ??nullnull.""""
    // System.out.println(StringUtils.substring("", 2));
    // ?
    // System.out.println(StringUtils.substring("", 2, 4));
    // ?
    // System.out.println(StringUtils.left("", 3));
    // ??
    // System.out.println(StringUtils.right("", 3));
    // ???
    // System.out.println(StringUtils.mid("", 3, 2));
    // ??
    // System.out.println(StringUtils.substringBefore("", ""));
    // ?????
    // System.out.println(StringUtils.substringAfter("", ""));
    // ??.
    // System.out.println(StringUtils.substringBeforeLast("", ""));
    // ?????
    // System.out.println(StringUtils.substringAfterLast("", ""));
    // ???null:2010?
    // System.out.println(StringUtils.substringBetween("??2010?????",
    // "??"));
    // ???
    // ArrayToList(StringUtils.substringsBetween("[a][b][c]", "[", "]"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?nullnull
    // ArrayToList(StringUtils.split("?  "));
    // ?
    // ArrayToList(StringUtils.split("? ,,", ","));
    // ???0
    // ArrayToList(StringUtils.split("? ", "", 2));
    // ???,?
    // ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef",
    // "-!-"));
    // ???,???
    // ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-",
    // 2));
    // " "?,?null
    // ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens(" ab
    // de fg ",
    // null));
    // ?," "??
    // ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de
    // fg",
    // null, 3));
    // ???,
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg "));
    // ???,?
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ",
    // null));
    // ???,???
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ", null,
    // 2));
    // ??
    // ArrayToList(StringUtils.splitByCharacterType("AEkjKr i39:"));
    // 
    // ArrayToList(StringUtils.splitByCharacterTypeCamelCase("ASFSRules234"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ??
    // System.out.println(StringUtils.concat(getArrayData()));
    // ?.?null
    // System.out.println(StringUtils.concatWith(",", getArrayData()));
    // ?
    // System.out.println(StringUtils.join(getArrayData()));
    // ?
    // System.out.println(StringUtils.join(getArrayData(), ":"));
    // (?)?(?,??)
    // System.out.println(StringUtils.join(getArrayData(), ":", 1, 3));
    // ?.?
    // System.out.println(StringUtils.join(getListData(), ":"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // 
    // System.out.println(StringUtils.deleteWhitespace(" s   4j"));
    // ?
    // System.out.println(StringUtils.removeStart("www.baidu.com", "www."));
    // ?,??
    // System.out.println(StringUtils.removeStartIgnoreCase("www.baidu.com",
    // "WWW"));
    // ???
    // System.out.println(StringUtils.removeEnd("www.baidu.com", ".com"));
    // ?????
    // System.out.println(StringUtils.removeEndIgnoreCase("www.baidu.com",
    // ".COM"));
    // ?
    // System.out.println(StringUtils.remove("www.baidu.com/baidu", "bai"));
    // "\n", "\r",  "\r\n".
    // System.out.println(StringUtils.chomp("abcrabc\r"));
    // ?
    // System.out.println(StringUtils.chomp("baidu.com", "com"));
    // ?."\n", "\r",  "\r\n"
    // System.out.println(StringUtils.chop("wwe.baidu"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ???
    // System.out.println(StringUtils.replaceOnce("www.baidu.com/baidu",
    // "baidu", "hao123"));
    // ?
    // System.out.println(StringUtils.replace("www.baidu.com/baidu",
    // "baidu", "hao123"));
    // ????
    // System.out.println(StringUtils.replace("www.baidu.com/baidu",
    // "baidu", "hao123", 1));
    // ?????:baidu?taobaocom?net
    // System.out.println(StringUtils.replaceEach("www.baidu.com/baidu", new
    // String[]{"baidu", "com"}, new String[]{"taobao", "net"}));
    // ????
    // System.out.println(StringUtils.replaceEachRepeatedly("www.baidu.com/baidu",
    // new String[]{"baidu", "com"}, new String[]{"taobao", "net"}));
    // ????.(????)
    // System.out.println(StringUtils.replaceChars("www.baidu.com", "bdm",
    // "qo"));
    // ?(?)?(?)
    // System.out.println(StringUtils.overlay("www.baidu.com", "hao123", 4,
    // 9));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ????
    // System.out.println(StringUtils.repeat("ba", 3));
    // ??????
    // System.out.println(StringUtils.repeat("ab", "ou", 3));
    // ??(???)
    // System.out.println(StringUtils.rightPad("?", 4));
    // ????(?)
    // System.out.println(StringUtils.rightPad("?", 4, "?"));
    // ???
    // System.out.println(StringUtils.leftPad("?", 4));
    // ??????(?)
    // System.out.println(StringUtils.leftPad("?", 4, ""));
    // ?????
    // System.out.println(StringUtils.center("?", 3));
    // ??????
    // System.out.println(StringUtils.center("?", 5, "?"));
    // ??(?),??(??+=?)
    // System.out.println(StringUtils.abbreviate("?", 5));
    // 2: ...ijklmno
    // System.out.println(StringUtils.abbreviate("abcdefghijklmno", 12,
    // 10));
    // ???.: ab.f
    // System.out.println(StringUtils.abbreviateMiddle("abcdef", ".", 4));
    // ?,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?.
    // System.out.println(StringUtils.capitalize("Ddf"));
    // ?.
    // System.out.println(StringUtils.uncapitalize("DTf"));
    // ????????
    // System.out.println(StringUtils.swapCase("I am Jiang, Hello"));
    // ?
    // System.out.println(StringUtils.reverse(""));
    // ?(?)??
    // System.out.println(StringUtils.reverseDelimited("::", ':'));
    // isEmpty
    System.out.println(StringUtils.isEmpty(null)); // true
    System.out.println(StringUtils.isEmpty("")); // true
    System.out.println(StringUtils.isEmpty(" ")); // false
    System.out.println(StringUtils.isEmpty("bob")); // false
    System.out.println(StringUtils.isEmpty("  bob  ")); // false

    // isBlank
    System.out.println(StringUtils.isBlank(null)); // true
    System.out.println(StringUtils.isBlank("")); // true
    System.out.println(StringUtils.isBlank(" ")); // true
    System.out.println(StringUtils.isBlank("bob")); // false
    System.out.println(StringUtils.isBlank("  bob  ")); // false

    // trim
    System.out.println(StringUtils.trim(null)); // null
    System.out.println(StringUtils.trim("")); // ""
    System.out.println(StringUtils.trim("     ")); // ""
    System.out.println(StringUtils.trim("abc")); // "abc"
    System.out.println(StringUtils.trim("    abc")); // "abc"
    System.out.println(StringUtils.trim("    abc  ")); // "abc"
    System.out.println(StringUtils.trim("    ab c  ")); // "ab c"

    // strip
    System.out.println(StringUtils.strip(null)); // null
    System.out.println(StringUtils.strip("")); // ""
    System.out.println(StringUtils.strip("   ")); // ""
    System.out.println(StringUtils.strip("abc")); // "abc"
    System.out.println(StringUtils.strip("  abc")); // "abc"
    System.out.println(StringUtils.strip("abc  ")); // "abc"
    System.out.println(StringUtils.strip(" abc ")); // "abc"
    System.out.println(StringUtils.strip(" ab c ")); // "ab c"
    System.out.println(StringUtils.strip("  abcyx", "xyz")); // " abc"
    System.out.println(StringUtils.stripStart("yxabcxyz  ", "xyz")); // "abcxyz
    // "
    System.out.println(StringUtils.stripEnd("  xyzabcyx", "xyz")); // "
    // xyzabc"
    // ?
    String str1 = "aaa bbb ccc";
    String[] dim1 = StringUtils.split(str1); // => ["aaa", "bbb", "ccc"]

    System.out.println(dim1.length);// 3
    System.out.println(dim1[0]);// "aaa"
    System.out.println(dim1[1]);// "bbb"
    System.out.println(dim1[2]);// "ccc"

    // 
    String str2 = "aaa,bbb,ccc";
    String[] dim2 = StringUtils.split(str2, ","); // => ["aaa", "bbb",
    // "ccc"]

    System.out.println(dim2.length);// 3
    System.out.println(dim2[0]);// "aaa"
    System.out.println(dim2[1]);// "bbb"
    System.out.println(dim2[2]);// "ccc"

    // 
    String str3 = "aaa,,bbb";
    String[] dim3 = StringUtils.split(str3, ","); // => ["aaa", "bbb"]

    System.out.println(dim3.length);// 2
    System.out.println(dim3[0]);// "aaa"
    System.out.println(dim3[1]);// "bbb"

    // ?
    String str4 = "aaa,,bbb";
    String[] dim4 = StringUtils.splitPreserveAllTokens(str4, ","); // =>
    // ["aaa",
    // "",
    // "bbb"]

    System.out.println(dim4.length);// 3
    System.out.println(dim4[0]);// "aaa"
    System.out.println(dim4[1]);// ""
    System.out.println(dim4[2]);// "bbb"

    // ??
    String str5 = "aaa,bbb,ccc";
    String[] dim5 = StringUtils.split(str5, ",", 2); // => ["aaa",
    // "bbb,ccc"]

    System.out.println(dim5.length);// 2
    System.out.println(dim5[0]);// "aaa"
    System.out.println(dim5[1]);// "bbb,ccc"

    // 
    String[] array = { "aaa", "bbb", "ccc" };
    String result1 = StringUtils.join(array, ",");

    System.out.println(result1);// "aaa,bbb,ccc"

    // ?
    List<String> list = new ArrayList<String>();
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");
    String result2 = StringUtils.join(list, ",");
    System.out.println(result2);// "aaa,bbb,ccc"

}

From source file:com.sludev.mssqlapplylog.MSSQLApplyLogMain.java

public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();

    // Most of the following defaults should be changed in
    // the --conf or "conf.properties" file
    String sqlURL = null;/*from  www .  j  a v a  2  s.  co m*/
    String sqlUser = null;
    String sqlPass = null;
    String sqlDb = null;
    String sqlHost = "127.0.0.1";
    String backupDirStr = null;
    String laterThanStr = "";
    String fullBackupPathStr = null;
    String fullBackupPatternStr = "(?:[\\w_-]+?)(\\d+)\\.bak";
    String fullBackupDatePatternStr = "yyyyMMddHHmm";
    String sqlProcessUser = null;
    String logBackupPatternStr = "(.*)\\.trn";
    String logBackupDatePatternStr = "yyyyMMddHHmmss";

    boolean doFullRestore = false;
    Boolean useLogFileLastMode = null;
    Boolean monitorLogBackupDir = null;

    options.addOption(Option.builder().longOpt("conf").desc("Configuration file.").hasArg().build());

    options.addOption(Option.builder().longOpt("laterthan").desc("'Later Than' file filter.").hasArg().build());

    options.addOption(Option.builder().longOpt("restore-full")
            .desc("Restore the full backup before continuing.").build());

    options.addOption(Option.builder().longOpt("use-lastmod")
            .desc("Sort/filter the log backups using their File-System 'Last Modified' date.").build());

    options.addOption(Option.builder().longOpt("monitor-backup-dir")
            .desc("Monitor the backup directory for new log backups, and apply them.").build());

    CommandLine line = null;
    try {
        try {
            line = parser.parse(options, args);
        } catch (ParseException ex) {
            throw new MSSQLApplyLogException(String.format("Error parsing command line.'%s'", ex.getMessage()),
                    ex);
        }

        String confFile = null;

        // Process the command line arguments
        Iterator cmdI = line.iterator();
        while (cmdI.hasNext()) {
            Option currOpt = (Option) cmdI.next();
            String currOptName = currOpt.getLongOpt();

            switch (currOptName) {
            case "conf":
                // Parse the configuration file
                confFile = currOpt.getValue();
                break;

            case "laterthan":
                // "Later Than" file date filter
                laterThanStr = currOpt.getValue();
                break;

            case "restore-full":
                // Do a full backup restore before restoring logs
                doFullRestore = true;
                break;

            case "monitor-backup-dir":
                // Monitor the backup directory for new logs
                monitorLogBackupDir = true;
                break;

            case "use-lastmod":
                // Use the last-modified date on Log Backup files for sorting/filtering
                useLogFileLastMode = true;
                break;
            }
        }

        Properties confProperties = null;

        if (StringUtils.isBlank(confFile) || Files.isReadable(Paths.get(confFile)) == false) {
            throw new MSSQLApplyLogException(
                    "Missing or unreadable configuration file.  Please specify --conf");
        } else {
            // Process the conf.properties file
            confProperties = new Properties();
            try {
                confProperties.load(Files.newBufferedReader(Paths.get(confFile)));
            } catch (IOException ex) {
                throw new MSSQLApplyLogException("Error loading properties file", ex);
            }

            sqlURL = confProperties.getProperty("sqlURL", "");
            sqlUser = confProperties.getProperty("sqlUser", "");
            sqlPass = confProperties.getProperty("sqlPass", "");
            sqlDb = confProperties.getProperty("sqlDb", "");
            sqlHost = confProperties.getProperty("sqlHost", "");
            backupDirStr = confProperties.getProperty("backupDir", "");

            if (StringUtils.isBlank(laterThanStr)) {
                laterThanStr = confProperties.getProperty("laterThan", "");
            }

            fullBackupPathStr = confProperties.getProperty("fullBackupPath", fullBackupPathStr);
            fullBackupPatternStr = confProperties.getProperty("fullBackupPattern", fullBackupPatternStr);
            fullBackupDatePatternStr = confProperties.getProperty("fullBackupDatePattern",
                    fullBackupDatePatternStr);
            sqlProcessUser = confProperties.getProperty("sqlProcessUser", "");

            logBackupPatternStr = confProperties.getProperty("logBackupPattern", logBackupPatternStr);
            logBackupDatePatternStr = confProperties.getProperty("logBackupDatePattern",
                    logBackupDatePatternStr);

            if (useLogFileLastMode == null) {
                String useLogFileLastModeStr = confProperties.getProperty("useLogFileLastMode", "false");
                useLogFileLastMode = Boolean
                        .valueOf(StringUtils.lowerCase(StringUtils.trim(useLogFileLastModeStr)));
            }

            if (monitorLogBackupDir == null) {
                String monitorBackupDirStr = confProperties.getProperty("monitorBackupDir", "false");
                monitorLogBackupDir = Boolean
                        .valueOf(StringUtils.lowerCase(StringUtils.trim(monitorBackupDirStr)));
            }
        }
    } catch (MSSQLApplyLogException ex) {
        try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) {
            pw.append(String.format("Error : '%s'\n\n", ex.getMessage()));

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(pw, 80, "\njava -jar mssqlapplylog.jar ",
                    "\nThe MSSQLApplyLog application can be used in a variety of options and modes.\n", options,
                    0, 2, " All Rights Reserved.", true);

            System.out.println(sw.toString());
        } catch (IOException iex) {
            LOGGER.debug("Error processing usage", iex);
        }

        System.exit(1);
    }

    MSSQLApplyLogConfig config = MSSQLApplyLogConfig.from(backupDirStr, fullBackupPathStr,
            fullBackupDatePatternStr, laterThanStr, fullBackupPatternStr, logBackupPatternStr,
            logBackupDatePatternStr, sqlHost, sqlDb, sqlUser, sqlPass, sqlURL, sqlProcessUser,
            useLogFileLastMode, doFullRestore, monitorLogBackupDir);

    MSSQLApplyLog logProc = MSSQLApplyLog.from(config);

    BasicThreadFactory thFactory = new BasicThreadFactory.Builder().namingPattern("restoreThread-%d").build();

    ExecutorService mainThreadExe = Executors.newSingleThreadExecutor(thFactory);

    Future<Integer> currRunTask = mainThreadExe.submit(logProc);

    mainThreadExe.shutdown();

    Integer resp = 0;
    try {
        resp = currRunTask.get();
    } catch (InterruptedException ex) {
        LOGGER.error("Application 'main' thread was interrupted", ex);
    } catch (ExecutionException ex) {
        LOGGER.error("Application 'main' thread execution error", ex);
    } finally {
        // If main leaves for any reason, shutdown all threads
        mainThreadExe.shutdownNow();
    }

    System.exit(resp);
}

From source file:com.mirth.connect.util.FilenameUtils.java

public static String getAbsolutePath(File baseDir, String path) {
    path = StringUtils.trim(path);
    File file = new File(path);

    if (file.isAbsolute()) {
        return file.getPath();
    }/*from  www.  jav a2 s .  co m*/

    char firstChar = path.charAt(0);

    /*
     * For Windows systems, if the path begins with a forward or back slash, extract the drive
     * letter from baseDir and use the drive's root directory as the new baseDir.
     */
    if (firstChar == '/' || firstChar == '\\') {
        File parent = baseDir.getParentFile();

        while (parent != null) {
            baseDir = parent;
            parent = baseDir.getParentFile();
        }

        return new File(baseDir, path).getAbsolutePath();
    }

    return new File(baseDir, path).getAbsolutePath();
}

From source file:com.creditcloud.investmentfund.enums.FundBrand.java

public static FundBrand fromKey(String k) {
    for (FundBrand b : FundBrand.values()) {
        if (b.getKey().equalsIgnoreCase(StringUtils.trim(k))) {
            return b;
        }//from ww w .j  a  v  a2  s. co  m
    }
    return null;
}

From source file:com.u2apple.rt.util.PartitionUtils.java

public static Partitions parsePartition(String partitionString) {
    Partitions partitions = new Partitions();
    if (StringUtils.isNotBlank(partitionString)) {
        String[] partitionArray = partitionString.split(";");
        for (String partitionStr : partitionArray) {
            String[] elements = partitionStr.split("\\|");
            String name = StringUtils.trim(elements[0]);
            Long size = Long.parseLong(StringUtils.trim(elements[1]));
            String path = StringUtils.trim(elements[2]);
            Partition partition = new Partition(name, size, path);
            if ("system".equalsIgnoreCase(name)) {
                partitions.setSystemPartition(partition);
            } else if ("cache".equalsIgnoreCase(name)) {
                partitions.setCachePartition(partition);
            } else if ("data".equalsIgnoreCase(name)) {
                partitions.setDataPartition(partition);
            }/*w ww . j  ava2  s . co  m*/
        }
    }
    return partitions;
}

From source file:learningresourcefinder.web.Slugify.java

public static String slugify(String input) {
    String ret = StringUtils.trim(input);
    if (StringUtils.isBlank(input)) {
        return "";
    }/*  w ww .j  a  v a  2  s  .  c om*/
    ret = Jsoup.parse(ret).text(); // In case the string contains some html, such as <em>.
    ret = normalize(ret);
    ret = removeSmallWords(ret);
    ret = removeDuplicateWhiteSpaces(ret);
    ret = StringUtils.stripAccents(ret); // It seems to be bad practice to have accents in slugs:  --> e
    return ret.replace(" ", "-").toLowerCase();
}

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

/**
 * Parse the category name from a full feed name  (category.feed)
 *//*from   w  ww. ja  v  a 2 s . c o m*/
public static String category(String name) {
    return StringUtils.trim(StringUtils.substringBefore(name, "."));
}

From source file:AIR.Common.Utilities.MathUtils.java

public static double parseAndTruncate(String doubleValue) {
    doubleValue = StringUtils.trim(doubleValue);
    return truncate(Double.parseDouble(doubleValue));
}

From source file:com.widowcrawler.core.util.DomainUtils.java

public static boolean isBaseDomain(String baseDomain, String url) {
    try {//from  w w w.ja  v a  2 s. c  o  m
        baseDomain = StringUtils.lowerCase(StringUtils.trim(baseDomain));
        String domain = StringUtils.lowerCase(StringUtils.trimToNull(new URI(url).getHost()));

        if (domain == null) {
            logger.info("Returning false because url's domain is null");
            return false;
        }

        while (StringUtils.isNotBlank(domain)) {
            if (StringUtils.equals(baseDomain, domain)) {
                return true;
            }

            domain = StringUtils.substringAfter(domain, ".");
        }

        return false;

    } catch (URISyntaxException ex) {
        logger.error("Could not determine base domain relationship. Returning default of false.", ex);
        return false;
    }
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.MacroAttributesUtils.java

protected static String trim(String text) {
    if (text.length() < 3) {
        return text;
    }// w  w  w.  j ava2  s . com
    String ttext = StringUtils.trim(text);
    if (ttext.length() > 0 && ttext.endsWith("\\")) {
        return text;
    }

    return ttext;
}