protected void writeAMF3ObjectArray(Object array) throws IOException { ensureCapacity(1); buffer[position++] = AMF3_ARRAY; int index = storedObjects.putIfAbsent(array); if (index >= 0) writeAMF3UnsignedIntegerData(index << 1); else { int length = Array.getLength(array); writeAMF3UnsignedIntegerData(length << 1 | 0x01); ensureCapacity(1); buffer[position++] = 0x01; for (int i = 0; i < length; i++) writeObject(Array.get(array, i)); } }
@Override public void write(AMF3Serializer serializer, Object o) throws IOException { serializer.writeAMF3ByteArray((byte[])o); } };
@Override public void write(AMF3Serializer serializer, Object o) throws IOException { serializer.writeAMF3Collection((Collection<?>)o); } };
protected void writeAMF3Integer(int i) throws IOException { if (i < AMF3_INTEGER_MIN || i > AMF3_INTEGER_MAX) writeAMF3Number(i); else { ensureCapacity(1); buffer[position++] = AMF3_INTEGER; writeAMF3UnsignedIntegerData(i & AMF3_SIGNED_INTEGER_MASK); } }
protected void writeAMF3ShortArray(short[] array) throws IOException { ensureCapacity(1); buffer[position++] = AMF3_ARRAY; int index = storedObjects.putIfAbsent(array); if (index >= 0) writeAMF3UnsignedIntegerData(index << 1); else { writeAMF3UnsignedIntegerData(array.length << 1 | 0x01); ensureCapacity(1); buffer[position++] = 0x01; for (short i : array) writeAMF3Integer(i); } }
protected void writeAMF3Array(Object array) throws IOException { if (debugMore) logMore.debug("writeAMF3Array(array=%s)", array); write(AMF3_ARRAY); int index = indexOfStoredObjects(array); if (index >= 0) writeAMF3IntegerData(index << 1); else { addToStoredObjects(array); int length = Array.getLength(array); writeAMF3IntegerData(length << 1 | 0x01); write(0x01); for (int i = 0; i < length; i++) writeObject(Array.get(array, i)); } }
write(AMF3_NULL); else if (!(o instanceof Externalizable)) { write(AMF3_NULL); else if (o instanceof String || o instanceof Character) writeAMF3String(o.toString()); else if (o instanceof Boolean) write(((Boolean)o).booleanValue() ? AMF3_BOOLEAN_TRUE : AMF3_BOOLEAN_FALSE); else if (o instanceof Number) { if (o instanceof Integer || o instanceof Short || o instanceof Byte) writeAMF3Integer(((Number)o).intValue()); else if (externalizeLong && o instanceof Long) writeAMF3Object(o); else if (externalizeBigInteger && o instanceof BigInteger) writeAMF3Object(o); else if (externalizeBigDecimal && o instanceof BigDecimal) writeAMF3Object(o); else writeAMF3Number(((Number)o).doubleValue()); writeAMF3Date((Date)o); else if (o instanceof Calendar) writeAMF3Date(((Calendar)o).getTime()); else if (o instanceof Document) writeAMF3Xml((Document)o); else if (o instanceof Collection<?>) writeAMF3Collection((Collection<?>)o); else if (o.getClass().isArray()) { if (o.getClass().getComponentType() == Byte.TYPE)
protected void writeAMF3VectorObject(AMFVectorObjectValue value) throws IOException { ensureCapacity(1); buffer[position++] = AMF3_VECTOR_OBJECT; Object o = value.value; int index = storedObjects.putIfAbsent(o); if (index >= 0) writeAMF3UnsignedIntegerData(index << 1); else { int length = getArrayOrCollectionLength(o); writeAMF3UnsignedIntegerData(length << 1 | 0x01); ensureCapacity(1); buffer[position++] = (byte)(value.fixed ? 0x01 : 0x00); writeAMF3StringData(value.type); if (o.getClass().isArray()) { for (int i = 0; i < length; i++) writeObject(Array.get(o, i)); } else { for (Object item : (Collection<?>)o) writeObject(item); } } }
protected void writeAMF3Object(Object o) throws IOException { ensureCapacity(1); buffer[position++] = AMF3_OBJECT; writeAMF3UnsignedIntegerData(index << 1); else { Class<?> oClass = classGetter.getClass(o); JavaClassDescriptor desc = writeAndGetAMF3Descriptor(oClass); if (desc.isExternalizable()) { Externalizer externalizer = desc.getExternalizer(); for (int i = 0; i < count; i++) { Property property = desc.getProperty(i); writeObject(property.getValue(o)); String propertyName = key.toString(); if (propertyName.length() > 0) { writeAMF3StringData(propertyName); writeObject(entry.getValue()); ensureCapacity(1); buffer[position++] = 0x01;
protected void writeAMF3Collection(Collection<?> c) throws IOException { if (legacyCollectionSerialization) writeAMF3ObjectArray(c.toArray()); else { ensureCapacity(1); buffer[position++] = AMF3_OBJECT; writeAMF3UnsignedIntegerData(index << 1); else { writeAndGetAMF3Descriptor(ArrayCollection.class); ensureCapacity(1); buffer[position++] = AMF3_ARRAY; writeAMF3UnsignedIntegerData(c.size() << 1 | 0x01); ensureCapacity(1); buffer[position++] = 0x01; writeObject(o);
@Override public void writeObject(Object o) throws IOException { if (o != null) o = converters.revert(o); if (o == null) writeAMF3Null(); else { Class<?> cls = o.getClass(); if (cls == String.class) { writeAMF3String((String)o); return; } if (cls == Integer.class) { writeAMF3Integer(((Integer)o).intValue()); return; } if (cls == Boolean.class) { writeAMF3Boolean(((Boolean)o).booleanValue()); return; } AMF3Writer writer = writersCache.get(cls); if (writer == null) { writer = getWriter(cls); writersCache.put(cls, writer); } writer.write(this, o); } }
@Override public void encode(Message[] messages, OutputStream output) throws IOException { SimpleGraniteContext.createThreadInstance(config.getGraniteConfig(), config.getServicesConfig(), new HashMap<String, Object>(0), getClientType().toString()); try { AMF3Serializer serializer = new AMF3Serializer(output); serializer.writeObject(messages); serializer.close(); } finally { GraniteContext.release(); } }
write(AMF3_OBJECT); int index = indexOfStoredObjects(o); if (index >= 0) writeAMF3IntegerData(index << 1); else { addToStoredObjects(o); IndexedJavaClassDescriptor iDesc = getFromStoredClassDescriptors(oClass); if (iDesc != null) { desc = iDesc.getDescriptor(); writeAMF3IntegerData(iDesc.getIndex() << 2 | 0x01); iDesc = addToStoredClassDescriptors(oClass); desc = iDesc.getDescriptor(); writeAMF3IntegerData((desc.getPropertiesCount() << 4) | (desc.getEncoding() << 2) | 0x03); writeAMF3StringData(desc.getName()); writeAMF3StringData(desc.getPropertyName(i)); Object obj = desc.getPropertyValue(i, o); if (debug) log.debug("writeAMF3Object() - writing defined property: %s=%s", desc.getPropertyName(i), obj); writeObject(obj); propertyName, entry.getValue() ); writeAMF3StringData(propertyName); writeObject(entry.getValue());
protected JavaClassDescriptor writeAndGetAMF3Descriptor(Class<?> cls) throws IOException { JavaClassDescriptor desc = null; IndexedJavaClassDescriptor iDesc = storedClassDescriptors.get(cls); if (iDesc != null) { desc = iDesc.getDescriptor(); writeAMF3UnsignedIntegerData(iDesc.getIndex() << 2 | 0x01); } else { iDesc = addToStoredClassDescriptors(cls); desc = iDesc.getDescriptor(); final int count = desc.getPropertiesCount(); writeAMF3UnsignedIntegerData((count << 4) | (desc.getEncoding() << 2) | 0x03); writeAMF3StringData(desc.getName()); for (int i = 0; i < count; i++) writeAMF3StringData(desc.getPropertyName(i)); } return desc; }
private void writeAMF3Data(AMF3Object data) throws IOException { dataOutput.writeByte(AMF0Body.DATA_TYPE_AMF3_OBJECT); AMF3Serializer amf3 = (AMF3Serializer)dataOutput; amf3.reset(); amf3.writeObject(data.getValue()); }
@Override public void writeObject(Object obj) throws IOException { if (obj instanceof AbstractMessage && ! (obj instanceof CommandMessage)) { AbstractMessage abstractMessage = (AbstractMessage) obj; OSGiGraniteClassUtil.setDestination(abstractMessage.getDestination()); abstractMessage.setHeader(OSGiConstants.BYTEARRAY_BODY_HEADER, Boolean.TRUE.toString()); ByteArrayOutputStream bais = new ByteArrayOutputStream(); AMF3Serializer ser = new AMF3Serializer(bais); ser.writeObject(abstractMessage.getBody()); abstractMessage.setBody(bais.toByteArray()); } super.writeObject(obj); } }
@Override public void write(AMF3Serializer serializer, Object o) throws IOException { serializer.writeAMF3Date((Date)o); } };
protected void writeAMF3Integer(int i) throws IOException { if (debugMore) logMore.debug("writeAMF3Integer(i=%d)", i); if (i < AMF3_INTEGER_MIN || i > AMF3_INTEGER_MAX) { if (debugMore) logMore.debug("writeAMF3Integer() - %d is out of AMF3 int range, writing it as a Number", i); writeAMF3Number(i); } else { write(AMF3_INTEGER); writeAMF3IntegerData(i); } }
protected void writeAMF3Collection(Collection<?> c) throws IOException { if (debugMore) logMore.debug("writeAMF3Collection(c=%s)", c); Channel channel = getChannel(); if (channel != null && channel.isLegacyCollectionSerialization()) writeAMF3Array(c.toArray()); else { ArrayCollection ac = (c instanceof ArrayCollection ? (ArrayCollection)c : new ArrayCollection(c)); writeAMF3Object(ac); } }
@Override public void write(AMF3Serializer serializer, Object o) throws IOException { serializer.writeAMF3Integer(((Number)o).intValue()); } };