Example usage for org.apache.commons.lang StringUtils substring

List of usage examples for org.apache.commons.lang StringUtils substring

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substring.

Prototype

public static String substring(String str, int start) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:com.zookeeper.zkadmin.util.ZK_ZxidUtils.java

public static void main(String[] args) {

    System.out.println(1 << 32);
    System.out.println(1L << 32);

    System.out.println(makeZxid(1, 268435457));

    long l = Long.parseLong(StringUtils.substring("0x10000001", 2), 16);

    System.out.println(getCounterFromZxid(l));
    System.out.println(getEpochFromZxid(l));

    System.out.println(0xffffffffL);

}

From source file:com.hangum.tadpole.commons.utils.zip.util.ZipUtils.java

/**
 * //ww w .  j av  a2 s.  c  om
 * @param base_dir
 * @param zipFile
 * @return
 * @throws Exception
 */
public static String pack(String base_dir, String zipFile) throws Exception {
    String zipFullPath = PublicTadpoleDefine.TEMP_DIR + zipFile + ".zip";
    ZipUtil.pack(new File(base_dir), new File(zipFullPath), new NameMapper() {
        public String map(String name) {
            try {
                if (!StringUtils.equals(name, StringEscapeUtils.escapeJava(name))) {
                    name = "download_files" + StringUtils.substring(name, StringUtils.lastIndexOf(name, '.'));
                }
                name = new String(name.getBytes(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return name;
        }
    });

    return zipFullPath;
}

From source file:edu.mayo.cts2.framework.plugin.service.lexevs.uri.UriUtils.java

/**
 * Gets the local part of a URI.//from  w  w  w  .  j  av a2  s  . com
 *
 * @param uri the uri
 * @return the local part
 */
public static String getLocalPart(String uri) {
    int separator = getSeparatorPosition(uri);

    return StringUtils.substring(uri, separator + 1);
}

From source file:de.thischwa.pmcms.view.context.object.Utils.java

public static String skipBeginningString(final String string, final String stringToSkip) {
    return StringUtils.substring(string, stringToSkip.length());
}

From source file:com.adobe.acs.commons.quickly.Command.java

public Command(final String raw) {
    this.raw = StringUtils.stripToEmpty(raw);

    String opWithPunctuation = StringUtils
            .stripToEmpty(StringUtils.lowerCase(StringUtils.substringBefore(this.raw, " ")));
    int punctuationIndex = StringUtils.indexOfAny(opWithPunctuation, PUNCTUATIONS);

    if (punctuationIndex > 0) {
        this.punctuation = StringUtils.substring(opWithPunctuation, punctuationIndex).split("(?!^)");
        this.operation = StringUtils.substring(opWithPunctuation, 0, punctuationIndex);
    } else {/*from  w  ww . jav a  2  s.co m*/
        this.punctuation = new String[] {};
        this.operation = opWithPunctuation;
    }

    this.param = StringUtils.stripToEmpty(StringUtils.removeStart(this.raw, opWithPunctuation));
    this.params = StringUtils.split(this.param);

    if (log.isTraceEnabled()) {
        log.trace("Raw: {}", this.raw);
        log.trace("Operation: {}", this.operation);
        log.trace("Punctuation: {}", Arrays.toString(this.punctuation));
        log.trace("Param: {}", this.param);
        log.trace("Params: {}", Arrays.toString(this.params));
    }
}

From source file:net.shopxx.util.CompressUtils.java

public static void archive(File[] srcFiles, File destFile, String archiverName) {
    Assert.notNull(destFile);//from  w ww .j ava 2s.c om
    Assert.state(!destFile.exists() || destFile.isFile());
    Assert.hasText(archiverName);

    File parentFile = destFile.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }
    ArchiveOutputStream archiveOutputStream = null;
    try {
        archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiverName,
                new BufferedOutputStream(new FileOutputStream(destFile)));
        if (ArrayUtils.isNotEmpty(srcFiles)) {
            for (File srcFile : srcFiles) {
                if (srcFile == null || !srcFile.exists()) {
                    continue;
                }
                Set<File> files = new HashSet<File>();
                if (srcFile.isFile()) {
                    files.add(srcFile);
                }
                if (srcFile.isDirectory()) {
                    files.addAll(FileUtils.listFilesAndDirs(srcFile, TrueFileFilter.INSTANCE,
                            TrueFileFilter.INSTANCE));
                }
                String basePath = FilenameUtils.getFullPath(srcFile.getCanonicalPath());
                for (File file : files) {
                    try {
                        String entryName = FilenameUtils.separatorsToUnix(
                                StringUtils.substring(file.getCanonicalPath(), basePath.length()));
                        ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, entryName);
                        archiveOutputStream.putArchiveEntry(archiveEntry);
                        if (file.isFile()) {
                            InputStream inputStream = null;
                            try {
                                inputStream = new BufferedInputStream(new FileInputStream(file));
                                IOUtils.copy(inputStream, archiveOutputStream);
                            } catch (FileNotFoundException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } catch (IOException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } finally {
                                IOUtils.closeQuietly(inputStream);
                            }
                        }
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    } finally {
                        archiveOutputStream.closeArchiveEntry();
                    }
                }
            }
        }
    } catch (ArchiveException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
    }
}

From source file:eionet.meta.filters.DDCORSFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) resp;

    HttpServletRequest request = (HttpServletRequest) req;
    String requestUrl = request.getRequestURL().toString();

    // filter only if request ends with /json
    int lastIndexOfSlash = StringUtils.lastIndexOf(requestUrl, "/");
    String subString = StringUtils.substring(requestUrl, lastIndexOfSlash);
    if (StringUtils.startsWith(subString, "/json")) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
    }// www  .jav a2s. co m

    chain.doFilter(req, resp);
}

From source file:ch.cyberduck.core.cloud.CloudPath.java

@Override
public boolean isContainer() {
    return !StringUtils.contains(StringUtils.substring(this.getAbsolute(), 1), this.getPathDelimiter());
}

From source file:net.duckling.ddl.service.pan.FileInfo.java

public String getExt() {
    return StringUtils.substring(this.getFileName().toLowerCase(), this.getFileName().lastIndexOf(".") + 1);
}

From source file:mitm.common.cifs.SMBURLBuilder.java

private String removeStartingSlash(String input) {
    if (input.startsWith("/")) {
        input = StringUtils.substring(input, 1);
    }//from   w w  w . j av  a  2  s.com

    return input;
}