2013-08-31 1 views
3

Java에서 flex.messaging.io.amf.Amf3Input을 사용하여 amf 바이너리 형식을 deserialize하려고합니다. 그러나 deserialization의 흐름을 찾지 못했습니다. 단계 또는 코드 스 니펫을 제공하여 어떤 도움을받을 수 있습니까? 나는 꼬리표로 ..... 시도했지만 readObject() null을 반환합니다 ...... 도와주세요.자바에서 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; 
     } 
    } 

} 

} 

답변

0

나는 직장을 구할 수있었습니다. AmfDeserializer가 있습니다 :

import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 

import org.apache.commons.lang.builder.ToStringBuilder; 
import org.apache.commons.lang.builder.ToStringStyle; 

import flex.messaging.io.SerializationContext; 
import flex.messaging.io.amf.Amf3Input; 
import flex.messaging.messages.AcknowledgeMessage; 

public class AmfDeserializer 
{ 

    /** 
    * @param args 
    * @throws IOException 
    * @throws ClassNotFoundException 
    */ 
    public static void main(String[] args) throws ClassNotFoundException, IOException 
    { 
     if(null == args || args.length != 1) 
     { 
     usage(); 
     System.exit(1); 
     } 

     File f = new File(args[0]); 
     if(f.exists() && f.canRead()) 
     { 
     Amf3Input deserializer = new Amf3Input( SerializationContext.getSerializationContext()); 
     deserializer.setInputStream(new FileInputStream(f)); 
     Object o = deserializer.readObject(); 

     if(o instanceof AcknowledgeMessage) 
    { 
      AcknowledgeMessage ack = (AcknowledgeMessage)o; 
      System.out.println(ack.getCorrelationId()); 
      System.out.println(ack.getClientId()); 
      Object myObj = ack.getBody(); 
      System.out.println(ToStringBuilder.reflectionToString(myObj, ToStringStyle.SHORT_PREFIX_STYLE)); 
     } 
     } 
    } 

    private static void usage() 
    { 
     System.out.println("args: absolute path to the .amf file"); 
    } 
} 
관련 문제