| | |
| | | { |
| | | 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); |
| | | } |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | } |
| | | |
| | | channel = null; |
| | | header = null; |
| | | header = null; |
| | | } |
| | | |
| | | public boolean supportsRandomAccess() |
| | |
| | | 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); |
| | |
| | | // 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 |
| | |
| | | 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 |
| | |
| | | { |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | |
| | | // looks good |
| | | boolean hasNext = true; |
| | | short type = buffer.getShort(); |
| | | short type = buffer.getShort(); |
| | | |
| | | if (type == -1) |
| | | { |
| | |
| | | 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) |
| | | { |
| | |
| | | { |
| | | 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 |
| | | { |
| | |
| | | |
| | | 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())) |
| | | { |
| | |
| | | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | 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() |