Search in sources :

Example 71 with CharArrayReader

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);
    }
}
Also used : CharArrayReader(java.io.CharArrayReader)

Example 72 with CharArrayReader

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();
}
Also used : CharArrayReader(java.io.CharArrayReader) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader)

Example 73 with CharArrayReader

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;
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CharsetDecoder(java.nio.charset.CharsetDecoder) CharArrayReader(java.io.CharArrayReader) CharBuffer(java.nio.CharBuffer) BufferedReader(java.io.BufferedReader) UnmarshalException(org.eclipse.epp.mpc.core.service.UnmarshalException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 74 with CharArrayReader

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());
}
Also used : CharArrayReader(java.io.CharArrayReader) Test(org.junit.Test)

Example 75 with CharArrayReader

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();
}
Also used : CharArrayReader(java.io.CharArrayReader) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Clob(java.sql.Clob)

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