Java Code Examples for org.iq80.leveldb.DBIterator#seekToFirst()
The following examples show how to use
org.iq80.leveldb.DBIterator#seekToFirst() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectLevelDBData.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
public static void data(String dataName) { Options options = new Options(); //options.createIfMissing(true); DB db = null; try { System.out.println("Path: " + path + dataName); db = factory.open(new File(path + dataName), options); logger.info("---------------------------------------------"); System.out.println(); DBIterator iterator = db.iterator(); iterator.seekToFirst(); int count = 0; while (iterator.hasNext()) { count++; switch (dataName) { case "properties": properties(iterator.peekNext().getKey(), iterator.peekNext().getValue()); break; case "peers": peers(iterator.peekNext().getKey(), iterator.peekNext().getValue()); break; case "nodes": peers(iterator.peekNext().getKey(), iterator.peekNext().getValue()); break; default: break; } iterator.next(); } iterator.close(); System.out.println(dataName + " Num: " + count); System.out.println(); logger.info("---------------------------------------------"); db.close(); } catch (IOException e) { e.printStackTrace(); } }
Example 2
Source File: LevelDB.java From aion with MIT License | 5 votes |
/** * @implNote Building two wrappers for the same {@link DBIterator} will lead to inconsistent * behavior. */ LevelDBIteratorWrapper(final ReadOptions readOptions, final DBIterator iterator, final Logger log) { this.readOptions = readOptions; this.iterator = iterator; iterator.seekToFirst(); closed = false; this.LOG = log; }
Example 3
Source File: LevelDBEntityStoreMixin.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public Stream<Reader> entityStates() { DBIterator iterator = db.iterator(); iterator.seekToFirst(); return StreamSupport.stream( new Spliterators.AbstractSpliterator<Reader>( Long.MAX_VALUE, Spliterator.ORDERED ) { @Override public boolean tryAdvance( final Consumer<? super Reader> action ) { if( !iterator.hasNext() ) { return false; } action.accept( new StringReader( new String( iterator.next().getValue(), charset ) ) ); return true; } }, false ).onClose( () -> { try { iterator.close(); } catch( IOException ex ) { throw new EntityStoreException( "Unable to close DB iterator" ); } } ); }
Example 4
Source File: LevelDbStore.java From dubbox with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Kryo kryo = new Kryo(); kryo.setReferences(false); kryo.setRegistrationRequired(false); kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); // kryo.register(Transaction.class); // kryo.register(Xid.class); // kryo.register(TransactionType.class); // kryo.register(TransactionStatus.class); // kryo.register(Participant.class); // Output output = new Output(new ByteArrayOutputStream());//new Output(new FileOutputStream("file.bin")); // // DefaultTransaction defaultTransaction = new DefaultTransaction(); // defaultTransaction.setXid(new DefaultXid("1", "2", "3")); // // kryo.writeObject(output, defaultTransaction); // output.flush(); // output.close(); Options options = new Options(); options.createIfMissing(true); options.cacheSize(100 * 1048576); // 100MB cache options.logger(new org.iq80.leveldb.Logger() { public void log(String message) { TransactionLog.REPOSITORY.info(message); } }); DB db = Iq80DBFactory.factory.open(new File("txtreedb"), options); // String stats = db.getProperty("leveldb.stats"); // System.out.println(stats); DBIterator iterator = null; try { iterator = db.iterator(); for(iterator.seekToFirst(); iterator.hasNext(); iterator.next()) { String key = Iq80DBFactory.asString(iterator.peekNext().getKey()); Transaction value = (Transaction) SerializationUtil.deserialize(iterator.peekNext().getValue()); System.out.println(key+" = "+value); } } finally { if (iterator != null) { iterator.close(); } } // String transactionId = "f282205a-e794-4bda-83a2-bb28b8839cad"; // Input input = new Input(db.get(Iq80DBFactory.bytes(transactionId))); // Transaction transaction = (Transaction) kryo.readClassAndObject(input); // System.out.println(transaction); }