Example usage for java.lang Character isISOControl

List of usage examples for java.lang Character isISOControl

Introduction

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

Prototype

public static boolean isISOControl(int codePoint) 

Source Link

Document

Determines if the referenced character (Unicode code point) is an ISO control character.

Usage

From source file:org.apache.asterix.external.classad.ClassAdUnParser.java

/**
 * Unparse a value//from  w  ww .  j a  v  a  2  s  . c  o m
 *
 * @param buffer
 *            The string to unparse to
 * @param val
 *            The value to unparse
 * @throws HyracksDataException
 */
public void unparse(AMutableCharArrayString buffer, Value val) throws HyracksDataException {
    switch (val.getType()) {
    case NULL_VALUE:
        buffer.appendString("(null-value)");
        break;

    case STRING_VALUE: {
        AMutableCharArrayString s = objectPool.strPool.get();
        val.isStringValue(s);
        buffer.appendChar('"');
        for (int i = 0; i < s.getLength(); i++) {
            char ch = s.charAt(i);
            if (ch == delimiter) {
                if (delimiter == '\"') {
                    buffer.appendString("\\\"");
                    continue;
                } else {
                    buffer.appendString("\\\'");
                    continue;
                }
            }
            switch (ch) {
            case '\b':
                buffer.appendString("\\b");
                continue;
            case '\f':
                buffer.appendString("\\f");
                continue;
            case '\n':
                buffer.appendString("\\n");
                continue;
            case '\r':
                buffer.appendString("\\r");
                continue;
            case '\t':
                buffer.appendString("\\t");
                continue;
            case '\\':
                buffer.appendString("\\\\");
                continue;
            case '\'':
                buffer.appendString("\'");
                continue;
            case '\"':
                buffer.appendString("\"");
                continue;
            default:
                if (Character.isISOControl(ch)) {
                    // print octal representation
                    buffer.appendString(String.format("\\%03o", ch));
                    continue;
                }
                break;
            }

            buffer.appendChar(ch);
        }
        buffer.appendChar('"');
        return;
    }
    case INTEGER_VALUE: {
        AMutableInt64 i = objectPool.int64Pool.get();
        val.isIntegerValue(i);
        buffer.appendString(String.valueOf(i.getLongValue()));
        return;
    }
    case REAL_VALUE: {
        AMutableDouble real = objectPool.doublePool.get();
        val.isRealValue(real);
        if (real.getDoubleValue() == 0.0) {
            // It might be positive or negative and it's
            // hard to tell. printf is good at telling though.
            // We also want to print it with as few
            // digits as possible, which is why we don't use the
            // case below.
            buffer.appendString(String.valueOf(real.getDoubleValue()));
        } else if (Util.isNan(real.getDoubleValue())) {
            buffer.appendString("real(\"NaN\")");
        } else if (Util.isInf(real.getDoubleValue()) == -1) {
            buffer.appendString("real(\"-INF\")");
        } else if (Util.isInf(real.getDoubleValue()) == 1) {
            buffer.appendString("real(\"INF\")");
        } else {
            buffer.appendString(String.format("%1.15E", real.getDoubleValue()));
        }
        return;
    }
    case BOOLEAN_VALUE: {
        MutableBoolean b = objectPool.boolPool.get();
        val.isBooleanValue(b);
        buffer.appendString(b.booleanValue() ? "true" : "false");
        return;
    }
    case UNDEFINED_VALUE: {
        buffer.appendString("undefined");
        return;
    }
    case ERROR_VALUE: {
        buffer.appendString("error");
        return;
    }
    case ABSOLUTE_TIME_VALUE: {
        ClassAdTime asecs = objectPool.classAdTimePool.get();
        val.isAbsoluteTimeValue(asecs);

        buffer.appendString("absTime(\"");
        Util.absTimeToString(asecs, buffer);
        buffer.appendString("\")");
        return;
    }
    case RELATIVE_TIME_VALUE: {
        ClassAdTime rsecs = objectPool.classAdTimePool.get();
        val.isRelativeTimeValue(rsecs);
        buffer.appendString("relTime(\"");
        Util.relTimeToString(rsecs.getRelativeTime(), buffer);
        buffer.appendString("\")");

        return;
    }
    case CLASSAD_VALUE: {
        ClassAd ad = objectPool.classAdPool.get();
        Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
        val.isClassAdValue(ad);
        ad.getComponents(attrs, objectPool);
        unparseAux(buffer, attrs);
        return;
    }
    case SLIST_VALUE:
    case LIST_VALUE: {
        ExprList el = objectPool.exprListPool.get();
        val.isListValue(el);
        unparseAux(buffer, el);
        return;
    }
    }
}

From source file:org.archive.io.warc.WARCWriter.java

protected void baseCharacterCheck(final char c, final String parameter) throws IllegalArgumentException {
    // TODO: Too strict?  UNICODE control characters?
    if (Character.isISOControl(c) || !Character.isValidCodePoint(c)) {
        throw new IllegalArgumentException(
                "Contains illegal character 0x" + Integer.toHexString(c) + ": " + parameter);
    }// w  w  w  . j a  v  a 2 s .  c  om
}

From source file:asterix.parser.classad.ClassAdUnParser.java

/**
 * Unparse a value/*from   www .  j  a  va  2s  .c  o  m*/
 * 
 * @param buffer
 *            The string to unparse to
 * @param val
 *            The value to unparse
 * @throws HyracksDataException
 */
public void unparse(AMutableCharArrayString buffer, Value val) throws HyracksDataException {
    switch (val.getType()) {
    case NULL_VALUE:
        buffer.appendString("(null-value)");
        break;

    case STRING_VALUE: {
        AMutableCharArrayString s = new AMutableCharArrayString();
        val.isStringValue(s);
        buffer.appendChar('"');
        for (int i = 0; i < s.getLength(); i++) {
            char ch = s.charAt(i);
            if (ch == delimiter) {
                if (delimiter == '\"') {
                    buffer.appendString("\\\"");
                    continue;
                } else {
                    buffer.appendString("\\\'");
                    continue;
                }
            }
            switch (ch) {
            case '\b':
                buffer.appendString("\\b");
                continue;
            case '\f':
                buffer.appendString("\\f");
                continue;
            case '\n':
                buffer.appendString("\\n");
                continue;
            case '\r':
                buffer.appendString("\\r");
                continue;
            case '\t':
                buffer.appendString("\\t");
                continue;
            case '\\':
                buffer.appendString("\\\\");
                continue;
            case '\'':
                buffer.appendString("\'");
                continue;
            case '\"':
                buffer.appendString("\"");
                continue;
            default:
                if (Character.isISOControl(ch)) {
                    // print octal representation
                    buffer.appendString(String.format("\\%03o", ch));
                    continue;
                }
                break;
            }

            buffer.appendChar(ch);
        }
        buffer.appendChar('"');
        return;
    }
    case INTEGER_VALUE: {
        AMutableInt64 i = new AMutableInt64(0);
        val.isIntegerValue(i);
        buffer.appendString(String.valueOf(i.getLongValue()));
        return;
    }
    case REAL_VALUE: {
        AMutableDouble real = new AMutableDouble(0);
        val.isRealValue(real);
        if (real.getDoubleValue() == 0.0) {
            // It might be positive or negative and it's
            // hard to tell. printf is good at telling though.
            // We also want to print it with as few
            // digits as possible, which is why we don't use the 
            // case below.
            buffer.appendString(String.valueOf(real.getDoubleValue()));
        } else if (Util.isNan(real.getDoubleValue())) {
            buffer.appendString("real(\"NaN\")");
        } else if (Util.isInf(real.getDoubleValue()) == -1) {
            buffer.appendString("real(\"-INF\")");
        } else if (Util.isInf(real.getDoubleValue()) == 1) {
            buffer.appendString("real(\"INF\")");
        } else {
            buffer.appendString(String.format("%1.15E", real.getDoubleValue()));
        }
        return;
    }
    case BOOLEAN_VALUE: {
        MutableBoolean b = new MutableBoolean();
        val.isBooleanValue(b);
        buffer.appendString(b.booleanValue() ? "true" : "false");
        return;
    }
    case UNDEFINED_VALUE: {
        buffer.appendString("undefined");
        return;
    }
    case ERROR_VALUE: {
        buffer.appendString("error");
        return;
    }
    case ABSOLUTE_TIME_VALUE: {
        ClassAdTime asecs = new ClassAdTime();
        val.isAbsoluteTimeValue(asecs);

        buffer.appendString("absTime(\"");
        Util.absTimeToString(asecs, buffer);
        buffer.appendString("\")");
        return;
    }
    case RELATIVE_TIME_VALUE: {
        ClassAdTime rsecs = new ClassAdTime();
        val.isRelativeTimeValue(rsecs);
        buffer.appendString("relTime(\"");
        Util.relTimeToString(rsecs.getRelativeTime(), buffer);
        buffer.appendString("\")");

        return;
    }
    case CLASSAD_VALUE: {
        ClassAd ad = new ClassAd();
        Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>();
        val.isClassAdValue(ad);
        ad.getComponents(attrs);
        unparseAux(buffer, attrs);
        return;
    }
    case SLIST_VALUE:
    case LIST_VALUE: {
        ExprList el = new ExprList();
        val.isListValue(el);
        unparseAux(buffer, el);
        return;
    }
    }
}

From source file:com.igormaznitsa.charsniffer.CharSnifferMojo.java

static boolean checkForAbc(@Nonnull final String text, @Nonnull final CheckConfig config,
        @Nonnull final StringBuilder errorBuffer) {
    final String allowed = config.abc;
    final String disallowed = config.noAbc;

    final Set<Character> errorChars = new HashSet<Character>();

    if (allowed != null || disallowed != null) {
        for (int i = 0; i < text.length(); i++) {
            final char c = text.charAt(i);

            if (config.ignoreAbcForISOControl && Character.isISOControl(c)) {
                continue;
            }//from   www .ja  v a 2s .c om

            if (allowed != null) {
                if (allowed.indexOf(c) < 0) {
                    if (!errorChars.contains(c)) {
                        errorChars.add(c);
                        if (errorBuffer.length() > 0) {
                            errorBuffer.append(',');
                        }
                        errorBuffer.append('\'').append(c).append('\'');
                    }
                }
            }

            if (disallowed != null) {
                if (disallowed.indexOf(c) >= 0) {
                    if (!errorChars.contains(c)) {
                        errorChars.add(c);
                        if (errorBuffer.length() > 0) {
                            errorBuffer.append(',');
                        }
                        errorBuffer.append('\'').append(c).append('\'');
                    }
                }
            }
        }
    }

    return errorChars.isEmpty();
}

From source file:com.kappaware.logtrawler.MFile.java

/**
 * Note we use the timestamp of the triggering event.
 * @param timestamp/*from   w w w  . j av a 2  s  .  c o m*/
 * @return
 * @throws IOException
 */

String readLine(long timestamp) throws IOException {
    //try {
    this.lastAccessTime = timestamp;
    while (true) {
        int c = this.reader.read();
        switch (c) {
        case '\n':
            this.nbrCharRead++;
            this.lastFetchTime = this.lastAccessTime;
            this.position = this.channel.position();
            String r = this.line.toString();
            this.line.delete(0, this.line.length());
            if (r.length() > this.maxLineLength) {
                this.maxLineLength = r.length();
            }
            this.lastLine = r;
            this.nbrLineRead++;
            return r;
        //break;
        case -1:
            this.position = this.channel.position();
            return null;
        case '\r':
        case '\t':
            // handle specially to skip isIsoControl()
            this.nbrCharRead++;
            this.line.append((char) c);
            break;
        default:
            this.nbrCharRead++;
            if (Character.isISOControl(c)) {
                this.nbrControlCharRead++;
            }
            this.line.append((char) c);
            break;
        }
        // Check every 50 characters
        if (this.nbrCharRead % 50 == 0) {
            if (this.line.length() > config.getMaxLineLength()) {
                this.isLog = false;
                log.info(String.format("File '%s' is flagged as non-log, due to oversized line (> %d)",
                        this.path, config.getMaxLineLength()));
                this.comment = String.format("File is flagged as non-log, due to oversized line (> %d)",
                        config.getMaxLineLength());
                // Delete line, as it can introduce parsing error on stats
                this.line.delete(0, this.line.length());
                return null;
            }
            if (((this.nbrControlCharRead * 100) / this.nbrCharRead) > config.getMaxControlCharPercent()) {
                this.isLog = false;
                log.info(String.format(
                        "File '%s' is flagged as non-log, due to too many control char (%d for %d exceed %d percent)",
                        this.path, this.nbrControlCharRead, this.nbrCharRead,
                        config.getMaxControlCharPercent()));
                this.comment = String.format(
                        "File is flagged as non-log, due to too many control char (%d for %d exceed %d percent)",
                        this.nbrControlCharRead, this.nbrCharRead, config.getMaxControlCharPercent());
                // Delete line, as it can introduce parsing error on stats
                this.line.delete(0, this.line.length());
                return null;
            }
        }
    }
    //} catch (IOException e) {
    //log.error(String.format("Error on reading '%s'", this.path), e);
    //return null;
    //}
}

From source file:com.exalttech.trex.ui.controllers.PacketViewerController.java

/**
 * Convert hex to string//from   www.  j a va2s .c om
 *
 * @param hex
 * @return
 */
private String convertHexToString(String hex) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hex.length() - 1; i += 2) {
        String output = hex.substring(i, i + 2);
        int decimal = Integer.parseInt(output, 16);
        if (!Character.isISOControl(decimal)) {
            sb.append((char) decimal);
        } else {
            sb.append('.');
        }
    }
    return sb.toString();
}

From source file:StringUtils.java

public static final String javaEscape(String s) {
    if (s == null)
        return null;
    char c;//from   w  w  w  .j  a  va 2s .  c  o m
    int len = s.length();
    StringBuffer b = new StringBuffer(len);
    for (int i = 0; i < len; i++) {
        c = s.charAt(i);
        switch (c) {
        case '\n':
            b.append("\\n");
            break;
        case '\t':
            b.append("\\t");
            break;
        case '\r':
            b.append("\\r");
            break;
        case '"':
            b.append("\"");
            break;
        case '\\':
            b.append("\\\\");
            break;
        default:
            if (c > 127 || Character.isISOControl(c)) {
                b.append("\\u");
                String nb = Integer.toString((int) c, 16);
                int nblen = nb.length();
                switch (nblen) {
                case 1:
                    b.append(0);
                case 2:
                    b.append(0);
                case 3:
                    b.append(0);
                case 4:
                    b.append(nb);
                    break;
                default:
                    throw new IllegalArgumentException("Should not happen !");
                }
            } else
                b.append(c);
        }
    }
    return b.toString();
}

From source file:brut.androlib.res.xml.ResXmlEncoders.java

private static boolean isPrintableChar(char c) {
    Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
    return !Character.isISOControl(c) && c != KeyEvent.CHAR_UNDEFINED && block != null
            && block != Character.UnicodeBlock.SPECIALS;
}

From source file:com.shvet.poi.util.HexDump.java

public static char toAscii(int dataB) {
    char charB = (char) (dataB & 0xFF);
    if (Character.isISOControl(charB))
        return '.';

    switch (charB) {
    case 0xFF://from ww w.j av a2 s  .com
    case 0xDD: // printable, but not compilable with current compiler encoding
        charB = '.';
        break;
    }
    return charB;
}

From source file:pyromaniac.IO.MMFastqImporter.java

/**
 * Checks if the char is printable//w  w w  .j  a v a 2 s . c o m
 *
 * @param c the c
 * @return true, if is printable char
 */
public boolean isPrintableChar(char c) {
    Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
    return (!Character.isISOControl(c)) && block != null && block != Character.UnicodeBlock.SPECIALS;
}