use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupRequest method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final byte[] groupBytes = distributionGroup.getBytes();
final byte[] placementBytes = distributionGroupConfiguration.getPlacementStrategy().getBytes();
final byte[] placementConfigBytes = distributionGroupConfiguration.getPlacementStrategyConfig().getBytes();
final byte[] spacePartitionierBytes = distributionGroupConfiguration.getSpacePartitioner().getBytes();
final byte[] spacePartitionierConfigBytes = distributionGroupConfiguration.getSpacePartitionerConfig().getBytes();
final ByteBuffer bb = ByteBuffer.allocate(28);
bb.order(Const.APPLICATION_BYTE_ORDER);
bb.putInt(distributionGroupConfiguration.getDimensions());
bb.putShort(distributionGroupConfiguration.getReplicationFactor());
bb.putShort((short) groupBytes.length);
bb.putShort((short) placementBytes.length);
bb.putShort((short) spacePartitionierBytes.length);
bb.putInt((int) placementConfigBytes.length);
bb.putInt((int) spacePartitionierConfigBytes.length);
bb.putInt(distributionGroupConfiguration.getMaximumRegionSize());
bb.putInt(distributionGroupConfiguration.getMinimumRegionSize());
// Body length
final long bodyLength = bb.capacity() + groupBytes.length + placementBytes.length + placementConfigBytes.length + spacePartitionierBytes.length + spacePartitionierConfigBytes.length;
final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
// Write body
outputStream.write(bb.array());
outputStream.write(groupBytes);
outputStream.write(placementBytes);
outputStream.write(placementConfigBytes);
outputStream.write(spacePartitionierBytes);
outputStream.write(spacePartitionierConfigBytes);
return headerLength + bodyLength;
} 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 CreateTableRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static CreateTableRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_TABLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
// Table length
final short tableLength = encodedPackage.getShort();
// Allow duplicates
boolean allowDuplicates = false;
if (encodedPackage.get() != 0) {
allowDuplicates = true;
}
// Unused
encodedPackage.get();
// TTL
final long ttl = encodedPackage.getLong();
// Versions
final int versions = encodedPackage.getInt();
// Spatial reader length
final short spatialReaderLength = encodedPackage.getShort();
// Spatial writer length
final short spatialWriterLength = encodedPackage.getShort();
// Table name
final byte[] tableBytes = new byte[tableLength];
encodedPackage.get(tableBytes, 0, tableBytes.length);
final String table = new String(tableBytes);
// Spatial index reader
final byte[] spatialReaderBytes = new byte[spatialReaderLength];
encodedPackage.get(spatialReaderBytes, 0, spatialReaderBytes.length);
final String spatialIndexReader = new String(spatialReaderBytes);
// Spatial index writer
final byte[] spatialWriterBytes = new byte[spatialWriterLength];
encodedPackage.get(spatialWriterBytes, 0, spatialWriterBytes.length);
final String spatialIndexWriter = new String(spatialWriterBytes);
final TupleStoreConfiguration tupleStoreConfiguration = new TupleStoreConfiguration();
tupleStoreConfiguration.setAllowDuplicates(allowDuplicates);
tupleStoreConfiguration.setTtl(ttl);
tupleStoreConfiguration.setVersions(versions);
tupleStoreConfiguration.setSpatialIndexReader(spatialIndexReader);
tupleStoreConfiguration.setSpatialIndexWriter(spatialIndexWriter);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
return new CreateTableRequest(sequenceNumber, table, tupleStoreConfiguration);
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class CreateTableRequest method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final byte[] tableBytes = table.getFullnameBytes();
final ByteBuffer bb = ByteBuffer.allocate(20);
bb.putShort((short) tableBytes.length);
if (ssTableConfiguration.isAllowDuplicates()) {
bb.put((byte) 0x01);
} else {
bb.put((byte) 0x00);
}
// Unused
bb.put((byte) 0x00);
// TTL
bb.putLong(ssTableConfiguration.getTTL());
// Versions
bb.putInt(ssTableConfiguration.getVersions());
// Spatial index reader
final byte[] spatialIndexReaderBytes = ssTableConfiguration.getSpatialIndexReader().getBytes();
bb.putShort((short) spatialIndexReaderBytes.length);
// Spatial index writer
final byte[] spatialIndexWriterBytes = ssTableConfiguration.getSpatialIndexWriter().getBytes();
bb.putShort((short) spatialIndexWriterBytes.length);
// Body length
final long bodyLength = bb.capacity() + tableBytes.length + spatialIndexReaderBytes.length + spatialIndexWriterBytes.length;
final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
// Write body
outputStream.write(bb.array());
outputStream.write(tableBytes);
outputStream.write(spatialIndexReaderBytes);
outputStream.write(spatialIndexWriterBytes);
return headerLength + bodyLength;
} 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 DeleteDistributionGroupRequest method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final byte[] groupBytes = distributionGroup.getBytes();
final ByteBuffer bb = DataEncoderHelper.shortToByteBuffer((short) groupBytes.length);
// Body length
final long bodyLength = bb.capacity() + groupBytes.length;
final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
// Write body
outputStream.write(bb.array());
outputStream.write(groupBytes);
return headerLength + bodyLength;
} 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 DeleteTableRequest method writeToOutputStream.
@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
try {
final byte[] tableBytes = table.getFullnameBytes();
final ByteBuffer bb = DataEncoderHelper.shortToByteBuffer((short) tableBytes.length);
// Body length
final long bodyLength = bb.capacity() + tableBytes.length;
final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
// Write body
outputStream.write(bb.array());
outputStream.write(tableBytes);
return headerLength + bodyLength;
} catch (IOException e) {
throw new PackageEncodeException("Got exception while converting package into bytes", e);
}
}
Aggregations