Search in sources :

Example 26 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_ConstructorLjava_io_OutputStream.

public void test_ConstructorLjava_io_OutputStream() {
    // Test for method java.io.FilterOutputStream(java.io.OutputStream)
    try {
        bos = new ByteArrayOutputStream();
        os = new FilterOutputStream(bos);
        os.write('t');
    } catch (java.io.IOException e) {
        fail("Constructor test failed : " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FilterOutputStream(java.io.FilterOutputStream)

Example 27 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_write$BII_Exception.

public void test_write$BII_Exception() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    byte[] buf = new byte[10];
    try {
        os.write(buf, -1, 1);
        fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        os.write(buf, 0, -1);
        fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        os.write(buf, 10, 1);
        fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) FilterOutputStream(java.io.FilterOutputStream)

Example 28 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_write$BII.

public void test_write$BII() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes(), 10, testLength - 10);
    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Bytes have not been written.", bis.available() == testLength - 10);
    byte[] wbytes = new byte[testLength - 10];
    bis.read(wbytes);
    assertTrue("Test 2: Incorrect bytes written or read.", fileString.substring(10).equals(new String(wbytes)));
    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be eventually.
        os.write(fileString.getBytes());
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 29 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_writeI.

public void test_writeI() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(1);
    os = new FilterOutputStream(sos);
    os.write(42);
    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Byte has not been written.", bis.available() == 1);
    assertEquals("Test 2: Incorrect byte written or read;", 42, bis.read());
    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be now.
        os.write(42);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 30 with FilterOutputStream

use of java.io.FilterOutputStream in project voldemort by voldemort.

the class VoldemortAdminTool method writeBinary.

private static void writeBinary(File outputFile, Printable printable) throws IOException {
    OutputStream outputStream = null;
    if (outputFile == null) {
        outputStream = new FilterOutputStream(System.out) {

            @Override
            public void close() throws IOException {
                flush();
            }
        };
    } else {
        outputStream = new FileOutputStream(outputFile);
    }
    DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(outputStream));
    try {
        printable.printTo(dataOutputStream);
    } finally {
        dataOutputStream.close();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) FilterOutputStream(java.io.FilterOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

FilterOutputStream (java.io.FilterOutputStream)36 IOException (java.io.IOException)27 Support_OutputStream (tests.support.Support_OutputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 File (java.io.File)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 BufferedOutputStream (java.io.BufferedOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 FileInputStream (java.io.FileInputStream)3 FilterInputStream (java.io.FilterInputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ByteSink (com.google.common.io.ByteSink)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2