protected void writePrimitiveArray()

in core/src/main/java/flex/messaging/io/amf/Amf3Output.java [750:841]


    protected void writePrimitiveArray(Object obj) throws IOException {
        Class aType = obj.getClass().getComponentType();

        if (aType.equals(Character.TYPE)) {
            //Treat char[] as a String
            char[] c = (char[]) obj;
            writeCharArrayAsString(c);
        } else if (aType.equals(Byte.TYPE)) {
            writeAMFByteArray((byte[]) obj);
        } else {
            out.write(kArrayType);

            if (!byReference(obj)) {
                if (aType.equals(Boolean.TYPE)) {
                    boolean[] b = (boolean[]) obj;

                    // Write out an invalid reference, storing the length in the unused 28-bits.
                    writeUInt29((b.length << 1) | 1);

                    // Send an empty string to imply no named keys
                    writeStringWithoutType(EMPTY_STRING);

                    if (isDebug) {
                        trace.startAMFArray(getObjectTableSize());

                        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 if (aType.equals(Integer.TYPE) || aType.equals(Short.TYPE)) {
                    //We have a primitive number, either an int or short
                    //We write all of these as Integers...
                    int length = Array.getLength(obj);

                    // Write out an invalid reference, storing the length in the unused 28-bits.
                    writeUInt29((length << 1) | 1);
                    // Send an empty string to imply no named keys
                    writeStringWithoutType(EMPTY_STRING);

                    if (isDebug) {
                        trace.startAMFArray(getObjectTableSize());

                        for (int i = 0; i < length; i++) {
                            trace.arrayElement(i);
                            int v = Array.getInt(obj, i);
                            writeAMFInt(v);
                        }

                        trace.endAMFArray();
                    } else {
                        for (int i = 0; i < length; i++) {
                            int v = Array.getInt(obj, i);
                            writeAMFInt(v);
                        }
                    }
                } else {
                    //We have a primitive number, either a double, float, or long
                    //We write all of these as doubles...
                    int length = Array.getLength(obj);

                    // Write out an invalid reference, storing the length in the unused 28-bits.
                    writeUInt29((length << 1) | 1);
                    // Send an empty string to imply no named keys
                    writeStringWithoutType(EMPTY_STRING);

                    if (isDebug) {
                        trace.startAMFArray(getObjectTableSize());

                        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);
                        }
                    }
                }
            }
        }
    }