Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将其转换为java_Java_Actionscript 3 - Fatal编程技术网

将其转换为java

将其转换为java,java,actionscript-3,Java,Actionscript 3,我正在尝试将此ase文件编码器从actionscript 3转换为java: const FILE_SIGNATURE : String = "ASEF"; function encode ( pixels : Array ):ByteArray { var swatch : ByteArray = new ByteArray(); var ase : ByteArray = new ByteArray(); var hex:String; var pix:ui

我正在尝试将此ase文件编码器从actionscript 3转换为java:

const FILE_SIGNATURE : String = "ASEF";

function encode ( pixels : Array ):ByteArray
{
    var swatch : ByteArray = new ByteArray();
    var ase : ByteArray = new ByteArray();
    var hex:String;
    var pix:uint;

    ase.writeUTFBytes (FILE_SIGNATURE);// header
    ase.writeInt (0x10000);// version
    ase.writeInt (pixels.length * 2);// blocks

    for (var i : int = 0; i < pixels.length; ++i)
    {
        pix = pixels[i];
        swatch.length = 0;

        // start of group

        ase.writeShort (0xC001);
        ase.writeInt (0);
        ase.writeShort (1);

        // swatch name

        hex = pix.toString(16);
        while (hex.length < 6) hex = "0" + hex;

        swatch.writeShort ((hex = "#" + hex).length + 1);
        for (var n : int = 0; n < hex.length; ++n) swatch.writeShort (hex.charCodeAt(n));
        swatch.writeShort (0);

        // colours

        swatch.writeUTFBytes ("RGB ");
        swatch.writeFloat ((pix >> 16 & 0xFF) / 255);
        swatch.writeFloat ((pix >> 8 & 0xFF) / 255);
        swatch.writeFloat ((pix & 0xFF) / 255);
        swatch.writeShort (2);

        // write swatch

        ase.writeInt (swatch.length);
        ase.writeBytes (swatch);
    }

    return ase;
}
const FILE\u签名:String=“ASEF”;
函数编码(像素:数组):ByteArray
{
变量样例:ByteArray=newbytearray();
变量ase:ByteArray=newbytearray();
var十六进制:字符串;
var-pix:uint;
ase.writeUTFBytes(文件_签名);//头
ase.writeInt(0x10000);//版本
ase.writeInt(pixels.length*2);//块
对于(变量i:int=0;i>16&0xFF)/255);
swatch.writeFloat((pix>>8&0xFF)/255);
swatch.writeFloat((pix&0xFF)/255);
swatch.writeShort(2);
//写样本
ase.writeInt(样本长度);
ase.writeBytes(样本);
}
返回ase;
}
这是我提出的,但似乎不起作用:

public void Encoder(int[] pixels, File output) throws IOException {
        String FILE_SIGNATURE = "ASEF";
        DataOutputStream ase = new DataOutputStream(new FileOutputStream(output));
        DataOutputStream swatch = new DataOutputStream(ase);
        String hex;
        int pix;

        ase.writeUTF(FILE_SIGNATURE);
        ase.writeInt (0x10000);// version
        ase.writeInt (pixels.length * 2);// blocks

        for (int i = 0; i < pixels.length; ++i)
        {
            pix = pixels[i];

            // start of group
            ase.writeShort (0xC001);
            ase.writeInt (0);
            ase.writeShort (1);

            // swatch name
            hex = Integer.toHexString(pix);


            while (hex.length() < 6) hex = "0" + hex;

            swatch.writeShort ((hex = "#" + hex).length() + 1);
            for (int n = 0; n < hex.length(); ++n) swatch.writeShort (hex.charAt(n));
            swatch.writeShort (0);

            // colours
            swatch.writeUTF("RGB ");
            swatch.writeFloat ((pix >> 16 & 0xFF) / 255);
            swatch.writeFloat ((pix >> 8 & 0xFF) / 255);
            swatch.writeFloat ((pix & 0xFF) / 255);
            swatch.writeShort (2);

            // write swatch
            ase.writeInt (swatch.size());
            ase.writeBytes (swatch.toString());
        }

    }
public void编码器(int[]像素,文件输出)引发IOException{
字符串文件\u SIGNATURE=“ASEF”;
DataOutputStream ase=newDataOutputStream(newFileOutputStream(output));
DataOutputStream样例=新DataOutputStream(ase);
字符串十六进制;
int-pix;
ase.writeUTF(文件签名);
ase.writeInt(0x10000);//版本
ase.writeInt(pixels.length*2);//块
用于(int i=0;i>16&0xFF)/255);
swatch.writeFloat((pix>>8&0xFF)/255);
swatch.writeFloat((pix&0xFF)/255);
swatch.writeShort(2);
//写样本
ase.writeInt(swatch.size());
ase.writeBytes(swatch.toString());
}
}
我认为问题在于最后一行
ase.writeBytes(swatch.toString()),因为输出包含“java.io”。DataOutputStream@...“而不是outputstream拥有的数据


我是否必须使用与DataOutputStream不同的方法,或者我只是在某个地方出错了?请提供帮助。

“它不工作”,除了来源之外没有其他信息,在这个网站上提出了一个糟糕的问题。告诉我们你做过什么,指出什么让你困惑,至少告诉我们什么不起作用。这个网站在特定的技术问题上做得非常出色,而在要求别人为你调试某些东西的情况下就更是如此了。@arcy我解释了编辑中的问题所在。你认为
swatch.toString()
有什么作用?你为什么这么认为?@SotiriosDelimanolis我试着转换
ase.writeBytes(swatch)
。想法是编写样本的内容,我建议阅读javadoc,仔细查看
DataOutputStream样本=new DataOutputStream(ase)以及它与
var样例:ByteArray=newbytearray()的比较