/** * Creates a message from the properly sized byte buffer * and adds it to the messages queue. */ protected void createMessage( ByteBuffer buffer ) { try { Object obj = Serializer.readClassAndObject( buffer ); Message m = (Message)obj; messages.add(m); } catch( IOException e ) { throw new RuntimeException( "Error deserializing object, class ID:" + buffer.getShort(0), e ); } } }
private RemoteMethodReturnMessage readMethodReturn(ByteBuffer buffer) throws IOException{ RemoteMethodReturnMessage ret = new RemoteMethodReturnMessage(); ret.invocationID = buffer.getShort(); if (buffer.get() == (byte)0x01){ ret.retVal = Serializer.readClassAndObject(buffer); } return ret; }
private RemoteMethodCallMessage readMethodCall(ByteBuffer buffer) throws IOException{ RemoteMethodCallMessage call = new RemoteMethodCallMessage(); call.objectId = buffer.getShort(); call.methodId = buffer.getShort(); call.invocationId = buffer.getShort(); int numArgs = buffer.get() & 0xff; if (numArgs > 0){ Object[] args = new Object[numArgs]; for (int i = 0; i < numArgs; i++){ if (buffer.get() == (byte)0x01){ args[i] = Serializer.readClassAndObject(buffer); } } call.args = args; } return call; }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { GZIPCompressedMessage result = new GZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
private void readArray (Serializer elementSerializer, Class elementClass, ByteBuffer buffer, Object array, int dimension, int[] dimensions) throws IOException { boolean elementsAreArrays = dimension < dimensions.length - 1; int length; if (dimension == 0) { length = dimensions[0]; } else { length = buffer.getInt(); } for (int i = 0; i < length; i++) { if (elementsAreArrays) { // Nested array. Object element = Array.get(array, i); if (element != null) readArray(elementSerializer, elementClass, buffer, element, dimension + 1, dimensions); } else if (elementSerializer != null) { // Use same converter (and class) for all elements. Array.set(array, i, elementSerializer.readObject(buffer, elementClass)); } else { // Each element could be a different type. Look up the class with the object. Array.set(array, i, Serializer.readClassAndObject(buffer)); } } } }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { ZIPCompressedMessage result = new ZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(byteArray)); in.getNextEntry(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } in.closeEntry(); out.flush(); in.close(); result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
value = serializer.readObject(data, field.getType()); } else { value = Serializer.readClassAndObject(data);
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
Object value; if (uniqueKeys){ key = Serializer.readClassAndObject(data); }else{ key = keySerial.readObject(data, keyClazz); value = Serializer.readClassAndObject(data); }else{ value = valSerial.readObject(data, valClazz);
/** * Creates a message from the properly sized byte buffer * and adds it to the messages queue. */ protected void createMessage( ByteBuffer buffer ) { try { Object obj = Serializer.readClassAndObject( buffer ); Message m = (Message)obj; messages.add(m); } catch( IOException e ) { throw new RuntimeException( "Error deserializing object", e ); } } }
/** * Creates a message from the properly sized byte buffer * and adds it to the messages queue. */ protected void createMessage( ByteBuffer buffer ) { try { Object obj = Serializer.readClassAndObject( buffer ); Message m = (Message)obj; messages.add(m); } catch( IOException e ) { throw new RuntimeException( "Error deserializing object, class ID:" + buffer.getShort(0), e ); } } }
private RemoteMethodReturnMessage readMethodReturn(ByteBuffer buffer) throws IOException{ RemoteMethodReturnMessage ret = new RemoteMethodReturnMessage(); ret.invocationID = buffer.getShort(); if (buffer.get() == (byte)0x01){ ret.retVal = Serializer.readClassAndObject(buffer); } return ret; }
private RemoteMethodReturnMessage readMethodReturn(ByteBuffer buffer) throws IOException{ RemoteMethodReturnMessage ret = new RemoteMethodReturnMessage(); ret.invocationID = buffer.getShort(); if (buffer.get() == (byte)0x01){ ret.retVal = Serializer.readClassAndObject(buffer); } return ret; }
private RemoteMethodCallMessage readMethodCall(ByteBuffer buffer) throws IOException{ RemoteMethodCallMessage call = new RemoteMethodCallMessage(); call.objectId = buffer.getShort(); call.methodId = buffer.getShort(); call.invocationId = buffer.getShort(); int numArgs = buffer.get() & 0xff; if (numArgs > 0){ Object[] args = new Object[numArgs]; for (int i = 0; i < numArgs; i++){ if (buffer.get() == (byte)0x01){ args[i] = Serializer.readClassAndObject(buffer); } } call.args = args; } return call; }
private RemoteMethodCallMessage readMethodCall(ByteBuffer buffer) throws IOException{ RemoteMethodCallMessage call = new RemoteMethodCallMessage(); call.objectId = buffer.getShort(); call.methodId = buffer.getShort(); call.invocationId = buffer.getShort(); int numArgs = buffer.get() & 0xff; if (numArgs > 0){ Object[] args = new Object[numArgs]; for (int i = 0; i < numArgs; i++){ if (buffer.get() == (byte)0x01){ args[i] = Serializer.readClassAndObject(buffer); } } call.args = args; } return call; }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { GZIPCompressedMessage result = new GZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { GZIPCompressedMessage result = new GZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
private void readArray (Serializer elementSerializer, Class elementClass, ByteBuffer buffer, Object array, int dimension, int[] dimensions) throws IOException { boolean elementsAreArrays = dimension < dimensions.length - 1; int length; if (dimension == 0) { length = dimensions[0]; } else { length = buffer.getInt(); } for (int i = 0; i < length; i++) { if (elementsAreArrays) { // Nested array. Object element = Array.get(array, i); if (element != null) readArray(elementSerializer, elementClass, buffer, element, dimension + 1, dimensions); } else if (elementSerializer != null) { // Use same converter (and class) for all elements. Array.set(array, i, elementSerializer.readObject(buffer, elementClass)); } else { // Each element could be a different type. Look up the class with the object. Array.set(array, i, Serializer.readClassAndObject(buffer)); } } } }
@SuppressWarnings("unchecked") public <T> T readObject( ByteBuffer data, Class<T> c ) throws IOException { EntityId id = idSerializer.readObject(data, EntityId.class); Class type = classSerializer.readObject(data, Class.class); Object component = Serializer.readClassAndObject(data); return c.cast(new EntityChange(id, type, (EntityComponent)component)); }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }