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