Search in sources :

Example 1 with CompactObjectInputStream

use of org.teiid.netty.handler.codec.serialization.CompactObjectInputStream in project teiid by teiid.

the class ObjectDecoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
    if (result == null) {
        ByteBuf frame = null;
        try {
            frame = (ByteBuf) super.decode(ctx, buffer);
        } catch (TooLongFrameException e) {
            throw new IOException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40166), e);
        }
        if (frame == null) {
            return null;
        }
        CompactObjectInputStream cois = new CompactObjectInputStream(new ByteBufInputStream(frame), classLoader);
        result = cois.readObject();
        streams = ExternalizeUtil.readList(cois, StreamFactoryReference.class);
        streamIndex = 0;
    }
    while (streamIndex < streams.size()) {
        // read the new chunk size
        if (streamDataToRead == -1) {
            if (buffer.readableBytes() < 2) {
                return null;
            }
            streamDataToRead = buffer.readUnsignedShort();
        }
        if (stream == null) {
            // $NON-NLS-1$
            store = storageManager.createFileStore("temp-stream");
            StreamFactoryReference sfr = streams.get(streamIndex);
            sfr.setStreamFactory(new FileStoreInputStreamFactory(store, Streamable.ENCODING));
            this.stream = new BufferedOutputStream(store.createOutputStream());
        }
        // end of stream
        if (streamDataToRead == 0) {
            stream.close();
            stream = null;
            streamIndex++;
            streamDataToRead = -1;
            continue;
        }
        if (store.getLength() + streamDataToRead > maxLobSize) {
            if (error == null) {
                error = new StreamCorruptedException(// $NON-NLS-1$ //$NON-NLS-2$
                "lob too big: " + (store.getLength() + streamDataToRead) + " (max: " + maxLobSize + ')');
            }
        }
        int toRead = Math.min(buffer.readableBytes(), streamDataToRead);
        if (toRead == 0) {
            return null;
        }
        if (error == null) {
            buffer.readBytes(this.stream, toRead);
        } else {
            buffer.skipBytes(toRead);
        }
        streamDataToRead -= toRead;
        if (streamDataToRead == 0) {
            // get the next chunk
            streamDataToRead = -1;
        }
    }
    Object toReturn = result;
    result = null;
    streams = null;
    stream = null;
    store = null;
    if (error != null) {
        StreamCorruptedException sce = error;
        error = null;
        throw sce;
    }
    return toReturn;
}
Also used : CompactObjectInputStream(org.teiid.netty.handler.codec.serialization.CompactObjectInputStream) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) StreamFactoryReference(org.teiid.core.types.InputStreamFactory.StreamFactoryReference) ByteBuf(io.netty.buffer.ByteBuf) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with CompactObjectInputStream

use of org.teiid.netty.handler.codec.serialization.CompactObjectInputStream in project teiid by teiid.

the class ResultsMessage method processResults.

public void processResults() throws TeiidSQLException {
    if (results == null && resultBytes != null) {
        try {
            CompactObjectInputStream ois = new CompactObjectInputStream(new ByteArrayInputStream(resultBytes), ResultsMessage.class.getClassLoader());
            results = BatchSerializer.readBatch(ois, dataTypes);
        } catch (IOException e) {
            throw TeiidSQLException.create(e);
        } catch (ClassNotFoundException e) {
            throw TeiidSQLException.create(e);
        } finally {
            resultBytes = null;
        }
    }
}
Also used : CompactObjectInputStream(org.teiid.netty.handler.codec.serialization.CompactObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 3 with CompactObjectInputStream

use of org.teiid.netty.handler.codec.serialization.CompactObjectInputStream in project teiid by teiid.

the class TestRequestMessage method test83.

@Test
public void test83() throws FileNotFoundException, IOException, ClassNotFoundException {
    CompactObjectInputStream ois = new CompactObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("req.ser")), RequestMessage.class.getClassLoader());
    RequestMessage rm = (RequestMessage) ois.readObject();
    ois.close();
    assertFalse(rm.isReturnAutoGeneratedKeys());
    assertFalse(rm.isDelaySerialization());
}
Also used : CompactObjectInputStream(org.teiid.netty.handler.codec.serialization.CompactObjectInputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

CompactObjectInputStream (org.teiid.netty.handler.codec.serialization.CompactObjectInputStream)3 IOException (java.io.IOException)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 StreamCorruptedException (java.io.StreamCorruptedException)1 Test (org.junit.Test)1 FileStoreInputStreamFactory (org.teiid.common.buffer.FileStoreInputStreamFactory)1 StreamFactoryReference (org.teiid.core.types.InputStreamFactory.StreamFactoryReference)1