Example usage for java.io CharArrayReader CharArrayReader

List of usage examples for java.io CharArrayReader CharArrayReader

Introduction

In this page you can find the example usage for java.io CharArrayReader CharArrayReader.

Prototype

public CharArrayReader(char buf[], int offset, int length) 

Source Link

Document

Creates a CharArrayReader from the specified array of chars.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    char[] ch = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', };

    CharArrayReader car = new CharArrayReader(ch, 2, 3);

}

From source file:org.unitime.commons.hibernate.blob.XmlClobType.java

public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session)
        throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {//from ww  w.ja v a 2  s.  c  o  m
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(bytes, OutputFormat.createCompactFormat());
            writer.write((Document) value);
            writer.flush();
            writer.close();
            ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(), 0, bytes.size()),
                    bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(), e);
        }
    }
}

From source file:ro.nextreports.designer.ui.sqleditor.syntax.SyntaxDocument.java

/**
 * Parse the entire document and return list of tokens that do not already
 * exist in the tokens list. There may be overlaps, and replacements, 
 * which we will cleanup later.//from   www  .  j a  va  2s.co m
 * 
 * @return list of tokens that do not exist in the tokens field 
 */
private void parse() {
    // if we have no lexer, then we must have no tokens...
    if (lexer == null) {
        tokens = null;
        return;
    }

    List<Token> tokens = new ArrayList<Token>(getLength() / 10);
    long time = System.nanoTime();
    int length = getLength();
    try {
        Segment segment = new Segment();
        getText(0, getLength(), segment);
        CharArrayReader reader = new CharArrayReader(segment.array, segment.offset, segment.count);
        lexer.yyreset(reader);
        Token token;
        while ((token = lexer.yylex()) != null) {
            tokens.add(token);
        }
    } catch (BadLocationException e) {
        LOG.error(e.getMessage(), e);
    } catch (IOException e) {
        // This will not be thrown from the Lexer
        LOG.error(e.getMessage(), e);
    } finally {
        // Benchmarks:
        // Parsed 574038 chars in 81 ms, giving 74584 tokens
        //                System.out.printf("Parsed %d in %d ms, giving %d tokens",
        //                        len, (System.nanoTime() - ts) / 1000000, toks.size());
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Parsed %d in %d ms, giving %d tokens", length,
                    (System.nanoTime() - time) / 1000000, tokens.size()));
        }
        this.tokens = tokens;
    }
}

From source file:ClosableCharArrayWriter.java

/**
 * Performs an effecient (zero-copy) conversion of the character data
 * accumulated in this writer to a reader. 
 *
 * To ensure the integrity of the resulting reader, {@link #free()
 * free} is invoked upon this writer as a side-effect.
 *
 * @return a reader representing this writer's accumulated
 *      character data/*w w w  .jav a  2s . co m*/
 * @throws java.io.IOException if an I/O error occurs.
 *      In particular, an <tt>IOException</tt> may be thrown
 *      if this writer has been {@link #free() freed}.
 */
public synchronized CharArrayReader toCharArrayReader() throws IOException {

    checkFreed();

    CharArrayReader reader = new CharArrayReader(buf, 0, count);

    //System.out.println("toCharArrayReader::buf.length: " + buf.length);
    free();

    return reader;
}

From source file:com.google.openrtb.json.OpenRtbJsonReader.java

protected void readNativeField(JsonParser par, Native.Builder nativ, String fieldName) throws IOException {
    switch (fieldName) {
    case "request":
        if (par.getCurrentToken() == JsonToken.VALUE_STRING) {
            nativ.setRequestNative(factory().newNativeReader().readNativeRequest(
                    new CharArrayReader(par.getTextCharacters(), par.getTextOffset(), par.getTextLength())));
        } else { // Object
            nativ.setRequestNative(factory().newNativeReader().readNativeRequest(par));
        }//from w ww.  ja  v a 2s .c  om
        break;
    case "ver":
        nativ.setVer(par.getText());
        break;
    case "api":
        for (startArray(par); endArray(par); par.nextToken()) {
            APIFramework value = APIFramework.valueOf(par.getIntValue());
            if (checkEnum(value)) {
                nativ.addApi(value);
            }
        }
        break;
    case "battr":
        for (startArray(par); endArray(par); par.nextToken()) {
            CreativeAttribute value = CreativeAttribute.valueOf(par.getIntValue());
            if (checkEnum(value)) {
                nativ.addBattr(value);
            }
        }
        break;
    default:
        readOther(nativ, par, fieldName);
    }
}