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

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

Introduction

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

Prototype

public static boolean isEmpty(String str) 

Source Link

Document

Checks if a String is empty ("") or null.

Usage

From source file:com.usefullc.platform.common.utils.IOUtils.java

/**
 * //  w ww .j  a v  a  2  s  .co  m
 * 
 * @param path
 * @param fileName
 * @param response
 * @return
 */
public static void download(String path, String fileName, HttpServletResponse response) {
    try {

        if (StringUtils.isEmpty(path)) {
            throw new IllegalArgumentException("?");
        } else {
            File file = new File(path);
            if (!file.exists()) {
                throw new IllegalArgumentException("??");
            }
        }
        if (StringUtils.isEmpty(fileName)) {
            throw new IllegalArgumentException("???");
        }
        if (response == null) {
            throw new IllegalArgumentException("response ?");
        }

        // path
        File file = new File(path);

        // ??
        InputStream fis = new BufferedInputStream(new FileInputStream(path));
        byte[] buffer = new byte[fis.available()];
        fis.read(buffer);
        fis.close();
        // response
        response.reset();

        // ??linux ?  linux utf-8,windows  GBK)
        String defaultEncoding = System.getProperty("file.encoding");
        if (defaultEncoding != null && defaultEncoding.equals("UTF-8")) {

            response.addHeader("Content-Disposition",
                    "attachment;filename=" + new String(fileName.getBytes("GBK"), "iso-8859-1"));
        } else {
            response.addHeader("Content-Disposition",
                    "attachment;filename=" + new String(fileName.getBytes(), "iso-8859-1"));
        }

        // responseHeader
        response.addHeader("Content-Length", "" + file.length());
        response.setContentType("application/octet-stream");
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        toClient.write(buffer);
        toClient.flush();
        toClient.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.zb.app.biz.cons.ColumnHotEnum.java

public static ColumnHotEnum getAction(String name) {
    if (StringUtils.isEmpty(name)) {
        return null;
    }/*from  www .  j  ava2  s  .c o m*/
    for (ColumnHotEnum type : values()) {
        if (StringUtils.equals(name, type.name))
            return type;
    }
    return null;
}

From source file:com.sap.hana.cloud.samples.jenkins.common.ConfigurationRootDirectory.java

/**
 * Returns the common root directory for all configuration files. On the SAP HANA Cloud
 * Platform, this is the user.home directory.
 */// w w w  . jav a2  s  .c om
public static File getDirectory() {

    final String explicitValue = System
            .getProperty("com.sap.hana.cloud.samples.jenkins.common.ConfigurationRootDirectory");
    if (!StringUtils.isEmpty(explicitValue)) {
        // allow tests to override the configuration location
        return new File(explicitValue);

    } else {
        return new File(System.getProperty("user.home"));
    }
}

From source file:com.baomidou.framework.common.JarHelper.java

public static List<String> listFiles(JarFile jarFile, String endsWith) {
    if (jarFile == null || StringUtils.isEmpty(endsWith)) {
        return null;
    }/*from   w w w  .  j a  va  2 s.c o  m*/
    List<String> files = new ArrayList<String>();
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(endsWith)) {
            files.add(name);
        }
    }
    return files;
}

From source file:me.smoe.adar.utils.cam.o.common.SentenceAnalyzer.java

public static Set<String> analyzer(String sentence) throws Exception {
    if (StringUtils.isEmpty(sentence)) {
        return Collections.emptySet();
    }/* w  ww .j a v  a  2 s. c  om*/

    Analyzer analyzer = new StandardAnalyzer();
    try {
        TokenStream tokenStream = analyzer.tokenStream(StringUtils.EMPTY, new StringReader(sentence));
        tokenStream.addAttribute(CharTermAttribute.class);
        tokenStream.reset();

        Set<String> words = new LinkedHashSet<>();
        while (tokenStream.incrementToken()) {
            String word = ((CharTermAttribute) tokenStream.getAttribute(CharTermAttribute.class)).toString();

            if (word.length() <= 1) {
                continue;
            }

            words.add(word);
        }

        return words;
    } finally {
        analyzer.close();
    }
}

From source file:net.sf.sze.util.StringUtil.java

/**
 * /&auml;&ouml;&uuml;&Auml;&Ouml;&Uuml;&szlig;+- werden gelscht.
 * @param text ein Text//from www  . j a va2  s  .co  m
 * @return der bereinigte Text
 */
public static String deleteSpecialCharaters(String text) {
    if (StringUtils.isEmpty(text)) {
        return text;
    }
    return text.replaceAll("[ /+-]", "");
}

From source file:com.tek271.reverseProxy.utils.RegexTools.java

/** Find all matches in a string */
public static List<Tuple3<Integer, Integer, String>> findAll(Pattern pattern, String text,
        boolean matchGroups) {
    if (StringUtils.isEmpty(text))
        return Collections.emptyList();

    Matcher matcher = pattern.matcher(text);
    List<Tuple3<Integer, Integer, String>> r = Lists.newArrayList();
    while (matcher.find()) {
        int groupCount = matcher.groupCount();
        if (groupCount == 0 || !matchGroups) {
            r.add(getMatch(matcher, 0));
        } else {//  w  ww  . j a v  a 2  s  . c o m
            for (int i = 1; i <= groupCount; i++) {
                r.add(getMatch(matcher, i));
            }
        }
    }
    return r;
}

From source file:com.googlecode.jtiger.modules.ecside.core.bean.RowDefaults.java

static String getHighlightClass(TableModel model, String highlightClass) {
    if (StringUtils.isEmpty(highlightClass)) {
        return model.getPreferences().getPreference(PreferencesConstants.ROW_HIGHLIGHT_CLASS);
    }/*from w ww  . j a v a 2s  . co  m*/

    return highlightClass;
}

From source file:com.cy.common.util.ValidateUtil.java

/**
 * ???//from  w ww.j  a  v  a2s.  c om
 * @return false:?; true:
 * */
public static boolean validateIdentityLicenseNum(String identityLicenseNum) {
    if (StringUtils.isEmpty(identityLicenseNum)) {
        return false;
    }
    Pattern pattern = Pattern
            .compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[A-Z])$");
    Matcher macher = pattern.matcher(identityLicenseNum);
    return macher.matches();
}

From source file:com.haulmont.cuba.gui.components.SizeUnit.java

public static SizeUnit getUnitFromSymbol(String symbol) {
    if (StringUtils.isEmpty(symbol)) {
        return SizeUnit.PIXELS; // Defaults to pixels
    }/*from   w w w  . j  a  va 2  s.c o  m*/

    for (SizeUnit unit : SizeUnit.values()) {
        if (symbol.equals(unit.getSymbol())) {
            return unit;
        }
    }

    throw new IllegalArgumentException("Passed symbol cannot be recognized as known SizeUnit");
}