Search in sources :

Example 56 with PushbackInputStream

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

the class OldPushbackInputStreamTest method test_read$BII_Exception.

public void test_read$BII_Exception() throws IOException {
    PushbackInputStream tobj;
    byte[] buf = new byte[10];
    tobj = new PushbackInputStream(underlying);
    try {
        tobj.read(buf, -1, 1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        tobj.read(buf, 0, -1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        tobj.read(buf, 10, 1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream)

Example 57 with PushbackInputStream

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

the class OldPushbackInputStreamTest method test_unread$B.

public void test_unread$B() throws IOException {
    PushbackInputStream tobj;
    String str2 = "0123456789";
    byte[] buf2 = str2.getBytes();
    byte[] readBuf = new byte[10];
    tobj = new PushbackInputStream(underlying, 10);
    tobj.unread(buf2);
    assertEquals("Wrong number!", 30 + 10, tobj.available());
    try {
        tobj.unread(buf2);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    tobj.read(readBuf);
    assertEquals("Incorrect bytes read", str2, new String(readBuf));
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read(buf2);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    // Test for method void java.io.PushbackInputStream.unread(byte [])
    try {
        byte[] buf = new byte[100];
        pis.read(buf, 0, buf.length);
        assertTrue("Incorrect bytes read", new String(buf).equals(fileString.substring(0, 100)));
        pis.unread(buf);
        pis.read(buf, 0, 50);
        assertTrue("Failed to unread bytes", new String(buf, 0, 50).equals(fileString.substring(0, 50)));
    } catch (IOException e) {
        fail("IOException during unread test : " + e.getMessage());
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) IOException(java.io.IOException)

Example 58 with PushbackInputStream

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

the class OldPushbackInputStreamTest method test_unread$BII.

public void test_unread$BII() throws IOException {
    PushbackInputStream tobj;
    String str2 = "0123456789";
    byte[] buf2 = (str2 + str2 + str2).getBytes();
    byte[] readBuf = new byte[10];
    tobj = new PushbackInputStream(underlying, 10);
    tobj.unread(buf2, 15, 10);
    assertEquals("Wrong number!", 30 + 10, tobj.available());
    try {
        tobj.unread(buf2, 15, 10);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    tobj.read(readBuf);
    assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read(buf2, 15, 10);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    // int)
    try {
        byte[] buf = new byte[100];
        pis.read(buf, 0, buf.length);
        assertTrue("Incorrect bytes read", new String(buf).equals(fileString.substring(0, 100)));
        pis.unread(buf, 50, 50);
        pis.read(buf, 0, 50);
        assertTrue("Failed to unread bytes", new String(buf, 0, 50).equals(fileString.substring(50, 100)));
    } catch (IOException e) {
        fail("IOException during unread test : " + e.getMessage());
    }
    try {
        byte[] buf = new byte[10];
        pis.unread(buf, 0, -1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        byte[] buf = new byte[10];
        pis.unread(buf, -1, 1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        byte[] buf = new byte[10];
        pis.unread(buf, 10, 1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) IOException(java.io.IOException)

Example 59 with PushbackInputStream

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

the class OldPushbackInputStreamTest method test_read.

public void test_read() throws IOException {
    PushbackInputStream tobj;
    tobj = new PushbackInputStream(underlying);
    assertEquals("Test 1: Incorrect byte read;", 66, tobj.read());
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // expected
    }
    assertEquals("Test 3: Incorrect byte read;", fileString.getBytes()[0], pis.read());
}
Also used : PushbackInputStream(java.io.PushbackInputStream) IOException(java.io.IOException)

Example 60 with PushbackInputStream

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

the class OldAndroidPushbackInputStreamTest method testPushbackInputStream.

public void testPushbackInputStream() throws Exception {
    String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
    ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
    ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
    ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
    PushbackInputStream a = new PushbackInputStream(aa, 7);
    try {
        a.unread("push".getBytes());
        Assert.assertEquals("pushAbCdEfGhIjKlM\nOpQrStUvWxYz", read(a));
    } finally {
        a.close();
    }
    PushbackInputStream b = new PushbackInputStream(ba, 9);
    try {
        b.unread('X');
        Assert.assertEquals("XAbCdEfGhI", read(b, 10));
    } finally {
        b.close();
    }
    PushbackInputStream c = new PushbackInputStream(ca);
    try {
        Assert.assertEquals("bdfhjl\nprtvxz", skipRead(c));
    } finally {
        c.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream)

Aggregations

PushbackInputStream (java.io.PushbackInputStream)130 IOException (java.io.IOException)61 InputStream (java.io.InputStream)34 ByteArrayInputStream (java.io.ByteArrayInputStream)21 FileInputStream (java.io.FileInputStream)10 GZIPInputStream (java.util.zip.GZIPInputStream)10 InputStreamReader (java.io.InputStreamReader)8 File (java.io.File)5 CertificateException (java.security.cert.CertificateException)5 Test (org.junit.Test)5 OutputStream (java.io.OutputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 CRLException (java.security.cert.CRLException)4 CertificateParsingException (java.security.cert.CertificateParsingException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 BufferedInputStream (java.io.BufferedInputStream)3 BufferedReader (java.io.BufferedReader)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Charset (java.nio.charset.Charset)3