public IndexedFidReader(String typeName, RecordNumberTracker reader, ReadableByteChannel readChannel) throws IOException { this.reader = reader; this.typeName = typeName + "."; this.readChannel = readChannel; getHeader(); buffer = ByteBuffer.allocateDirect(12 * 1024); buffer.position(buffer.limit()); }
goTo(predictedRec); hasNext(); // force data reading next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return search(desired, minRec + 1, maxRec, minRec + 1); } else { long newOffset = desired - currentId; return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction);
public long next() throws IOException { if (current != -1) write(); if (reader.hasNext()) { reader.next(); fidIndex = reader.getCurrentFIDIndex(); } else { fidIndex++; } current = fidIndex; return fidIndex; }
reader = new IndexedFidReader(getCurrentTypeName(), getReadChannel(fixURL)); if (reader.getRemoves() >= reader.getCount() / 2) { indexFile.deleteOnExit(); def.addField(Long.class); for (int i = 0; i < fids.length; i++) { long recno = reader.findFid(fids[i]); if (recno == -1) continue; reader.close();
IndexedFidReader reader = new IndexedFidReader(shpFiles); for (Identifier identifier : idsSet) { String fid = identifier.toString(); long recno = reader.findFid(fid); if (recno == -1){ if(LOGGER.isLoggable(Level.FINEST)){ reader.close();
new IndexedFidReader(filename.substring(indexslash), writeChannel));
goTo(predictedRec); buffer.limit(IndexedFidWriter.RECORD_SIZE); next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return search( desired, minRec+1, maxRec, minRec+1 ); }else{ long newOffset = desired - currentId; return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction);
private void init( ShpFiles shpFiles, StorageFile storageFile ) throws IOException { if (!shpFiles.isLocal()) { throw new IllegalArgumentException( "Currently only local files are supported for writing"); } try { reader = new IndexedFidReader(shpFiles); } catch (FileNotFoundException e) { reader = new IndexedFidReader(shpFiles, storageFile.getWriteChannel()); } this.channel = storageFile.getWriteChannel(); streamLogger.open(); allocateBuffers(); removes = reader.getRemoves(); writeBuffer.position(HEADER_SIZE); closed = false; position = 0; current = -1; recordIndex = 0; fidIndex = 0; }
public boolean hasNext() throws IOException { return reader.hasNext(); }
public void close() throws IOException { if (closed) { return; } try { finishLastWrite(); } finally { try { reader.close(); } finally { closeWriterChannels(); } if (storageFile != null) { storageFile.replaceOriginal(); } } closed = true; }
/** * Returns the offset to the location in the SHX file that the fid * identifies. This search take logN time. * * @param fid the fid to find. * * @return Returns the record number of the record in the SHX file that the * fid identifies. Will return -1 if the fid was not found. * * @throws IOException * @throws IllegalArgumentException DOCUMENT ME! */ public long findFid(String fid) throws IOException { try { long desired = Long.parseLong(fid.substring(fid.lastIndexOf(".") + 1)); if ((desired < 0)) { return -1; } if( desired<count ){ return search(desired, -1, this.count, desired - 1); }else{ return search( desired, -1, this.count, count - 1 ); } } catch (NumberFormatException e) { LOGGER.warning( "Fid is not recognized as a fid for this shapefile: " + typeName); return -1; } }
if (removes > getCount() / 2) { URL url = shpFiles.acquireRead(FIX, this); try {
public IndexedFidWriter(FileChannel writeChannel, IndexedFidReader reader2) throws IOException { this.channel = writeChannel; reader = reader2; streamLogger.open(); allocateBuffers(); removes = reader.getRemoves(); writeBuffer.position(HEADER_SIZE); closed = false; position=0; current=-1; recordIndex=0; fidIndex=0; }
IndexedFidReader reader = new IndexedFidReader(shpFiles); for (Identifier identifier : idsSet) { String fid = identifier.toString(); long recno = reader.findFid(fid); if (recno == -1){ if(LOGGER.isLoggable(Level.FINEST)){ reader.close();
public static FIDReader getFidReader( ShapefileDataStore datastore, RecordNumberTracker tracker ) throws MalformedURLException { if (datastore instanceof IndexedShapefileDataStore) { IndexedShapefileDataStore ids = (IndexedShapefileDataStore)datastore; if( !ids.indexUseable(ShpFileType.FIX) ) return createBasicFidReader(datastore, tracker); try{ return new IndexedFidReader(ids.shpFiles, tracker); }catch (Exception e) { return createBasicFidReader(datastore,tracker); } } else { return createBasicFidReader(datastore, tracker); } }
public long next() throws IOException { if (current != -1) write(); if (reader.hasNext()) { reader.next(); fidIndex = reader.getCurrentFIDIndex(); } else { fidIndex++; } current = fidIndex; return fidIndex; }
private void init( ShpFiles shpFiles, StorageFile storageFile ) throws IOException { if (!shpFiles.isLocal()) { throw new IllegalArgumentException( "Currently only local files are supported for writing"); } try { reader = new IndexedFidReader(shpFiles); } catch (FileNotFoundException e) { reader = new IndexedFidReader(shpFiles, storageFile.getWriteChannel()); } this.channel = storageFile.getWriteChannel(); streamLogger.open(); allocateBuffers(); removes = reader.getRemoves(); writeBuffer.position(HEADER_SIZE); closed = false; position = 0; current = -1; recordIndex = 0; fidIndex = 0; }
public String next() throws IOException { if (reader != null) { goTo(reader.getRecordNumber() - 1); } if (!hasNext()) { throw new NoSuchElementException( "Feature could not be read; a the index may be invalid"); } currentId = buffer.getLong(); currentShxIndex = buffer.getInt(); fidBuilder.setLength(typeName.length()); fidBuilder.append(currentId); return fidBuilder.toString(); }