Search in sources :

Example 6 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class OldPushbackInputStreamTest method test_ConstructorLjava_io_InputStream.

public void test_ConstructorLjava_io_InputStream() {
    // Test for method java.io.PushbackInputStream(java.io.InputStream)
    try {
        pis = new PushbackInputStream(new ByteArrayInputStream("Hello".getBytes()));
        pis.unread("He".getBytes());
    } catch (IOException e) {
        // Pushback buffer should be full
        return;
    }
    fail("Failed to throw exception on unread when buffer full");
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 7 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

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 8 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class OldPushbackInputStreamTest method test_ConstructorLjava_io_InputStreamI.

public void test_ConstructorLjava_io_InputStreamI() {
    ByteArrayInputStream bas = new ByteArrayInputStream("Hello".getBytes());
    try {
        pis = new PushbackInputStream(bas, 0);
        fail("Test 1: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // Expected.
    }
    try {
        pis = new PushbackInputStream(bas, -1);
        fail("Test 2: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // Expected.
    }
    pis = new PushbackInputStream(bas, 5);
    try {
        pis.unread("Hello world".getBytes());
        fail("Test 3: IOException expected when the unread buffer is full.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream) IOException(java.io.IOException)

Example 9 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

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 10 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

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)72 IOException (java.io.IOException)40 ByteArrayInputStream (java.io.ByteArrayInputStream)12 InputStream (java.io.InputStream)12 FileInputStream (java.io.FileInputStream)6 CertificateException (java.security.cert.CertificateException)5 File (java.io.File)4 CRLException (java.security.cert.CRLException)4 CertificateParsingException (java.security.cert.CertificateParsingException)4 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)4 InputStreamReader (java.io.InputStreamReader)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Charset (java.nio.charset.Charset)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Attributes (java.util.jar.Attributes)2 JarEntry (java.util.jar.JarEntry)2