use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class HelloResponse method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final ByteBuffer bb = DataEncoderHelper.intToByteBuffer(protocolVersion);
final byte[] peerCapabilitiesBytes = peerCapabilities.toByteArray();
// Body length
final long bodyLength = bb.capacity() + peerCapabilitiesBytes.length;
final long headerLength = appendResponsePackageHeader(bodyLength, outputStream);
// Write body
outputStream.write(bb.array());
outputStream.write(peerCapabilitiesBytes);
return headerLength + bodyLength;
} catch (Exception e) {
throw new PackageEncodeException("Got exception while converting package into bytes", e);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class ListTablesResponse method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final byte[] bodyBytes = createBody();
final long headerLength = appendResponsePackageHeader(bodyBytes.length, outputStream);
outputStream.write(bodyBytes);
return headerLength + bodyBytes.length;
} catch (IOException e) {
throw new PackageEncodeException("Got exception while converting package into bytes", e);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class TupleResponse method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final byte[] encodedBytes = NetworkTupleEncoderDecoder.encode(tuple, table);
final long headerLength = appendResponsePackageHeader(encodedBytes.length, outputStream);
outputStream.write(encodedBytes);
return headerLength + encodedBytes.length;
} catch (IOException e) {
throw new PackageEncodeException("Got exception while converting package into bytes", e);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class ResponseHandlerHelper method castAndSetFutureResult.
/**
* Cast the content on the result list according to the future type
* @param future
* @param resultList
* @param completeResult
* @throws PackageEncodeException
*/
public static void castAndSetFutureResult(final NetworkOperationFuture future, final List<PagedTransferableEntity> resultList, final boolean completeResult) throws PackageEncodeException {
if (resultList.isEmpty()) {
future.setCompleteResult(completeResult);
future.setOperationResult(new ArrayList<>());
future.fireCompleteEvent();
return;
}
final PagedTransferableEntity firstElement = resultList.get(0);
if (firstElement instanceof Tuple) {
final List<Tuple> tupleList = new ArrayList<>();
for (final PagedTransferableEntity entity : resultList) {
tupleList.add((Tuple) entity);
}
future.setCompleteResult(completeResult);
future.setOperationResult(tupleList);
future.fireCompleteEvent();
} else if (firstElement instanceof JoinedTuple) {
final List<JoinedTuple> tupleList = new ArrayList<>();
for (final PagedTransferableEntity entity : resultList) {
tupleList.add((JoinedTuple) entity);
}
future.setCompleteResult(completeResult);
future.setOperationResult(tupleList);
future.fireCompleteEvent();
} else {
throw new PackageEncodeException("Unknown future type: " + firstElement);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class CancelQueryRequest method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final ByteBuffer bb = ByteBuffer.allocate(2);
bb.order(Const.APPLICATION_BYTE_ORDER);
bb.putShort((short) querySequenceNumber);
// Calculate body length
final long bodyLength = bb.capacity();
final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
// Write body
outputStream.write(bb.array());
return headerLength + bodyLength;
} catch (Exception e) {
throw new PackageEncodeException("Got exception while converting package into bytes", e);
}
}
Aggregations