⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fspush.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        for (Iterator i = obj.values.iterator(); i.hasNext();)
        {
            Object value = i.next();
            
            if (value instanceof Boolean)
                values.add(new Boolean(((Boolean)value).booleanValue()));
            else if (value instanceof Integer)
                values.add(new Integer(((Integer)value).intValue()));
            else if (value instanceof Float)
                values.add(new Float(((Float)value).floatValue()));
            else if (value instanceof Double)
                values.add(new Double(((Double)value).doubleValue()));
            else if (value instanceof String)
                values.add(new String((String)value));
            else if (value instanceof FSProperty)
                values.add(new FSProperty((FSProperty)value));
            else if (value instanceof FSNull)
                values.add(((FSNull)value).clone());
            else if (value instanceof FSVoid)
                values.add(((FSVoid)value).clone());
            else if (value instanceof FSTableIndex)
                values.add(((FSTableIndex)value).clone());
            else if (value instanceof FSRegisterIndex)
                values.add(((FSRegisterIndex)value).clone());
        }
    }    

    /** Adds a boolean value to the array of values that will be pushed onto the stack.

        @param aBool a boolean value.
        */
    public void add(boolean aBool)
    {
        values.add(new Boolean(aBool));
    } 

    /** Adds an integer value to the array of values that will be pushed onto the stack.

        @param anInt an integer (int) value.
        */
    public void add(int anInt)
    {
        values.add(new Integer(anInt));
    } 

    /** Adds a double value to the array of values that will be pushed onto the stack.

        @param aDouble a double-precision floating-point value.
        */
    public void add(double aDouble)
    {
        values.add(new Double(aDouble));
    } 

    /** Adds a null value to the array of values that will be pushed onto the stack.

        @param nullValue a lightweight FSNull object.
        */
    public void add(FSNull nullValue)
    {
        values.add(nullValue);
    } 

    /** Adds a void value to the array of values that will be pushed onto the stack.

        @param voidValue a lightweight FSVoid object.
        */
    public void add(FSVoid voidValue)
    {
        values.add(voidValue);
    } 

    /** Adds a String to the array of values that will be pushed onto the stack.

        @param aString a String.
        */
    public void add(String aString)
    {
        values.add(aString);
    } 

    /** Adds an FSTableIndex to the array of values that will be pushed onto the stack.

        @param anIndex a FSTableIndex referencing an entry in a table of literals.
        */
    public void add(FSTableIndex anIndex)
    {
        values.add(anIndex);
    } 

    /** Adds an FSRegisterIndex to the array of values that will be pushed onto the stack.

        @param anIndex a FSRegisterIndex referencing one of the Flash Player's internal registers.
        */
    public void add(FSRegisterIndex anIndex)
    {
        values.add(anIndex);
    } 

    /** Gets the array of values.

        @return the array of values that will be pushed onto the stack.
        */
    public ArrayList getValues() { return values; }

    /** Sets the array of values.

        @param anArray replaces the existing array of value with anArray. The values in the array must be one of the following classes: Boolean, Integer, Double, String, FSNull, FSVoid, FSRegisterIndex or FSTableIndex.
        */
    public void setValues(ArrayList anArray)
    {
        values = anArray;
    }

    public Object clone()
    {
        FSPush anObject = (FSPush)super.clone();
        
        anObject.values = new ArrayList(values.size());

        for (Iterator i = values.iterator(); i.hasNext();)
        {
            Object obj = i.next();
            
            if (obj instanceof Boolean)
                anObject.values.add(new Boolean(((Boolean)obj).booleanValue()));
            else if (obj instanceof Integer)
                anObject.values.add(new Integer(((Integer)obj).intValue()));
            else if (obj instanceof Float)
                anObject.values.add(new Float(((Float)obj).floatValue()));
            else if (obj instanceof Double)
                anObject.values.add(new Double(((Double)obj).doubleValue()));
            else if (obj instanceof String)
                anObject.values.add(new String((String)obj));
            else if (obj instanceof FSProperty)
                anObject.values.add(new FSProperty((FSProperty)obj));
            else if (obj instanceof FSNull)
                anObject.values.add(((FSNull)obj).clone());
            else if (obj instanceof FSVoid)
                anObject.values.add(((FSVoid)obj).clone());
            else if (obj instanceof FSTableIndex)
                anObject.values.add(((FSTableIndex)obj).clone());
            else if (obj instanceof FSRegisterIndex)
                anObject.values.add(((FSRegisterIndex)obj).clone());
        }

        return anObject;
    }

    public boolean equals(Object anObject)
    {
        boolean result = false;
        
        if (super.equals(anObject))
            result = values.equals(((FSPush)anObject).values);
        
        return result;
    }

    public void appendDescription(StringBuffer buffer, int depth)
    {
        buffer.append(name());
        
        if (depth > 0)
        {
            buffer.append(": { ");
            Transform.append(buffer, "values", values, depth);
            buffer.append("}");
        }
    }

    public int length(FSCoder coder)
    {
        super.length(coder);
        
        for (Iterator i=values.iterator(); i.hasNext();)
        {
            Object anObject = i.next();
            
            if (anObject instanceof Boolean)
                length += 2;
            else if (anObject instanceof FSProperty)
                length += 5;
            else if (anObject instanceof Integer)
                length += 5;
            else if (anObject instanceof Double)
                length += 9;
            else if (anObject instanceof String)
                length += 1 + coder.strlen((String)anObject, true);
            else if (anObject instanceof FSNull)
                length += 1;
            else if (anObject instanceof FSVoid)
                length += 1;
            else if (anObject instanceof FSTableIndex)
            {
                if (((FSTableIndex)anObject).getIndex() < 256)
                    length += 2;
                else
                    length += 3;
            }
            else if (anObject instanceof FSRegisterIndex)
                length += 2;
        }

        return length;
    }
    
    public void encode(FSCoder coder)
    {
        super.encode(coder);

        for (Iterator i=values.iterator(); i.hasNext();)
        {
            Object anObject = i.next();
            
            if (anObject instanceof Boolean)
            {
                coder.writeWord(5, 1);
                coder.writeWord(((Boolean)anObject).booleanValue() ? 1 : 0, 1);
            }
            else if (anObject instanceof Integer)
            {
                coder.writeWord(7, 1);
                coder.writeWord(((Integer)anObject).intValue(), 4);
            }
            else if (anObject instanceof FSProperty)
            {
                coder.writeWord(1, 1);
                coder.writeWord(((FSProperty)anObject).getValue(), 4);
            }
            else if (anObject instanceof Double)
            {
                coder.writeWord(6, 1);
                coder.writeDouble(((Double)anObject).doubleValue());
            }
            else if (anObject instanceof String)
            {               
                coder.writeWord(0, 1);
                coder.writeString((String)anObject);
                coder.writeWord(0, 1);
            }
            else if (anObject instanceof FSNull)
            {
                coder.writeWord(2, 1);
            }
            else if (anObject instanceof FSVoid)
            {
                coder.writeWord(3, 1);
            }
            else if (anObject instanceof FSTableIndex)
            {
                if (((FSTableIndex)anObject).getIndex() < 256)
                {
                    coder.writeWord(8, 1);
                    coder.writeWord(((FSTableIndex)anObject).getIndex(), 1);
                }
                else
                {
                    coder.writeWord(9, 1);
                    coder.writeWord(((FSTableIndex)anObject).getIndex(), 2);
                }
            }
            else if (anObject instanceof FSRegisterIndex)
            {
                coder.writeWord(4, 1);
                coder.writeWord(((FSRegisterIndex)anObject).getIndex(), 1);
            }
        }

        coder.endObject(name());
    }
    
    public void decode(FSCoder coder)
    {
        super.decode(coder);
        
        int valuesLength = length;

        while (valuesLength > 0)
        {
            int dataType = coder.scanWord(1, false);
            
            coder.adjustPointer(8);
            
            switch (dataType)
            {
                case 0:
                    int start = coder.getPointer();
                    int strlen = 0;
                    
                    for (strlen=0; coder.scanWord(1, false) != 0; coder.adjustPointer(8), strlen++);
                    
                    coder.setPointer(start);
                    values.add(coder.readString(strlen));
                    coder.adjustPointer(8);
                    valuesLength -= strlen + 2;
                    break;
                case 1: // Pre version 5 property
                    int propertyValue = coder.readWord(4, false);
                    values.add(new FSProperty(propertyValue));
                    valuesLength -= 5;
                    break;
                case 2:
                    values.add(FSNull.getInstance());
                    valuesLength -= 1;
                    break;
                case 3:
                    values.add(FSVoid.getInstance());
                    valuesLength -= 1;
                    break;
                case 4:
                    int registerIndex = coder.readWord(1, false);
                    values.add(new FSRegisterIndex(registerIndex));
                    valuesLength -= 2;
                    break;
                case 5:
                    boolean boolValue = coder.readWord(1, false) != 0 ? true : false;
                    values.add(new Boolean(boolValue));
                    valuesLength -= 2;
                    break;
                case 6:
                    double doubleValue = coder.readDouble();
                    values.add(new Double(doubleValue));
                    valuesLength -= 9;
                    break;
                case 7:
                    int intValue = coder.readWord(4, false);
                    values.add(new Integer(intValue));
                    valuesLength -= 5;
                    break;
                case 8:
                case 9:
                    int tableIndex = coder.readWord(dataType == 8 ? 1 : 2, false);
                    values.add(new FSTableIndex(tableIndex));
                    valuesLength -= (dataType == 8) ? 2 : 3;
                    break;
            }
        }

        coder.endObject(name());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -