Example usage for org.apache.commons.lang CharUtils isAscii

List of usage examples for org.apache.commons.lang CharUtils isAscii

Introduction

In this page you can find the example usage for org.apache.commons.lang CharUtils isAscii.

Prototype

public static boolean isAscii(char ch) 

Source Link

Document

Checks whether the character is ASCII 7 bit.

Usage

From source file:jef.testbase.JefTester.java

private static void sampleAdd(Map<Integer, Integer> data, BufferedReader r) throws IOException {
    String line;/*  w w  w.  j a va2 s . c  om*/
    while ((line = r.readLine()) != null) {
        for (char c : line.toCharArray()) {
            total++;
            Integer i = (int) c;
            if (!CharUtils.isAscii((char) i.intValue())) {
                totalStat++;
                if (data.containsKey(i)) {
                    data.put(i, data.get(i) + 1);
                } else {
                    data.put(i, 1);
                }
            }
        }
    }
}

From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java

/**
 * Stops newlines tabs and EOF from being written, adds an escape to brackets and backslash, converts non-ascii
 * characters to their RTF tag and lets all other characters through.
 * /*from  w  w w.ja v  a 2  s .  co  m*/
 * @param c
 * @return
 */
private String getMiddleChar(char c) {
    StringBuilder output = new StringBuilder(EMPTY);
    if (c != '\n' && c != '\t' && c != '\0') {
        if (c == '{' || c == '}' || c == '\\') {
            output.append(BACKSLASH);
        }

        if (CharUtils.isAscii(c)) {
            output.append(c);
        } else {
            int unicode = (int) c;
            output = new StringBuilder(UNICODE_START_TAG + unicode + UNICODE_END_TAG);
        }
    }
    return output.toString();
}

From source file:org.apache.hawq.pxf.plugins.hive.HiveResolver.java

void parseDelimiterChar(InputData input) {

    String userDelim = input.getUserProperty("DELIMITER");

    if (userDelim == null) {
        throw new IllegalArgumentException("DELIMITER is a required option");
    }//from ww w .  j ava2s . c o  m

    final int VALID_LENGTH = 1;
    final int VALID_LENGTH_HEX = 4;

    if (userDelim.startsWith("\\x")) { // hexadecimal sequence

        if (userDelim.length() != VALID_LENGTH_HEX) {
            throw new IllegalArgumentException("Invalid hexdecimal value for delimiter (got" + userDelim + ")");
        }

        delimiter = (char) Integer.parseInt(userDelim.substring(2, VALID_LENGTH_HEX), 16);

        if (!CharUtils.isAscii(delimiter)) {
            throw new IllegalArgumentException(
                    "Invalid delimiter value. Must be a single ASCII character, or a hexadecimal sequence (got non ASCII "
                            + delimiter + ")");
        }

        return;
    }

    if (userDelim.length() != VALID_LENGTH) {
        throw new IllegalArgumentException(
                "Invalid delimiter value. Must be a single ASCII character, or a hexadecimal sequence (got "
                        + userDelim + ")");
    }

    if (!CharUtils.isAscii(userDelim.charAt(0))) {
        throw new IllegalArgumentException(
                "Invalid delimiter value. Must be a single ASCII character, or a hexadecimal sequence (got non ASCII "
                        + userDelim + ")");
    }

    delimiter = userDelim.charAt(0);
}

From source file:org.executequery.gui.editor.LobDataItemViewerPanel.java

private void loadTextData() {

    String dataAsText = null;//from  w  w w  .j  a  v a  2 s . c o m
    byte[] data = recordDataItemByteArray();
    boolean isValidText = true;

    if (data != null) {

        dataAsText = new String(data);
        char[] charArray = dataAsText.toCharArray();

        int defaultEndPoint = 256;
        int endPoint = Math.min(charArray.length, defaultEndPoint);

        for (int i = 0; i < endPoint; i++) {

            if (!CharUtils.isAscii(charArray[i])) {

                isValidText = false;
                break;
            }

        }

    } else {

        isValidText = false;
    }

    if (isValidText) {

        setTextAreaText(textArea, dataAsText);

    } else {

        setTextAreaText(textArea, CANNOT_DISPLAY_BINARY_DATA_AS_TEXT);
    }

}

From source file:org.yccheok.jstock.gui.Utils.java

/**
 * Returns list of Han Yu Pin Yin's prefix of every characters. If the
 * character is an alphabet or numerical, the original character will be
 * used. If there is any error occur during conversion, that particular
 * character will be ignored./*from w  w  w  .ja  v a2 s . c  o m*/
 *
 * @param chinese String to be converted
 * @return List of Han Yu Pin Yin's prefix of every characters.
 */
public static List<String> toHanyuPinyin(String chinese) {
    // Is this an empty string?
    if (chinese.isEmpty()) {
        return new ArrayList<String>();
    }

    // Use StringBuilder instead of String during processing for speed
    // optimization.
    List<StringBuilder> stringBuilders = null;

    for (int i = 0, length = chinese.length(); i < length; i++) {
        final char c = chinese.charAt(i);

        String[] pinyins = null;
        final java.util.Set<Character> set = new java.util.HashSet<Character>();
        // Is this Chinese character?
        if (CharUtils.isAscii(c)) {
            if (CharUtils.isAsciiAlphanumeric(c)) {
                // We are only interested in 'abc' and '123'.
                set.add(c);
            }
        } else {
            // This is possible a Chinese character.
            try {
                pinyins = PinyinHelper.toHanyuPinyinStringArray(c, DEFAULT_HANYU_PINYIN_OUTPUT_FORMAT);
                if (pinyins != null) {
                    for (String pinyin : pinyins) {
                        set.add(pinyin.charAt(0));
                    }
                }
            } catch (BadHanyuPinyinOutputFormatCombination ex) {
                log.error(null, ex);
                // No. This is not Chinese character.
                // Just ignore the error. Continue for the rest of characters.
                // return new ArrayList<String>();
            }
        }
        final List<StringBuilder> tmps = stringBuilders;
        stringBuilders = new ArrayList<StringBuilder>();

        if (tmps == null) {
            // This will be the first converted character.
            for (Character character : set) {
                final StringBuilder me = new StringBuilder();
                me.append(character);
                stringBuilders.add(me);
            }
        } else {
            for (Character character : set) {
                for (StringBuilder tmp : tmps) {
                    final StringBuilder me = new StringBuilder();
                    me.append(tmp);
                    me.append(character);
                    stringBuilders.add(me);
                }
            }
        }
    }

    List<String> result = new ArrayList<String>();
    // Do we have any converted characters?
    if (stringBuilders != null) {
        for (StringBuilder stringBuilder : stringBuilders) {
            result.add(stringBuilder.toString());
        }
    }

    return result;
}