Example usage for java.lang Character toChars

List of usage examples for java.lang Character toChars

Introduction

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

Prototype

public static char[] toChars(int codePoint) 

Source Link

Document

Converts the specified character (Unicode code point) to its UTF-16 representation stored in a char array.

Usage

From source file:net.metanotion.json.StreamingParser.java

private String lexDigits(final Reader in) throws IOException {
    final StringBuilder sb = new StringBuilder();
    while (true) {
        in.mark(MAX_BUFFER);//from w w  w .  jav  a 2  s. com
        final int c = in.read();
        if (Character.isDigit(c)) {
            sb.append(Character.toChars(c));
        } else {
            in.reset();
            if (sb.length() == 0) {
                throw new ParserException(EXPECTED_DIGIT);
            }
            return sb.toString();
        }
    }
}

From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java

/**
 * Numbering scheme using UTF Dingbat Negative Circled Digit characters `?-?`.
 * //from w  w  w  .jav a2s .  co m
 * ----
 * ? item 1
 * ? item 2
 * ? item 3
 * ...
 * ? item 10
 * ----
 * 
 * @return the line
 */
public static TA_Numbering numberDingbatNegativeCircledDigit() {
    return new TA_Numbering() {
        @Override
        public String getNumber(int number) {
            Validate.validState(0 < number && number < 11,
                    "numbering supported 0<number<11 - number was: " + number);
            return new String(Character.toChars(number + 10101));
        }

        @Override
        public int getMinNumber() {
            return 1;
        }

        @Override
        public int getMaxNumber() {
            return 10;
        }

        @Override
        public String getDescription() {
            return "numbering scheme using UTF Dingbat Negative Circled Digit characters '?-?'";
        }
    };
}

From source file:co.nubetech.apache.hadoop.TextSplitter.java

/**
 * Return the string encoded in a BigDecimal. Repeatedly multiply the input
 * value by 65536; the integer portion after such a multiplication
 * represents a single character in base 65536. Convert that back into a
 * char and create a string out of these until we have no data left.
 *///from www .  j  av a 2 s .c  om
String bigDecimalToString(BigDecimal bd) {
    BigDecimal cur = bd.stripTrailingZeros();
    StringBuilder sb = new StringBuilder();

    for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
        cur = cur.multiply(ONE_PLACE);
        int curCodePoint = cur.intValue();
        if (0 == curCodePoint) {
            break;
        }

        cur = cur.subtract(new BigDecimal(curCodePoint));
        sb.append(Character.toChars(curCodePoint));
    }

    return sb.toString();
}

From source file:spark.help.CustomNTriplesParser.java

private int parseTriple(int c) throws IOException, RDFParseException, RDFHandlerException {
    boolean ignoredAnError = false;
    try {/*from   www .j  a  v  a2s  .co  m*/
        c = parseSubject(c, buffer);
        subject = buffer.toString();
        clearBuffer(buffer);

        c = skipWhitespace(c);

        c = parsePredicate(c, buffer);
        predicate = buffer.toString();
        clearBuffer(buffer);

        c = skipWhitespace(c);

        c = parseObject(c, buffer);
        object = buffer.toString();
        clearBuffer(buffer);
        clearBuffer(datatypeUri);
        clearBuffer(languageTag);

        c = skipWhitespace(c);

        if (c == -1) {
            throwEOFException();
        } else if (c != '.') {
            reportError("Expected '.', found: " + new String(Character.toChars(c)),
                    NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
        }

        c = assertLineTerminates(c);
    } catch (RDFParseException rdfpe) {
        if (getParserConfig().isNonFatalError(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES)) {
            reportError(rdfpe, NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
            ignoredAnError = true;
        } else {
            throw rdfpe;
        }
    }

    c = skipLine(c);

    if (!ignoredAnError) {

        Tuple2<String, String> po = new Tuple2<String, String>(predicate, object);
        result.add(new Tuple2<String, Tuple2<String, String>>(subject, po));
        //result.add(new Tuple2<String,String>(subject,predicate+DataFormatter.SEPERATOR+object));
        /*Statement st = createStatement(subject, predicate, object);
        if (rdfHandler != null) {
           rdfHandler.handleStatement(st);
        }*/
    }

    subject = null;
    predicate = null;
    object = null;

    return c;
}

From source file:net.metanotion.json.StreamingParser.java

private Lexeme lexString(final Reader in) throws IOException {
    final StringBuilder sb = new StringBuilder();
    boolean escape = false;
    while (true) {
        final int c = in.read();
        if (c == -1) {
            throw new ParserException("Expected a character instead of end of stream");
        }//  w ww.  j a  v  a2  s.co  m
        final String cbuf = new String(Character.toChars(c));
        if (("\"".equals(cbuf)) && !escape) {
            return new Lexeme(Token.STRING, StringEscapeUtils.unescapeJson(sb.toString()));
        } else if ("\\".equals(cbuf)) {
            escape = true;
            sb.append(cbuf);
        } else {
            escape = false;
            sb.append(cbuf);
        }
    }
}

From source file:org.apache.sqoop.mapreduce.db.TextSplitter.java

/**
 * Return the string encoded in a BigDecimal.
 * Repeatedly multiply the input value by 65536; the integer portion after
 * such a multiplication represents a single character in base 65536.
 * Convert that back into a char and create a string out of these until we
 * have no data left./*w w w . j  a  v  a  2 s  .  c  o  m*/
 */
public String bigDecimalToString(BigDecimal bd) {
    BigDecimal cur = bd.stripTrailingZeros();
    StringBuilder sb = new StringBuilder();

    for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
        cur = cur.multiply(ONE_PLACE);
        int curCodePoint = cur.intValue();
        if (0 == curCodePoint) {
            break;
        }

        cur = cur.subtract(new BigDecimal(curCodePoint));
        sb.append(Character.toChars(curCodePoint));
    }

    return sb.toString();
}

From source file:org.openrdf.rio.turtle.TurtleParser.java

protected void parseStatement() throws IOException, RDFParseException, RDFHandlerException {

    StringBuilder sb = new StringBuilder(8);

    int codePoint;
    // longest valid directive @prefix
    do {/*w w w.  j av a 2  s. c om*/
        codePoint = readCodePoint();
        if (codePoint == -1 || TurtleUtil.isWhitespace(codePoint)) {
            unread(codePoint);
            break;
        }
        sb.append(Character.toChars(codePoint));
    } while (sb.length() < 8);

    String directive = sb.toString();

    if (directive.startsWith("@") || directive.equalsIgnoreCase("prefix")
            || directive.equalsIgnoreCase("base")) {
        parseDirective(directive);
        skipWSC();
        // SPARQL BASE and PREFIX lines do not end in .
        if (directive.startsWith("@")) {
            verifyCharacterOrFail(readCodePoint(), ".");
        }
    } else {
        unread(directive);
        parseTriples();
        skipWSC();
        verifyCharacterOrFail(readCodePoint(), ".");
    }
}

From source file:com.careerly.utils.TextUtils.java

/**
 * ?//from   w  w  w .  j a  v a2 s  .  c  o  m
 *
 * @param text
 * @return
 */
public static String removeDoubleByte(String text) {

    if (StringUtils.isBlank(text)) {
        return StringUtils.EMPTY;
    }

    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < text.codePointCount(0, text.length()); i++) {
        char[] chars = Character.toChars(text.codePointAt(i));
        if (chars.length == 1) {
            stringBuilder.append(String.valueOf(chars));
        }
    }
    return stringBuilder.toString();
}

From source file:org.eclipse.rdf4j.rio.ntriples.NTriplesParser.java

private int parseTriple(int c) throws IOException, RDFParseException, RDFHandlerException {
    boolean ignoredAnError = false;
    try {//from w  w w .j a  v a  2  s  .  com
        c = parseSubject(c);

        c = skipWhitespace(c);

        c = parsePredicate(c);

        c = skipWhitespace(c);

        c = parseObject(c);

        c = skipWhitespace(c);

        if (c == -1) {
            throwEOFException();
        } else if (c != '.') {
            reportError("Expected '.', found: " + new String(Character.toChars(c)),
                    NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
        }

        c = assertLineTerminates(c);
    } catch (RDFParseException rdfpe) {
        if (getParserConfig().isNonFatalError(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES)) {
            reportError(rdfpe, NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
            ignoredAnError = true;
        } else {
            throw rdfpe;
        }
    }

    c = skipLine(c);

    if (!ignoredAnError) {
        Statement st = createStatement(subject, predicate, object);
        if (rdfHandler != null) {
            rdfHandler.handleStatement(st);
        }
    }

    subject = null;
    predicate = null;
    object = null;

    return c;
}

From source file:org.jumpmind.symmetric.io.PostgresBulkDatabaseWriter.java

protected String encode(byte[] byteData) {
    StringBuilder sb = new StringBuilder();
    for (byte b : byteData) {
        int i = b & 0xff;
        if (i >= 0 && i <= 7) {
            sb.append("\\00").append(Integer.toString(i, 8));
        } else if (i >= 8 && i <= 31) {
            sb.append("\\0").append(Integer.toString(i, 8));
        } else if (i == 92 || i >= 127) {
            sb.append("\\").append(Integer.toString(i, 8));
        } else {//ww  w  .  j av  a  2s .  co m
            sb.append(Character.toChars(i));
        }
    }
    return sb.toString();
}