Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright 2012-04-26 Werner Randelshofer
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.monte.media.binary
Class StructParser

    java.lang.Object
      org.monte.media.binary.StructParser

    public class StructParser

extends java.lang.Object

Parses structured binary data using C-like data declarations. Syntax:

     Declarations ::= { MagicDeclaration | DescriptionDeclaration | EnumDeclaration | SetDeclaration | TypedefDeclaration } EOF
     MagicDeclaration ::= "magic" identifier ("ushort" hexLiteral[".." hexLiteral] | stringLiteral) ";"
     DescriptionDeclaration ::= "description" identifier stringLiteral "," stringLiteral ";"
     EnumDeclaration ::= EnumSpecifier identifier ";"
     SetDeclaration ::= SetSpecifier identifier ";"
     TypedefDeclaration ::= "typedef" TypeSpecifier identifier ";"
     EnumSpecifier ::= "enum" ( identifier | "{" identifier ["=" magicOrIntLiteral] {"," identifier ["=" intLiteral]} "}" )
     SetSpecifier ::= "set" ( identifier | "{" identifier "=" intLiteral {"," identifier "=" intLiteral} "}" )
     TypeSpecifier ::= ( StructSpecifier | (PrimitiveSpecifier [EnumSpecifier | SetSpecifier]) ) [ArrayList]
     StructSpecifier ::= "struct (identifier | "{" MemberDeclaration {"," MemberDeclaration } "}" )
     MemberDeclaration ::= TypeSpecifier identifier [ArrayList] ";"
     PrimitiveSpecifier ::= "uint1" | "uint2" | "uint4" | "uint5" | "uint8" | "uint12" | "uint16" | "uint32"
                             | "int9" | "int16" | "int32"
                             | "ubyte" | "byte" | "short"
                             | "ushort" | "int" | "long" | "float" | "double"
                             | "extended"
                             | "char" | "charbyte" | "cstring" | "utf8" | "pstring"
                             | "pstring32"
                             | "utf16le" | "magic" | "mactimestamp" | "bcd2"
                             | "bcd4"
                             | "fixed16d16" | "fixed2d30" | "fixed8d8"
                             | "ataricolor"
     ArrayList ::= "[" [ArraySize] "]" {"," identifier "[" [ArraySize] "]" }
     ArraySize ::= () | intLiteral [("-"|"+"|"=="|"!=") intLiteral]

Version:
  2.7.3 2011-08-16 Fixes class comments.
  2.7.2 2011-01-12 Adds int32, int16.
  2.7.1 2011-01-04 Fixes reading of pstring32.
  2.7 2011-01-03 Adds uint5 and int9. Uses ImageInputStream for reading data bitwise. Adds support for equality- and inequality-checks in array indizes. Adds support for string literals in enum-names.
  2.6 2010-12-31 Return UBYTE as byte array because it can be displayed better in the table.
  2.5 2010-12-28 Adds uint1, uint2.
  2.4.2 2010-10-02 Fixes Mactimestamp.
  2.4.1 2010-04-02 Added pstring32.
  2.4 2009-12-26 Added utf16le String.
  2.3.1 2009-11-19 MagicOrInt accepts now negative integers as well.
  2.3 2008-10-13 Added special treatment for ubyte- and charbyte-arrays. Added support for uint4.
  2.2 2008-06-15 Added support for fixed decimal numbers.
  2.1.1 2007-12-11 Don't fail when there are not enough bytes available to fully read a pstring.
  2.1 2007-12-08 Added support for BCD numbers.
  2.0 2006-12-29 Added support for short magics, character bytes and improved presentation of struct arrays.
  1.4 2006-07-20 Reworked for Java 1.5.
  1.3 2005-01-09 Support for little-endian data types added. Support for magic enumerations added.
  1.2.1 2003-04-01 Revised.
  1.2 2000-10-04 Support for set's added.
  1.1 2000-10-03 Support for enm's added.
  1.0 2000-06-11
Author:
  Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Swityerland

Nested Class Summary
`protected static class` | `StructParser.ArraySize` ArraySize expression.
`protected static class` | `StructParser.Declarations` Declarations expression.
`protected static class` | `StructParser.DescriptionDeclaration` DescriptionDeclaration expression.
`protected static class` | `StructParser.EnumDeclaration` EnumDeclaration expression.
`protected static class` | `StructParser.EnumSpecifier` EnumSpecifier expression.
`protected static class` | `StructParser.IntLiteral` IntLiteral expression.
`protected static class` | `StructParser.MagicDeclaration` MagicDeclaration expression.
`protected static class` | `StructParser.MagicOrIntLiteral` MagicOrIntLiteral expression.
`protected static class` | `StructParser.MemberDeclaration` MemberDeclaration expression.
`protected static class` | `StructParser.PrimitiveSpecifier` PrimitiveSpecifier expression.
`protected static class` | `StructParser.SetDeclaration` SetDeclaration expression.
`protected static class` | `StructParser.SetSpecifier` SetSpecifier expression.
`protected static class` | `StructParser.StructSpecifier` StructSpecifier expression.
`protected static class` | `StructParser.TypedefDeclaration` TypedefDeclaration expression.
`protected static class` | `StructParser.TypeSpecifier` TypeSpecifier expression.

Field Summary
`protected static long` | `MAC_TIMESTAMP_EPOCH`

Constructor Summary
`StructParser()`
`StructParser(java.io.Reader r)`

Method Summary
`java.lang.String` | `getDescription(java.lang.Object magic)`
`java.lang.String` | `getDescription(java.lang.String magic)`
`java.lang.String` | `getIdentifierName(java.lang.String magic)`
`java.lang.String` | `getName(java.lang.Object magic)`
`java.lang.String` | `getName(java.lang.String magic)`
`boolean` | `isMagicDeclared(java.lang.Object magic)`
`boolean` | `isMagicDeclared(java.lang.String magic)`
`boolean` | `isTypeDeclared(java.lang.Object magic)`
`boolean` | `isTypeDeclared(java.lang.String magic)`
`protected void` | `parse(java.io.Reader r)`
`StructTableModel` | `readStruct(int magic, byte[] data)`
`StructTableModel` | `readStruct(int magic, java.io.InputStream data)`
`StructTableModel` | `readStruct(java.lang.String magic, byte[] data)`
`StructTableModel` | `readStruct(java.lang.String magic, java.io.InputStream data)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MAC_TIMESTAMP_EPOCH

    protected static final long MAC_TIMESTAMP_EPOCH

Constructor Detail

### StructParser

    public StructParser()

### StructParser

    public StructParser(java.io.Reader r)
                 throws java.io.IOException,
                        ParseException

Throws:
  `java.io.IOException`
  `ParseException`

Method Detail

### getName

    public java.lang.String getName(java.lang.String magic)

### getName

    public java.lang.String getName(java.lang.Object magic)

### getIdentifierName

    public java.lang.String getIdentifierName(java.lang.String magic)

### isMagicDeclared

    public boolean isMagicDeclared(java.lang.String magic)

### isMagicDeclared

    public boolean isMagicDeclared(java.lang.Object magic)

### isTypeDeclared

    public boolean isTypeDeclared(java.lang.String magic)

### isTypeDeclared

    public boolean isTypeDeclared(java.lang.Object magic)

### getDescription

    public java.lang.String getDescription(java.lang.String magic)

### getDescription

    public java.lang.String getDescription(java.lang.Object magic)

### readStruct

    public StructTableModel readStruct(java.lang.String magic,
                                       byte[] data)
                                throws java.io.IOException

  Throws:
    `java.io.IOException`

### readStruct

    public StructTableModel readStruct(int magic,
                                       byte[] data)
                                throws java.io.IOException

  Throws:
    `java.io.IOException`

### readStruct

    public StructTableModel readStruct(java.lang.String magic,
                                       java.io.InputStream data)
                                throws java.io.IOException

  Throws:
    `java.io.IOException`

### readStruct

    public StructTableModel readStruct(int magic,
                                       java.io.InputStream data)
                                throws java.io.IOException

  Throws:
    `java.io.IOException`

### parse

    protected void parse(java.io.Reader r)
                  throws java.io.IOException,
                         ParseException

  Throws:
    `java.io.IOException`
    `ParseException`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright 2012-04-26 Werner Randelshofer
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD