Search in sources :

Example 76 with StringReader

use of java.io.StringReader in project guava by google.

the class BaseEncodingTest method testStreamingDecodes.

// Reader
@GwtIncompatible
private static void testStreamingDecodes(BaseEncoding encoding, String encoded, String decoded) throws IOException {
    byte[] bytes = decoded.getBytes(UTF_8);
    InputStream decodingStream = encoding.decodingStream(new StringReader(encoded));
    for (int i = 0; i < bytes.length; i++) {
        assertThat(decodingStream.read()).isEqualTo(bytes[i] & 0xFF);
    }
    assertThat(decodingStream.read()).isEqualTo(-1);
    decodingStream.close();
}
Also used : InputStream(java.io.InputStream) StringReader(java.io.StringReader) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 77 with StringReader

use of java.io.StringReader in project guava by google.

the class CharSinkTest method testWriteFrom_reader.

public void testWriteFrom_reader() throws IOException {
    StringReader reader = new StringReader(STRING);
    sink.writeFrom(reader);
    assertTrue(sink.wasStreamOpened() && sink.wasStreamClosed());
    assertEquals(STRING, sink.getString());
}
Also used : StringReader(java.io.StringReader)

Example 78 with StringReader

use of java.io.StringReader in project guava by google.

the class CharStreamsTest method testCopy.

public void testCopy() throws IOException {
    StringBuilder builder = new StringBuilder();
    long copied = CharStreams.copy(new StringReader(ASCII), builder);
    assertEquals(ASCII, builder.toString());
    assertEquals(ASCII.length(), copied);
    StringBuilder builder2 = new StringBuilder();
    copied = CharStreams.copy(new StringReader(I18N), builder2);
    assertEquals(I18N, builder2.toString());
    assertEquals(I18N.length(), copied);
}
Also used : StringReader(java.io.StringReader)

Example 79 with StringReader

use of java.io.StringReader in project guava by google.

the class CharStreamsTest method testSkipFully_EOF.

public void testSkipFully_EOF() throws IOException {
    Reader reader = new StringReader("abcde");
    try {
        CharStreams.skipFully(reader, 6);
        fail("expected EOFException");
    } catch (EOFException e) {
    // expected
    }
}
Also used : StringReader(java.io.StringReader) EOFException(java.io.EOFException) StringReader(java.io.StringReader) FilterReader(java.io.FilterReader) Reader(java.io.Reader)

Example 80 with StringReader

use of java.io.StringReader in project siena by mandubian.

the class JdbcDBUtils method setObject.

public static void setObject(PreparedStatement ps, int index, Object value, Field field, String DB) throws SQLException {
    if (value == null) {
        ps.setNull(index, JdbcDBUtils.toSqlType(value, field, DB));
        return;
    }
    Class<?> type = field.getType();
    if (type == Byte.class || type == Byte.TYPE)
        ps.setByte(index, (Byte) value);
    else if (type == Short.class || type == Short.TYPE)
        ps.setShort(index, (Short) value);
    else if (type == Integer.class || type == Integer.TYPE)
        ps.setInt(index, (Integer) value);
    else if (type == Long.class || type == Long.TYPE)
        ps.setLong(index, (Long) value);
    else if (type == Float.class || type == Float.TYPE)
        ps.setFloat(index, (Float) value);
    else if (type == Double.class || type == Double.TYPE)
        ps.setDouble(index, (Double) value);
    else if (type == String.class) {
        ps.setString(index, (String) value);
    } else if (type == Boolean.class || type == Boolean.TYPE)
        ps.setBoolean(index, (Boolean) value);
    else if (type == Date.class) {
        if (field.getAnnotation(DateTime.class) != null) {
            java.sql.Timestamp ts = new java.sql.Timestamp(((Date) value).getTime());
            ps.setTimestamp(index, ts);
        } else if (field.getAnnotation(Time.class) != null) {
            java.sql.Time ts = new java.sql.Time(((Date) value).getTime());
            ps.setTime(index, ts);
        } else if (field.getAnnotation(SimpleDate.class) != null) {
            java.sql.Date d = new java.sql.Date(((Date) value).getTime());
            ps.setDate(index, d);
        } else {
            java.sql.Timestamp ts = new java.sql.Timestamp(((Date) value).getTime());
            ps.setTimestamp(index, ts);
        }
    } else if (type == Json.class) {
        ps.setString(index, (String) value);
    } else if (type == byte[].class) {
        ByteArrayInputStream bis = new ByteArrayInputStream((byte[]) value);
        ps.setBlob(index, bis);
    } else if (Enum.class.isAssignableFrom(type)) {
        ps.setString(index, (String) value);
    } else if (type == BigDecimal.class) {
        DecimalPrecision an = field.getAnnotation(DecimalPrecision.class);
        if (an == null) {
            ps.setObject(index, value);
        } else {
            if (an.storageType() == DecimalPrecision.StorageType.NATIVE) {
                ps.setBigDecimal(index, (BigDecimal) value);
            } else if (an.storageType() == DecimalPrecision.StorageType.STRING) {
                ps.setString(index, ((BigDecimal) value).toPlainString());
            } else if (an.storageType() == DecimalPrecision.StorageType.DOUBLE) {
                ps.setDouble(index, ((BigDecimal) value).doubleValue());
            } else {
                ps.setBigDecimal(index, (BigDecimal) value);
            }
        }
    } else {
        Embedded embedded = field.getAnnotation(Embedded.class);
        if (embedded != null) {
            if ("h2".equals(DB)) {
                StringReader reader = new StringReader((String) value);
                ps.setClob(index, reader);
            } else {
                ps.setString(index, (String) value);
            }
        } else if (field.isAnnotationPresent(Polymorphic.class)) {
            ByteArrayInputStream bis = new ByteArrayInputStream((byte[]) value);
            ps.setBlob(index, bis);
        } else {
            throw new SienaRestrictedApiException(DB, "createColumn", "Unsupported type for field " + type.getName() + "." + field.getName());
        }
    }
}
Also used : SienaRestrictedApiException(siena.SienaRestrictedApiException) DecimalPrecision(siena.core.DecimalPrecision) Time(siena.Time) DateTime(siena.DateTime) Json(siena.Json) DateTime(siena.DateTime) Date(java.util.Date) SimpleDate(siena.SimpleDate) BigDecimal(java.math.BigDecimal) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDate(siena.SimpleDate) StringReader(java.io.StringReader) Embedded(siena.embed.Embedded) Polymorphic(siena.core.Polymorphic)

Aggregations

StringReader (java.io.StringReader)4150 Test (org.junit.Test)1003 IOException (java.io.IOException)589 Reader (java.io.Reader)445 InputSource (org.xml.sax.InputSource)408 BufferedReader (java.io.BufferedReader)342 TokenStream (org.apache.lucene.analysis.TokenStream)302 ArrayList (java.util.ArrayList)273 StringWriter (java.io.StringWriter)251 Tokenizer (org.apache.lucene.analysis.Tokenizer)241 Document (org.w3c.dom.Document)232 JSONReader (com.alibaba.fastjson.JSONReader)195 DocumentBuilder (javax.xml.parsers.DocumentBuilder)180 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)157 Map (java.util.Map)144 HashMap (java.util.HashMap)136 Element (org.w3c.dom.Element)134 StreamSource (javax.xml.transform.stream.StreamSource)132 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120