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

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

Introduction

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

Prototype

public static String right(final String str, final int len) 

Source Link

Document

Gets the rightmost len characters of a String.

If len characters are not available, or the String is null , the String will be returned without an an exception.

Usage

From source file:kenh.expl.functions.Right.java

public String process(String str, int len) {
    return StringUtils.right(str, len);
}

From source file:jobhunter.api.infojobs.OfferRequest.java

/**
 * Generates a OfferRequest after parsing the given URL for the
 * InfoJobs' key.//  w ww  . j  a  v  a2s.c  o  m
 * FTM I know of two URL formats where we can get the key from:
 * - Using the "of_codigo" query param
 * - Using the last 30 chars from a path param
 * This method handles both cases.
 * @param url
 * @return OfferRequest
 * @throws InfoJobsAPIException 
 */
public static OfferRequest of(String url) throws InfoJobsAPIException {
    List<NameValuePair> params = new ArrayList<>();
    try {
        params = URLEncodedUtils.parse(new URI(url), "UTF-8");
    } catch (URISyntaxException e) {
        l.error("Failed to build URI", e);
        throw new InfoJobsAPIException("Invalid URL " + url);
    }

    NameValuePair key = params.stream().filter(nvp -> nvp.getName().equalsIgnoreCase("of_codigo")).findFirst()
            .orElse(new BasicNameValuePair("of_codigo", StringUtils.right(url, 30)));

    return new OfferRequest(key);
}

From source file:com.github.steveash.jg2p.seq.LeadingTrailingFeature.java

@Override
public Instance pipe(Instance carrier) {
    TokenSequence ts = (TokenSequence) carrier.getData();
    if (ts.size() >= 2) {
        Token first = ts.get(0);//from w  w  w.  j a  v a2 s .  c  o  m
        Token last = ts.get(ts.size() - 1);
        String firstShape = TokenSeqUtil.convertShape(StringUtils.left(first.getText(), 1));
        String lastShape = TokenSeqUtil.convertShape(StringUtils.right(last.getText(), 1));
        first.setFeatureValue("FIRST", 1.0);
        if (isNotBlank(firstShape)) {
            first.setFeatureValue("FIRST-" + firstShape, 1.0);
        }
        last.setFeatureValue("LAST", 1.0);
        if (isNotBlank(lastShape)) {
            last.setFeatureValue("LAST-" + lastShape, 1.0);
        }
    }
    return carrier;
}

From source file:io.cloudex.framework.components.Context.java

/**
 * Resolve the underlying key name, e.g. #key returns key
 * @param key - the key reference//from   w  w w .ja  va2s.  c  om
 * @return underlying key
 */
public static String resolveKey(String key) {
    int size = key.length();
    if (key.startsWith(VARIABLE_PREFIX) && (size > 1)) {
        key = StringUtils.right(key, size - 1);
    }
    return key;
}

From source file:com.github.steveash.jg2p.seq.SurroundingTokenFeature.java

@Override
public Instance pipe(Instance carrier) {
    TokenSequence ts = (TokenSequence) carrier.getData();
    for (int i = 1; i < ts.size() - 1; i++) {
        Token a = ts.get(i - 1);/*from   w  ww . j  a  v  a2s . c o  m*/
        Token t = ts.get(i);
        Token z = ts.get(i + 1);
        String before = StringUtils.right(a.getText(), 1);
        String after = StringUtils.left(z.getText(), 1);

        if (isNotBlank(before) && isNotBlank(after)) {
            String f = prefix + xform(before) + "^" + xform(t.getText()) + "^" + xform(after);
            t.setFeatureValue(f, 1.0);
        }
    }
    return carrier;
}

From source file:com.bellman.bible.service.common.CommonUtils.java

/** return true if Android 2.3.7 or greater
 *//*from w  ww.java  2 s.com*/
public static boolean is2_3_7_Plus() {
    if (Build.VERSION.SDK_INT > 9) {
        return true;
    } else if (Build.VERSION.SDK_INT < 9) {
        return false;
    } else {
        // this isn't brilliant code but should not fail and should work most times, maybe all
        String rel = Build.VERSION.RELEASE;
        String finalDigit = StringUtils.right(rel, 1);
        return "789".contains(finalDigit);
    }
}

From source file:com.github.utils.mycollect.util.EmojiUtil.java

/**
 * Unicode??// ww w  .  j a  v a 2s .  c  o  m
 *
 * @param one
 * @param two
 * @return ??codePoint
 */
private static Integer codePointToExtUnicode(int one, int two) {

    if (one > 0 && two > 0) {
        //U+D80055296,U+DC0056320
        String binStrHigh = Integer.toBinaryString(one - 55296);
        String binStrLow = Integer.toBinaryString(two - 56320);
        if (StringUtils.isNotBlank(binStrHigh) && StringUtils.isNotBlank(binStrLow)) {
            StringBuilder binStrRes = new StringBuilder();
            binStrRes.append(StringUtils.right(binStrHigh, 10));
            if (StringUtils.length(binStrLow) < 10) {
                binStrRes.append(StringUtils.leftPad(binStrLow, 10, "0"));
            } else {
                binStrRes.append(StringUtils.right(binStrLow, 10));
            }
            Integer resInt = Integer.parseInt(binStrRes.toString(), 2);
            //U+10000
            return resInt + 65536;
        }
    }

    return 0;
}

From source file:de.micromata.genome.util.types.DateUtils.java

/**
 * Parses the h hmm to minutes./*from   w  w  w. j a v a2 s.c  om*/
 *
 * @param time Zeitangabe der Form "1223". Minimalwert "0000", Maximalwert "2400".
 * @return Minutenangabe der Tageszeit.
 */
public static int parseHHmmToMinutes(String time) {
    Validate.notEmpty(time, "time is empty");

    try {
        Validate.isTrue(time.length() == 4, "time string expected to be 4 digits, but was ", time);

        String hoursPart = StringUtils.left(time, 2);
        String minutesPart = StringUtils.right(time, 2);

        int hours;
        int minutes;

        hours = Integer.parseInt(hoursPart);
        Validate.isTrue(hours >= 0, "hours negative");
        Validate.isTrue(hours <= 24, "hours too big");

        minutes = Integer.parseInt(minutesPart);
        Validate.isTrue(minutes >= 0, "minutes negative");
        Validate.isTrue(minutes <= 60, "minutes too big");

        final int result = hours * 60 + minutes;
        Validate.isTrue(result <= 24 * 60, "result too big");
        return result;
    } catch (Exception e) {
        throw new RuntimeException("Error parsing time string '" + time + "': " + e);
    }
}

From source file:io.mapzone.controller.vm.http.HttpRequestForwarder.java

public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, URISyntaxException {
    targetUriObj = new URI(targetUri.get());
    targetHost = URIUtils.extractHost(targetUriObj);

    // Make the Request
    // note: we won't transfer the protocol version because I'm not sure it would
    // truly be compatible
    String method = request.getMethod();
    String proxyRequestUri = rewriteUrlFromRequest(request);

    // spec: RFC 2616, sec 4.3: either of these two headers signal that there is
    // a message body.
    if (request.getHeader(HttpHeaders.CONTENT_LENGTH) != null
            || request.getHeader(HttpHeaders.TRANSFER_ENCODING) != null) {
        HttpEntityEnclosingRequest eProxyRequest = new BasicHttpEntityEnclosingRequest(method, proxyRequestUri);
        // Add the input entity (streamed)
        // note: we don't bother ensuring we close the servletInputStream since
        // the container handles it
        eProxyRequest.setEntity(new InputStreamEntity(request.getInputStream(), request.getContentLength()));
        proxyRequest = eProxyRequest;/*w w  w.ja  va2s  . c o  m*/
    } else {
        proxyRequest = new BasicHttpRequest(method, proxyRequestUri);
    }

    copyRequestHeaders(request);

    setXForwardedForHeader(request);

    // Execute the request
    try {
        active.set(this);

        log.debug("REQUEST " + "[" + StringUtils.right(Thread.currentThread().getName(), 2) + "] " + method
                + ": " + request.getRequestURI() + " -- " + proxyRequest.getRequestLine().getUri());
        proxyResponse = proxyClient.execute(targetHost, proxyRequest);
    } catch (Exception e) {
        // abort request, according to best practice with HttpClient
        if (proxyRequest instanceof AbortableHttpRequest) {
            AbortableHttpRequest abortableHttpRequest = (AbortableHttpRequest) proxyRequest;
            abortableHttpRequest.abort();
        }
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        if (e instanceof ServletException) {
            throw (ServletException) e;
        }
        // noinspection ConstantConditions
        if (e instanceof IOException) {
            throw (IOException) e;
        }
        throw new RuntimeException(e);
    } finally {
        active.set(null);
    }
    // Note: Don't need to close servlet outputStream:
    // http://stackoverflow.com/questions/1159168/should-one-call-close-on-httpservletresponse-getoutputstream-getwriter
}

From source file:net.sf.jsignpdf.Signer.java

/**
 * Sign the files// ww w  .j a v a  2s  .  c o  m
 * 
 * @param anOpts
 */
private static void signFiles(SignerOptionsFromCmdLine anOpts) {
    final SignerLogic tmpLogic = new SignerLogic(anOpts);
    if (ArrayUtils.isEmpty(anOpts.getFiles())) {
        // we've used -lp (loadproperties) parameter
        if (!tmpLogic.signFile()) {
            exit(Constants.EXIT_CODE_ALL_SIG_FAILED);
        }
        return;
    }
    int successCount = 0;
    int failedCount = 0;

    for (final String wildcardPath : anOpts.getFiles()) {
        final File wildcardFile = new File(wildcardPath);

        File[] inputFiles;
        if (StringUtils.containsAny(wildcardFile.getName(), '*', '?')) {
            final File inputFolder = wildcardFile.getAbsoluteFile().getParentFile();
            final FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE,
                    new WildcardFileFilter(wildcardFile.getName()));
            inputFiles = inputFolder.listFiles(fileFilter);
            if (inputFiles == null) {
                continue;
            }
        } else {
            inputFiles = new File[] { wildcardFile };
        }
        for (File inputFile : inputFiles) {
            final String tmpInFile = inputFile.getPath();
            if (!inputFile.canRead()) {
                failedCount++;
                System.err.println(RES.get("file.notReadable", new String[] { tmpInFile }));
                continue;
            }
            anOpts.setInFile(tmpInFile);
            String tmpNameBase = inputFile.getName();
            String tmpSuffix = ".pdf";
            if (StringUtils.endsWithIgnoreCase(tmpNameBase, tmpSuffix)) {
                tmpSuffix = StringUtils.right(tmpNameBase, 4);
                tmpNameBase = StringUtils.left(tmpNameBase, tmpNameBase.length() - 4);
            }
            final StringBuilder tmpName = new StringBuilder(anOpts.getOutPath());
            tmpName.append(anOpts.getOutPrefix());
            tmpName.append(tmpNameBase).append(anOpts.getOutSuffix()).append(tmpSuffix);
            String outFile = anOpts.getOutFile();
            if (outFile == null)
                anOpts.setOutFile(tmpName.toString());
            if (tmpLogic.signFile()) {
                successCount++;
            } else {
                failedCount++;
            }

        }
    }
    if (failedCount > 0) {
        exit(successCount > 0 ? Constants.EXIT_CODE_SOME_SIG_FAILED : Constants.EXIT_CODE_ALL_SIG_FAILED);
    }
}