Example usage for java.lang Character isDefined

List of usage examples for java.lang Character isDefined

Introduction

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

Prototype

public static boolean isDefined(int codePoint) 

Source Link

Document

Determines if a character (Unicode code point) is defined in Unicode.

Usage

From source file:it.geosdi.era.server.servlet.HTTPProxy.java

public static int escapeHtmlFull(int ch) {
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') {
        // safe// w w w .j a v a  2 s .c o  m
        return ch;
    } else if (Character.isWhitespace(ch)) {
        if (ch != '\n' && ch != '\r' && ch != '\t')
            // safe
            return ch;
    } else if (Character.isDefined(ch)) {
        // safe
        return ch;
    } else if (Character.isISOControl(ch)) {
        // paranoid version:isISOControl which are not isWhitespace
        // removed !
        // do nothing do not include in output !
        return -1;
    } else if (Character.isHighSurrogate((char) ch)) {
        // do nothing do not include in output !
        return -1;
    } else if (Character.isLowSurrogate((char) ch)) {
        // wrong char[] sequence, //TODO: LOG !!!
        return -1;
    }

    return -1;
}

From source file:org.beryx.viewreka.fxapp.Viewreka.java

private static boolean isProbablyBinary(File file) {
    try {//from  www. jav a 2s  .c o m
        List<String> lines = Files.readAllLines(Paths.get(file.getAbsolutePath()));
        if (!lines.isEmpty()) {
            long binCharCount = 0;
            long binLineCount = 0;
            for (String line : lines) {
                if (CONTROL_PATTERN.matcher(line).matches())
                    return true;
                if (line.chars().filter(ch -> !Character.isDefined(ch)).findFirst().isPresent())
                    return true;
                long count = line.chars().filter(ch -> (ch > 127)).count();
                if (count > 0) {
                    binCharCount += count;
                    binLineCount++;
                }
            }
            if (binCharCount == 0 || binLineCount == 0)
                return false;
            long length = file.length();
            if (length < 100) {
                if (binCharCount > 10)
                    return true;
            } else {
                if (100.0 * binCharCount / length > 10)
                    return true;
                if (100.0 * binLineCount / lines.size() > 50)
                    return true;
            }
        }
    } catch (Throwable t) {
        log.error("An error occurred while analyzing the file", t);
        return true;
    }
    return false;
}

From source file:org.commoncrawl.util.shared.ArcFileReaderTests.java

static String randomString(final Random random, final int minLength, final int maxLength) {
    final int length = random.nextInt(maxLength - minLength) + minLength;
    final char[] chars = new char[length];
    for (int i = 0, x = chars.length; i < x;)
        do {//www.j  a  va 2  s  .c  o  m
            final int cp = random.nextInt(0x10FFFF + 1);
            if (!Character.isDefined(cp))
                continue;
            final char[] chs = Character.toChars(cp);
            if (chs.length > x - i)
                continue;
            for (final char ch : chs) {
                if (!Character.isWhitespace(ch)) {
                    chars[i++] = ch;
                }
            }
            break;

        } while (true);

    return new String(chars);
}