Class DwgUtil


  • public final class DwgUtil
    extends Object
    The DwgUtil class contains the essential set of functions for reading bitstreams in DWG files
    Author:
    jmorell
    • Constructor Summary

      Constructors 
      Constructor Description
      DwgUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int[] bytesToMachineBytes​(byte[] data)
      Convert bytes to machine value bytes
      static Vector getBitDouble​(int[] data, int offset)
      Read a double value from a group of unsigned bytes
      static Vector getBitLong​(int[] data, int offset)
      Read a long value from a group of unsigned bytes
      static Object getBits​(int[] data, int count, int offset)
      Returns a set of bits from a group of unsigned bytes
      static Vector getBitShort​(int[] data, int offset)
      Read a short value from a group of unsigned bytes
      static Vector getDefaultDouble​(int[] data, int offset, double defVal)
      Read a double value from a group of unsigned bytes and a default double
      static Vector getHandle​(int[] data, int offset)
      Read a int value (the handle of a DWG object) from a group of unsigned bytes
      static Vector getModularChar​(int[] data, int offset)
      Read a char value from a group of unsigned bytes
      static int getModularShort​(ByteBuffer bb)
      Read a int value (the size of a modular short) from a ByteBuffer
      static Vector getRawChar​(int[] data, int offset)
      Read a char value from a group of unsigned bytes
      static Vector getRawDouble​(int[] data, int offset)
      Read a double value from a group of unsigned bytes
      static Vector getRawLong​(int[] data, int offset)
      Read a long value from a group of unsigned bytes
      static Vector getRawShort​(int[] data, int offset)
      Read a short value from a group of unsigned bytes
      static Vector getTextString​(int[] data, int offset)
      Read a String from a group of unsigned bytes
      static int handleBinToHandleInt​(Vector layerHandle)
      Obtain the int value of a handle given in binary format
      static Vector readExtendedData​(int[] data, int offset)
      Read the extended data for a DWG object Don't use in this version.
      static Vector testBit​(int[] data, int offset)
      Test a bit obtained from a set of unsigned bytes
    • Constructor Detail

      • DwgUtil

        public DwgUtil()
    • Method Detail

      • readExtendedData

        public static Vector readExtendedData​(int[] data,
                                              int offset)
                                       throws Exception
        Read the extended data for a DWG object Don't use in this version. Serious bugs detected
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the extended data of a DWG object
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getDefaultDouble

        public static Vector getDefaultDouble​(int[] data,
                                              int offset,
                                              double defVal)
                                       throws Exception
        Read a double value from a group of unsigned bytes and a default double
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        defVal - Default double value
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the double value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getBitDouble

        public static Vector getBitDouble​(int[] data,
                                          int offset)
                                   throws Exception
        Read a double value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the double value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getRawDouble

        public static Vector getRawDouble​(int[] data,
                                          int offset)
                                   throws Exception
        Read a double value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the double value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getBitShort

        public static Vector getBitShort​(int[] data,
                                         int offset)
                                  throws Exception
        Read a short value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the short value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getRawShort

        public static Vector getRawShort​(int[] data,
                                         int offset)
                                  throws Exception
        Read a short value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the short value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getBitLong

        public static Vector getBitLong​(int[] data,
                                        int offset)
                                 throws Exception
        Read a long value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the long value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getRawLong

        public static Vector getRawLong​(int[] data,
                                        int offset)
        Read a long value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the long value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getRawChar

        public static Vector getRawChar​(int[] data,
                                        int offset)
                                 throws Exception
        Read a char value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the char value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getModularChar

        public static Vector getModularChar​(int[] data,
                                            int offset)
                                     throws Exception
        Read a char value from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the char value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getTextString

        public static Vector getTextString​(int[] data,
                                           int offset)
                                    throws Exception
        Read a String from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the String
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getHandle

        public static Vector getHandle​(int[] data,
                                       int offset)
                                throws Exception
        Read a int value (the handle of a DWG object) from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is the int value (handle of a DWG object)
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • getModularShort

        public static int getModularShort​(ByteBuffer bb)
        Read a int value (the size of a modular short) from a ByteBuffer
        Parameters:
        bb - Data given as a ByteBuffer
        Returns:
        int Size of the modular short
      • getBits

        public static Object getBits​(int[] data,
                                     int count,
                                     int offset)
                              throws Exception
        Returns a set of bits from a group of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        count - Bit counter
        offset - The current bit offset where the value begins
        Returns:
        This method returns an array of bytes or an int value
        Throws:
        Exception - If an unexpected bit value is found in the DWG file. Occurs when we are looking for LwPolylines.
      • testBit

        public static Vector testBit​(int[] data,
                                     int offset)
        Test a bit obtained from a set of unsigned bytes
        Parameters:
        data - Array of unsigned bytes obtained from the DWG binary file
        offset - The current bit offset where the value begins
        Returns:
        Vector This vector has two parts. First is an int value that represents the new offset, and second is a bit flag
      • bytesToMachineBytes

        public static int[] bytesToMachineBytes​(byte[] data)
        Convert bytes to machine value bytes
        Parameters:
        data - Input of array of bytes
        Returns:
        int[] Output of array of machine bytes
      • handleBinToHandleInt

        public static int handleBinToHandleInt​(Vector layerHandle)
        Obtain the int value of a handle given in binary format
        Parameters:
        layerHandle - Handle in binary format
        Returns:
        int Int value of the handle