Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.metacosm.bin2xml
Class Bin2XML  view Bin2XML download Bin2XML.java

java.lang.Object
  extended byorg.metacosm.bin2xml.Bin2XML
All Implemented Interfaces:
java.io.ObjectStreamConstants

public class Bin2XML
extends java.lang.Object
implements java.io.ObjectStreamConstants

Converts a binary serialized file into XML.
There is no support for Block Data mode of serialization. There is no exhaustive tests on binary format: it is supposed to be correct. No support for JDK 1.3 modifications


Nested Class Summary
(package private)  class Bin2XML.Pair
           
(package private)  class Bin2XML.ReturnedClassDescription
           
 
Field Summary
private static java.lang.String ARRAY_TAG
          Tag for arrays
private static int baseWireHandle
          Value for base reference (= reference 0) (defined by Sun)
private static java.lang.String BOOLEAN_TAG
          Tag for booleans
private static java.lang.String BYTE_TAG
          Tag for bytes
private static java.lang.String CHAR_TAG
          Tag for chars
private static java.lang.String CLASS_PARAM
          Parameter name for items class name for an array
private static java.lang.String CLASSDESC_TAG
          Tag for class descriptions
private static java.lang.String DEFAULT_OUTPUTS
          Default outputs for DTD and XML streams
private static java.lang.String DOUBLE_TAG
          Tag for doubles
private static java.lang.String DTD_EXTENSION
          DTD extension
private static java.lang.String FLOAT_TAG
          Tag for floats
private  java.util.HashMap hash
          Link class names and references
private static java.lang.String INT_TAG
          Tag for ints
private static java.lang.String LONG_TAG
          Tag for longs
private  java.io.DataInputStream m_dis
          Input stream for serialized binary
private  java.io.PrintStream m_dtd
          Output stream for DTD
private  java.io.PrintStream m_xml
          Output stream for XML
private static java.lang.String MAGIC_TAG
          Tag for magic number
private static java.lang.String NAME_PARAM
          Parameter name for class name
private static java.lang.String NAME_TAG
          Tag for name
private static java.lang.String NULL_OPTAG
          One part tag for null
private static java.lang.String OBJECT_TAG
          Tag for objects
private  java.util.ArrayList ref
          ArrayList containing references on objects and class descriptions
private static java.lang.String REF_PARAM
          Parameter name for references
private static byte SC_BLOCK_DATA
          Bit mask for classes implementing block data mode serialization (defined by Sun)
private static byte SC_EXTERNALIZABLE
          Bit mask for classes externalizable (defined by Sun)
private static byte SC_SERIALIZABLE
          Bit mask for classes serializable (defined by Sun)
private static java.lang.String SC_TAG
          Tag for Stream Class bit flags
private static byte SC_WRITE_METHOD
          Bit mask for classes implementing writeObject() serialization (defined by Sun)
private static java.lang.String SHORT_TAG
          Tag for shorts
private static java.lang.String SIG_TAG
          Tag for class SHA signature
private static short STREAM_MAGIC
          Identifier for serialized binary (defined by Sun)
private static short STREAM_VERSION
          Stream version (defined by Sun)
private static java.lang.String STRING_TAG
          Tag for Strings
private static byte TC_ARRAY
          Code for new array (defined by Sun)
private static byte TC_BASE
          First tag value (defined by Sun)
private static byte TC_BLOCKDATA
          Code for block data (defined by Sun) UNUSED BY Bin2XML
private static byte TC_BLOCKDATALONG
          Code for block data long mode (defined by Sun) UNUSED BY Bin2XML
private static byte TC_CLASS
          Code for class (defined by Sun)
UNUSED BY Bin2XML
private static byte TC_CLASSDESC
          Code for new class description (defined by Sun)
private static byte TC_ENDBLOCKDATA
          Code for end of block (defined by Sun)
private static byte TC_EXCEPTION
          Code for exception (defined by Sun) UNUSED BY Bin2XML
private static byte TC_MAX
          Last tag value (defined by Sun) UNUSED BY Bin2XML
private static byte TC_NULL
          Code for null (defined by Sun)
private static byte TC_OBJECT
          Code for new object (defined by Sun)
private static byte TC_REFERENCE
          Code for reference (defined by Sun)
private static byte TC_RESET
          Code for reset stream context (defined by Sun) UNUSED BY Bin2XML
private static byte TC_STRING
          Code for new String (defined by Sun)
private static java.lang.String TOP_TAG
          Top level tag
private static java.lang.String VERSION_TAG
          Tag for serialization version number
private static java.lang.String XML_EXTENSION
          XML extension
 
Fields inherited from interface java.io.ObjectStreamConstants
PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_LONGSTRING, TC_PROXYCLASSDESC
 
Constructor Summary
Bin2XML(java.lang.String fileName, java.io.PrintStream ps_dtd, java.io.PrintStream ps_xml)
          Exits in file not found.
 
Method Summary
private static java.lang.String ctag(java.lang.String tagname)
           
(package private)  void debug()
          Debug method which prints references list
private static java.lang.String encoding()
          FIXME
static void main(java.lang.String[] argv)
          Does the translation from binary to XML.
Takes from one to three arguments:
First argument = binary filename Optional second argument = DTD output filename Optional third argument = XML output filename Default output filenames are input_filename.dtd and input_filename.xml.
private static java.lang.String optag(java.lang.String tagname)
           
private static java.lang.String optag(java.lang.String tagname, java.lang.String parName, java.lang.String parValue)
           
private static java.lang.String optag(java.lang.String tagname, java.lang.String parName1, java.lang.String parValue1, java.lang.String parName2, java.lang.String parValue2)
           
private static java.lang.String otag(java.lang.String tagname)
           
private static java.lang.String param(java.lang.String name, java.lang.String value)
           
(package private)  void readArray()
          Reads an array.
(package private)  void readBoolean()
          Reads and outputs a boolean.
(package private)  void readByte()
          Reads and outputs a byte.
(package private)  void readChar()
          Reads and outputs a char.
(package private)  Bin2XML.ReturnedClassDescription readClassDescription(boolean isArray)
          Reads a class description.
(package private)  ClassDescription readClassReference(byte refType)
           
(package private)  void readDouble()
          Reads and outputs a double.
(package private)  void readFieldDescription(ClassDescription classDesc)
          Reads a field description.
(package private)  void readFloat()
          Reads and outputs a float.
(package private)  void readHeader()
          Reads the header of serialization format.
(package private)  void readInt()
          Reads and outputs an int.
(package private)  void readLong()
          Reads and outputs a long.
(package private)  void readObject()
          Reads an object.
(package private)  Bin2XML.Pair readObjectReference(byte refType)
           
(package private)  void readShort()
          Reads and outputs a short.
(package private)  void readSomething(boolean emptyObject)
          Reads something (object, array, string, null or reference).
(package private)  java.lang.String readString()
           
(package private)  void readStringData()
          Reads and outputs a String.
 void run()
          Does the translation.
private static java.lang.String tag(java.lang.String tagname, java.lang.String tagcontent)
           
static void usage()
          Prints a usage message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STREAM_MAGIC

private static final short STREAM_MAGIC
Identifier for serialized binary (defined by Sun)

See Also:
Constant Field Values

STREAM_VERSION

private static final short STREAM_VERSION
Stream version (defined by Sun)

See Also:
Constant Field Values

TC_BASE

private static final byte TC_BASE
First tag value (defined by Sun)

See Also:
Constant Field Values

TC_NULL

private static final byte TC_NULL
Code for null (defined by Sun)

See Also:
Constant Field Values

TC_REFERENCE

private static final byte TC_REFERENCE
Code for reference (defined by Sun)

See Also:
Constant Field Values

TC_CLASSDESC

private static final byte TC_CLASSDESC
Code for new class description (defined by Sun)

See Also:
Constant Field Values

TC_OBJECT

private static final byte TC_OBJECT
Code for new object (defined by Sun)

See Also:
Constant Field Values

TC_STRING

private static final byte TC_STRING
Code for new String (defined by Sun)

See Also:
Constant Field Values

TC_ARRAY

private static final byte TC_ARRAY
Code for new array (defined by Sun)

See Also:
Constant Field Values

TC_CLASS

private static final byte TC_CLASS
Code for class (defined by Sun)
UNUSED BY Bin2XML

See Also:
Constant Field Values

TC_BLOCKDATA

private static final byte TC_BLOCKDATA
Code for block data (defined by Sun) UNUSED BY Bin2XML

See Also:
Constant Field Values

TC_ENDBLOCKDATA

private static final byte TC_ENDBLOCKDATA
Code for end of block (defined by Sun)

See Also:
Constant Field Values

TC_RESET

private static final byte TC_RESET
Code for reset stream context (defined by Sun) UNUSED BY Bin2XML

See Also:
Constant Field Values

TC_BLOCKDATALONG

private static final byte TC_BLOCKDATALONG
Code for block data long mode (defined by Sun) UNUSED BY Bin2XML

See Also:
Constant Field Values

TC_EXCEPTION

private static final byte TC_EXCEPTION
Code for exception (defined by Sun) UNUSED BY Bin2XML

See Also:
Constant Field Values

TC_MAX

private static final byte TC_MAX
Last tag value (defined by Sun) UNUSED BY Bin2XML

See Also:
Constant Field Values

SC_WRITE_METHOD

private static final byte SC_WRITE_METHOD
Bit mask for classes implementing writeObject() serialization (defined by Sun)

See Also:
Constant Field Values

SC_BLOCK_DATA

private static final byte SC_BLOCK_DATA
Bit mask for classes implementing block data mode serialization (defined by Sun)

See Also:
Constant Field Values

SC_SERIALIZABLE

private static final byte SC_SERIALIZABLE
Bit mask for classes serializable (defined by Sun)

See Also:
Constant Field Values

SC_EXTERNALIZABLE

private static final byte SC_EXTERNALIZABLE
Bit mask for classes externalizable (defined by Sun)

See Also:
Constant Field Values

baseWireHandle

private static final int baseWireHandle
Value for base reference (= reference 0) (defined by Sun)

See Also:
Constant Field Values

DTD_EXTENSION

private static final java.lang.String DTD_EXTENSION
DTD extension

See Also:
Constant Field Values

XML_EXTENSION

private static final java.lang.String XML_EXTENSION
XML extension

See Also:
Constant Field Values

DEFAULT_OUTPUTS

private static final java.lang.String DEFAULT_OUTPUTS
Default outputs for DTD and XML streams

See Also:
Constant Field Values

ARRAY_TAG

private static final java.lang.String ARRAY_TAG
Tag for arrays

See Also:
Constant Field Values

BOOLEAN_TAG

private static final java.lang.String BOOLEAN_TAG
Tag for booleans

See Also:
Constant Field Values

BYTE_TAG

private static final java.lang.String BYTE_TAG
Tag for bytes

See Also:
Constant Field Values

CHAR_TAG

private static final java.lang.String CHAR_TAG
Tag for chars

See Also:
Constant Field Values

CLASSDESC_TAG

private static final java.lang.String CLASSDESC_TAG
Tag for class descriptions

See Also:
Constant Field Values

DOUBLE_TAG

private static final java.lang.String DOUBLE_TAG
Tag for doubles

See Also:
Constant Field Values

FLOAT_TAG

private static final java.lang.String FLOAT_TAG
Tag for floats

See Also:
Constant Field Values

INT_TAG

private static final java.lang.String INT_TAG
Tag for ints

See Also:
Constant Field Values

LONG_TAG

private static final java.lang.String LONG_TAG
Tag for longs

See Also:
Constant Field Values

MAGIC_TAG

private static final java.lang.String MAGIC_TAG
Tag for magic number

See Also:
Constant Field Values

NAME_TAG

private static final java.lang.String NAME_TAG
Tag for name

See Also:
Constant Field Values

OBJECT_TAG

private static final java.lang.String OBJECT_TAG
Tag for objects

See Also:
Constant Field Values

SC_TAG

private static final java.lang.String SC_TAG
Tag for Stream Class bit flags

See Also:
Constant Field Values

SHORT_TAG

private static final java.lang.String SHORT_TAG
Tag for shorts

See Also:
Constant Field Values

SIG_TAG

private static final java.lang.String SIG_TAG
Tag for class SHA signature

See Also:
Constant Field Values

STRING_TAG

private static final java.lang.String STRING_TAG
Tag for Strings

See Also:
Constant Field Values

TOP_TAG

private static final java.lang.String TOP_TAG
Top level tag

See Also:
Constant Field Values

VERSION_TAG

private static final java.lang.String VERSION_TAG
Tag for serialization version number

See Also:
Constant Field Values

NULL_OPTAG

private static final java.lang.String NULL_OPTAG
One part tag for null

See Also:
Constant Field Values

CLASS_PARAM

private static final java.lang.String CLASS_PARAM
Parameter name for items class name for an array

See Also:
Constant Field Values

NAME_PARAM

private static final java.lang.String NAME_PARAM
Parameter name for class name

See Also:
Constant Field Values

REF_PARAM

private static final java.lang.String REF_PARAM
Parameter name for references

See Also:
Constant Field Values

m_dis

private java.io.DataInputStream m_dis
Input stream for serialized binary


m_dtd

private java.io.PrintStream m_dtd
Output stream for DTD


m_xml

private java.io.PrintStream m_xml
Output stream for XML


ref

private java.util.ArrayList ref
ArrayList containing references on objects and class descriptions


hash

private java.util.HashMap hash
Link class names and references

Constructor Detail

Bin2XML

public Bin2XML(java.lang.String fileName,
               java.io.PrintStream ps_dtd,
               java.io.PrintStream ps_xml)
Exits in file not found.

Method Detail

main

public static final void main(java.lang.String[] argv)
Does the translation from binary to XML.
Takes from one to three arguments:
  • First argument = binary filename
  • Optional second argument = DTD output filename
  • Optional third argument = XML output filename
Default output filenames are input_filename.dtd and input_filename.xml. Exits in case of to few or to many arguments, or if problems with outputs.


usage

public static final void usage()
Prints a usage message.


debug

void debug()
Debug method which prints references list


run

public void run()
Does the translation. Exits in case of IOException or in invalid (or unsupported) format.


readHeader

void readHeader()
          throws java.io.IOException,
                 InvalidBinaryFormatException
Reads the header of serialization format.


readSomething

void readSomething(boolean emptyObject)
             throws java.io.IOException,
                    InvalidBinaryFormatException
Reads something (object, array, string, null or reference).


readObject

void readObject()
          throws java.io.IOException,
                 InvalidBinaryFormatException
Reads an object. Called after a TC_OBJECT is found.
Reads first a class description or a reference to a class description, then data.


readArray

void readArray()
         throws java.io.IOException,
                InvalidBinaryFormatException
Reads an array. Called after a TC_ARRAY is found.
Reads first a class description or a reference to a class description, then data.


readClassDescription

Bin2XML.ReturnedClassDescription readClassDescription(boolean isArray)
                                                throws java.io.IOException,
                                                       InvalidBinaryFormatException
Reads a class description.


readFieldDescription

void readFieldDescription(ClassDescription classDesc)
                    throws java.io.IOException,
                           InvalidBinaryFormatException
Reads a field description.


readString

java.lang.String readString()
                      throws java.io.IOException

readClassReference

ClassDescription readClassReference(byte refType)
                              throws java.io.IOException,
                                     InvalidBinaryFormatException

readObjectReference

Bin2XML.Pair readObjectReference(byte refType)
                           throws java.io.IOException,
                                  InvalidBinaryFormatException

readBoolean

void readBoolean()
           throws java.io.IOException
Reads and outputs a boolean.


readByte

void readByte()
        throws java.io.IOException
Reads and outputs a byte.


readChar

void readChar()
        throws java.io.IOException
Reads and outputs a char.


readDouble

void readDouble()
          throws java.io.IOException
Reads and outputs a double.


readFloat

void readFloat()
         throws java.io.IOException
Reads and outputs a float.


readInt

void readInt()
       throws java.io.IOException
Reads and outputs an int.


readLong

void readLong()
        throws java.io.IOException
Reads and outputs a long.


readShort

void readShort()
         throws java.io.IOException
Reads and outputs a short.


readStringData

void readStringData()
              throws java.io.IOException
Reads and outputs a String.


otag

private static final java.lang.String otag(java.lang.String tagname)

ctag

private static final java.lang.String ctag(java.lang.String tagname)

param

private static final java.lang.String param(java.lang.String name,
                                            java.lang.String value)

tag

private static final java.lang.String tag(java.lang.String tagname,
                                          java.lang.String tagcontent)

optag

private static final java.lang.String optag(java.lang.String tagname,
                                            java.lang.String parName,
                                            java.lang.String parValue)

optag

private static final java.lang.String optag(java.lang.String tagname,
                                            java.lang.String parName1,
                                            java.lang.String parValue1,
                                            java.lang.String parName2,
                                            java.lang.String parValue2)

optag

private static final java.lang.String optag(java.lang.String tagname)

encoding

private static final java.lang.String encoding()
FIXME