You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2017/04/16 22:32:10 UTC
[19/72] [abbrv] [partial] flex-blazeds git commit: - Major code scrub
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/ActionContext.java
----------------------------------------------------------------------
diff --git a/core/src/flex/messaging/io/amf/ActionContext.java b/core/src/flex/messaging/io/amf/ActionContext.java
deleted file mode 100644
index 3b7d2a5..0000000
--- a/core/src/flex/messaging/io/amf/ActionContext.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.io.amf;
-
-import flex.messaging.io.MessageIOConstants;
-import flex.messaging.messages.MessagePerformanceInfo;
-
-import java.io.ByteArrayOutputStream;
-import java.io.Serializable;
-
-/**
- * A context for reading and writing messages.
- *
- */
-public class ActionContext implements Serializable
-{
- static final long serialVersionUID = 2300156738426801921L;
- private int messageNumber;
- private ActionMessage requestMessage;
- private ActionMessage responseMessage;
- private ByteArrayOutputStream outBuffer;
-
- private int status;
- private int version;
-
- private boolean legacy;
- public boolean isPush;
- public boolean isDebug;
-
- /**
- *
- * Performance metrics related field, keeps track of bytes deserialized using this context
- */
- private int deserializedBytes;
-
- /**
- *
- * Performance metrics related field, keeps track of bytes serialized using this context
- */
- private int serializedBytes;
-
- /**
- *
- * Performance metrics related field, recordMessageSizes flag
- */
- private boolean recordMessageSizes;
-
- /**
- *
- * Performance metrics related field, recordMessageTimes flag
- */
- private boolean recordMessageTimes;
-
- /**
- *
- * Performance metrics related field, incoming MPI object, will only be populated when one of
- * the record-message-* params is enabled
- */
- private MessagePerformanceInfo mpii;
-
- /**
- *
- * Performance metrics related field, outgoing MPI object, will only be populated when one of
- * the record-message-* params is enabled
- */
- private MessagePerformanceInfo mpio;
-
- public ActionContext()
- {
- status = MessageIOConstants.STATUS_OK;
- }
-
- public boolean isLegacy()
- {
- return legacy;
- }
-
- public void setLegacy(boolean legacy)
- {
- this.legacy = legacy;
- }
-
- public int getMessageNumber()
- {
- return messageNumber;
- }
-
- public void setMessageNumber(int messageNumber)
- {
- this.messageNumber = messageNumber;
- }
-
- public MessageBody getRequestMessageBody()
- {
- return requestMessage.getBody(messageNumber);
- }
-
- public ActionMessage getRequestMessage()
- {
- return requestMessage;
- }
-
- public void setRequestMessage(ActionMessage requestMessage)
- {
- this.requestMessage = requestMessage;
- }
-
- public ActionMessage getResponseMessage()
- {
- return responseMessage;
- }
-
- public MessageBody getResponseMessageBody()
- {
- return responseMessage.getBody(messageNumber);
- }
-
- public void setResponseMessage(ActionMessage responseMessage)
- {
- this.responseMessage = responseMessage;
- }
-
- public void setResponseOutput(ByteArrayOutputStream out)
- {
- outBuffer = out;
- }
-
- public ByteArrayOutputStream getResponseOutput()
- {
- return outBuffer;
- }
-
- public int getStatus()
- {
- return status;
- }
-
- public void setStatus(int status)
- {
- this.status = status;
- }
-
- public void setVersion(int v)
- {
- version = v;
- }
-
- public int getVersion()
- {
- return version;
- }
-
- public void incrementMessageNumber()
- {
- messageNumber++;
- }
-
- public int getDeserializedBytes()
- {
- return deserializedBytes;
- }
-
- public void setDeserializedBytes(int deserializedBytes)
- {
- this.deserializedBytes = deserializedBytes;
- }
-
- public int getSerializedBytes()
- {
- return serializedBytes;
- }
-
- public void setSerializedBytes(int serializedBytes)
- {
- this.serializedBytes = serializedBytes;
- }
-
- public MessagePerformanceInfo getMPII()
- {
- return mpii;
- }
-
- public void setMPII(MessagePerformanceInfo mpii)
- {
- this.mpii = mpii;
- }
-
- public MessagePerformanceInfo getMPIO()
- {
- return mpio;
- }
-
- public void setMPIO(MessagePerformanceInfo mpio)
- {
- this.mpio = mpio;
- }
-
- public boolean isRecordMessageSizes()
- {
- return recordMessageSizes;
- }
-
- public void setRecordMessageSizes(boolean recordMessageSizes)
- {
- this.recordMessageSizes = recordMessageSizes;
- }
-
- public boolean isRecordMessageTimes()
- {
- return recordMessageTimes;
- }
-
- public boolean isMPIenabled()
- {
- return recordMessageTimes || recordMessageSizes;
- }
-
- public void setRecordMessageTimes(boolean recordMessageTimes)
- {
- this.recordMessageTimes = recordMessageTimes;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/ActionMessage.java
----------------------------------------------------------------------
diff --git a/core/src/flex/messaging/io/amf/ActionMessage.java b/core/src/flex/messaging/io/amf/ActionMessage.java
deleted file mode 100644
index 8d30a87..0000000
--- a/core/src/flex/messaging/io/amf/ActionMessage.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.io.amf;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-
-
-public class ActionMessage implements Serializable
-{
- static final long serialVersionUID = 7970778672727624188L;
-
- public static final int CURRENT_VERSION = 3;
-
- private int version;
-
- private ArrayList headers = null;
-
- private ArrayList bodies = null;
-
-
- public ActionMessage()
- {
- version = CURRENT_VERSION;
- headers = new ArrayList();
- bodies = new ArrayList();
- }
-
-
- public ActionMessage(int version)
- {
- this.version = version;
- headers = new ArrayList();
- bodies = new ArrayList();
- }
-
-
- public int getVersion()
- {
- return version;
- }
-
- public void setVersion(int version)
- {
- this.version = version;
- }
-
-
- public int getHeaderCount()
- {
- return headers.size();
- }
-
-
- public MessageHeader getHeader(int pos)
- {
- return (MessageHeader)headers.get(pos);
- }
-
- public ArrayList getHeaders()
- {
- return headers;
- }
-
- public void addHeader(MessageHeader h)
- {
- headers.add(h);
- }
-
-
- public int getBodyCount()
- {
- return bodies.size();
- }
-
-
- public MessageBody getBody(int pos)
- {
- return (MessageBody)bodies.get(pos);
- }
-
-
- public ArrayList getBodies()
- {
- return bodies;
- }
-
- public void addBody(MessageBody b)
- {
- bodies.add(b);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/ActionMessageInput.java
----------------------------------------------------------------------
diff --git a/core/src/flex/messaging/io/amf/ActionMessageInput.java b/core/src/flex/messaging/io/amf/ActionMessageInput.java
deleted file mode 100644
index 8d8ecd3..0000000
--- a/core/src/flex/messaging/io/amf/ActionMessageInput.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.io.amf;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInput;
-
-/**
- * This simple interface allows the MessageDeserializer to
- * handle multiple versions of AMF.
- *
- * Entry point for deserializing an individual ActionMessage
- * request message for AMF, AMFX or RTMP.
- *
- * @see flex.messaging.io.amf.Amf0Input Classic Version 0 Deserializer
- * @see flex.messaging.io.amf.Amf3Input AVM+ Version 3 Deserializer
- *
- * @see flex.messaging.io.amf.ActionMessageOutput The serialization equivalent
- */
-public interface ActionMessageInput extends ObjectInput
-{
- // java.io.ObjectInput METHODS
-
- /**
- * Reads in an AMF formatted Object.
- *
- * <p>
- * The following is a guide to the ActionScript to Java type mappings:
- * <table cellpadding="2" cellspacing="2" border="1">
- * <tr><td width="50%"><b>ActionScript Type (AMF 3)</b></td><td width="50%"><b>Java Type</b></td></tr>
- * <tr><td>String</td><td>java.lang.String</td></tr>
- * <tr><td>Boolean</td><td>java.lang.Boolean</td></tr>
- * <tr><td>int<br />uint</td><td>java.lang.Integer</td></tr>
- * <tr><td>Number</td><td>java.lang.Double</td></tr>
- * <tr><td>Date</td><td>java.util.Date</td></tr>
- * <tr><td>ByteArray</td><td>java.util.Byte.TYPE[]</td></tr>
- * <tr><td>mx.collections.ArrayCollection</td><td>flex.messaging.io.ArrayCollection</td></tr>
- * <tr><td>Array</td><td>java.lang.Object[] (Native Array)</td></tr>
- * <tr><td>Object</td><td>java.util.Map</td></tr>
- * <tr><td>flash.utils.IExternalizable</td><td>java.io.Externalizable</td></tr>
- * <tr><td>Typed Object (other than the above)</td><td>An instance of type Class (java.lang.Object)</td></tr>
- * <tr><td>null</td><td>null</td></tr>
- * </table>
- * </p>
- *
- * <p>
- * <table cellpadding="2" cellspacing="2" border="1">
- * <tr><td width="50%"><b>ActionScript Type (AMF 0)</b></td><td width="50%"><b>Java Type</b></td></tr>
- * <tr><td>String</td><td>java.lang.String</td></tr>
- * <tr><td>Boolean</td><td>java.lang.Boolean</td></tr>
- * <tr><td>int<br />uint</td><td>java.lang.Double</td></tr>
- * <tr><td>Number</td><td>java.lang.Double</td></tr>
- * <tr><td>Date</td><td>java.util.Date</td></tr>
- * <tr><td>ByteArray</td><td>(Not supported)</td></tr>
- * <tr><td>mx.collections.ArrayCollection</td><td>flex.messaging.io.ArrayCollection</td></tr>
- * <tr><td>Array</td><td>java.lang.Object[] (Native Array)</td></tr>
- * <tr><td>Object</td><td>java.util.Map</td></tr>
- * <tr><td>flash.utils.IExternalizable</td><td>(Not supported)</td></tr>
- * <tr><td>Typed Object (other than the above)</td><td>An instance of type Class (java.lang.Object)</td></tr>
- * <tr><td>null</td><td>null</td></tr>
- * </table>
- * </p>
- */
- Object readObject() throws ClassNotFoundException, IOException;
-
-
- //
- // INITIALIZATION UTILITIES
- //
-
- /**
- * Internal use only.
- *
- */
- void setInputStream(InputStream in);
-
- /**
- * Internal use only.
- *
- */
- void setDebugTrace(AmfTrace trace);
-
- /**
- * Internal use only.
- *
- */
- void reset();
-}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/ActionMessageOutput.java
----------------------------------------------------------------------
diff --git a/core/src/flex/messaging/io/amf/ActionMessageOutput.java b/core/src/flex/messaging/io/amf/ActionMessageOutput.java
deleted file mode 100644
index 7b319af..0000000
--- a/core/src/flex/messaging/io/amf/ActionMessageOutput.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.io.amf;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.ObjectOutput;
-
-/**
- * Entry point for serializing an individual ActionMessage
- * response message for AMF, AMFX or RTMP Channels.
- *
- * @see flex.messaging.io.amf.Amf0Input Classic Version 0 Deserializer
- * @see flex.messaging.io.amf.Amf3Input AVM+ Version 3 Deserializer
- *
- * @see flex.messaging.io.amf.ActionMessageOutput The serialization equivalent
- */
-public interface ActionMessageOutput extends ObjectOutput
-{
- // java.io.ObjectOutput METHODS
-
- /**
- * A convenient entry point for writing out any Object for conversion to ActionScript.
- * The Java class type of the Object will determine the corresponding ActionScript type
- * that will be specified in the AMF stream.
- * <p>
- * The following is a guide to the Java to ActionScript type mappings:
- * <table cellpadding="2" cellspacing="2" border="1">
- * <tr><td width="34%"><b>Java Type</b></td><td width="33%"><b>ActionScript Type (AMF 0)</b></td><td width="33%"><b>ActionScript Type (AMF 3 / AMFX)</b></td></tr>
- * <tr><td>java.lang.String</td><td>String</td><td>String</td></tr>
- * <tr><td>java.lang.Boolean</td><td>Boolean</td><td>Boolean</td></tr>
- * <tr><td>java.lang.Integer<br />java.lang.Short<br />java.lang.Byte</td><td>Number</td><td>int<sup>(a)</sup></td></tr>
- * <tr><td>java.lang.Double<br />java.lang.Long<br />java.lang.Float</td><td>Number</td><td>Number</td></tr>
- * <tr><td>java.util.Calendar<br />java.util.Date</td><td>Date<sup>(b)</sup></td><td>Date<sup>(b)</sup></td></tr>
- * <tr><td>java.lang.Character<br />java.lang.Character[]</td><td>String</td><td>String</td></tr>
- * <tr><td>java.lang.Byte[]</td><td>Array (of Numbers)</td><td>ByteArray</td></tr>
- * <tr><td>java.util.Collection</td><td>mx.collections.ArrayCollection<sup>(c)</sup></td><td>mx.collections.ArrayCollection<sup>(c)</sup></td></tr>
- * <tr><td>java.lang.Object[] (Native Array)</td><td>Array</td><td>Array</td></tr>
- * <tr><td>java.util.Map<br />java.util.Dictionary</td><td>Object<sup>(d)</sup></td><td>Object<sup>(d)</sup></td></tr>
- * <tr><td>java.lang.Object (Other than the above)</td><td>Typed Object<sup>(e)</sup></td><td>Typed Object<sup>(e)</sup></td></tr>
- * <tr><td>null</td><td>null</td><td>null</td></tr>
- * </table>
- * </p>
- * <p>
- * (a) - For AMF 3 ints, taking sign into consideration, if i < 0xF0000000 || i > 0x0FFFFFFF, then value is promoted to Number.
- * <br/>
- * (b) - Dates are sent in the UTC timezone. Clients and servers must adjust time accordingly for timezones.
- * <br/>
- * (c) - Channel serialization configuration can be set to support legacy Collection to ActionScript Array conversion.
- * <br/>
- * (d) - Channel serialization configuration can be set to support legacy Map to ActionScript Array (associative) conversion.
- * <br/>
- * (e) - Objects are serialized using Java Bean introspection rules. Fields that are static, transient or non-public are excluded.
- * </p>
- *
- * @param object the Object to be written
- * @throws IOException if an I/O error occurs
- */
- void writeObject(Object object) throws IOException;
-
- /**
- * Internal use only.
- *
- */
- void writeObjectTraits(TraitsInfo traits) throws IOException;
-
- /**
- * Internal use only.
- *
- */
- void writeObjectProperty(String name, Object value) throws IOException;
-
- /**
- * Internal use only.
- *
- */
- void writeObjectEnd() throws IOException;
-
-
- //
- // INITIALIZATION UTILITIES
- //
-
- /**
- * Internal use only.
- *
- */
- void setDebugTrace(AmfTrace debugBuffer);
-
- /**
- * Internal use only.
- *
- */
- void setOutputStream(OutputStream out);
-
- /**
- * Internal use only.
- *
- */
- void reset();
-
-}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/Amf0Input.java
----------------------------------------------------------------------
diff --git a/core/src/flex/messaging/io/amf/Amf0Input.java b/core/src/flex/messaging/io/amf/Amf0Input.java
deleted file mode 100644
index fa66ae9..0000000
--- a/core/src/flex/messaging/io/amf/Amf0Input.java
+++ /dev/null
@@ -1,541 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.io.amf;
-
-import java.io.IOException;
-import java.io.UTFDataFormatException;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import flex.messaging.io.PropertyProxy;
-import flex.messaging.io.SerializationContext;
-import flex.messaging.io.SerializationException;
-import flex.messaging.io.UnknownTypeException;
-import flex.messaging.util.ClassUtil;
-
-/**
- * An Amf0 input object.
- *
- */
-public class Amf0Input extends AbstractAmfInput implements AmfTypes
-{
- /**
- * Unfortunately the Flash Player starts AMF 3 messages off with the legacy
- * AMF 0 format and uses a type, AmfTypes.kAvmPlusObjectType, to indicate
- * that the next object in the stream is to be deserialized differently. The
- * original hope was for two independent encoding versions... but for now
- * we just keep a reference to objectInput here.
- *
- */
- protected ActionMessageInput avmPlusInput;
-
- /**
- *
- */
- protected List objectsTable;
-
- public Amf0Input(SerializationContext context)
- {
- super(context);
-
- objectsTable = new ArrayList(64);
- }
-
- /**
- * Clear all object reference information so that the instance
- * can be used to deserialize another data structure.
- *
- * Reset should be called before reading a top level object,
- * such as a new header or a new body.
- */
- @Override
- public void reset()
- {
- super.reset();
-
- objectsTable.clear();
-
- if (avmPlusInput != null)
- avmPlusInput.reset();
- }
-
-
- //
- // java.io.ObjectInput SERIALIZATION IMPLEMENTATIONS
- //
-
- /**
- * Public entry point to read a top level AMF Object, such as
- * a header value or a message body.
- */
- public Object readObject() throws ClassNotFoundException, IOException
- {
- int type = in.readByte();
-
- Object value = readObjectValue(type);
- return value;
- }
-
- protected Object readObjectValue(int type) throws ClassNotFoundException, IOException
- {
- Object value = null;
- switch (type)
- {
- case kNumberType:
- value = Double.valueOf(readDouble());
- break;
-
- case kBooleanType:
- value = Boolean.valueOf(readBoolean());
- break;
-
- case kStringType:
- value = readString();
- break;
-
- case kAvmPlusObjectType:
-
- if (avmPlusInput == null)
- {
- avmPlusInput = new Amf3Input(context);
- avmPlusInput.setDebugTrace(trace);
- avmPlusInput.setInputStream(in);
- }
- value = avmPlusInput.readObject();
- break;
-
- case kStrictArrayType:
- value = readArrayValue();
- break;
-
- case kTypedObjectType:
- String typeName = in.readUTF();
- value = readObjectValue(typeName);
- break;
-
- case kLongStringType:
- ClassUtil.validateCreation(String.class);
-
- value = readLongUTF();
- if (isDebug)
- trace.writeString((String)value);
- break;
-
- case kObjectType:
- value = readObjectValue(null);
- break;
-
- case kXMLObjectType:
- value = readXml();
- break;
-
- case kNullType:
- if (isDebug)
- trace.writeNull();
- break;
-
- case kDateType:
- value = readDate();
- break;
-
- case kECMAArrayType:
- value = readECMAArrayValue();
- break;
-
- case kReferenceType:
- int refNum = in.readUnsignedShort();
-
- if (isDebug)
- trace.writeRef(refNum);
-
- value = objectsTable.get(refNum);
- break;
-
- case kUndefinedType:
-
- if (isDebug)
- trace.writeUndefined();
- break;
-
- case kUnsupportedType:
-
- if (isDebug)
- trace.write("UNSUPPORTED");
-
- //Unsupported type found in AMF stream.
- UnknownTypeException ex = new UnknownTypeException();
- ex.setMessage(10302);
- throw ex;
-
- case kObjectEndType:
-
- if (isDebug)
- trace.write("UNEXPECTED OBJECT END");
-
- //Unexpected object end tag in AMF stream.
- UnknownTypeException ex1 = new UnknownTypeException();
- ex1.setMessage(10303);
- throw ex1;
-
- case kRecordsetType:
-
- if (isDebug)
- trace.write("UNEXPECTED RECORDSET");
-
- //AMF Recordsets are not supported.
- UnknownTypeException ex2 = new UnknownTypeException();
- ex2.setMessage(10304);
- throw ex2;
-
- default:
-
- if (isDebug)
- trace.write("UNKNOWN TYPE");
-
- UnknownTypeException ex3 = new UnknownTypeException();
- ex3.setMessage(10301, new Object[]{new Integer(type)});
- throw ex3;
- }
- return value;
- }
-
- protected Date readDate() throws IOException
- {
- ClassUtil.validateCreation(Date.class);
-
- long time = (long)in.readDouble();
- /*
- We read in the timezone but do nothing with the value as
- we expect dates to be written in the UTC timezone. Client
- and servers are responsible for applying their own
- timezones.
- */
- in.readShort();
-
- Date d = new Date(time);
-
- if (isDebug)
- trace.write(d.toString());
-
- return d;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean readBoolean() throws IOException
- {
- ClassUtil.validateCreation(Boolean.class);
-
- boolean b = super.readBoolean();
- if (isDebug)
- trace.write(b);
- return b;
- }
-
- /** {@inheritDoc} */
- @Override
- public double readDouble() throws IOException
- {
- ClassUtil.validateCreation(Double.class);
-
- double d = super.readDouble();
- if (isDebug)
- trace.write(d);
- return d;
- }
-
- /**
- * Deserialize the bits of an ECMA array w/o a prefixing type byte.
- */
- protected Map readECMAArrayValue() throws ClassNotFoundException, IOException
- {
- ClassUtil.validateCreation(HashMap.class);
-
- int size = in.readInt();
- HashMap h;
- if (size == 0)
- {
- h = new HashMap();
- }
- else
- {
- int initialCapacity = size < INITIAL_COLLECTION_CAPACITY? size : INITIAL_COLLECTION_CAPACITY;
- h = new HashMap(initialCapacity);
- }
-
- rememberObject(h);
-
- if (isDebug)
- trace.startECMAArray(objectsTable.size() - 1);
-
- String name = in.readUTF();
- int type = in.readByte();
- while (type != kObjectEndType)
- {
- if (type != kObjectEndType)
- {
- if (isDebug)
- trace.namedElement(name);
-
- // Always read value but be careful to ignore erroneous 'length' prop that is sometimes sent by the player.
- Object value = readObjectValueOneLevelDown(type, true);
- if (!name.equals("length"))
- {
- ClassUtil.validateAssignment(h, name, value);
- h.put(name, value);
- }
- }
-
- name = in.readUTF();
- type = in.readByte();
- }
-
- if (isDebug)
- trace.endAMFArray();
-
- return h;
- }
-
- protected String readString() throws IOException
- {
- ClassUtil.validateCreation(String.class);
-
- String s = readUTF();
- if (isDebug)
- trace.writeString(s);
- return s;
- }
-
-
- /**
- * Deserialize the bits of an array w/o a prefixing type byte.
- */
- protected Object readArrayValue() throws ClassNotFoundException, IOException
- {
- int size = in.readInt();
- // Don't instantiate List/Array right away with the supplied size if it is more than
- // INITIAL_COLLECTION_CAPACITY in case the supplied size has been tampered.
- boolean useListTemporarily = false;
- Object l;
- if (context.legacyCollection || size > INITIAL_COLLECTION_CAPACITY)
- {
- useListTemporarily = !context.legacyCollection;
- ClassUtil.validateCreation(ArrayList.class);
- int initialCapacity = size < INITIAL_COLLECTION_CAPACITY? size : INITIAL_COLLECTION_CAPACITY;
- l = new ArrayList(initialCapacity);
- }
- else
- {
- ClassUtil.validateCreation(Object[].class);
- l = new Object[size];
- }
- int objectId = rememberObject(l); // Remember the List/Object[].
-
- if (isDebug)
- trace.startAMFArray(objectsTable.size() - 1);
-
- for (int i = 0; i < size; ++i)
- {
- if (isDebug)
- trace.arrayElement(i);
-
- // Add value to the array
- int type = in.readByte();
- Object value = readObjectValueOneLevelDown(type, true);
- ClassUtil.validateAssignment(l, i, value);
- if (l instanceof ArrayList)
- ((ArrayList)l).add(value);
- else
- Array.set(l, i, value);
- }
-
- if (isDebug)
- trace.endAMFArray();
-
- if (useListTemporarily)
- {
- l = ((ArrayList)l).toArray();
- objectsTable.set(objectId, l);
- }
-
- return l;
- }
-
- /**
- * Deserialize the bits of a map w/o a prefixing type byte.
- */
- protected Object readObjectValue(String className) throws ClassNotFoundException, IOException
- {
- // Prepare the parameters for createObjectInstance(). Use an array as a holder
- // to simulate two 'by-reference' parameters className and (initially null) proxy
- Object[] params = new Object[] {className, null};
- Object object = createObjectInstance(params);
-
- // Retrieve any changes to the className and the proxy parameters
- className = (String)params[0];
- PropertyProxy proxy = (PropertyProxy)params[1];
-
- int objectId = rememberObject(object);
-
- if (isDebug)
- trace.startAMFObject(className, objectsTable.size() - 1);
-
- boolean isCollectionClass = isCollectionClass(object);
- String propertyName = in.readUTF();
- int type = in.readByte();
- while (type != kObjectEndType)
- {
- if (isDebug)
- trace.namedElement(propertyName);
- Object value = readObjectValueOneLevelDown(type, isCollectionClass);
- proxy.setValue(object, propertyName, value);
- propertyName = in.readUTF();
- type = in.readByte();
- }
-
- if (isDebug)
- trace.endAMFObject();
-
- // This lets the BeanProxy substitute a new instance into the BeanProxy
- // at the end of the serialization. You might for example create a Map, store up
- // the properties, then construct the instance based on that. Note that this does
- // not support recursive references to the parent object however.
- Object newObj = proxy.instanceComplete(object);
-
- // TODO: It is possible we gave out references to the
- // temporary object. it would be possible to warn users about
- // that problem by tracking if we read any references to this object
- // in the readObject call above.
- if (newObj != object)
- {
- objectsTable.set(objectId, newObj);
- object = newObj;
- }
-
- return object;
- }
-
- /**
- * This code borrows heavily from DataInputStreat.readUTF().
- * However, it uses a 32-bit string length.
- *
- * @return the read String
- * @throws java.io.UTFDataFormatException if the UTF-8 encoding is incorrect
- * @throws IOException if an I/O error occurs.
- */
- protected String readLongUTF() throws IOException
- {
- int utflen = in.readInt();
- checkUTFLength(utflen);
-
- int c, char2, char3;
- char[] charr = getTempCharArray(utflen);
- byte bytearr [] = getTempByteArray(utflen);
- int count = 0;
- int chCount = 0;
-
- in.readFully(bytearr, 0, utflen);
-
- while (count < utflen)
- {
- c = (int)bytearr[count] & 0xff;
- switch (c >> 4)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- /* 0xxxxxxx*/
- count++;
- charr[chCount] = (char)c;
- break;
- case 12:
- case 13:
- /* 110x xxxx 10xx xxxx*/
- count += 2;
- if (count > utflen)
- throw new UTFDataFormatException();
- char2 = (int)bytearr[count - 1];
- if ((char2 & 0xC0) != 0x80)
- throw new UTFDataFormatException();
- charr[chCount] = (char)(((c & 0x1F) << 6) | (char2 & 0x3F));
- break;
- case 14:
- /* 1110 xxxx 10xx xxxx 10xx xxxx */
- count += 3;
- if (count > utflen)
- throw new UTFDataFormatException();
- char2 = (int)bytearr[count - 2];
- char3 = (int)bytearr[count - 1];
- if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
- throw new UTFDataFormatException();
- charr[chCount] = (char)
- (((c & 0x0F) << 12) |
- ((char2 & 0x3F) << 6) |
- ((char3 & 0x3F) << 0));
- break;
- default:
- /* 10xx xxxx, 1111 xxxx */
- throw new UTFDataFormatException();
- }
- chCount++;
- }
- // The number of chars produced may be less than utflen
- return new String(charr, 0, chCount);
- }
-
- protected Object readXml() throws IOException
- {
- String xml = readLongUTF();
-
- if (isDebug)
- trace.write(xml);
-
- return stringToDocument(xml);
- }
-
-
- /**
- * Remember a deserialized object so that you can use it later through a reference.
- */
- protected int rememberObject(Object obj)
- {
- int id = objectsTable.size();
- objectsTable.add(obj);
- return id;
- }
-
- protected Object readObjectValueOneLevelDown(int type, boolean nestCollectionLevelDown) throws ClassNotFoundException, IOException
- {
- increaseNestObjectLevel();
- if (nestCollectionLevelDown)
- increaseNestCollectionLevel();
- Object value = readObjectValue(type);
- decreaseNestObjectLevel();
- if (nestCollectionLevelDown)
- decreaseNestCollectionLevel();
- return value;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/Amf0Output.java
----------------------------------------------------------------------
diff --git a/core/src/flex/messaging/io/amf/Amf0Output.java b/core/src/flex/messaging/io/amf/Amf0Output.java
deleted file mode 100644
index b04713a..0000000
--- a/core/src/flex/messaging/io/amf/Amf0Output.java
+++ /dev/null
@@ -1,874 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.io.amf;
-
-import flex.messaging.MessageException;
-
-import flex.messaging.io.ArrayCollection;
-import flex.messaging.io.PagedRowSet;
-import flex.messaging.io.PropertyProxy;
-import flex.messaging.io.PropertyProxyRegistry;
-import flex.messaging.io.SerializationContext;
-import flex.messaging.io.SerializationDescriptor;
-import flex.messaging.io.StatusInfoProxy;
-import flex.messaging.io.BeanProxy;
-
-import java.io.IOException;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-import javax.sql.RowSet;
-
-/**
- * An Amf0 output object.
- *
- */
-public class Amf0Output extends AbstractAmfOutput implements AmfTypes
-{
- /**
- * 3-byte marker for object end; used for faster serialization
- * than a combination of writeUTF("") and writeByte(kObjectEndType).
- *
- */
- public static final byte[] OBJECT_END_MARKER = {0, 0, kObjectEndType};
-
- /**
- * A mapping of object instances to their serialization numbers
- * for storing object references on the stream.
- *
- */
- protected IdentityHashMap serializedObjects;
-
- /**
- * Number of serialized objects.
- *
- */
- protected int serializedObjectCount = 0;
-
- /**
- * AVM+ Encoding.
- *
- */
- protected boolean avmPlus;
-
- /**
- *
- */
- protected Amf3Output avmPlusOutput;
-
- /**
- * Construct a serializer without connecting it to an output stream.
- * @param context the context to use
- */
- public Amf0Output(SerializationContext context)
- {
- super(context);
- context.supportDatesByReference = false;
-
- serializedObjects = new IdentityHashMap(64);
- }
-
- /**
- * Set to true if the AMF0 stream should switch to use AMF3 on encountering
- * the first complex Object during serialization.
- *
- * @param a Whether the client is running in AVMPlus and can handle AMF3 encoding.
- */
- public void setAvmPlus(boolean a)
- {
- avmPlus = a;
- }
-
- /**
- * Reset all object reference information allowing the class to be used to
- * write a "new" data structure.
- */
- public void reset()
- {
- super.reset();
-
- serializedObjects.clear();
- serializedObjectCount = 0;
-
- if (avmPlusOutput != null)
- avmPlusOutput.reset();
- }
-
- /**
- * Creates a new Amf3Output instance which is initialized with the
- * current SerializationContext, OutputStream and debug trace settings
- * to switch the version of the AMF protocol mid-stream.
- */
- protected void createAMF3Output()
- {
- avmPlusOutput = new Amf3Output(context);
- avmPlusOutput.setOutputStream(out);
- avmPlusOutput.setDebugTrace(trace);
- }
-
- //
- // java.io.ObjectOutput implementations
- //
-
- /**
- * Serialize an Object using AMF 0.
- */
- public void writeObject(Object o) throws IOException
- {
- if (o == null)
- {
- writeAMFNull();
- return;
- }
-
- if (o instanceof String)
- {
- writeAMFString((String)o);
- }
- else if (o instanceof Number)
- {
- if (!context.legacyBigNumbers &&
- (o instanceof BigInteger || o instanceof BigDecimal))
- {
- // Using double to write big numbers such as BigInteger or
- // BigDecimal can result in information loss so we write
- // them as String by default...
- writeAMFString((o).toString());
- }
- else
- {
- writeAMFDouble(((Number)o).doubleValue());
- }
- }
- else if (o instanceof Boolean)
- {
- writeAMFBoolean(((Boolean)o).booleanValue());
- }
- else if (o instanceof Character)
- {
- String s = o.toString();
- writeAMFString(s);
- }
- else if (o instanceof Date)
- {
- // Note that dates are not considered complex types in AMF 0
- writeAMFDate((Date)o);
- }
- else if (o instanceof Calendar)
- {
- writeAMFDate(((Calendar)o).getTime());
- }
- // If there is a proxy for this,write it as a custom object so the default
- // behavior can be overriden.
- else if (o instanceof Enum && PropertyProxyRegistry.getRegistry().getProxy(o.getClass()) == null)
- {
- Enum<?> enumValue = (Enum<?>)o;
- writeAMFString(enumValue.name());
- }
- else
- {
- // We have a complex object.
-
- // If we're using AMF 3, delegate to AVM+ encoding format
- if (avmPlus)
- {
- if (avmPlusOutput == null)
- {
- createAMF3Output();
- }
-
- out.writeByte(kAvmPlusObjectType);
- avmPlusOutput.writeObject(o);
- }
- else
- {
- Class cls = o.getClass();
-
- if (cls.isArray())
- {
- writeAMFArray(o, cls.getComponentType());
- }
- else if (o instanceof Map && context.legacyMap && !(o instanceof ASObject))
- {
- writeMapAsECMAArray((Map)o);
- }
- else if (o instanceof Collection)
- {
- if (context.legacyCollection)
- writeCollection((Collection)o, null);
- else
- writeArrayCollection((Collection)o, null);
- }
- else if (o instanceof org.w3c.dom.Document)
- {
- out.write(kXMLObjectType);
- String xml = documentToString(o);
- if (isDebug)
- trace.write(xml);
-
- writeUTF(xml, true, false);
- }
- else
- {
- // Special Case: wrap RowSet in PageableRowSet for Serialization
- if (o instanceof RowSet)
- {
- o = new PagedRowSet((RowSet)o, Integer.MAX_VALUE, false);
- }
- else if (o instanceof Throwable && context.legacyThrowable)
- {
- o = new StatusInfoProxy((Throwable)o);
- }
-
- writeCustomObject(o);
- }
- }
- }
- }
-
- /**
- *
- */
- public void writeObjectTraits(TraitsInfo traits) throws IOException
- {
- String className = null;
- if (traits != null)
- className = traits.getClassName();
-
- if (isDebug)
- trace.startAMFObject(className, serializedObjectCount - 1);
-
- if (className == null || className.length() == 0)
- {
- out.write(kObjectType);
- }
- else
- {
- out.write(kTypedObjectType);
- out.writeUTF(className);
- }
- }
-
- /**
- *
- */
- public void writeObjectProperty(String name, Object value) throws IOException
- {
- if (isDebug)
- trace.namedElement(name);
-
- out.writeUTF(name);
- increaseNestObjectLevel();
- writeObject(value);
- decreaseNestObjectLevel();
- }
-
- /**
- *
- */
- public void writeObjectEnd() throws IOException
- {
- out.write(OBJECT_END_MARKER, 0, OBJECT_END_MARKER.length);
-
- if (isDebug)
- trace.endAMFObject();
- }
-
-
- //
- // AMF SPECIFIC SERIALIZATION METHODS
- //
-
- /**
- *
- */
- protected void writeAMFBoolean(boolean b) throws IOException
- {
- if (isDebug)
- trace.write(b);
-
- out.write(kBooleanType);
-
- out.writeBoolean(b);
- }
-
- /**
- *
- */
- protected void writeAMFDouble(double d) throws IOException
- {
- if (isDebug)
- trace.write(d);
-
- out.write(kNumberType);
-
- out.writeDouble(d);
- }
-
- /**
- *
- */
- protected void writeAMFDate(Date d) throws IOException
- {
- if (isDebug)
- trace.write(d);
-
- out.write(kDateType);
- // Write the time as 64bit value in ms
- out.writeDouble((double)d.getTime());
- int nCurrentTimezoneOffset = TimeZone.getDefault().getRawOffset();
- out.writeShort(nCurrentTimezoneOffset / 60000);
- }
-
- /**
- *
- */
- protected void writeAMFArray(Object o, Class componentType) throws IOException
- {
- if (componentType.isPrimitive())
- {
- writePrimitiveArray(o);
- }
- else if (componentType.equals(Character.class))
- {
- writeCharArrayAsString((Character[])o);
- }
- else
- {
- writeObjectArray((Object[])o, null);
- }
- }
-
- /**
- *
- */
- protected void writeArrayCollection(Collection col, SerializationDescriptor desc) throws IOException
- {
- if (!serializeAsReference(col))
- {
- ArrayCollection ac;
-
- if (col instanceof ArrayCollection)
- {
- ac = (ArrayCollection)col;
- // TODO: QUESTION: Pete ignoring the descriptor here... not sure if
- // we should modify the user's AC as that could cause corruption?
- }
- else
- {
- // Wrap any Collection in an ArrayCollection
- ac = new ArrayCollection(col);
- if (desc != null)
- ac.setDescriptor(desc);
- }
-
- // Then wrap ArrayCollection in PropertyProxy for bean-like serialization
- PropertyProxy proxy = PropertyProxyRegistry.getProxy(ac);
- writePropertyProxy(proxy, ac);
- }
- }
-
- /**
- *
- */
- protected void writeCustomObject(Object o) throws IOException
- {
- PropertyProxy proxy = null;
-
- if (o instanceof PropertyProxy)
- {
- proxy = (PropertyProxy)o;
- o = proxy.getDefaultInstance();
-
- // The proxy may wrap a null default instance, if so, short circuit here.
- if (o == null)
- {
- writeAMFNull();
- return;
- }
- // HACK: Short circuit and unwrap if PropertyProxy is wrapping an Array
- // or Collection type since we don't yet have the ability to proxy multiple
- // AMF types. We write an AMF Array directly instead of an AMF Object
- else if (o instanceof Collection)
- {
- if (context.legacyCollection)
- writeCollection((Collection)o, proxy.getDescriptor());
- else
- writeArrayCollection((Collection)o, proxy.getDescriptor());
- return;
- }
- else if (o.getClass().isArray())
- {
- writeObjectArray((Object[])o, proxy.getDescriptor());
- return;
- }
- else if (context.legacyMap && o instanceof Map && !(o instanceof ASObject))
- {
- writeMapAsECMAArray((Map)o);
- return;
- }
- }
-
- if (!serializeAsReference(o))
- {
- if (proxy == null)
- {
- proxy = PropertyProxyRegistry.getProxyAndRegister(o);
- }
-
- writePropertyProxy(proxy, o);
- }
- }
-
- /**
- *
- */
- protected void writePropertyProxy(PropertyProxy pp, Object instance) throws IOException
- {
- /*
- * At this point we substitute the instance we want to serialize.
- */
- Object newInst = pp.getInstanceToSerialize(instance);
- if (newInst != instance)
- {
- // We can't use writeAMFNull here I think since we already added this object
- // to the object table on the server side. The player won't have any way
- // of knowing we have this reference mapped to null.
- if (newInst == null)
- throw new MessageException("PropertyProxy.getInstanceToSerialize class: " + pp.getClass() + " returned null for instance class: " + instance.getClass().getName());
-
- // Grab a new proxy if necessary for the new instance
- pp = PropertyProxyRegistry.getProxyAndRegister(newInst);
- instance = newInst;
- }
-
- //FIXME: Throw exception or use unsupported type for externalizable as it's not supported in AMF 0?
- boolean externalizable = false; //sp.isExternalizable(instance);
- List propertyNames = pp.getPropertyNames(instance);
- // filter write-only properties
- if (pp instanceof BeanProxy)
- {
- BeanProxy bp = (BeanProxy) pp;
- Iterator it = propertyNames.iterator();
- while (it.hasNext())
- {
- String propName = (String) it.next();
- if (bp.isWriteOnly(instance, propName))
- { // do not serialize this, as we cannot get the value
- it.remove();
- }
- }
- }
- TraitsInfo ti = new TraitsInfo(pp.getAlias(instance), pp.isDynamic(), externalizable, propertyNames);
- writeObjectTraits(ti);
-
- if (propertyNames != null)
- {
- Iterator it = propertyNames.iterator();
- while (it.hasNext())
- {
- String propName = (String)it.next();
- Object value = pp.getValue(instance, propName);
- writeObjectProperty(propName, value);
- }
- }
-
- writeObjectEnd();
- }
-
- /**
- *
- */
- protected void writeMapAsECMAArray(Map m) throws IOException
- {
- if (!serializeAsReference(m))
- {
- if (isDebug)
- trace.startECMAArray(serializedObjectCount - 1);
-
- out.write(kECMAArrayType);
- out.writeInt(0);
-
- Iterator it = m.keySet().iterator();
- while (it.hasNext())
- {
- Object key = it.next();
- Object value = m.get(key);
- writeObjectProperty(key.toString(), value);
- }
-
- writeObjectEnd();
- }
- }
-
- /**
- *
- */
- protected void writeAMFNull() throws IOException
- {
- if (isDebug)
- trace.writeNull();
-
- out.write(kNullType);
- }
-
- /**
- *
- */
- protected void writeAMFString(String str) throws IOException
- {
- if (isDebug)
- trace.writeString(str);
-
- writeUTF(str, false, true);
- }
-
- /**
- *
- */
- protected void writeObjectArray(Object[] values, SerializationDescriptor descriptor) throws IOException
- {
- if (!serializeAsReference(values))
- {
- if (isDebug)
- trace.startAMFArray(serializedObjectCount - 1);
-
- out.write(kStrictArrayType);
- out.writeInt(values.length);
- for (int i = 0; i < values.length; ++i)
- {
- if (isDebug)
- trace.arrayElement(i);
-
- Object item = values[i];
- if (item != null && descriptor != null && !(item instanceof String)
- && !(item instanceof Number) && !(item instanceof Boolean)
- && !(item instanceof Character))
- {
-
- PropertyProxy proxy = PropertyProxyRegistry.getProxy(item);
- proxy = (PropertyProxy)proxy.clone();
- proxy.setDescriptor(descriptor);
- item = proxy;
- }
- increaseNestObjectLevel();
- writeObject(item);
- decreaseNestObjectLevel();
- }
-
- if (isDebug)
- trace.endAMFArray();
- }
- }
-
- /**
- * Serialize a Collection.
- *
- * @param c Collection to be serialized as an array.
- * @throws java.io.IOException The exception can be generated by the output stream
- *
- */
- protected void writeCollection(Collection c, SerializationDescriptor descriptor) throws IOException
- {
- if (!serializeAsReference(c))
- {
- if (isDebug)
- trace.startAMFArray(serializedObjectCount - 1);
-
- out.write(kStrictArrayType);
- out.writeInt(c.size());
- Iterator it = c.iterator();
- int i = 0;
- while (it.hasNext())
- {
- if (isDebug)
- trace.arrayElement(i++);
-
- Object item = it.next();
- if (item != null && descriptor != null && !(item instanceof String)
- && !(item instanceof Number) && !(item instanceof Boolean)
- && !(item instanceof Character))
- {
- PropertyProxy proxy = PropertyProxyRegistry.getProxy(item);
- proxy = (PropertyProxy)proxy.clone();
- proxy.setDescriptor(descriptor);
- item = proxy;
- }
- increaseNestObjectLevel();
- writeObject(item);
- decreaseNestObjectLevel();
- }
-
- if (isDebug)
- trace.endAMFArray();
- }
- }
-
- /**
- * Serialize an array of primitives.
- * <p>
- * Primitives include the following:
- * boolean, char, double, float, long, int, short, byte
- * </p>
- * @param obj An array of primitives
- *
- */
- protected void writePrimitiveArray(Object obj) throws IOException
- {
- Class aType = obj.getClass().getComponentType();
-
- //Treat char[] as a String
- if (aType.equals(Character.TYPE))
- {
- char[] c = (char[])obj;
- writeCharArrayAsString(c);
- }
- else if (!serializeAsReference(obj))
- {
- if (aType.equals(Boolean.TYPE))
- {
- out.write(kStrictArrayType);
-
- boolean[] b = (boolean[])obj;
- out.writeInt(b.length);
-
- if (isDebug)
- {
- trace.startAMFArray(serializedObjectCount - 1);
-
- for (int i = 0; i < b.length; i++)
- {
- trace.arrayElement(i);
- writeAMFBoolean(b[i]);
- }
-
- trace.endAMFArray();
- }
- else
- {
- for (int i = 0; i < b.length; i++)
- {
- writeAMFBoolean(b[i]);
- }
- }
- }
- else
- {
- //We have a primitive number, either a double, float, long, int, short or byte.
- //We write all of these as doubles...
- out.write(kStrictArrayType);
-
- int length = Array.getLength(obj);
- out.writeInt(length);
-
- if (isDebug)
- {
- trace.startAMFArray(serializedObjectCount - 1);
-
- for (int i = 0; i < length; i++)
- {
- trace.arrayElement(i);
- double v = Array.getDouble(obj, i);
- writeAMFDouble(v);
- }
-
- trace.endAMFArray();
- }
- else
- {
- for (int i = 0; i < length; i++)
- {
- double v = Array.getDouble(obj, i);
- writeAMFDouble(v);
- }
- }
- }
- }
- }
-
- /**
- *
- */
- protected void writeCharArrayAsString(Character[] ca) throws IOException
- {
- int length = ca.length;
- char[] chars = new char[length];
-
- for (int i = 0; i < length; i++)
- {
- Character c = ca[i];
- if (c == null)
- chars[i] = 0;
- else
- chars[i] = ca[i].charValue();
- }
- writeCharArrayAsString(chars);
- }
-
- /**
- *
- */
- protected void writeCharArrayAsString(char[] ca) throws IOException
- {
- writeAMFString(new String(ca));
- }
-
- /**
- *
- */
- protected void writeUTF(String str, boolean forceLong, boolean writeType) throws IOException
- {
- int strlen = str.length();
- int utflen = 0;
- int c, count = 0;
-
- char[] charr = getTempCharArray(strlen);
- str.getChars(0, strlen, charr, 0);
-
- for (int i = 0; i < strlen; i++)
- {
- c = charr[i];
- if (c <= 0x007F)
- {
- utflen++;
- }
- else if (c > 0x07FF)
- {
- utflen += 3;
- }
- else
- {
- utflen += 2;
- }
- }
-
- int type;
- if (forceLong)
- {
- type = kLongStringType;
- }
- else
- {
- if (utflen <= 65535)
- type = kStringType;
- else
- type = kLongStringType;
- }
-
- byte[] bytearr;
- if (writeType)
- {
- bytearr = getTempByteArray(utflen + (type == kStringType ? 3 : 5));
- bytearr[count++] = (byte)(type);
- }
- else
- bytearr = getTempByteArray(utflen + (type == kStringType ? 2 : 4));
-
- if (type == kLongStringType)
- {
- bytearr[count++] = (byte)((utflen >>> 24) & 0xFF);
- bytearr[count++] = (byte)((utflen >>> 16) & 0xFF);
- }
- bytearr[count++] = (byte)((utflen >>> 8) & 0xFF);
- bytearr[count++] = (byte)((utflen) & 0xFF);
- for (int i = 0; i < strlen; i++)
- {
- c = charr[i];
- if (c <= 0x007F)
- {
- bytearr[count++] = (byte)c;
- }
- else if (c > 0x07FF)
- {
- bytearr[count++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
- bytearr[count++] = (byte)(0x80 | ((c >> 6) & 0x3F));
- bytearr[count++] = (byte)(0x80 | ((c) & 0x3F));
- }
- else
- {
- bytearr[count++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
- bytearr[count++] = (byte)(0x80 | ((c) & 0x3F));
- }
- }
- out.write(bytearr, 0, count);
- }
-
- /**
- * Remember the object's serialization number so that it can be referred to
- * as a reference later. Only complex ojects should be stored as references.
- *
- *
- */
- protected void rememberObjectReference(Object obj)
- {
- serializedObjects.put(obj, new Integer(serializedObjectCount++));
- }
-
- /**
- * Attempts to serialize the object as a reference.
- * If the object cannot be serialized as a reference, it is stored
- * in the reference collection for potential future encounter.
- *
- * @return Success/failure indicator as to whether the object could be
- * serialized as a reference.
- *
- */
- protected boolean serializeAsReference(Object obj) throws IOException
- {
- Object ref = serializedObjects.get(obj);
- if (ref != null)
- {
- try
- {
- int refNum = ((Integer)ref).intValue();
- out.write(kReferenceType);
- out.writeShort(refNum);
-
- if (isDebug)
- trace.writeRef(refNum);
- }
- catch (ClassCastException e)
- {
- throw new IOException("Object reference value is not an Integer");
- }
- }
- else
- {
- rememberObjectReference(obj);
- }
- return (ref != null);
- }
-
- /**
- protected void writeUnsupported() throws IOException
- {
- if (isDebug)
- trace.write("UNSUPPORTED");
-
- out.write(kUnsupportedType);
- }
- */
-}