Java Code Examples for com.sleepycat.bind.tuple.TupleInput#readInt()

The following examples show how to use com.sleepycat.bind.tuple.TupleInput#readInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * This is a utility method that can be used to dump the contents of the iidToIvfpqDB to a txt file.<br>
 * Currently, only the list id of each item is dumped.
 * 
 * @param dumpFilename
 *            Full path to the file where the dump will be written.
 * @throws Exception
 */
public void dumpIidToIvfpqDB(String dumpFilename) throws Exception {
	DatabaseEntry foundKey = new DatabaseEntry();
	DatabaseEntry foundData = new DatabaseEntry();

	ForwardCursor cursor = iidToIvfpqDB.openCursor(null, null);
	BufferedWriter out = new BufferedWriter(new FileWriter(new File(dumpFilename)));
	while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
		int iid = IntegerBinding.entryToInt(foundKey);
		TupleInput input = TupleBinding.entryToInput(foundData);
		int listId = input.readInt();
		out.write(iid + " " + listId + "\n");
	}
	cursor.close();
	out.close();
}
 
Example 2
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the pq code of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public byte[] getPQCodeByte(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}
	if (numProductCentroids > 256) {
		throw new Exception("Call the short variant of the method!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		input.readInt(); // skip the list id
		byte[] code = new byte[numSubVectors];
		for (int i = 0; i < numSubVectors; i++) {
			code[i] = input.readByte();
		}
		return code;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example 3
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the pq code of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public short[] getPQCodeShort(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}
	if (numProductCentroids <= 256) {
		throw new Exception("Call the short variant of the method!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		input.readInt(); // skip the list id
		short[] code = new short[numSubVectors];
		for (int i = 0; i < numSubVectors; i++) {
			code[i] = input.readShort();
		}
		return code;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example 4
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the inverted list of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public int getInvertedListId(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		int listId = input.readInt();
		return listId;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example 5
Source File: LinkValueEntryBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private Object read(final TupleInput input)
{
    int size = input.readInt();
    byte[] bytes = new byte[size];
    input.read(bytes);

    return LinkStoreUtils.amqpBytesToObject(bytes);
}
 
Example 6
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public OldDataValue entryToObject(final TupleInput input)
{
    int size = input.readInt();
    byte[] data = new byte[size];
    input.read(data);
    return new OldDataValue(size, data);
}
 
Example 7
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private NewRecordImpl[] readRecords(TupleInput input)
{
    NewRecordImpl[] records = new NewRecordImpl[input.readInt()];
    for (int i = 0; i < records.length; i++)
    {
        records[i] = new NewRecordImpl(new UUID(input.readLong(), input.readLong()), input.readLong());
    }
    return records;
}
 
Example 8
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private OldRecordImpl[] readRecords(TupleInput input)
{
    OldRecordImpl[] records = new OldRecordImpl[input.readInt()];
    for (int i = 0; i < records.length; i++)
    {
        records[i] = new OldRecordImpl(input.readString(), input.readLong());
    }
    return records;
}
 
Example 9
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private ContentHeaderBody readContentHeaderBody(TupleInput tupleInput) throws AMQFrameDecodingException,
        AMQProtocolVersionException
{
    int bodySize = tupleInput.readInt();
    byte[] underlying = new byte[bodySize];
    tupleInput.readFast(underlying);

    return ContentHeaderBody.createFromBuffer(QpidByteBuffer.wrap(underlying),
            bodySize);

}
 
Example 10
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public MessageContentKey entryToObject(TupleInput tupleInput)
{
    long messageId = tupleInput.readLong();
    int chunk = tupleInput.readInt();
    return new MessageContentKey(messageId, chunk);
}
 
Example 11
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuffer entryToObject(TupleInput tupleInput)
{
    final int size = tupleInput.readInt();
    byte[] underlying = new byte[size];
    tupleInput.readFast(underlying);
    return ByteBuffer.wrap(underlying);
}
 
Example 12
Source File: PreparedTransactionBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private static Transaction.EnqueueRecord[] readEnqueueRecords(final CachingUUIDFactory uuidFactory, TupleInput input)
{
    Transaction.EnqueueRecord[] records = new Transaction.EnqueueRecord[input.readInt()];
    for(int i = 0; i < records.length; i++)
    {
        UUID queueId = uuidFactory.createUuidFromBits(input.readLong(), input.readLong());
        records[i] = new EnqueueRecordImpl(queueId, input.readLong());
    }
    return records;
}
 
Example 13
Source File: PreparedTransactionBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private static Transaction.DequeueRecord[] readDequeueRecords(final CachingUUIDFactory uuidFactory, TupleInput input)
{
    Transaction.DequeueRecord[] records = new Transaction.DequeueRecord[input.readInt()];
    for(int i = 0; i < records.length; i++)
    {
        UUID queueId = uuidFactory.createUuidFromBits(input.readLong(), input.readLong());
        records[i] = new DequeueRecordImpl(queueId, input.readLong());
    }
    return records;
}
 
Example 14
Source File: XidBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public Xid entryToObject(TupleInput input)
{
    long format = input.readLong();
    byte[] globalId = new byte[input.readInt()];
    input.readFast(globalId);
    byte[] branchId = new byte[input.readInt()];
    input.readFast(branchId);
    return new Xid(format,globalId,branchId);
}
 
Example 15
Source File: StringMapBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> entryToObject(final TupleInput tupleInput)
{
    int entries = tupleInput.readInt();
    Map<String,String> map = new HashMap<String,String>(entries);
    for(int i = 0; i < entries; i++)
    {
        map.put(tupleInput.readString(), tupleInput.readString());
    }
    return map;
}
 
Example 16
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
public CompoundKey entryToObject(final TupleInput input)
{
    return new CompoundKey(input.readLong(), input.readInt());
}