/** * Creates a new instance. * * @param elementType * The type of index element to be stored in the index. * @param ordering * A comparator that sorts index elements desired index key * ordering. * @param indexFile * The file to use for storing the index. */ public IndexStore(Class<T> elementType, Comparator<K> ordering, File indexFile) { this.ordering = ordering; this.indexFile = indexFile; serializationFactory = new SingleClassObjectSerializationFactory(elementType); indexStore = new RandomAccessObjectStore<T>(serializationFactory, indexFile); sorted = true; elementCount = 0; elementSize = -1; complete = false; }
/** * {@inheritDoc} */ public void close() { indexStore.close(); } }
/** * {@inheritDoc} */ @Override public void complete() { objectStore.complete(); indexStore.complete(); }
indexStore.complete(); )) { try (RandomAccessObjectStoreReader<T> indexStoreReader = indexStore.createReader()) { Iterator<T> indexIterator; indexStore.close(); if (indexFile != null) { indexStore = new RandomAccessObjectStore<T>(serializationFactory, indexFile); } else { indexStore = new RandomAccessObjectStore<T>(serializationFactory, tempFilePrefix); indexStore.add(sortIterator.next());
/** * Creates a new reader capable of accessing the contents of this store. The * reader must be explicitly released when no longer required. Readers must * be released prior to this store. * * @return A store reader. */ public IndexStoreReader<K, T> createReader() { return new IndexStoreReader<K, T>(indexStore.createReader(), ordering); }
/** * Adds the specified object to the store. * * @param id * The identifier allowing the object to be retrieved. * @param data * The object to be added. */ public void add(long id, T data) { long objectOffset; // Write the object to the object store. objectOffset = objectStore.add(data); // Write the object offset keyed by the id to the index store. indexStore.write(new LongLongIndexElement(id, objectOffset)); }
/** * Adds the specified object to the store. * * @param data * The object to be added. * @return The offset within the output file of the object written. */ public long add(T data) { long objectFileOffset; initializeAddStage(); objectFileOffset = offsetTrackingStream.getByteCount(); // Write the object to the store. objectWriter.writeObject(data); return objectFileOffset; }
/** * Creates a new reader capable of accessing the contents of this store. The * reader must be explicitly released when no longer required. Readers must * be released prior to this store. * * @return A store reader. */ public RandomAccessObjectStoreReader<T> createReader() { initializeReadingStage(); try { BufferedRandomAccessFileInputStream randomFileReader; randomFileReader = new BufferedRandomAccessFileInputStream(storageFile); return new RandomAccessObjectStoreReader<T>( randomFileReader, serializationFactory.createObjectReader( new DataInputStoreReader( new DataInputStream(randomFileReader)), storeClassRegister) ); } catch (FileNotFoundException e) { throw new OsmosisRuntimeException( "Unable to create object stream reading from file " + storageFile + ".", e); } }
indexStore.complete(); )) { try (RandomAccessObjectStoreReader<T> indexStoreReader = indexStore.createReader()) { Iterator<T> indexIterator; indexStore.close(); if (indexFile != null) { indexStore = new RandomAccessObjectStore<T>(serializationFactory, indexFile); } else { indexStore = new RandomAccessObjectStore<T>(serializationFactory, tempFilePrefix); indexStore.add(sortIterator.next());
/** * Creates a new reader capable of accessing the contents of this store. The * reader must be explicitly released when no longer required. Readers must * be released prior to this store. * * @return A store reader. */ public IndexStoreReader<K, T> createReader() { return new IndexStoreReader<K, T>(indexStore.createReader(), ordering); }
/** * Adds the specified object to the store. * * @param id * The identifier allowing the object to be retrieved. * @param data * The object to be added. */ public void add(long id, T data) { long objectOffset; // Write the object to the object store. objectOffset = objectStore.add(data); // Write the object offset keyed by the id to the index store. indexStore.write(new LongLongIndexElement(id, objectOffset)); }
/** * Adds the specified object to the store. * * @param data * The object to be added. * @return The offset within the output file of the object written. */ public long add(T data) { long objectFileOffset; initializeAddStage(); objectFileOffset = offsetTrackingStream.getByteCount(); // Write the object to the store. objectWriter.writeObject(data); return objectFileOffset; }
/** * Creates a new reader capable of accessing the contents of this store. The * reader must be explicitly released when no longer required. Readers must * be released prior to this store. * * @return A store reader. */ public RandomAccessObjectStoreReader<T> createReader() { initializeReadingStage(); try { BufferedRandomAccessFileInputStream randomFileReader; randomFileReader = new BufferedRandomAccessFileInputStream(storageFile); return new RandomAccessObjectStoreReader<T>( randomFileReader, serializationFactory.createObjectReader( new DataInputStoreReader( new DataInputStream(randomFileReader)), storeClassRegister) ); } catch (FileNotFoundException e) { throw new OsmosisRuntimeException( "Unable to create object stream reading from file " + storageFile + ".", e); } }
/** * Creates a new instance. * * @param elementType * The type of index element to be stored in the index. * @param ordering * A comparator that sorts index elements desired index key * ordering. * @param indexFile * The file to use for storing the index. */ public IndexStore(Class<T> elementType, Comparator<K> ordering, File indexFile) { this.ordering = ordering; this.indexFile = indexFile; serializationFactory = new SingleClassObjectSerializationFactory(elementType); indexStore = new RandomAccessObjectStore<T>(serializationFactory, indexFile); sorted = true; elementCount = 0; elementSize = -1; complete = false; }
RandomAccessObjectStoreReader<T> objectStoreReader = null; objectStoreReader = objectStore.createReader();
/** * {@inheritDoc} */ public void close() { indexStore.close(); } }
fileOffset = indexStore.add(element);
/** * {@inheritDoc} */ @Override public void complete() { // If we're already in the reading stage, we don't need to perform a // complete. if (stage.compareTo(StorageStage.Reading) != 0) { // We need to make sure we pass through the add stage to ensure an // output file is created. initializeAddStage(); try { offsetTrackingStream.close(); offsetTrackingStream = null; } catch (IOException e) { throw new OsmosisRuntimeException("Unable to close the file " + storageFile + "."); } stage = StorageStage.Reading; } }
/** * {@inheritDoc} */ @Override public void complete() { objectStore.complete(); indexStore.complete(); }
/** * Creates a new instance. * * * @param elementType * The type of index element to be stored in the index. * @param ordering * A comparator that sorts index elements desired index key * ordering. * @param tempFilePrefix * The prefix of the temporary file. */ public IndexStore(Class<T> elementType, Comparator<K> ordering, String tempFilePrefix) { this.ordering = ordering; this.tempFilePrefix = tempFilePrefix; serializationFactory = new SingleClassObjectSerializationFactory(elementType); indexStore = new RandomAccessObjectStore<T>(serializationFactory, tempFilePrefix); sorted = true; elementCount = 0; elementSize = -1; complete = false; }