Search in sources :

Example 41 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class DataInputOutputTest method testDataStreams.

private void testDataStreams(Object object, ByteOrder byteOrder, boolean allowUnsafe) throws IOException {
    InternalSerializationService ss = createSerializationServiceBuilder().setUseNativeByteOrder(false).setAllowUnsafe(allowUnsafe).setByteOrder(byteOrder).build();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectDataOutput out = createObjectDataOutputStream(bout, ss);
    out.writeObject(object);
    byte[] data1 = bout.toByteArray();
    ObjectDataOutput out2 = ss.createObjectDataOutput(1024);
    out2.writeObject(object);
    byte[] data2 = out2.toByteArray();
    assertEquals(data1.length, data2.length);
    assertTrue(Arrays.equals(data1, data2));
    final ByteArrayInputStream bin = new ByteArrayInputStream(data2);
    final ObjectDataInput in = createObjectDataInputStream(bin, ss);
    final Object object1 = in.readObject();
    final ObjectDataInput in2 = ss.createObjectDataInput(data1);
    final Object object2 = in2.readObject();
    Assert.assertEquals(object, object1);
    Assert.assertEquals(object, object2);
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 42 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class OperationPacketFilter method filterOperation.

private Action filterOperation(Packet packet, Address endpoint) {
    try {
        ObjectDataInput input = serializationService.createObjectDataInput(packet);
        byte header = input.readByte();
        boolean identified = (header & 1) != 0;
        if (identified) {
            boolean compressed = (header & 1 << 2) != 0;
            int factory = compressed ? input.readByte() : input.readInt();
            int type = compressed ? input.readByte() : input.readInt();
            return filterOperation(endpoint, factory, type);
        }
    } catch (IOException e) {
        throw new HazelcastException(e);
    }
    return Action.ALLOW;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 43 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class TransferableJobProcessInformation method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    processedRecords = reader.readInt("processedRecords");
    ObjectDataInput in = reader.getRawDataInput();
    partitionStates = in.readObject();
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 44 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class PortableCollection method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    boolean list = reader.readBoolean("l");
    int size = reader.readInt("s");
    if (size == -1) {
        return;
    }
    if (list) {
        collection = new ArrayList<Data>(size);
    } else {
        collection = new HashSet<Data>(size);
    }
    final ObjectDataInput in = reader.getRawDataInput();
    for (int i = 0; i < size; i++) {
        Data data = in.readData();
        collection.add(data);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 45 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class PortableReadResultSet method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    readCount = reader.readInt("readCount");
    // reading the items.
    int size = reader.readInt("count");
    this.items = new ArrayList<Data>(size);
    ObjectDataInput rawDataInput = reader.getRawDataInput();
    for (int k = 0; k < size; k++) {
        Data item = rawDataInput.readData();
        items.add(item);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Aggregations

ObjectDataInput (com.hazelcast.nio.ObjectDataInput)80 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 FieldKind (com.hazelcast.nio.serialization.FieldKind)16 IOException (java.io.IOException)13 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)12 Nullable (javax.annotation.Nullable)9 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)6 Data (com.hazelcast.nio.serialization.Data)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 HeapData (com.hazelcast.internal.serialization.impl.HeapData)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 SerializerConfig (com.hazelcast.config.SerializerConfig)2