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

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

Introduction

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

Prototype

public static String stripStart(final String str, final String stripChars) 

Source Link

Document

Strips any of a set of characters from the start of a String.

A null input String returns null .

Usage

From source file:io.stallion.dataAccess.file.FilePersisterBase.java

/**
 * Derives a Long id by hashing the file path and then taking the first 8 bytes
 * of the path.//from   ww w  .  jav  a  2 s . c  om
 *
 * This is used if the model object doesn't have a defined id field.
 *
 * @param path
 * @return
 */
public Long makeIdFromFilePath(String path) {
    path = path.toLowerCase();
    path = path.replace(getBucketFolderPath().toLowerCase(), "");
    path = StringUtils.stripStart(path, "/");
    path = getBucket() + "-----" + path;
    // Derive a long id by hashing the file path
    byte[] bs = Arrays.copyOfRange(DigestUtils.md5(path), 0, 6);
    bs = ArrayUtils.addAll(new byte[] { 0, 0 }, bs);
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.put(bs);
    buffer.flip();//need flip
    Long l = buffer.getLong();
    if (l < 0) {
        l = -l;
    }
    Log.finest("calculated id is {0}", l);
    return l;
}

From source file:ca.hec.commons.utils.MergePropertiesUtils.java

/**
 * @param strLine /*from w  w  w .  ja  v a  2s.com*/
 * @return the key extracted. Example returns 'prop1' for input 'prop1 = the small dog'
 *    Null is returned if the line is empty, or is a comment line (i.e. starts with a #)
 */
private static KeyValue extractKeyValue(String strLine) {
    String line = strLine.trim();

    if (line.startsWith("#")) {
        return null;
    }

    int indexOfEqual = line.indexOf('=');

    if (indexOfEqual < 0) {
        return null;
    }

    String key = line.substring(0, indexOfEqual);
    String value = line.substring(indexOfEqual + 1);

    return new KeyValue(key.trim(), StringUtils.stripStart(value, null)); // NOTE: Note that value is NOT trimmed to be similar to Properties.load().
    //return new KeyValue(key.trim(), value.trim()); // NOTE: Note that value is NOT trimmed to be similar to Properties.load().
}

From source file:io.stallion.utils.ResourceHelpers.java

public static File findDevModeFileForResource(String plugin, String resourcePath) {
    if (!Settings.instance().getDevMode()) {
        throw new UsageException("You can only call this method in dev mode!");
    }//from  ww w.  j  a v  a2s.  co m
    try {
        if (!resourcePath.startsWith("/")) {
            resourcePath = "/" + resourcePath;
        }
        // We find the URL of the root, not the actual file, since if the file was just created, we want it to be
        // accessible even if mvn hasn't recompiled the project. This allows us to iterate more quickly.
        URL url = pluginPathToUrl(plugin, resourcePath);
        // Maybe the file was just created? We'll try to find the root folder path, and then add the file path
        if (url == null) {
            url = new URL(StringUtils.stripStart(url.toString(), "/") + resourcePath);
        }
        return urlToFileMaybe(url, plugin);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

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));
    // ??/*from w w w  .j a  v  a2s .c o m*/
    // 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:net.sourceforge.pmd.docs.RuleDocGenerator.java

private static String stripIndentation(String description) {
    if (description == null || description.isEmpty()) {
        return "";
    }/*from   www .j a  va2 s  . co  m*/

    String stripped = StringUtils.stripStart(description, "\n\r");
    stripped = StringUtils.stripEnd(stripped, "\n\r ");

    int indentation = 0;
    int strLen = stripped.length();
    while (Character.isWhitespace(stripped.charAt(indentation)) && indentation < strLen) {
        indentation++;
    }

    String[] lines = stripped.split("\\n");
    String prefix = StringUtils.repeat(' ', indentation);
    StringBuilder result = new StringBuilder(stripped.length());

    if (StringUtils.isNotEmpty(prefix)) {
        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];
            if (i > 0) {
                result.append(StringUtils.LF);
            }
            result.append(StringUtils.removeStart(line, prefix));
        }
    } else {
        result.append(stripped);
    }
    return result.toString();
}

From source file:org.apache.falcon.entity.FeedHelper.java

public static String normalizePartitionExpression(String part1, String part2) {
    String partExp = StringUtils.stripToEmpty(part1) + "/" + StringUtils.stripToEmpty(part2);
    partExp = partExp.replaceAll("//+", "/");
    partExp = StringUtils.stripStart(partExp, "/");
    partExp = StringUtils.stripEnd(partExp, "/");
    return partExp;
}

From source file:org.apache.falcon.replication.FeedReplicator.java

private void executePostProcessing(Configuration conf, DistCpOptions options)
        throws IOException, FalconException {
    Path targetPath = options.getTargetPath();
    FileSystem fs = HadoopClientFactory.get().createProxiedFileSystem(targetPath.toUri(), getConf());
    List<Path> inPaths = options.getSourcePaths();
    assert inPaths.size() == 1 : "Source paths more than 1 can't be handled";

    Path sourcePath = inPaths.get(0);
    Path includePath = new Path(getConf().get("falcon.include.path"));
    assert includePath.toString().substring(0, sourcePath.toString().length())
            .equals(sourcePath.toString()) : "Source path is not a subset of include path";

    String relativePath = includePath.toString().substring(sourcePath.toString().length());
    String fixedPath = getFixedPath(relativePath);

    fixedPath = StringUtils.stripStart(fixedPath, "/");
    Path finalOutputPath;/* w ww. j  a  va  2  s . c  o  m*/
    if (StringUtils.isNotEmpty(fixedPath)) {
        finalOutputPath = new Path(targetPath, fixedPath);
    } else {
        finalOutputPath = targetPath;
    }

    final String availabilityFlag = conf.get("falcon.feed.availability.flag");
    FileStatus[] files = fs.globStatus(finalOutputPath);
    if (files != null) {
        for (FileStatus file : files) {
            fs.create(new Path(file.getPath(), availabilityFlag)).close();
            LOG.info("Created {}", new Path(file.getPath(), availabilityFlag));
        }
    } else {
        // As distcp is not copying empty directories we are creating availabilityFlag file here
        fs.create(new Path(finalOutputPath, availabilityFlag)).close();
        LOG.info("No files present in path: {}", finalOutputPath);
    }
}

From source file:org.craftercms.commons.lang.UrlUtils.java

/**
 * Concats two urls, adding any "/" needed between them.
 *
 * @param mainUrl      the main url//from  w  w w.java2 s .  co  m
 * @param relativeUrl  the relative url
 *
 * @return mainPath + relativeUrl
 */
public static String concat(String mainUrl, String relativeUrl) {
    if (StringUtils.isEmpty(mainUrl)) {
        return relativeUrl;
    } else if (StringUtils.isEmpty(relativeUrl)) {
        return mainUrl;
    } else {
        StringBuilder joinedUrl = new StringBuilder(mainUrl);

        if (mainUrl.endsWith("/") && relativeUrl.startsWith("/")) {
            relativeUrl = StringUtils.stripStart(relativeUrl, "/");
        } else if (!mainUrl.endsWith("/") && !relativeUrl.startsWith("/")) {
            joinedUrl.append("/");
        }

        joinedUrl.append(relativeUrl);

        return joinedUrl.toString();
    }
}

From source file:org.dbgl.model.conf.Autoexec.java

void parseLines(final List<String> orgLines) {
    char driveletter = '\0';
    String remainder = StringUtils.EMPTY;
    String executable = StringUtils.EMPTY;
    String image1 = StringUtils.EMPTY;
    String image2 = StringUtils.EMPTY;
    String image3 = StringUtils.EMPTY;
    int exeIndex = -1;

    String customEchos = StringUtils.EMPTY;
    List<String> leftOvers = new ArrayList<String>();
    int customSection = -1;

    line: for (String orgLine : orgLines) {
        orgLine = orgLine.trim();//from   w w w .j ava  2 s . co m

        for (int i = 0; i < SECTIONS; i++) {
            if (orgLine.startsWith(CUSTOM_SECTION_MARKERS[i * 2])) {
                customSection = i;
                continue line;
            }
        }

        if (customSection > -1) {
            if (orgLine.startsWith(CUSTOM_SECTION_MARKERS[customSection * 2 + 1]))
                customSection = -1;
            else
                customSections[customSection] += orgLine + PlatformUtils.EOLN;
            continue;
        }

        orgLine = StringUtils.stripStart(orgLine, "@").trim();

        Matcher loadhighMatcher = LOADHIGH_PATRN.matcher(orgLine);
        Matcher loadfixMatcher = LOADFIX_PATRN.matcher(orgLine);
        Matcher bootMatcher = BOOT_PATRN.matcher(orgLine);

        if (loadhighMatcher.matches()) {
            loadhigh = true;
            orgLine = loadhighMatcher.group(1).trim();
        }

        if (loadfixMatcher.matches()) {
            if (!loadfix) {
                loadfixValue = 64;
                loadfix = true;
            }
            if (loadfixMatcher.group(1) != null) // -f
                continue;
            if (loadfixMatcher.group(2) != null) {
                try {
                    loadfixValue = Integer.parseInt(loadfixMatcher.group(2).trim().substring(1));
                } catch (NumberFormatException e) {
                    // use default value of 64
                }
            }
            if (loadfixMatcher.group(3) == null)
                continue;
            orgLine = loadfixMatcher.group(3).trim();
        }

        String line = orgLine.toLowerCase();

        if (StringUtils.isEmpty(line)) {
            continue;
        } else if (line.startsWith("mount ") || line.startsWith("imgmount ")) {
            addMount(orgLine);
        } else if ((line.endsWith(":") && line.length() == 2) || (line.endsWith(":\\") && line.length() == 3)) {
            driveletter = Character.toUpperCase(line.charAt(0));
            remainder = StringUtils.EMPTY;
        } else if (line.startsWith("cd\\")) {
            if (driveletter != '\0') {
                String add = PlatformUtils.toNativePath(orgLine).substring(2);
                if (add.startsWith("\\"))
                    remainder = add;
                else
                    remainder = new File(remainder, add).getPath();
            }
        } else if (line.startsWith("cd ")) {
            if (driveletter != '\0') {
                String add = PlatformUtils.toNativePath(orgLine).substring(3);
                if (add.startsWith("\\"))
                    remainder = add;
                else
                    remainder = new File(remainder, add).getPath();
            }
        } else if (line.startsWith("keyb ") || line.startsWith("keyb.com ")) {
            keyb = orgLine.substring(line.indexOf(' ') + 1);
        } else if (line.startsWith("mixer ") || line.startsWith("mixer.com ")) {
            mixer = orgLine.substring(line.indexOf(' ') + 1);
        } else if (line.startsWith("ipxnet ") || line.startsWith("ipxnet.com ")) {
            ipxnet = orgLine.substring(line.indexOf(' ') + 1);
        } else if (line.equals("pause")) {
            pause = true;
        } else if (line.startsWith("z:\\config.com")) {
            // just ignore
        } else if ((exeIndex = StringUtils.indexOfAny(line, FileUtils.EXECUTABLES)) != -1) {
            executable = orgLine;
            // If there is a space BEFORE executable name, strip everything before it
            int spaceBeforeIndex = executable.lastIndexOf(' ', exeIndex);
            if (spaceBeforeIndex != -1) {
                executable = executable.substring(spaceBeforeIndex + 1);
            }
            // If there is a space AFTER executable name, define it as being parameters
            int spaceAfterIndex = executable.indexOf(' ');
            if (spaceAfterIndex != -1) {
                params = orgLine.substring(spaceBeforeIndex + spaceAfterIndex + 2);
                executable = executable.substring(0, spaceAfterIndex);
            }
        } else if (bootMatcher.matches()) {
            Matcher bootImgsMatcher = BOOTIMGS_PATRN.matcher(bootMatcher.group(1).trim());
            if (bootImgsMatcher.matches()) {
                if (bootImgsMatcher.group(1) != null)
                    image1 = StringUtils.strip(bootImgsMatcher.group(1), "\"");
                if (bootImgsMatcher.group(2) != null)
                    image2 = StringUtils.strip(bootImgsMatcher.group(2), "\"");
                if (bootImgsMatcher.group(3) != null)
                    image3 = StringUtils.strip(bootImgsMatcher.group(3), "\"");
            }
            if (bootMatcher.group(2) != null)
                imgDriveletter = bootMatcher.group(2).trim().toUpperCase();
            if (StringUtils.isEmpty(image1) && StringUtils.isNotEmpty(imgDriveletter)) {
                char driveNumber = (char) ((int) imgDriveletter.charAt(0) - 17);
                String matchingImageMount = findImageMatchByDrive(driveNumber, imgDriveletter.charAt(0));
                if (matchingImageMount != null)
                    image1 = matchingImageMount;
            }
            if ("\\file".equals(image1)) {
                img1 = "file"; // for template if . was unavailable
            }
        } else if (line.equals("exit") || line.startsWith("exit ")) {
            exit = true;
        } else if (line.equals("echo off")) {
            // just ignore
        } else if (line.equals("echo") || line.startsWith("echo ") || line.startsWith("echo.")) {
            customEchos += orgLine + PlatformUtils.EOLN;
        } else if (line.startsWith(":") || line.equals("cd") || line.equals("cls") || line.startsWith("cls ")
                || line.startsWith("cls\\") || line.equals("rem") || line.startsWith("rem ")
                || line.startsWith("goto ") || line.startsWith("if errorlevel ")) {
            // just ignore
        } else {
            leftOvers.add(orgLine);
        }
    }

    if (StringUtils.isNotEmpty(customEchos) && !customEchos.equalsIgnoreCase("echo." + PlatformUtils.EOLN)) {
        customSections[1] += "@echo off" + PlatformUtils.EOLN + customEchos; // add echo commands to pre-launch custom section
        customSections[1] += "pause" + PlatformUtils.EOLN; // add pause statement to make it all readable
    }

    if (executable.equals(StringUtils.EMPTY) && !leftOvers.isEmpty()) {
        for (int i = 0; i < leftOvers.size(); i++) {
            executable = leftOvers.get(i).trim();
            if (i == (leftOvers.size() - 1)) { // the last executable should be the main game
                boolean isCalledBatch = executable.toLowerCase().startsWith("call ");
                if (isCalledBatch)
                    executable = executable.substring(5);
                int spaceAfterIndex = executable.indexOf(' ');
                if (spaceAfterIndex != -1) {
                    params = executable.substring(spaceAfterIndex + 1);
                    executable = executable.substring(0, spaceAfterIndex);
                }
                executable += isCalledBatch ? FileUtils.EXECUTABLES[2] : FileUtils.EXECUTABLES[0];
            } else {
                customSections[1] += executable + PlatformUtils.EOLN; // add other statements to pre-launch custom section
            }
        }
    }

    for (Mount mount : mountingpoints) {
        char mount_drive = mount.getDriveletter();
        String mountPath = mount.getHostPathAsString();
        if (driveMatches(executable, mount_drive, driveletter))
            main = splitInThree(executable, mountPath, remainder);
        else {
            if (mount.matchesImageMountPath(image1))
                img1 = image1;
            else if (driveMatches(image1, mount_drive, driveletter))
                img1 = splitInThree(image1, mountPath, remainder);
            if (mount.matchesImageMountPath(image2))
                img2 = image2;
            else if (driveMatches(image2, mount_drive, driveletter))
                img2 = splitInThree(image2, mountPath, remainder);
            if (mount.matchesImageMountPath(image3))
                img3 = image1;
            else if (driveMatches(image3, mount_drive, driveletter))
                img3 = splitInThree(image3, mountPath, remainder);
        }
    }

    if (exit == null)
        exit = false;
}

From source file:org.dbgl.util.FileUtils.java

private static ShortFile createShortFile(File file, Set<ShortFile> curDir) {
    String filename = file.getName().toUpperCase();
    boolean createShort = false;
    if (StringUtils.contains(filename, ' ')) {
        filename = StringUtils.remove(filename, ' ');
        createShort = true;//from   w ww  .j  a v a2 s  .  c  o m
    }
    int len = 0;
    int idx = filename.indexOf('.');
    if (idx != -1) {
        if (filename.length() - idx - 1 > 3) {
            filename = StringUtils.stripStart(filename, ".");
            createShort = true;
        }
        idx = filename.indexOf('.');
        len = (idx != -1) ? idx : filename.length();
    } else {
        len = filename.length();
    }
    createShort |= len > 8;

    ShortFile shortFile = null;
    if (!createShort) {
        shortFile = new ShortFile(file, StringUtils.removeEnd(filename, "."));
    } else {
        int i = 1;
        do {
            String nr = String.valueOf(i++);
            StringBuffer sb = new StringBuffer(StringUtils.left(filename, Math.min(8 - nr.length() - 1, len)));
            sb.append('~').append(nr);
            idx = filename.lastIndexOf('.');
            if (idx != -1)
                sb.append(StringUtils.left(filename.substring(idx), 4));
            shortFile = new ShortFile(file, StringUtils.removeEnd(sb.toString(), "."));
        } while (shortFile.isContainedIn(curDir));
    }
    return shortFile;
}