Search in sources :

Example 1 with AccessibleBufferedInputStream

use of org.teiid.core.util.AccessibleBufferedInputStream in project teiid by teiid.

the class TestObjectDecoderInputStream method testReplaceObject.

@Test
public void testReplaceObject() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectEncoderOutputStream out = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512);
    ClobImpl clob = new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            // $NON-NLS-1$
            return new ReaderInputStream(new StringReader("Clob contents"), Charset.forName(Streamable.ENCODING));
        }
    }, -1);
    out.writeObject(clob);
    ObjectDecoderInputStream in = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(new ByteArrayInputStream(baos.toByteArray()), 1024), Thread.currentThread().getContextClassLoader(), 1024);
    Object result = in.readObject();
    assertTrue(result instanceof ClobImpl);
}
Also used : DataOutputStream(java.io.DataOutputStream) AccessibleBufferedInputStream(org.teiid.core.util.AccessibleBufferedInputStream) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InputStreamFactory(org.teiid.core.types.InputStreamFactory) AccessibleBufferedInputStream(org.teiid.core.util.AccessibleBufferedInputStream) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 2 with AccessibleBufferedInputStream

use of org.teiid.core.util.AccessibleBufferedInputStream in project teiid by teiid.

the class TestObjectDecoderInputStream method testTimeoutException.

@Test
public void testTimeoutException() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectEncoderOutputStream oeos = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512);
    List<Integer> obj = Arrays.asList(1, 2, 3);
    oeos.writeObject(obj);
    oeos.close();
    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    InputStream is = new InputStream() {

        int count;

        @Override
        public int read() throws IOException {
            if (count++ % 2 == 0) {
                throw new SocketTimeoutException();
            }
            return bais.read();
        }
    };
    ObjectDecoderInputStream odis = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(is, 1024), Thread.currentThread().getContextClassLoader(), 1024);
    Object result = null;
    do {
        try {
            result = odis.readObject();
        } catch (IOException e) {
        }
    } while (result == null);
    assertEquals(obj, result);
}
Also used : AccessibleBufferedInputStream(org.teiid.core.util.AccessibleBufferedInputStream) SocketTimeoutException(java.net.SocketTimeoutException) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) AccessibleBufferedInputStream(org.teiid.core.util.AccessibleBufferedInputStream) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 AccessibleBufferedInputStream (org.teiid.core.util.AccessibleBufferedInputStream)2 ReaderInputStream (org.teiid.core.util.ReaderInputStream)2 StringReader (java.io.StringReader)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ClobImpl (org.teiid.core.types.ClobImpl)1 InputStreamFactory (org.teiid.core.types.InputStreamFactory)1