Пример #1
0
 /**
  * Clean up any resources. Closes the channel.
  *
  * @throws IOException If errors occur while closing the channel.
  */
 public void close() throws IOException {
   // don't throw NPE on double close
   if (channel == null) return;
   try {
     if (channel.isOpen()) {
       channel.close();
       streamLogger.close();
     }
     NIOUtilities.clean(buffer, useMemoryMappedBuffer);
   } finally {
     if (shxReader != null) shxReader.close();
   }
   shxReader = null;
   channel = null;
   header = null;
 }
Пример #2
0
 /**
  * Creates a new instance of ShapeFile.
  *
  * @param shapefileFiles The ReadableByteChannel this reader will use.
  * @param strict True to make the header parsing throw Exceptions if the version or magic number
  *     are incorrect.
  * @throws IOException If problems arise.
  * @throws ShapefileException If for some reason the file contains invalid records.
  */
 public ShapefileReader(
     ShpFiles shapefileFiles, boolean strict, boolean useMemoryMapped, GeometryFactory gf)
     throws IOException, ShapefileException {
   this.channel = shapefileFiles.getReadChannel(ShpFileType.SHP, this);
   this.useMemoryMappedBuffer = useMemoryMapped;
   streamLogger.open();
   randomAccessEnabled = channel instanceof FileChannel;
   try {
     shxReader = new IndexFile(shapefileFiles, this.useMemoryMappedBuffer);
   } catch (Exception e) {
     LOGGER.log(
         Level.WARNING,
         "Could not open the .shx file, continuing " + "assuming the .shp file is not sparse",
         e);
     currentShape = UNKNOWN;
   }
   init(strict, gf);
 }