use of java.nio.ByteBuffer in project honeycomb by altamiracorp.
the class RowOperationsIT method testUpdateRow.
@Test
public void testUpdateRow() {
final Map<String, ByteBuffer> map = Maps.newHashMap();
map.put(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE));
map.put(TestConstants.COLUMN2, ITUtils.encodeValue(6));
final Row row = new Row(map, UUID.randomUUID());
proxy.insertRow(row.serialize());
proxy.flush();
final QueryKey key = ITUtils.createKey(INDEX_COL_VALUE, QueryType.EXACT_KEY);
proxy.startIndexScan(key.serialize());
final Row r = Row.deserialize(proxy.getNextRow());
map.put(TestConstants.COLUMN1, ITUtils.encodeValue(3));
final Row newRow = new Row(map, r.getUUID());
proxy.updateRow(r.serialize(), newRow.serialize());
proxy.flush();
final byte[] result = proxy.getRow(Util.UUIDToBytes(r.getUUID()));
assertThat(Row.deserialize(result), equalTo(newRow));
}
use of java.nio.ByteBuffer in project honeycomb by altamiracorp.
the class ScanOperationsIT method testAfterKeyWithNullScan.
@Test
public void testAfterKeyWithNullScan() {
ITUtils.insertNullData(proxy, ROW_COUNT, TestConstants.COLUMN1);
ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE);
ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE + 1);
final Map<String, ByteBuffer> keyValues = Maps.newHashMap();
keyValues.put(TestConstants.COLUMN1, ITUtils.encodeValue(2));
final QueryKey key = new QueryKey(TestConstants.INDEX2, QueryType.AFTER_KEY, keyValues);
ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT + ROW_COUNT);
}
use of java.nio.ByteBuffer in project honeycomb by altamiracorp.
the class IndexRowKeyBuilder method build.
/**
* Creates an {@link IndexRowKey} instance with the parameters supplied to the builder.
* Precondition:
*
* @return A new row instance constructed by the builder
*/
public IndexRowKey build() {
checkState(order != null, "Sort order must be set on IndexRowBuilder.");
List<byte[]> encodedRecords = Lists.newArrayList();
if (fields != null) {
for (String column : tableSchema.getIndexSchema(indexName).getColumns()) {
if (!fields.containsKey(column)) {
continue;
}
ByteBuffer record = fields.get(column);
if (record != null) {
byte[] encodedRecord = encodeValue(record, tableSchema.getColumnSchema(column));
encodedRecords.add(order == SortOrder.Ascending ? encodedRecord : reverseValue(encodedRecord));
} else {
encodedRecords.add(null);
}
}
}
if (order == SortOrder.Ascending) {
return new AscIndexRowKey(tableId, indexId, encodedRecords, uuid);
}
return new DescIndexRowKey(tableId, indexId, encodedRecords, uuid);
}
use of java.nio.ByteBuffer in project platform_frameworks_base by android.
the class BluetoothSocket method readInt.
private int readInt(InputStream is) throws IOException {
byte[] ibytes = new byte[4];
int ret = readAll(is, ibytes);
if (VDBG)
Log.d(TAG, "inputStream.read ret: " + ret);
ByteBuffer bb = ByteBuffer.wrap(ibytes);
bb.order(ByteOrder.nativeOrder());
return bb.getInt();
}
use of java.nio.ByteBuffer in project platform_frameworks_base by android.
the class BluetoothSocket method waitSocketSignal.
private String waitSocketSignal(InputStream is) throws IOException {
byte[] sig = new byte[SOCK_SIGNAL_SIZE];
int ret = readAll(is, sig);
if (VDBG)
Log.d(TAG, "waitSocketSignal read " + SOCK_SIGNAL_SIZE + " bytes signal ret: " + ret);
ByteBuffer bb = ByteBuffer.wrap(sig);
/* the struct in native is decorated with __attribute__((packed)), hence this is possible */
bb.order(ByteOrder.nativeOrder());
int size = bb.getShort();
if (size != SOCK_SIGNAL_SIZE)
throw new IOException("Connection failure, wrong signal size: " + size);
byte[] addr = new byte[6];
bb.get(addr);
int channel = bb.getInt();
int status = bb.getInt();
// Convert to unsigned value
mMaxTxPacketSize = (bb.getShort() & 0xffff);
// Convert to unsigned value
mMaxRxPacketSize = (bb.getShort() & 0xffff);
String RemoteAddr = convertAddr(addr);
if (VDBG)
Log.d(TAG, "waitSocketSignal: sig size: " + size + ", remote addr: " + RemoteAddr + ", channel: " + channel + ", status: " + status + " MaxRxPktSize: " + mMaxRxPacketSize + " MaxTxPktSize: " + mMaxTxPacketSize);
if (status != 0)
throw new IOException("Connection failure, status: " + status);
return RemoteAddr;
}
Aggregations