Search in sources :

Example 6 with InputStreamFileInput

use of org.embulk.spi.util.InputStreamFileInput in project embulk by embulk.

the class TestInputStreamFileInput method testEmptyProvider.

@Test
public void testEmptyProvider() throws IOException {
    InputStreamFileInput subject = new InputStreamFileInput(runtime.getBufferAllocator(), provider(new InputStream[0]));
    assertEquals(false, subject.nextFile());
    subject.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamFileInput(org.embulk.spi.util.InputStreamFileInput) Test(org.junit.Test)

Example 7 with InputStreamFileInput

use of org.embulk.spi.util.InputStreamFileInput in project embulk by embulk.

the class TestInputStreamFileInput method testInputStreamReadException.

@Test
public void testInputStreamReadException() {
    InputStreamFileInput subject = new InputStreamFileInput(runtime.getBufferAllocator(), new InputStreamFileInput.Provider() {

        @Override
        public InputStream openNext() throws IOException {
            return new InputStream() {

                @Override
                public int read() throws IOException {
                    throw new IOException("emulated exception");
                }
            };
        }

        @Override
        public void close() throws IOException {
        }
    });
    assertEquals(true, subject.nextFile());
    try {
        subject.poll();
        fail();
    } catch (RuntimeException re) {
    // OK
    }
    subject.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamFileInput(org.embulk.spi.util.InputStreamFileInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with InputStreamFileInput

use of org.embulk.spi.util.InputStreamFileInput in project embulk by embulk.

the class TestInputStreamFileInput method testEmptyStream.

@Test
public void testEmptyStream() throws IOException {
    InputStreamFileInput subject = new InputStreamFileInput(runtime.getBufferAllocator(), provider(new ByteArrayInputStream(new byte[0])));
    assertEquals(true, subject.nextFile());
    assertEquals(null, subject.poll());
    subject.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamFileInput(org.embulk.spi.util.InputStreamFileInput) Test(org.junit.Test)

Example 9 with InputStreamFileInput

use of org.embulk.spi.util.InputStreamFileInput in project embulk by embulk.

the class TestInputStreamFileInput method testProviderOpenNextException.

@Test
public void testProviderOpenNextException() {
    InputStreamFileInput subject = new InputStreamFileInput(runtime.getBufferAllocator(), new InputStreamFileInput.Provider() {

        @Override
        public InputStream openNext() throws IOException {
            throw new IOException("emulated exception");
        }

        @Override
        public void close() throws IOException {
        }
    });
    try {
        subject.nextFile();
        fail();
    } catch (RuntimeException re) {
    // OK
    }
    subject.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamFileInput(org.embulk.spi.util.InputStreamFileInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with InputStreamFileInput

use of org.embulk.spi.util.InputStreamFileInput in project embulk by embulk.

the class TestInputStreamFileInput method testProviderCloseException.

@Test
public void testProviderCloseException() {
    InputStreamFileInput subject = new InputStreamFileInput(runtime.getBufferAllocator(), new InputStreamFileInput.Provider() {

        @Override
        public InputStream openNext() throws IOException {
            return new ByteArrayInputStream(new byte[0]);
        }

        @Override
        public void close() throws IOException {
            throw new IOException("emulated exception");
        }
    });
    try {
        subject.close();
        fail();
    } catch (RuntimeException re) {
    // OK
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamFileInput(org.embulk.spi.util.InputStreamFileInput) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

InputStreamFileInput (org.embulk.spi.util.InputStreamFileInput)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Test (org.junit.Test)8 InputStream (java.io.InputStream)6 IOException (java.io.IOException)5 FileInputInputStream (org.embulk.spi.util.FileInputInputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)1 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)1 ValueFactory.newString (org.msgpack.value.ValueFactory.newString)1