Search in sources :

Example 86 with CharArrayReader

use of java.io.CharArrayReader in project ceylon-compiler by ceylon.

the class JavaPositionsRetriever method addCeylonLinesComments.

private String addCeylonLinesComments(char[] source) {
    String annotatedSourceCode = "";
    BufferedReader reader = new BufferedReader(new CharArrayReader(source));
    String line = null;
    int javaLine = 1;
    try {
        while ((line = reader.readLine()) != null) {
            annotatedSourceCode += line;
            String ceylonLines = getCeylonLinesForJavaLine(revertMap(ceylonToJavaLines), javaLine);
            annotatedSourceCode += ceylonLines.isEmpty() ? "" : " // line " + ceylonLines;
            annotatedSourceCode += "\n";
            javaLine++;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return annotatedSourceCode;
}
Also used : CharArrayReader(java.io.CharArrayReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 87 with CharArrayReader

use of java.io.CharArrayReader in project j2objc by google.

the class OldCharArrayReaderTest method test_markI.

/**
 * java.io.CharArrayReader#mark(int)
 */
public void test_markI() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Failed to mark correct position;", 'W', cr.read());
    cr.close();
    try {
        cr.mark(100);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 88 with CharArrayReader

use of java.io.CharArrayReader in project j2objc by google.

the class OldCharArrayReaderTest method test_markSupported.

/**
 * java.io.CharArrayReader#markSupported()
 */
public void test_markSupported() {
    cr = new CharArrayReader(hw);
    assertTrue("markSupported returned false", cr.markSupported());
}
Also used : CharArrayReader(java.io.CharArrayReader)

Example 89 with CharArrayReader

use of java.io.CharArrayReader in project j2objc by google.

the class OldCharArrayReaderTest method test_read$CII.

/**
 * java.io.CharArrayReader#read(char[], int, int)
 */
public void test_read$CII() throws IOException {
    // Test for method int java.io.CharArrayReader.read(char [], int, int)
    char[] c = new char[11];
    cr = new CharArrayReader(hw);
    cr.read(c, 1, 10);
    assertTrue("Test 1: Read returned incorrect chars.", new String(c, 1, 10).equals(new String(hw, 0, 10)));
    // Illegal argument checks.
    try {
        cr.read(null, 1, 0);
        fail("Test 2: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
    try {
        cr.read(c, -1, 1);
        fail("Test 3: ArrayIndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cr.read(c, 1, -1);
        fail("Test 4: ArrayIndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cr.read(c, 1, c.length);
        fail("Test 5: ArrayIndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    cr.close();
    try {
        cr.read(c, 1, 1);
        fail("Test 6: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 90 with CharArrayReader

use of java.io.CharArrayReader in project j2objc by google.

the class OldCharArrayReaderTest method test_Constructor$CII.

/**
 * java.io.CharArrayReader#CharArrayReader(char[], int, int)
 */
public void test_Constructor$CII() throws IOException {
    try {
        cr = new CharArrayReader(null, 0, 0);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
    try {
        cr = new CharArrayReader(hw, -1, 0);
        fail("Test 2: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // Expected.
    }
    try {
        cr = new CharArrayReader(hw, 0, -1);
        fail("Test 3: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // Expected.
    }
    try {
        cr = new CharArrayReader(hw, hw.length + 1, 1);
        fail("Test 4: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // Expected.
    }
    cr = new CharArrayReader(hw, 5, 5);
    assertTrue("Test 5: Failed to create reader", cr.ready());
    assertEquals("Test 6: Incorrect character read;", 'W', cr.read());
}
Also used : CharArrayReader(java.io.CharArrayReader)

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