forked from geodmms/xdgnjobs

?? ?
2008-06-09 bd210ee7438fd203c19d3e8080ea12b79fe56159
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
@@ -33,27 +33,27 @@
{
    private static final Logger logger = LogManager.getLogger(Dgn7fileReader.class);
    private Dgn7fileHeader      header;
    private Dgn7fileHeader header;
    private ReadableByteChannel channel;
    ByteBuffer                  buffer;
    private ElementType         fileElementType = ElementType.UNDEFINED;
    private ByteBuffer          headerTransfer;
    private final Record        record = new Record();
    private final boolean       randomAccessEnabled;
    private Lock                lock;
    private boolean             useMemoryMappedBuffer;
    private long                currentOffset = 0L;
    private StreamLogging       streamLogger  = new StreamLogging("Shapefile Reader");
    private int                 maxElementId  = 0;
    ByteBuffer buffer;
    private ElementType fileElementType = ElementType.UNDEFINED;
    private ByteBuffer headerTransfer;
    private final Record record = new Record();
    private final boolean randomAccessEnabled;
    private Lock lock;
    private boolean useMemoryMappedBuffer;
    private long currentOffset = 0L;
    private StreamLogging streamLogger = new StreamLogging("Shapefile Reader");
    private int maxElementId = 0;
    public Dgn7fileReader(ReadableByteChannel channel, boolean strict, boolean useMemoryMapped, Lock lock)
        throws IOException, Dgn7fileException
            throws IOException, Dgn7fileException
    {
        this.channel               = channel;
        this.channel = channel;
        this.useMemoryMappedBuffer = useMemoryMapped;
        streamLogger.open();
        randomAccessEnabled = channel instanceof FileChannel;
        this.lock           = lock;
        this.lock = lock;
        lock.lockRead();
        init(strict);
    }
@@ -129,8 +129,8 @@
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        int        length = buffer.getShort(2) * 2;
        ByteBuffer old    = buffer;
        int length = buffer.getShort(2) * 2;
        ByteBuffer old = buffer;
        old.position(0);
@@ -173,7 +173,7 @@
        }
        channel = null;
        header  = null;
        header = null;
    }
    public boolean supportsRandomAccess()
@@ -190,8 +190,8 @@
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        // read shape record header
        int   recordNumber = ++maxElementId;
        short signature    = buffer.getShort();
        int recordNumber = ++maxElementId;
        short signature = buffer.getShort();
        // byte type = (byte) (buffer.get() & 0x7f);
        byte type = (byte) ((signature >>> 8) & 0x007f);
@@ -201,7 +201,7 @@
        // track the record location
        int elementLength = (buffer.getShort() * 2) + 4;
        if (!buffer.isReadOnly() &&!useMemoryMappedBuffer)
        if (!buffer.isReadOnly() && !useMemoryMappedBuffer)
        {
            // capacity is less than required for the record
            // copy the old into the newly allocated
@@ -218,16 +218,16 @@
                buffer.position(0);
            } else
            // remaining is less than record length
            // compact the remaining data and read again,
            // allowing enough room for one more record header
            if (buffer.remaining() < elementLength)
            {
                this.currentOffset += buffer.position();
                buffer.compact();
                fill(buffer, channel);
                buffer.position(0);
            }
                // remaining is less than record length
                // compact the remaining data and read again,
                // allowing enough room for one more record header
                if (buffer.remaining() < elementLength)
                {
                    this.currentOffset += buffer.position();
                    buffer.compact();
                    fill(buffer, channel);
                    buffer.position(0);
                }
        }
        // shape record is all little endian
@@ -256,32 +256,32 @@
        {
            int lowCoorX = buffer.getInt();
            lowCoorX    = DgnUtility.convertFromDGN(lowCoorX);
            lowCoorX = DgnUtility.convertFromDGN(lowCoorX);
            record.minX = DgnUtility.converUnitToCoord(lowCoorX);
            int lowCoorY = buffer.getInt();
            lowCoorY    = DgnUtility.convertFromDGN(lowCoorY);
            lowCoorY = DgnUtility.convertFromDGN(lowCoorY);
            record.minY = DgnUtility.converUnitToCoord(lowCoorY);
            int lowCoorZ = buffer.getInt();
            lowCoorZ    = DgnUtility.convertFromDGN(lowCoorZ);
            lowCoorZ = DgnUtility.convertFromDGN(lowCoorZ);
            record.minZ = DgnUtility.converUnitToCoord(lowCoorZ);
            int highCoorX = buffer.getInt();
            highCoorX   = DgnUtility.convertFromDGN(highCoorX);
            highCoorX = DgnUtility.convertFromDGN(highCoorX);
            record.maxX = DgnUtility.converUnitToCoord(highCoorX);
            int highCoorY = buffer.getInt();
            highCoorY   = DgnUtility.convertFromDGN(highCoorY);
            highCoorY = DgnUtility.convertFromDGN(highCoorY);
            record.maxY = DgnUtility.converUnitToCoord(highCoorY);
            int highCoorZ = buffer.getInt();
            highCoorZ   = DgnUtility.convertFromDGN(highCoorZ);
            highCoorZ = DgnUtility.convertFromDGN(highCoorZ);
            record.maxZ = DgnUtility.converUnitToCoord(highCoorZ);
        }
@@ -289,9 +289,9 @@
        record.offset = record.end;
        // update all the record info.
        record.length    = elementLength;
        record.length = elementLength;
        record.signature = signature;
        record.number    = recordNumber;
        record.number = recordNumber;
        // remember, we read one int already...
        record.end = this.toFileOffset(buffer.position()) + elementLength - 4;
@@ -390,7 +390,7 @@
        // looks good
        boolean hasNext = true;
        short   type    = buffer.getShort();
        short type = buffer.getShort();
        if (type == -1)
        {
@@ -553,8 +553,8 @@
    public static void main(String[] args)
    {
        JFileChooser jfc = new JFileChooser("D:/TEMP");
        File         f   = null;
        int          r   = jfc.showOpenDialog(new JFrame());
        File f = null;
        int r = jfc.showOpenDialog(new JFrame());
        if (r == JFileChooser.APPROVE_OPTION)
        {
@@ -562,16 +562,16 @@
            {
                f = jfc.getSelectedFile();
                FileChannel    channel = new FileInputStream(f).getChannel();
                Dgn7fileReader reader  = new Dgn7fileReader(channel, new Lock());
                FileChannel channel = new FileInputStream(f).getChannel();
                Dgn7fileReader reader = new Dgn7fileReader(channel, new Lock());
                System.out.println(reader.getHeader().toString());
                GeometryFactory factory = new GeometryFactory();
                int             count, size;
                int count, size;
                count = 0;
                size  = 0;
                size = 0;
                try
                {
@@ -585,8 +585,8 @@
                        if (record.element() != null)
                        {
                            Element     element = (Element) record.element();
                            ElementType type    = element.getElementType();
                            Element element = (Element) record.element();
                            ElementType type = element.getElementType();
                            if ((!type.isComplexElement()) && (!element.isComponentElement()))
                            {
@@ -647,10 +647,10 @@
    public final class Record
    {
        int   length;
        int   number = 0;
        int   offset;           // Relative to the whole file
        int   start     = 0;    // Relative to the current loaded buffer
        int length;
        int number = 0;
        int offset;           // Relative to the whole file
        int start = 0;    // Relative to the current loaded buffer
        short signature = 0;
        /**
@@ -684,8 +684,8 @@
        public double maxZ;
        // ElementType type;
        int             end     = 0;    // Relative to the whole file
        Object          element = null;
        int end = 0;    // Relative to the whole file
        Object element = null;
        IElementHandler handler;
        public Object element()