private void readHeader(ReadableByteChannel channel) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(100); try { while (buffer.remaining() > 0) { channel.read(buffer); } buffer.flip(); header = new ShapefileHeader(); header.read(buffer, true); } finally { NIOUtilities.clean(buffer, false); } }
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()); }
header = new ShapefileHeader(); header.read(buf, true); } else {
buffer.flip(); ShapefileHeader header = new ShapefileHeader(); header.read(buffer, true);
ShapefileHeader header = new ShapefileHeader(); header.write( shapeBuffer,
private void readHeader(ReadableByteChannel channel) throws IOException { ByteBuffer buffer = ByteBuffer.allocateDirect(100); while (buffer.remaining() > 0) { channel.read(buffer); } buffer.flip(); header = new ShapefileHeader(); header.read(buffer, true); NIOUtilities.clean(buffer); }
private void readHeader(ReadableByteChannel channel) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(100); try { while (buffer.remaining() > 0) { channel.read(buffer); } buffer.flip(); header = new ShapefileHeader(); header.read(buffer, true); } finally { NIOUtilities.clean(buffer, false); } }
private void readHeader(ReadableByteChannel channel) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(100); try { while (buffer.remaining() > 0) { channel.read(buffer); } buffer.flip(); header = new ShapefileHeader(); header.read(buffer, true); } finally { NIOUtilities.clean(buffer, false); } }
/** * 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; }
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()); }
header = new ShapefileHeader(); header.read(buf, true); } else {
header = new ShapefileHeader(); header.read(buf, true); } else {
buffer.flip(); ShapefileHeader header = new ShapefileHeader(); header.read(buffer, true);
buffer.flip(); ShapefileHeader header = new ShapefileHeader(); header.read(buffer, true);
buffer.flip(); ShapefileHeader header = new ShapefileHeader(); header.read(buffer, true);
/** * Write the headers for this shapefile including the bounds, shape type, the * number of geometries and the total fileLength (in actual bytes, NOT * 16 bit words). */ public void writeHeaders(Envelope bounds,ShapeType type,int numberOfGeometries,int fileLength) throws IOException { try { handler = type.getShapeHandler(); } catch (ShapefileException se) { throw new RuntimeException("unexpected Exception",se); } if (shapeBuffer == null) allocateBuffers(); ShapefileHeader header = new ShapefileHeader(); header.write(shapeBuffer, type, numberOfGeometries, fileLength/2, bounds.getMinX(),bounds.getMinY(),bounds.getMaxX(),bounds.getMaxY()); header.write(indexBuffer, type, numberOfGeometries, 50 + 4 * numberOfGeometries, bounds.getMinX(),bounds.getMinY(),bounds.getMaxX(),bounds.getMaxY()); offset = 50; this.type = type; cnt = 0; shpChannel.position(0); shxChannel.position(0); drain(); }
/** * Write the headers for this shapefile including the bounds, shape type, * the number of geometries and the total fileLength (in actual bytes, NOT * 16 bit words). */ public void writeHeaders(Envelope bounds, ShapeType type, int numberOfGeometries, int fileLength) throws IOException { try { handler = type.getShapeHandler(gf); } catch (ShapefileException se) { throw new RuntimeException("unexpected Exception", se); } if (shapeBuffer == null) allocateBuffers(); ShapefileHeader header = new ShapefileHeader(); header.write(shapeBuffer, type, numberOfGeometries, fileLength / 2, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds .getMaxY()); header.write(indexBuffer, type, numberOfGeometries, 50 + 4 * numberOfGeometries, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY()); offset = 50; this.type = type; cnt = 0; shpChannel.position(0); shxChannel.position(0); drain(); }
/** * Write the headers for this shapefile including the bounds, shape type, * the number of geometries and the total fileLength (in actual bytes, NOT * 16 bit words). */ public void writeHeaders(Envelope bounds, ShapeType type, int numberOfGeometries, int fileLength) throws IOException { try { handler = type.getShapeHandler(gf); } catch (ShapefileException se) { throw new RuntimeException("unexpected Exception", se); } if (shapeBuffer == null) allocateBuffers(); ShapefileHeader header = new ShapefileHeader(); header.write(shapeBuffer, type, numberOfGeometries, fileLength / 2, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds .getMaxY()); header.write(indexBuffer, type, numberOfGeometries, 50 + 4 * numberOfGeometries, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY()); offset = 50; this.type = type; cnt = 0; shpChannel.position(0); shxChannel.position(0); drain(); }