Search in sources :

Example 11 with Support_ASimpleInputStream

use of tests.support.Support_ASimpleInputStream in project j2objc by google.

the class OldDataInputStreamTest method test_read$BII.

public void test_read$BII() throws IOException {
    byte[] rbytes = new byte[testLength - 5];
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
    int r;
    os.write(fileString.getBytes());
    os.close();
    openDataInputStream();
    r = dis.read(rbytes, 1, testLength - 10);
    assertEquals("Test 1: Incorrect number of bytes read;", testLength - 10, r);
    assertEquals("Test 2: Incorrect data read.", 0, rbytes[0]);
    assertTrue("Test 3: Incorrect data written or read.", new String(rbytes, 1, r).equals(fileString.substring(0, r)));
    r = dis.read(rbytes, 0, 15);
    assertEquals("Test 3: Incorrect number of bytes read;", 10, r);
    assertTrue("Test 4: Incorrect data written or read.", new String(rbytes, 0, r).equals(fileString.substring(testLength - 10)));
    dis.close();
    sis.throwExceptionOnNextUse = true;
    dis = new DataInputStream(sis);
    try {
        dis.read(rbytes, 1, 5);
        fail("Test 5: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 12 with Support_ASimpleInputStream

use of tests.support.Support_ASimpleInputStream in project j2objc by google.

the class OldBufferedInputStreamTest method test_close.

public void test_close() throws IOException {
    is.close();
    try {
        is.read();
        fail("Test 1: IOException expected when reading after closing " + "the stream.");
    } catch (IOException e) {
    // Expected.
    }
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new BufferedInputStream(sis);
    try {
        is.close();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Example 13 with Support_ASimpleInputStream

use of tests.support.Support_ASimpleInputStream in project j2objc by google.

the class OldInputStreamReaderTest method test_close.

public void test_close() {
    // Test for method void java.io.InputStreamReader.close()
    try {
        is.close();
    } catch (IOException e) {
        fail("Failed to close reader : " + e.getMessage());
    }
    try {
        is.read();
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Exception means read failed due to close
    }
    is = new InputStreamReader(new Support_ASimpleInputStream(true));
    try {
        is.read();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 14 with Support_ASimpleInputStream

use of tests.support.Support_ASimpleInputStream in project j2objc by google.

the class OldSequenceInputStreamTest method setUp.

protected void setUp() {
    simple1 = new Support_ASimpleInputStream(s1);
    simple2 = new Support_ASimpleInputStream(s2);
    si = new SequenceInputStream(simple1, simple2);
}
Also used : SequenceInputStream(java.io.SequenceInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream)

Example 15 with Support_ASimpleInputStream

use of tests.support.Support_ASimpleInputStream in project j2objc by google.

the class OldDataInputStreamTest method test_read$B.

public void test_read$B() throws IOException {
    byte[] rbytes = new byte[testLength - 5];
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
    int r;
    os.write(fileString.getBytes());
    os.close();
    openDataInputStream();
    r = dis.read(rbytes);
    assertEquals("Test 1: Incorrect number of bytes read;", testLength - 5, r);
    assertTrue("Test 2: Incorrect data written or read.", new String(rbytes).equals(fileString.substring(0, testLength - 5)));
    r = dis.read(rbytes);
    assertEquals("Test 3: Incorrect number of bytes read;", 5, r);
    assertTrue("Test 4: Incorrect data written or read.", new String(rbytes, 0, 5).equals(fileString.substring(testLength - 5)));
    dis.close();
    sis.throwExceptionOnNextUse = true;
    dis = new DataInputStream(sis);
    try {
        dis.read(rbytes);
        fail("Test 5: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

Support_ASimpleInputStream (tests.support.Support_ASimpleInputStream)27 IOException (java.io.IOException)24 ObjectInputStream (java.io.ObjectInputStream)10 DataInputStream (java.io.DataInputStream)4 SequenceInputStream (java.io.SequenceInputStream)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 StreamTokenizer (java.io.StreamTokenizer)2 Support_StringReader (tests.support.Support_StringReader)2 DigestInputStream (java.security.DigestInputStream)1