/** * * @param requiredSize * @throws IOException */ void refillBuffer(int requiredSize) throws IOException { // compute the actual position up to we have read something long currentPosition = bufferStart + buffer.position(); // if the buffer is not big enough enlarge it if(buffer.capacity() < requiredSize) { int size = buffer.capacity(); while(size < requiredSize) size *= 2; buffer = ByteBuffer.allocateDirect(size); buffer.order(order); } readBuffer(currentPosition); }
public void getIntArray(int[] array) throws IOException { int size = array.length * 4; if (buffer.remaining() < size) refillBuffer(size); // read the array using a view IntBuffer intView = buffer.asIntBuffer(); intView.limit(array.length); intView.get(array); // don't forget to update the original buffer position, since the // view is independent buffer.position(buffer.position() + size); }
/** * @see org.geotools.index.quadtree.Node#getSubNode(int) */ public Node getSubNode(int pos) throws StoreException { if (this.subNodes.size() > pos) { return super.getSubNode(pos); } try { FileSystemNode subNode = null; // Getting prec subNode... int offset = this.subNodeStartByte; if (pos > 0) { subNode = (FileSystemNode) getSubNode(pos - 1); offset = subNode.getSubNodeStartByte() + subNode.getSubNodesLength(); } buffer.goTo(offset); for (int i = 0, ii = subNodes.size(); i < ((pos + 1) - ii); i++) { subNode = readNode(pos, this, buffer); this.addSubNode(subNode); } } catch (IOException e) { throw new StoreException(e); } return super.getSubNode(pos); }
/** * @see org.geotools.index.quadtree.Node#getSubNode(int) */ public Node getSubNode(int pos) throws StoreException { if (this.subNodes.size() > pos) { return super.getSubNode(pos); } try { FileSystemNode subNode = null; // Getting prec subNode... int offset = this.subNodeStartByte; if (pos > 0) { subNode = (FileSystemNode) getSubNode(pos - 1); offset = subNode.getSubNodeStartByte() + subNode.getSubNodesLength(); } buffer.goTo(offset); for (int i = 0, ii = subNodes.size(); i < ((pos + 1) - ii); i++) { subNode = readNode(pos, this, buffer); this.addSubNode(subNode); } } catch (IOException e) { throw new StoreException(e); } return super.getSubNode(pos); }
/** * @see org.geotools.index.quadtree.Node#getSubNode(int) */ public Node getSubNode(int pos) throws StoreException { if (this.subNodes.size() > pos) { return super.getSubNode(pos); } try { FileSystemNode subNode = null; // Getting prec subNode... int offset = this.subNodeStartByte; if (pos > 0) { subNode = (FileSystemNode) getSubNode(pos - 1); offset = subNode.getSubNodeStartByte() + subNode.getSubNodesLength(); } buffer.goTo(offset); for (int i = 0, ii = subNodes.size(); i < ((pos + 1) - ii); i++) { subNode = readNode(pos, this, buffer); this.addSubNode(subNode); } } catch (IOException e) { throw new StoreException(e); } return super.getSubNode(pos); }
static FileSystemNode readNode(int id, Node parent, ScrollingBuffer buf) throws IOException { // offset int offset = buf.getInt(); // envelope Envelope env = buf.getEnvelope(); // shapes in this node int numShapesId = buf.getInt(); int[] ids = null; if(numShapesId > 0) { ids = new int[numShapesId]; buf.getIntArray(ids); } else { ids = ZERO; } int numSubNodes = buf.getInt(); // let's create the new node FileSystemNode node = new FileSystemNode(env, buf, (int) buf.getPosition(), offset); node.setShapesId(ids); node.setNumSubNodes(numSubNodes); return node; }
static FileSystemNode readNode(int id, Node parent, ScrollingBuffer buf) throws IOException { // offset int offset = buf.getInt(); double x1; double y1; double x2; double y2; // envelope x1 = buf.getDouble(); y1 = buf.getDouble(); x2 = buf.getDouble(); y2 = buf.getDouble(); Envelope env = new Envelope(x1, x2, y1, y2); // shapes in this node int numShapesId = buf.getInt(); int[] ids = new int[numShapesId]; buf.getIntArray(ids); int numSubNodes = buf.getInt(); // let's create the new node FileSystemNode node = new FileSystemNode(env, id, parent, buf, (int) buf.getPosition(), offset); node.setShapesId(ids); node.setNumSubNodes(numSubNodes); return node; }
static FileSystemNode readNode(int id, Node parent, ScrollingBuffer buf) throws IOException { // offset int offset = buf.getInt(); // envelope Envelope env = buf.getEnvelope(); // shapes in this node int numShapesId = buf.getInt(); int[] ids = null; if(numShapesId > 0) { ids = new int[numShapesId]; buf.getIntArray(ids); } else { ids = ZERO; } int numSubNodes = buf.getInt(); // let's create the new node FileSystemNode node = new FileSystemNode(env, buf, (int) buf.getPosition(), offset); node.setShapesId(ids); node.setNumSubNodes(numSubNodes); return node; }
/** * * @param requiredSize * @throws IOException */ void refillBuffer(int requiredSize) throws IOException { // compute the actual position up to we have read something long currentPosition = bufferStart + buffer.position(); // if the buffer is not big enough enlarge it if (buffer.capacity() < requiredSize) { int size = buffer.capacity(); while (size < requiredSize) size *= 2; buffer = NIOUtilities.allocate(size); buffer.order(order); } readBuffer(currentPosition); }
/** * Jumps the buffer to the specified position in the file * * @param newPosition * @throws IOException */ public void goTo(long newPosition) throws IOException { // if the new position is already in the buffer, just move the // buffer position // otherwise we have to reload it if (useMemoryMapping || newPosition >= bufferStart && newPosition <= bufferStart + buffer.limit()) { buffer.position((int) (newPosition - bufferStart)); } else { readBuffer(newPosition); } }
/** * Jumps the buffer to the specified position in the file * * @param newPosition * @throws IOException */ public void goTo(long newPosition) throws IOException { // if the new position is already in the buffer, just move the // buffer position // otherwise we have to reload it if (useMemoryMapping || newPosition >= bufferStart && newPosition <= bufferStart + buffer.limit()) { buffer.position((int) (newPosition - bufferStart)); } else { readBuffer(newPosition); } }
/** * DOCUMENT ME! * * @param channel * @param order * DOCUMENT ME! * * * @throws IOException */ public static FileSystemNode readNode(int id, Node parent, FileChannel channel, ByteOrder order, boolean useMemoryMapping) throws IOException { ScrollingBuffer buffer = new ScrollingBuffer(channel, order, useMemoryMapping); return readNode(id, parent, buffer); }
/** * * @param requiredSize * @throws IOException */ void refillBuffer(int requiredSize) throws IOException { // compute the actual position up to we have read something long currentPosition = bufferStart + buffer.position(); // if the buffer is not big enough enlarge it if (buffer.capacity() < requiredSize) { int size = buffer.capacity(); while (size < requiredSize) size *= 2; buffer = NIOUtilities.allocate(size); buffer.order(order); } readBuffer(currentPosition); }
/** * Jumps the buffer to the specified position in the file * @param newPosition * @throws IOException */ public void goTo(long newPosition) throws IOException { // if the new position is already in the buffer, just move the buffer position // otherwise we have to reload it if(newPosition >= bufferStart && newPosition <= bufferStart + buffer.limit()) { buffer.position((int) (newPosition - bufferStart)); } else { readBuffer(newPosition); } }
/** * DOCUMENT ME! * * @param channel * @param order * DOCUMENT ME! * * * @throws IOException */ public static FileSystemNode readNode(int id, Node parent, FileChannel channel, ByteOrder order, boolean useMemoryMapping) throws IOException { ScrollingBuffer buffer = new ScrollingBuffer(channel, order, useMemoryMapping); return readNode(id, parent, buffer); }
/** * DOCUMENT ME! * * @param channel * @param order DOCUMENT ME! * * * @throws IOException */ public static FileSystemNode readNode(int id, Node parent, FileChannel channel, ByteOrder order) throws IOException { ScrollingBuffer buffer = new ScrollingBuffer(channel, order); return readNode(id, parent, buffer); }
public double getDouble() throws IOException { if(buffer.remaining() < 8) refillBuffer(8); return buffer.getDouble(); }
@Override public void close() { if(buffer != null) { buffer.close(); } buffer = null; }
@Override public void close() { if(buffer != null) { buffer.close(); } buffer = null; }
public void getIntArray(int[] array) throws IOException { int size = array.length * 4; if (buffer.remaining() < size) refillBuffer(size); // read the array using a view IntBuffer intView = buffer.asIntBuffer(); intView.limit(array.length); intView.get(array); // don't forget to update the original buffer position, since the // view is independent buffer.position(buffer.position() + size); }