com.sleepycat.bind.tuple.TupleInput Java Examples

The following examples show how to use com.sleepycat.bind.tuple.TupleInput. 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: LinkValueEntryBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public LinkValue entryToObject(final TupleInput input)
{
    byte version = input.readByte();
    Object source = read(input);
    if (!(source instanceof Source))
    {
        throw new StoreException(String.format("Unexpected object '%s' stored in the store where Source is expected",
                                               source.getClass()));
    }

    Object target = read(input);
    if (!(target instanceof Target))
    {
        throw new StoreException(String.format("Unexpected object '%s' stored in the store where Target is expected",
                                               target.getClass()));
    }

    return new LinkValue((Source) source, (Target)target, version);
}
 
Example #2
Source File: FieldTableEncoding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
public static FieldTable readFieldTable(TupleInput tupleInput) throws DatabaseException
{

    long length = tupleInput.readLong();
    if (length <= 0)
    {
        return null;
    }
    else
    {

        ByteBuffer buf = ByteBufferBinding.getInstance().readByteBuffer(tupleInput, (int) length);

        return FieldTableFactory.createFieldTable(QpidByteBuffer.wrap(buf));

    }

}
 
Example #3
Source File: MapBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> entryToObject(final TupleInput input)
{
    String json = input.readString();
    ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
    try
    {
        Map<String, Object> value = mapper.readValue(json, Map.class);
        return value;
    }
    catch (IOException e)
    {
        //should never happen
        throw new StoreException(e);
    }
}
 
Example #4
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public MessageMetaData entryToObject(final TupleInput input)
{
    try
    {
        final MessagePublishInfo publishBody = readMessagePublishInfo(input);
        final ContentHeaderBody contentHeaderBody = readContentHeaderBody(input);

        return new MessageMetaData(publishBody, contentHeaderBody);
    }
    catch (Exception e)
    {
        LOGGER.error("Error converting entry to object: " + e, e);
        // annoyingly just have to return null since we cannot throw
        return null;
    }
}
 
Example #5
Source File: ConfiguredObjectBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public BDBConfiguredObjectRecord entryToObject(TupleInput tupleInput)
{
    String type = tupleInput.readString();
    String json = tupleInput.readString();
    ObjectMapper mapper = new ObjectMapper();
    try
    {
        Map<String,Object> value = mapper.readValue(json, Map.class);
        BDBConfiguredObjectRecord configuredObject = new BDBConfiguredObjectRecord(_uuid, type, value);
        return configuredObject;
    }
    catch (IOException e)
    {
        //should never happen
        throw new StoreException(e);
    }

}
 
Example #6
Source File: AbstractSearchStructure.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link LatLng} object with the geolocation of the vector with the given internal id or null
 * if the internal id does not exist. Accesses the BDB store!
 * 
 * @param iid
 *            The internal id of the vector
 * @return The geolocation mapped to the given internal id or null if the internal id does not exist
 */
public LatLng getGeolocation(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToGeolocationDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		double latitude = input.readDouble();
		double longitude = input.readDouble();
		LatLng geolocation = new LatLng(latitude, longitude);
		return geolocation;
	} else {
		System.out.println("Internal id " + iid + " is in range but gelocation was not found.");
		return null;
	}
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
Source File: LinkKeyEntryBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public LinkKey entryToObject(final TupleInput input)
{
    String remoteContainerId =  input.readString();
    String linkName = input.readString();
    Role role = null;
    try
    {
        role = Role.valueOf(input.readBoolean());
    }
    catch (IllegalArgumentException e)
    {
        throw new StoreException("Cannot load link from store", e);
    }

    final String remoteContainerId1 = remoteContainerId;
    final String linkName1 = linkName;
    final Role role1 = role;
    return new LinkKey(remoteContainerId1, linkName1, role1);
}
 
Example #12
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 #13
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 #14
Source File: ByteBufferBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public QpidByteBuffer entryToObject(final TupleInput input)
{
    int available = input.available();
    QpidByteBuffer buf = QpidByteBuffer.allocateDirect(available);
    byte[] copyBuf = COPY_BUFFER.get();
    while(available > 0)
    {
        int read = input.read(copyBuf);
        buf.put(copyBuf,0,read);
        available = input.available();
    }
    buf.flip();
    return buf;
}
 
Example #15
Source File: ByteBufferBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public ByteBuffer readByteBuffer(final TupleInput input, int length)
{
    ByteBuffer buf = ByteBuffer.allocateDirect(length);
    byte[] copyBuf = COPY_BUFFER.get();
    while(length > 0)
    {
        int read = input.read(copyBuf, 0, Math.min(COPY_BUFFER_SIZE, length));
        buf.put(copyBuf,0,read);
        length -= read;
    }
    buf.flip();
    return buf;
}
 
Example #16
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 #17
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the vector which was assigned the given internal id or null if the internal id does not exist.
 * The vector is taken either from the ram-based (if loadIndexInMemory is true) or from the disk-based
 * index.
 * 
 * @param iid
 *            The internal id of the vector
 * @return The vector with the given internal id or null if the internal id does not exist
 */
public double[] getVector(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	double[] vector = new double[vectorLength];
	if (loadIndexInMemory) {
		for (int i = 0; i < vectorLength; i++) {
			vector[i] = vectorsList.getQuick(iid * vectorLength + i);
		}
	} else {
		// get the vector from the BDB structure
		DatabaseEntry key = new DatabaseEntry();
		IntegerBinding.intToEntry(iid, key);
		DatabaseEntry foundData = new DatabaseEntry();
		if (iidToVectorDB.get(null, key, foundData, null) == OperationStatus.SUCCESS) {
			TupleInput input = TupleBinding.entryToInput(foundData);
			for (int i = 0; i < vectorLength; i++) {
				vector[i] = input.readDouble();
			}
		} else {
			System.out.println("Internal id " + iid + " is in range but vector was not found..");
			System.out.println("Index is probably corrupted");
			System.exit(0);
			return null;
		}
	}
	return vector;
}
 
Example #18
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 #19
Source File: AMQShortStringEncoding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static AMQShortString readShortString(TupleInput tupleInput)
{
    int length = tupleInput.readShort();
    if (length < 0)
    {
        return null;
    }
    else
    {
        byte[] stringBytes = new byte[length];
        tupleInput.readFast(stringBytes);
        return AMQShortString.createAMQShortString(stringBytes);
    }

}
 
Example #20
Source File: UpgradeFrom7To8Test.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public UpgradeConfiguredObjectRecord entryToObject(TupleInput tupleInput)
{
    String type = tupleInput.readString();
    String json = tupleInput.readString();
    UpgradeConfiguredObjectRecord configuredObject = new UpgradeConfiguredObjectRecord(type, json);
    return configuredObject;
}
 
Example #21
Source File: UpgradeFrom7To8Test.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public UpgradeHierarchyKey entryToObject(TupleInput tupleInput)
{
    UUID childId = new UUID(tupleInput.readLong(), tupleInput.readLong());
    String parentType = tupleInput.readString();

    return new UpgradeHierarchyKey(childId, parentType);
}
 
Example #22
Source File: ConfiguredObjectBindingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testObjectToEntryAndEntryToObject()
{
    TupleOutput tupleOutput = new TupleOutput();

    _configuredObjectBinding.objectToEntry(_object, tupleOutput);

    byte[] entryAsBytes = tupleOutput.getBufferBytes();
    TupleInput tupleInput = new TupleInput(entryAsBytes);

    ConfiguredObjectRecord storedObject = _configuredObjectBinding.entryToObject(tupleInput);
    assertEquals("Unexpected attributes", DUMMY_ATTRIBUTES_MAP, storedObject.getAttributes());
    assertEquals("Unexpected type", DUMMY_TYPE_STRING, storedObject.getType());
}
 
Example #23
Source File: AMQShortStringEncodingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadNullValues()
{
    // write into tuple output
    TupleOutput tupleOutput = new TupleOutput();
    AMQShortStringEncoding.writeShortString(null, tupleOutput);
    byte[] data = tupleOutput.getBufferBytes();

    // read from tuple input
    TupleInput tupleInput = new TupleInput(data);
    AMQShortString result = AMQShortStringEncoding.readShortString(tupleInput);
    assertNull("Expected null but got " + result, result);
}
 
Example #24
Source File: AMQShortStringEncodingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadShortStringWithLengthOver127()
{
    AMQShortString value = createString('a', 128);

    // write into tuple output
    TupleOutput tupleOutput = new TupleOutput();
    AMQShortStringEncoding.writeShortString(value, tupleOutput);
    byte[] data = tupleOutput.getBufferBytes();

    // read from tuple input
    TupleInput tupleInput = new TupleInput(data);
    AMQShortString result = AMQShortStringEncoding.readShortString(tupleInput);
    assertEquals("Expected " + value + " but got " + result, value, result);
}
 
Example #25
Source File: AMQShortStringEncodingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadShortStringWithLengthLess127()
{
    AMQShortString value = AMQShortString.createAMQShortString("test");

    // write into tuple output
    TupleOutput tupleOutput = new TupleOutput();
    AMQShortStringEncoding.writeShortString(value, tupleOutput);
    byte[] data = tupleOutput.getBufferBytes();

    // read from tuple input
    TupleInput tupleInput = new TupleInput(data);
    AMQShortString result = AMQShortStringEncoding.readShortString(tupleInput);
    assertEquals("Expected " + value + " but got " + result, value, result);
}
 
Example #26
Source File: LinkBinding.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public HGPersistentHandle[] entryToObject(TupleInput input) {
	int size = input.getBufferLength() - input.getBufferOffset();
	if (size % handleSize != 0) {
		throw new HGException(
				"While reading link tuple: the value buffer size is not a multiple of the handle size.");
	}
	else {
		return readHandles(input.getBufferBytes(), 0, size);
	}
}
 
Example #27
Source File: LinkBinding.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public HGPersistentHandle[] entryToObject(TupleInput input)
{
    int size = input.getBufferLength() - input.getBufferOffset();
    if (size % handleSize != 0)
        throw new HGException("While reading link tuple: the value buffer size is not a multiple of the handle size.");
    else
    	return readHandles(input.getBufferBytes(), 0, size);
}
 
Example #28
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the persistent index in memory.
 * 
 * @throws Exception
 */
private void loadIndexInMemory() throws Exception {
	long start = System.currentTimeMillis();
	System.out.println("Loading persistent index in memory.");

	DatabaseEntry foundKey = new DatabaseEntry();
	DatabaseEntry foundData = new DatabaseEntry();

	ForwardCursor cursor = null;
	if (useDiskOrderedCursor) { // disk ordered cursor
		DiskOrderedCursorConfig docc = new DiskOrderedCursorConfig();
		cursor = iidToVectorDB.openCursor(docc);
	} else {
		cursor = iidToVectorDB.openCursor(null, null);
	}

	int counter = 0;
	while (cursor.getNext(foundKey, foundData, null) == OperationStatus.SUCCESS
			&& counter < maxNumVectors) {
		TupleInput input = TupleBinding.entryToInput(foundData);
		double[] vector = new double[vectorLength];
		for (int i = 0; i < vectorLength; i++) {
			vector[i] = input.readDouble();
		}
		// update ram based index
		vectorsList.add(vector);
		counter++;
		if (counter % 1000 == 0) {
			System.out.println(counter + " vectors loaded in memory!");
		}
	}
	cursor.close();
	long end = System.currentTimeMillis();
	System.out.println(counter + " vectors loaded in " + (end - start) + " ms!");
}
 
Example #29
Source File: HierarchyKeyBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public HierarchyKey entryToObject(TupleInput tupleInput)
{
    UUID childId = new UUID(tupleInput.readLong(), tupleInput.readLong());
    String parentType = tupleInput.readString();

    return new HierarchyKey(childId, parentType);
}
 
Example #30
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);
}