Search in sources :

Example 91 with ByteBuffer

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));
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) ByteBuffer(java.nio.ByteBuffer) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 92 with ByteBuffer

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);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) ByteBuffer(java.nio.ByteBuffer) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 93 with ByteBuffer

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);
}
Also used : ByteBuffer(java.nio.ByteBuffer)

Example 94 with ByteBuffer

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();
}
Also used : ByteBuffer(java.nio.ByteBuffer)

Example 95 with ByteBuffer

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;
}
Also used : IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)8919 Test (org.junit.Test)1965 IOException (java.io.IOException)1022 ArrayList (java.util.ArrayList)450 File (java.io.File)224 FileChannel (java.nio.channels.FileChannel)214 MappedByteBuffer (java.nio.MappedByteBuffer)196 HashMap (java.util.HashMap)177 CharBuffer (java.nio.CharBuffer)153 ByteArrayOutputStream (java.io.ByteArrayOutputStream)146 InetSocketAddress (java.net.InetSocketAddress)143 Random (java.util.Random)127 InputStream (java.io.InputStream)125 Map (java.util.Map)119 FileInputStream (java.io.FileInputStream)116 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)99 Test (org.testng.annotations.Test)98 IntBuffer (java.nio.IntBuffer)95 SocketChannel (java.nio.channels.SocketChannel)94 FileOutputStream (java.io.FileOutputStream)93