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;
}
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;
}
}
}
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());
}
Aggregations