public boolean hasNext() throws IOException { if (done) { return false; } if (buffer.position() == buffer.limit()) { buffer.position(0); FileChannel fc = (FileChannel) readChannel; bufferStart = fc.position(); int read = ShapefileReader.fill(buffer, readChannel); if (read != 0) { buffer.position(0); } } return buffer.remaining() != 0; }
private void positionBufferForOffset(ByteBuffer buffer, int offset) throws IOException { if (useMemoryMappedBuffer) { buffer.position(offset); return; } // Check to see if requested offset is already loaded; ensure that record header is in the // buffer if (currentOffset <= offset && currentOffset + buffer.limit() >= offset + 8) { buffer.position(toBufferOffset(offset)); } else { if (!randomAccessEnabled) { throw new UnsupportedOperationException("Random Access not enabled"); } FileChannel fc = (FileChannel) this.channel; fc.position(offset); currentOffset = offset; buffer.position(0); buffer.limit(buffer.capacity()); fill(buffer, fc); buffer.flip(); } }
private void init(boolean strict, GeometryFactory gf) throws IOException, ShapefileException { geometryFactory = gf; if (channel instanceof FileChannel && useMemoryMappedBuffer) { FileChannel fc = (FileChannel) channel; buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); buffer.position(0); this.currentOffset = 0; } else { // force useMemoryMappedBuffer to false this.useMemoryMappedBuffer = false; // start small buffer = NIOUtilities.allocate(1024); fill(buffer, channel); buffer.flip(); this.currentOffset = 0; } header = new ShapefileHeader(); header.read(buffer, strict); fileShapeType = header.getShapeType(); handler = fileShapeType.getShapeHandler(gf); if (handler == null) { throw new IOException("Unsuported shape type:" + fileShapeType); } headerTransfer = ByteBuffer.allocate(8); headerTransfer.order(ByteOrder.BIG_ENDIAN); // make sure the record end is set now... record.end = this.toFileOffset(buffer.position()); }
private void getHeader(ShpFiles shpFiles) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(IndexedFidWriter.HEADER_SIZE); try { ShapefileReader.fill(buffer, readChannel); if (buffer.position() == 0) { done = true; count = 0; return; } buffer.position(0); byte version = buffer.get(); if (version != 1) { throw new IOException( "File is not of a compatible version for this reader or file is corrupt."); } this.count = buffer.getLong(); this.removes = buffer.getInt(); if (removes > getCount() / 2) { URL url = shpFiles.acquireRead(FIX, this); try { URLs.urlToFile(url).deleteOnExit(); } finally { shpFiles.unlockRead(url, this); } } } finally { NIOUtilities.clean(buffer, false); } }
/** * Ensures that there is at least 1 integer (4 bytes) is in the buffer. * * @return true if there is data in the buffer, false less than a byte is in * the buffer. * @throws IOException * if exception during reading occurs. */ private boolean fillBuffer() throws IOException { int result = 1; if (buffer.limit() <= buffer.position() + 4) { result = fill(buffer, channel); } return result > 0; }
public boolean hasNext() throws IOException { if (done) { return false; } if (buffer.position() == buffer.limit()) { buffer.position(0); FileChannel fc = (FileChannel) readChannel; bufferStart = fc.position(); int read = ShapefileReader.fill(buffer, readChannel); if (read != 0) { buffer.position(0); } } return buffer.remaining() != 0; }
private void getHeader() throws IOException { ByteBuffer buffer = ByteBuffer.allocate(IndexedFidWriter.HEADER_SIZE); ShapefileReader.fill(buffer, readChannel); if (buffer.position() == 0) { done = true; count = 0; return; } buffer.position(0); byte version = buffer.get(); if (version != 1) { throw new IOException( "File is not of a compatible version for this reader or file is corrupt."); } this.count = buffer.getLong(); this.removes = buffer.getInt(); }
public boolean hasNext() throws IOException { if (done) { return false; } if (buffer.position() == buffer.limit()) { buffer.position(0); FileChannel fc = (FileChannel) readChannel; bufferStart = fc.position(); int read = ShapefileReader.fill(buffer, readChannel); if (read != 0) { buffer.position(0); } } return buffer.remaining() != 0; }
public boolean hasNext() throws IOException { if (done) { return false; } if (buffer.position() == buffer.limit()) { buffer.position(0); FileChannel fc = (FileChannel) readChannel; bufferStart = fc.position(); int read = ShapefileReader.fill(buffer, readChannel); if (read != 0) { buffer.position(0); } } return buffer.remaining() != 0; }
private void positionBufferForOffset(ByteBuffer buffer, int offset) throws IOException { if (useMemoryMappedBuffer) { buffer.position(offset); return; } // Check to see if requested offset is already loaded; ensure that record header is in the buffer if (currentOffset <= offset && currentOffset + buffer.limit() >= offset + 8) { buffer.position(toBufferOffset(offset)); } else { if (!randomAccessEnabled) { throw new UnsupportedOperationException("Random Access not enabled"); } FileChannel fc = (FileChannel) this.channel; fc.position(offset); currentOffset = offset; buffer.position(0); buffer.limit(buffer.capacity()); fill(buffer, fc); buffer.flip(); } }
this.currentOffset = offset; buffer.position(0); fill(buffer, fc); buffer.position(0);
private void init(boolean strict) throws IOException, ShapefileException { header = readHeader(channel, strict); fileShapeType = header.getShapeType(); handler = fileShapeType.getShapeHandler(); // recordHeader = ByteBuffer.allocateDirect(8); // recordHeader.order(ByteOrder.BIG_ENDIAN); if (handler == null) { throw new IOException("Unsuported shape type:" + fileShapeType); } if (channel instanceof FileChannel && useMemoryMappedBuffer) { FileChannel fc = (FileChannel) channel; buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); buffer.position(100); this.currentOffset = 0; } else { // force useMemoryMappedBuffer to false this.useMemoryMappedBuffer = false; // start with 8K buffer buffer = ByteBuffer.allocateDirect(8 * 1024); fill(buffer, channel); buffer.flip(); this.currentOffset = 100; } headerTransfer = ByteBuffer.allocate(8); headerTransfer.order(ByteOrder.BIG_ENDIAN); // make sure the record end is set now... record.end = this.toFileOffset(buffer.position()); }
/** * A short cut for reading the header from the given channel. * * @param channel * The channel to read from. * @param strict * True to make the header parsing throw Exceptions if the * version or magic number are incorrect. * @throws IOException * If problems arise. * @return A ShapefileHeader object. */ public static ShapefileHeader readHeader(ReadableByteChannel channel, boolean strict) throws IOException { ByteBuffer buffer = ByteBuffer.allocateDirect(100); if (fill(buffer, channel) == -1) { throw new EOFException("Premature end of header"); } buffer.flip(); ShapefileHeader header = new ShapefileHeader(); header.read(buffer, strict); NIOUtilities.clean(buffer); return header; }
buffer.position(0); buffer.limit(buffer.capacity()); fill(buffer, fc); buffer.position(0);
private void init(boolean strict, GeometryFactory gf) throws IOException, ShapefileException { geometryFactory = gf; if (channel instanceof FileChannel && useMemoryMappedBuffer) { FileChannel fc = (FileChannel) channel; buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); buffer.position(0); this.currentOffset = 0; } else { // force useMemoryMappedBuffer to false this.useMemoryMappedBuffer = false; // start small buffer = NIOUtilities.allocate(1024); fill(buffer, channel); buffer.flip(); this.currentOffset = 0; } header = new ShapefileHeader(); header.read(buffer, strict); fileShapeType = header.getShapeType(); handler = fileShapeType.getShapeHandler(gf); if (handler == null) { throw new IOException("Unsuported shape type:" + fileShapeType); } headerTransfer = ByteBuffer.allocate(8); headerTransfer.order(ByteOrder.BIG_ENDIAN); // make sure the record end is set now... record.end = this.toFileOffset(buffer.position()); }
private void init(boolean strict, GeometryFactory gf) throws IOException, ShapefileException { geometryFactory = gf; if (channel instanceof FileChannel && useMemoryMappedBuffer) { FileChannel fc = (FileChannel) channel; buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); buffer.position(0); this.currentOffset = 0; } else { // force useMemoryMappedBuffer to false this.useMemoryMappedBuffer = false; // start small buffer = NIOUtilities.allocate(1024); fill(buffer, channel); buffer.flip(); this.currentOffset = 0; } header = new ShapefileHeader(); header.read(buffer, strict); fileShapeType = header.getShapeType(); handler = fileShapeType.getShapeHandler(gf); if (handler == null) { throw new IOException("Unsuported shape type:" + fileShapeType); } headerTransfer = ByteBuffer.allocate(8); headerTransfer.order(ByteOrder.BIG_ENDIAN); // make sure the record end is set now... record.end = this.toFileOffset(buffer.position()); }
private void getHeader(ShpFiles shpFiles) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(IndexedFidWriter.HEADER_SIZE); try { ShapefileReader.fill(buffer, readChannel);
private void getHeader(ShpFiles shpFiles) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(IndexedFidWriter.HEADER_SIZE); try { ShapefileReader.fill(buffer, readChannel);