2013-07-25 74 views
0

我嘗試解碼CDR文件以將其轉換爲XMLAsn.1開發工具,使用Java將CDR轉換爲XML

我已經在我的PC上安裝了Java編譯器。 我用這個鏈接http://www.asnlab.org/asndt/overview.html

我試圖解碼我的CDR文件,但它不能正常工作。

它顯示正確的前19個記錄,然後它給了我錯誤,我嘗試了2個不同的CDR文件。而且他們都只顯示了19條記錄。

一號文件給了我這個錯誤:

Record 20 org.asnlab.asndt.runtime.error.AsnRuntimeException: Can not invoke method 'valueOf()' 794995 at org.asnlab.asndt.runtime.conv.ReflectionEnumeratedConverter.toObject(ed:40) at org.asnlab.asndt.runtime.type.EnumeratedType.I(mc:126) at org.asnlab.asndt.runtime.type.ImplicitType.I(xc:152) at org.asnlab.asndt.runtime.type.SetType.I(gb:191) at org.asnlab.asndt.runtime.type.SetType.I(gb:158) at org.asnlab.asndt.runtime.type.ImplicitType.I(xc:152) at org.asnlab.asndt.runtime.type.ChoiceType.I(hc:183) at org.asnlab.asndt.runtime.type.SequenceType.I(xb:221) at org.asnlab.asndt.runtime.type.SequenceType.I(xb:46) at org.asnlab.asndt.runtime.type.ImplicitType.I(xc:152) at org.asnlab.asndt.runtime.type.AsnType.I(bb:354) at org.asnlab.asndt.runtime.type.ByteBuffer.decode(fc:18) at org.asnlab.asndt.runtime.type.AsnType.decode(bb:338) at Test.main(Test.java:20)

和2檔給了我這個錯誤:

Record 20 org.asnlab.asndt.runtime.error.InvalidTagException 229505 at org.asnlab.asndt.runtime.type.AsnType.I(bb:369) at org.asnlab.asndt.runtime.type.ByteBuffer.decode(fc:18) at org.asnlab.asndt.runtime.type.AsnType.decode(bb:338) at Test.main(Test.java:20)

我不明白是它的問題,我ASN.1定義或沒有?

回答

0

對於您正在使用的ASN.1工具的供應商,最好問這個問題。另一種可能性是嘗試其他ASN.1工具,例如ITU-T ASN.1項目頁面(http://www.itu.int/ITU-T/asn1/links/index.htm)中列出的工具之一。還有免費的在線ASN.1編譯器和編碼器/解碼器,您可以試試http://asn1-playground.oss.com。這個免費的在線工具可以給你一個你的CDR的詳細分析,讓你知道什麼是錯的。

0

CDR文件不完全是ASN.1編碼格式,記錄之間有空格(ASCII 32)。一種解決方法是檢測和每次記錄解碼過濾掉這些空間,喜歡這裏的代碼示例:

 
     byte[] content = FileUtils.readFileToByteArray(new File("CDR1")); 
     ByteBuffer buffer = (ByteBuffer) Buffer.wrap(content, EncodingRules.BASIC_ENCODING_RULES); 

     CDMACallDataRecords records = new CDMACallDataRecords(); 
     try { 
      while (buffer.hasRemaining()) { 
       CDMACallDataRecord ccdr = (CDMACallDataRecord) CDMACallDataRecord.TYPE.decode(buffer, CDMACallDataRecord.CONVERTER); 
       records.records.add(ccdr); 

       if (buffer.hasRemaining()) { 
        byte b = buffer.getByte(); 
        while (b == 32 && buffer.hasRemaining()) { 
         b = buffer.getByte(); 
        } 
        if (b != 32) { 
         buffer.position(buffer.position() - 1); 
        } 
       } 

      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
      System.out.println(buffer.remaining()); 
     } 

此誤差沒有指定ASN.1編碼,所以它是不相關的ASN.1工具。

+0

謝謝你,對。 – Ryainad