3
我想在java中使用flex.messaging.io.amf.Amf3Input反序列化amf二進制格式。但沒有找到反序列化的流程。可以通過提供步驟或代碼片段來幫助我嗎? 我試圖用波紋管代碼.....但readObject()返回空......請幫助。在java中使用amf3input反序列化amf二進制格式
package amfnew;
import java.net.ServerSocket;
import java.net.Socket;
import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.Amf3Input;
import flex.messaging.io.amf.Amf3Output;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class MainAmf {
byte[] read(String aInputFileName){
File file = new File(aInputFileName);
byte[] result = new byte[(int)file.length()];
try {
InputStream input = null;
try {
int totalBytesRead = 0;
input = new BufferedInputStream(new FileInputStream(file));
while(totalBytesRead < result.length){
int bytesRemaining = result.length - totalBytesRead;
int bytesRead = input.read(result, totalBytesRead, bytesRemaining);
if (bytesRead > 0){
totalBytesRead = totalBytesRead + bytesRead;
}
}
}
finally {
input.close();
}
}
catch (FileNotFoundException ex) {
}
catch (IOException ex) {
}
return result;
}
public static void main(String[] args) throws FileNotFoundException {
MainAmf ma= new MainAmf();
byte[] amfBytes;
amfBytes = ma.read("C:\\JavaApp\\AmfNew\\sample.amf");
InputStream bais = new ByteArrayInputStream(amfBytes);
Amf3Input amf3Input = new Amf3Input(SerializationContext.getSerializationContext());
amf3Input.setInputStream(bais);
while(true)
{
try
{
Object obj = amf3Input.readObject();
System.out.println("Reading..");
System.out.println(obj);
if(obj!=null)
{
System.out.println(obj.getClass());
}
}
catch (Exception e)
{
e.printStackTrace();
break;
}
}
}
}