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.
}
}
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
}
}
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();
}
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);
}
}
}
}
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");
}
}
Aggregations