Are there any Java Frameworks for binary file parsing?

后端 未结 8 1364
情话喂你
情话喂你 2020-12-08 05:19

My problem is, that I want to parse binary files of different types with a generic parser which is implemented in JAVA. Maybe describing the file format with a configuration

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 05:56

    Using Preon:

    public class File {
    
      @BoundString(match="MAGIC")
      private String header;
    
      @BoundList(size="10", type=Body.class)
      private List body;
    
      private static class Body {
    
        @Bound
        byte value1;
    
        @Bound
        long value2;
    
        @BoundString(size="10")
        String value3;
    
      }
    
    
    }
    

    Decoding data:

    Codec codec = Codecs.create(File.class);
    File file = codecs.decode(codec, buffer);
    

    Let me know if you are running into problems.

提交回复
热议问题