Search in sources :

Example 16 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) ARecord(org.apache.asterix.om.base.ARecord) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 17 with DataInput

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);
    }
}
Also used : DataInput(java.io.DataInput) ARecord(org.apache.asterix.om.base.ARecord) ByteArrayInputStream(java.io.ByteArrayInputStream) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) DataInputStream(java.io.DataInputStream) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 18 with DataInput

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();
}
Also used : DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 19 with DataInput

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;
}
Also used : DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 20 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) File(java.io.File) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

DataInput (java.io.DataInput)295 Test (org.junit.Test)141 DataInputStream (java.io.DataInputStream)139 ByteArrayInputStream (java.io.ByteArrayInputStream)125 DataOutputStream (java.io.DataOutputStream)122 UnitTest (org.apache.geode.test.junit.categories.UnitTest)96 IOException (java.io.IOException)39 ByteArrayOutputStream (java.io.ByteArrayOutputStream)34 DataOutput (java.io.DataOutput)26 ArrayList (java.util.ArrayList)17 ARecord (org.apache.asterix.om.base.ARecord)14 BufferedInputStream (java.io.BufferedInputStream)11 EOFException (java.io.EOFException)11 ByteBuffer (java.nio.ByteBuffer)10 BigInteger (java.math.BigInteger)8 HashMap (java.util.HashMap)7 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)7 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)7 GrowableArray (org.apache.hyracks.data.std.util.GrowableArray)7 ChannelDataInput (org.apache.sis.internal.storage.io.ChannelDataInput)7