use of java.io.CharArrayReader in project Java-Tutorial by gpcodervn.
the class CharArrayReaderExample method main.
public static void main(String[] ag) throws Exception {
char[] ary = { 'g', 'p', 'c', 'o', 'd', 'e', 'r', '.', 'c', 'o', 'm' };
CharArrayReader reader = new CharArrayReader(ary);
int k = 0;
// Read until the end of a file
while ((k = reader.read()) != -1) {
char ch = (char) k;
System.out.print(ch + " : ");
System.out.println(k);
}
}
use of java.io.CharArrayReader in project webtools.sourceediting by eclipse.
the class TestHTMLResourceEncodingDetector method getContentType.
private String getContentType(String content) throws IOException {
Reader contentReader = new CharArrayReader(content.toCharArray());
htmlResouceEncodingDetector.set(contentReader);
return htmlResouceEncodingDetector.getEncoding();
}
use of java.io.CharArrayReader in project epp.mpc by eclipse.
the class MarketplaceUnmarshaller method createContentInfo.
private IStatus createContentInfo(ByteBuffer peekBuffer) {
try {
// $NON-NLS-1$
StringBuilder message = new StringBuilder("Received response begins with:\n\n");
// $NON-NLS-1$
CharsetDecoder decoder = Charset.forName("ASCII").newDecoder();
decoder.onMalformedInput(CodingErrorAction.REPLACE);
decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
// $NON-NLS-1$
decoder.replaceWith("?");
CharBuffer charBuffer = decoder.decode(peekBuffer);
BufferedReader reader = new BufferedReader(new CharArrayReader(charBuffer.array(), 0, charBuffer.limit()));
for (int i = 0; i < 3; i++) {
// include the first three lines
String line = reader.readLine();
if (line == null) {
break;
}
char[] safeChars = line.toCharArray();
for (int j = 0; j < safeChars.length; j++) {
char c = safeChars[j];
if (c < 32 || c >= 127) {
// replace potentially non-printable character
safeChars[j] = '?';
}
}
// $NON-NLS-1$ //$NON-NLS-2$
message.append(i + 1).append(": ").append(new String(safeChars)).append("\n");
}
return new Status(IStatus.INFO, MarketplaceClientCore.BUNDLE_ID, 0, message.toString(), null);
} catch (Exception e) {
// ignore - this is only additional diagnostic info, so don't bother anybody with errors assembling it
return null;
}
}
use of java.io.CharArrayReader in project mkgmap by openstreetmap.
the class SrtTextReaderTest method testDescription.
@Test
public void testDescription() throws Exception {
String val = "Euro Sort";
String s = String.format("codepage 1252\n" + "description '%s'\n", val);
SrtTextReader sr = new SrtTextReader(new CharArrayReader(s.toCharArray()));
assertEquals(val, sr.getSort().getDescription());
}
use of java.io.CharArrayReader in project h2database by h2database.
the class TestLob method testClob.
private void testClob() throws Exception {
deleteDb("lob");
Connection conn;
conn = reconnect(null);
conn.createStatement().execute("CREATE TABLE TEST(ID IDENTITY, C CLOB)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(C) VALUES(?)");
prep.setCharacterStream(1, new CharArrayReader("Bohlen".toCharArray()), "Bohlen".length());
prep.execute();
prep.setCharacterStream(1, new CharArrayReader("B\u00f6hlen".toCharArray()), "B\u00f6hlen".length());
prep.execute();
prep.setCharacterStream(1, getRandomReader(501, 1), -1);
prep.execute();
prep.setCharacterStream(1, getRandomReader(1501, 2), 401);
prep.execute();
conn = reconnect(conn);
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals("Bohlen", rs.getString("C"));
assertEqualReaders(new CharArrayReader("Bohlen".toCharArray()), rs.getCharacterStream("C"), -1);
rs.next();
assertEqualReaders(new CharArrayReader("B\u00f6hlen".toCharArray()), rs.getCharacterStream("C"), -1);
rs.next();
assertEqualReaders(getRandomReader(501, 1), rs.getCharacterStream("C"), -1);
Clob clob = rs.getClob("C");
assertEqualReaders(getRandomReader(501, 1), clob.getCharacterStream(), -1);
assertEquals(501, clob.length());
rs.next();
assertEqualReaders(getRandomReader(401, 2), rs.getCharacterStream("C"), -1);
assertEqualReaders(getRandomReader(1500, 2), rs.getCharacterStream("C"), 401);
clob = rs.getClob("C");
assertEqualReaders(getRandomReader(1501, 2), clob.getCharacterStream(), 401);
assertEqualReaders(getRandomReader(401, 2), clob.getCharacterStream(), 401);
assertEquals(401, clob.length());
assertFalse(rs.next());
conn.close();
}
Aggregations