private int readNestedPosition(String fieldName, FieldType type) throws IOException { String[] fieldNames = NESTED_FIELD_PATTERN.split(fieldName); if (fieldNames.length > 1) { FieldDefinition fd = null; DefaultPortableReader reader = this; for (int i = 0; i < fieldNames.length; i++) { fd = reader.cd.getField(fieldNames[i]); if (fd == null) { break; } if (i == fieldNames.length - 1) { break; } int pos = reader.readPosition(fd); in.position(pos); boolean isNull = in.readBoolean(); if (isNull) { throw new NullPointerException("Parent field is null: " + fieldNames[i]); } reader = serializer.createReader(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != type) { throw new HazelcastSerializationException("Not a '" + type + "' field: " + fieldName); } return reader.readPosition(fd); } throw throwUnknownFieldException(fieldName); }
public ObjectDataInput getRawDataInput() throws IOException { if (!raw) { int pos = in.readInt(offset + cd.getFieldCount() * 4); in.position(pos); } raw = true; return in; }
@Override public BufferObjectDataInput takeInputBuffer(Data data) { BufferObjectDataInput in = inputQueue.poll(); if (in == null) { in = serializationService.createObjectDataInput((byte[]) null); } in.init(data.toByteArray(), HeapData.DATA_OFFSET); return in; }
public short[] readShortArray(String fieldName) throws IOException { final int currentPos = in.position(); try { int pos = readPosition(fieldName, FieldType.SHORT_ARRAY); in.position(pos); return in.readShortArray(); } finally { in.position(currentPos); } }
public double[] readDoubleArray(String fieldName) throws IOException { final int currentPos = in.position(); try { int pos = readPosition(fieldName, FieldType.DOUBLE_ARRAY); in.position(pos); return in.readDoubleArray(); } finally { in.position(currentPos); } }
public long[] readLongArray(String fieldName) throws IOException { final int currentPos = in.position(); try { int pos = readPosition(fieldName, FieldType.LONG_ARRAY); in.position(pos); return in.readLongArray(); } finally { in.position(currentPos); } }
public char[] readCharArray(String fieldName) throws IOException { final int currentPos = in.position(); try { int pos = readPosition(fieldName, FieldType.CHAR_ARRAY); in.position(pos); return in.readCharArray(); } finally { in.position(currentPos); } }
public byte[] readByteArray(String fieldName) throws IOException { final int currentPos = in.position(); try { int pos = readPosition(fieldName, FieldType.BYTE_ARRAY); in.position(pos); return IOUtil.readByteArray(in); } finally { in.position(currentPos); } }
public String readUTF(String fieldName) throws IOException { final int currentPos = in.position(); try { int pos = readPosition(fieldName, FieldType.UTF); in.position(pos); return in.readUTF(); } finally { in.position(currentPos); } }
public DefaultPortableReader( PortableSerializer serializer, BufferObjectDataInput in, ClassDefinition cd) { this.in = in; this.serializer = serializer; this.cd = cd; try { // final position after portable is read finalPosition = in.readInt(); } catch (IOException e) { throw new HazelcastSerializationException(e); } this.offset = in.position(); }
public Portable[] readPortableArray(String fieldName) throws IOException { FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != FieldType.PORTABLE_ARRAY) { throw new HazelcastSerializationException("Not a Portable array field: " + fieldName); } final int currentPos = in.position(); try { int pos = readPosition(fd); in.position(pos); final int len = in.readInt(); final Portable[] portables = new Portable[len]; if (len > 0) { final int offset = in.position(); for (int i = 0; i < len; i++) { final int start = in.readInt(offset + i * 4); in.position(start); portables[i] = serializer.readAndInitialize(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } } return portables; } finally { in.position(currentPos); } }
private JoinMessage receive() { try { try { multicastSocket.receive(datagramPacketReceive); } catch (IOException ignore) { return null; } try { final byte[] data = datagramPacketReceive.getData(); final int offset = datagramPacketReceive.getOffset(); final BufferObjectDataInput input = node.getSerializationService().createObjectDataInput(data); input.position(offset); final byte packetVersion = input.readByte(); if (packetVersion != Packet.VERSION) { logger.warning( "Received a JoinRequest with a different packet version! This -> " + Packet.VERSION + ", Incoming -> " + packetVersion + ", Sender -> " + datagramPacketReceive.getAddress()); return null; } try { return input.readObject(); } finally { input.close(); } } catch (Exception e) { if (e instanceof EOFException || e instanceof HazelcastSerializationException) { logger.warning( "Received data format is invalid." + " (An old version of Hazelcast may be running here.)", e); } else { throw e; } } } catch (Exception e) { logger.warning(e); } return null; }
@Override public void returnInputBuffer(BufferObjectDataInput in) { if (in == null) { return; } in.clear(); offerOrClose(inputQueue, in); }
public Portable readPortable(String fieldName) throws IOException { FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != FieldType.PORTABLE) { throw new HazelcastSerializationException("Not a Portable field: " + fieldName); } final int currentPos = in.position(); try { int pos = readPosition(fd); in.position(pos); final boolean isNull = in.readBoolean(); if (!isNull) { return serializer.readAndInitialize( in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } return null; } finally { in.position(currentPos); } }
public double readDouble(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.DOUBLE); return in.readDouble(pos); }
public byte readByte(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.BYTE); return in.readByte(pos); }
public boolean readBoolean(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.BOOLEAN); return in.readBoolean(pos); }
public float readFloat(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.FLOAT); return in.readFloat(pos); }
public long readLong(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.LONG); return in.readLong(pos); }
public int readInt(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.INT); return in.readInt(pos); }
public short readShort(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.SHORT); return in.readShort(pos); }
void end() throws IOException { in.position(finalPosition); }
private int readPosition(FieldDefinition fd) throws IOException { return in.readInt(offset + fd.getIndex() * 4); }
public char readChar(String fieldName) throws IOException { int pos = readPosition(fieldName, FieldType.CHAR); return in.readChar(pos); }