use of java.io.DataInput in project asterixdb by apache.
the class FeedConnectionTupleTranslator method getMetadataEntityFromTuple.
@Override
public FeedConnection getMetadataEntityFromTuple(ITupleReference frameTuple) throws MetadataException, HyracksDataException {
byte[] serRecord = frameTuple.getFieldData(FEED_CONN_PAYLOAD_TUPLE_FIELD_INDEX);
int recordStartOffset = frameTuple.getFieldStart(FEED_CONN_PAYLOAD_TUPLE_FIELD_INDEX);
int recordLength = frameTuple.getFieldLength(FEED_CONN_PAYLOAD_TUPLE_FIELD_INDEX);
ByteArrayInputStream stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength);
DataInput in = new DataInputStream(stream);
ARecord feedConnRecord = recordSerDes.deserialize(in);
return createFeedConnFromRecord(feedConnRecord);
}
use of java.io.DataInput in project asterixdb by apache.
the class ExternalFileIndexAccessor method lookup.
public void lookup(int fileId, ExternalFile file) throws HyracksDataException {
// Set search parameters
currentFileNumber.setValue(fileId);
searchKeyTupleBuilder.reset();
searchKeyTupleBuilder.addField(intSerde, currentFileNumber);
searchKey.reset(searchKeyTupleBuilder.getFieldEndOffsets(), searchKeyTupleBuilder.getByteArray());
fileIndexSearchCursor.reset();
// Perform search
fileIndexAccessor.search(fileIndexSearchCursor, searchPredicate);
if (fileIndexSearchCursor.hasNext()) {
fileIndexSearchCursor.next();
ITupleReference tuple = fileIndexSearchCursor.getTuple();
// Deserialize
byte[] serRecord = tuple.getFieldData(FilesIndexDescription.FILE_PAYLOAD_INDEX);
int recordStartOffset = tuple.getFieldStart(FilesIndexDescription.FILE_PAYLOAD_INDEX);
int recordLength = tuple.getFieldLength(FilesIndexDescription.FILE_PAYLOAD_INDEX);
ByteArrayInputStream stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength);
DataInput in = new DataInputStream(stream);
ARecord externalFileRecord = (ARecord) externalFileRecordSerde.deserialize(in);
setFile(externalFileRecord, file);
} else {
// This should never happen
throw new RuntimeDataException(ErrorCode.INDEXING_EXTERNAL_FILE_INDEX_ACCESSOR_UNABLE_TO_FIND_FILE_INDEX);
}
}
use of java.io.DataInput in project asterixdb by apache.
the class TupleUtils method printTuple.
public static String printTuple(ITupleReference tuple, ISerializerDeserializer[] fields) throws HyracksDataException {
StringBuilder strBuilder = new StringBuilder();
int numPrintFields = Math.min(tuple.getFieldCount(), fields.length);
for (int i = 0; i < numPrintFields; i++) {
ByteArrayInputStream inStream = new ByteArrayInputStream(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
DataInput dataIn = new DataInputStream(inStream);
Object o = fields[i].deserialize(dataIn);
strBuilder.append(o.toString());
if (i != fields.length - 1) {
strBuilder.append(" ");
}
}
return strBuilder.toString();
}
use of java.io.DataInput in project asterixdb by apache.
the class TupleUtils method deserializeTuple.
public static Object[] deserializeTuple(ITupleReference tuple, ISerializerDeserializer[] fields) throws HyracksDataException {
int numFields = Math.min(tuple.getFieldCount(), fields.length);
Object[] objs = new Object[numFields];
for (int i = 0; i < numFields; i++) {
ByteArrayInputStream inStream = new ByteArrayInputStream(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
DataInput dataIn = new DataInputStream(inStream);
objs[i] = fields[i].deserialize(dataIn);
}
return objs;
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testFile.
/**
* Tests data serializing a {@link File}
*/
@Test
public void testFile() throws Exception {
File file = new File(System.getProperty("user.dir"));
DataOutputStream out = getDataOutput();
DataSerializer.writeFile(file, out);
out.flush();
DataInput in = getDataInput();
File file2 = DataSerializer.readFile(in);
assertEquals(file, file2);
}
Aggregations