Search in sources :

Example 91 with CharArrayReader

use of java.io.CharArrayReader in project j2objc by google.

the class OldCharArrayReaderTest method test_reset.

/**
 * java.io.CharArrayReader#reset()
 */
public void test_reset() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Reset failed to return to marker position.", 'W', cr.read());
    cr.close();
    try {
        cr.reset();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 92 with CharArrayReader

use of java.io.CharArrayReader in project j2objc by google.

the class PropertyResourceBundleTest method test_ConstructorLjava_io_Reader.

/**
 * @throws IOException
 * {@link java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.Reader)}
 * @since 1.6
 */
@SuppressWarnings("nls")
public void test_ConstructorLjava_io_Reader() throws IOException {
    Charset charset = Charset.forName("ISO-8859-1");
    String content = "p1=one\nfeature=good_feature";
    CharBuffer cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("ISO-8859-1")));
    char[] chars = new char[cbuffer.limit()];
    cbuffer.get(chars);
    prb = new PropertyResourceBundle(new CharArrayReader(chars));
    assertEquals(2, prb.keySet().size());
    assertEquals("one", prb.getString("p1"));
    assertEquals("good_feature", prb.getString("feature"));
    charset = Charset.forName("UTF-8");
    cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("UTF-8")));
    chars = new char[cbuffer.limit()];
    cbuffer.get(chars);
    prb = new PropertyResourceBundle(new CharArrayReader(chars));
    assertEquals(2, prb.keySet().size());
    assertEquals("one", prb.getString("p1"));
    assertEquals("good_feature", prb.getString("feature"));
    try {
        new PropertyResourceBundle((Reader) null);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) CharBuffer(java.nio.CharBuffer) Charset(java.nio.charset.Charset) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 93 with CharArrayReader

use of java.io.CharArrayReader in project jodd by oblac.

the class DecoraParserTest method trimLines.

private String trimLines(String string) throws IOException {
    BufferedReader in = new BufferedReader(new CharArrayReader(string.toCharArray()));
    StringBuilder result = new StringBuilder(string.length());
    String line;
    while ((line = in.readLine()) != null) {
        result.append(line.trim()).append('\n');
    }
    return result.toString();
}
Also used : CharArrayReader(java.io.CharArrayReader) BufferedReader(java.io.BufferedReader)

Example 94 with CharArrayReader

use of java.io.CharArrayReader in project hive by apache.

the class OpenCSVSerde method deserialize.

@Override
public Object deserialize(final Writable blob) throws SerDeException {
    Text rowText = (Text) blob;
    CSVReader csv = null;
    try {
        csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar, quoteChar, escapeChar);
        final String[] read = csv.readNext();
        for (int i = 0; i < numCols; i++) {
            if (read != null && i < read.length) {
                row.set(i, read[i]);
            } else {
                row.set(i, null);
            }
        }
        return row;
    } catch (final Exception e) {
        throw new SerDeException(e);
    } finally {
        if (csv != null) {
            try {
                csv.close();
            } catch (final Exception e) {
                log.error("fail to close csv writer", e);
            }
        }
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) CSVReader(au.com.bytecode.opencsv.CSVReader) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException)

Example 95 with CharArrayReader

use of java.io.CharArrayReader in project chuidiang-ejemplos by chuidiang.

the class PruebaCorrelacionIdiomas method analizaTextoYExtraeResultados.

private void analizaTextoYExtraeResultados() {
    String texto = areaDeTextoAAnalizar.getText();
    CharArrayReader stream = new CharArrayReader(texto.toCharArray());
    PorcentajeCorrelacion[] porcentajes = correlador.analizaIdioma(stream);
    areaResultados.setText("");
    for (int i = porcentajes.length - 1; i >= 0; i--) {
        areaResultados.append(porcentajes[i] + "\n");
    }
}
Also used : CharArrayReader(java.io.CharArrayReader)

Aggregations

CharArrayReader (java.io.CharArrayReader)102 IOException (java.io.IOException)45 BufferedReader (java.io.BufferedReader)22 Reader (java.io.Reader)19 File (java.io.File)11 InputStreamReader (java.io.InputStreamReader)10 Test (org.junit.Test)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 StringReader (java.io.StringReader)8 FileReader (java.io.FileReader)7 PreparedStatement (java.sql.PreparedStatement)7 BufferedWriter (java.io.BufferedWriter)5 CharArrayWriter (java.io.CharArrayWriter)5 FileWriter (java.io.FileWriter)5 InputStream (java.io.InputStream)5 ResultSet (java.sql.ResultSet)5 InputSource (org.xml.sax.InputSource)5 PipedReader (java.io.PipedReader)4 CharBuffer (java.nio.CharBuffer)4 Signature (java.security.Signature)4