Example usage for java.lang Character isWhitespace

List of usage examples for java.lang Character isWhitespace

Introduction

In this page you can find the example usage for java.lang Character isWhitespace.

Prototype

public static boolean isWhitespace(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is white space according to Java.

Usage

From source file:io.fabric8.kubernetes.client.dsl.base.OperationSupport.java

protected static <T> T unmarshal(InputStream is, Class<T> type) throws KubernetesClientException {
    try (BufferedInputStream bis = new BufferedInputStream(is)) {
        bis.mark(-1);/*from   w w w  .  j av a 2  s.  c  o m*/
        int intch;
        do {
            intch = bis.read();
        } while (intch > -1 && Character.isWhitespace(intch));
        bis.reset();

        ObjectMapper mapper = JSON_MAPPER;
        if (intch != '{') {
            mapper = YAML_MAPPER;
        }
        return mapper.readValue(bis, type);
    } catch (IOException e) {
        throw KubernetesClientException.launderThrowable(e);
    }
}

From source file:com.aurel.track.lucene.util.StringUtil.java

public static String trimLeading(String s) {
    for (int i = 0; i < s.length(); i++) {
        if (!Character.isWhitespace(s.charAt(i))) {
            return s.substring(i, s.length());
        }//from   ww  w .ja  v  a 2 s. c o  m
    }

    return StringPool.BLANK;
}

From source file:com.aerospike.load.Parser.java

/**
 * Parses the line into raw column string values
 * Format of data should follow one rule: No delimeter contain same character as data part
 * @param line One line in data file with CSV formated
 * @return List List of column entries from line
 *//*from www  . ja  v a 2s .  c o m*/
public static List<String> getCSVRawColumns(String line, char delimiter) {

    List<String> store = new ArrayList<String>();
    StringBuilder curVal = new StringBuilder();
    boolean inquotes = false;
    boolean prevDelimiter = false;
    for (int i = 0; i < line.length(); i++) {

        char ch = line.charAt(i);

        // trim white space and tabs after delimiter
        if (prevDelimiter) {
            if (Character.isWhitespace(ch)) {
                continue;
            } else {
                prevDelimiter = false;
            }
        }

        if (inquotes) {
            if (ch == Constants.DOUBLE_QOUTE_DELEMITER) {
                inquotes = false;
            } else {
                curVal.append(ch);
            }
        } else {

            if (ch == Constants.DOUBLE_QOUTE_DELEMITER) {
                inquotes = true;
                if (curVal.length() > 0) {
                    inquotes = false;
                    //if this is the second quote in a value, add a quote
                    //this is for the double quote in the middle of a value
                    curVal.append('\"');
                }
            }

            else if (ch == delimiter) {
                prevDelimiter = true;
                // trim will remove all whitespace character from end of string or
                // after ending double quotes 
                store.add(curVal.toString());
                curVal = new StringBuilder();
            } else {
                curVal.append(ch);
            }
        }
    }
    store.add(curVal.toString());
    return store;
}

From source file:com.g3net.tool.StringUtils.java

/**
 * str0?//from  w ww .j  a  va  2  s . c  o m
 * 
 * @param str
 * @param defaultValue
 * @return
 */
public static String trimWhitespace(String str, String defaultValue) {

    if (!hasLength(str)) {
        return defaultValue;
    }
    StringBuilder buf = new StringBuilder(str);
    while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
        buf.deleteCharAt(0);
    }
    while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) {
        buf.deleteCharAt(buf.length() - 1);
    }
    return buf.toString();
}

From source file:com.aurel.track.lucene.util.StringUtil.java

public static String trimTrailing(String s) {
    for (int i = s.length() - 1; i >= 0; i--) {
        if (!Character.isWhitespace(s.charAt(i))) {
            return s.substring(0, i + 1);
        }/*from   w  w  w  .  ja  v  a 2s .c  o m*/
    }

    return StringPool.BLANK;
}

From source file:net.sf.jabref.importer.fileformat.BibtexParser.java

private void skipWhitespace() throws IOException {
    int character;

    while (true) {
        character = read();/*from  ww w.  jav a2  s . co m*/
        if (isEOFCharacter(character)) {
            eof = true;
            return;
        }

        if (!Character.isWhitespace((char) character)) {
            // found non-whitespace char
            unread(character);
            break;
        }
    }
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

private Phrase processHtmlCodes(String name, Font baseFont, Font symbol) {

    final Font italicFont = new Font(baseFont);
    italicFont.setStyle(Font.FontStyle.ITALIC.getValue());

    final Font normalFont = new Font(baseFont);

    Font usedFont = normalFont;/*from  ww  w .j av  a  2  s  . c  om*/

    final Phrase phrase = new Phrase();

    if (!StringUtils.isEmpty(name)) {

        for (String[] alphabet : GreekAlphabet.getAlphabet()) {
            name = name.replaceAll(alphabet[0], DELIMETER + alphabet[0] + DELIMETER);
        }
        name = name.replaceAll("<sup>|<SUP>", DELIMETER + "<sup>");
        name = name.replaceAll("</sup>|</SUP>", DELIMETER);
        name = name.replaceAll("<i>|<I>|<em>|<EM>", DELIMETER + "<i>");
        name = name.replaceAll("</i>|</I>|</em>|</EM>", DELIMETER + "</i>");

        final String[] tokens = name.split(DELIMETER);
        for (String token : tokens) {

            String text = token;
            if (text.startsWith("<i>")) {
                usedFont = italicFont;
                text = text.substring(3);
            } else if (text.startsWith("</i>")) {
                usedFont = normalFont;
                text = text.substring(4);
            }

            usedFont.setSize(baseFont.getSize());

            if (text.startsWith("&")) {
                final char replacement = GreekAlphabet.getReplacement(text);
                if (!Character.isWhitespace(replacement)) {
                    phrase.add(SpecialSymbol.get(replacement, symbol));
                } else {
                    phrase.add(new Chunk(text, usedFont));
                }
            } else if (text.startsWith("<sup>")) {

                final Font superScriptFont = new Font(usedFont);
                superScriptFont.setSize(baseFont.getSize() - 1.5f);

                final Chunk superScript = new Chunk(text.substring(5), superScriptFont);
                superScript.setTextRise(4f);
                phrase.add(superScript);

            } else {
                phrase.add(new Chunk(text, usedFont));
            }

        }
    }

    return phrase;
}

From source file:importer.filters.PlayFilter.java

/**
 * Is an entire line just whitespace?/*from  w ww . j  a v a2s  .c  o m*/
 * @param line the line in question
 * @return true if it is
 */
boolean isWhitespace(String line) {
    for (int i = 0; i < line.length(); i++) {
        if (!Character.isWhitespace(line.charAt(i)))
            return false;
    }
    return true;
}

From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java

private static String ltrim(String s) {
    int i = 0;//from w  w w .java 2 s . com
    while (i < s.length() && Character.isWhitespace(s.charAt(i))) {
        i++;
    }
    return s.substring(i);
}

From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java

private void processHeaderLine(StringBuffer line) throws HttpException {

    int colonIndex = line.indexOf(":"); // key is up to colon
    if (colonIndex == -1) {
        int i;//from   ww  w.  j a  v  a 2s .co  m
        for (i = 0; i < line.length(); i++)
            if (!Character.isWhitespace(line.charAt(i)))
                break;
        if (i == line.length())
            return;
        throw new HttpException("No colon in header:" + line);
    }
    String key = line.substring(0, colonIndex);

    int valueStart = colonIndex + 1; // skip whitespace
    while (valueStart < line.length()) {
        int c = line.charAt(valueStart);
        if (c != ' ' && c != '\t')
            break;
        valueStart++;
    }
    String value = line.substring(valueStart);
    headers.addValue(key.toLowerCase(Locale.ROOT), value);
}