]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | // This source code is licensed under both the GPLv2 (found in the | |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
5 | ||
6 | package org.rocksdb; | |
7 | ||
8 | import java.nio.ByteBuffer; | |
9 | ||
10 | /** | |
11 | * <p>An iterator that yields a sequence of key/value pairs from a source. | |
12 | * Multiple implementations are provided by this library. | |
13 | * In particular, iterators are provided | |
14 | * to access the contents of a Table or a DB.</p> | |
15 | * | |
16 | * <p>Multiple threads can invoke const methods on an RocksIterator without | |
17 | * external synchronization, but if any of the threads may call a | |
18 | * non-const method, all threads accessing the same RocksIterator must use | |
19 | * external synchronization.</p> | |
20 | * | |
21 | * @see RocksObject | |
22 | */ | |
23 | public class SstFileReaderIterator extends AbstractRocksIterator<SstFileReader> { | |
1e59de90 | 24 | protected SstFileReaderIterator(final SstFileReader reader, final long nativeHandle) { |
f67539c2 TL |
25 | super(reader, nativeHandle); |
26 | } | |
27 | ||
28 | /** | |
29 | * <p>Return the key for the current entry. The underlying storage for | |
30 | * the returned slice is valid only until the next modification of | |
31 | * the iterator.</p> | |
32 | * | |
33 | * <p>REQUIRES: {@link #isValid()}</p> | |
34 | * | |
35 | * @return key for the current entry. | |
36 | */ | |
37 | public byte[] key() { | |
38 | assert (isOwningHandle()); | |
39 | return key0(nativeHandle_); | |
40 | } | |
41 | ||
42 | /** | |
43 | * <p>Return the key for the current entry. The underlying storage for | |
44 | * the returned slice is valid only until the next modification of | |
45 | * the iterator.</p> | |
46 | * | |
47 | * <p>REQUIRES: {@link #isValid()}</p> | |
48 | * | |
49 | * @param key the out-value to receive the retrieved key. | |
50 | * It is using position and limit. Limit is set according to key size. | |
51 | * Supports direct buffer only. | |
52 | * @return The size of the actual key. If the return key is greater than the | |
53 | * length of {@code key}, then it indicates that the size of the | |
54 | * input buffer {@code key} is insufficient and partial result will | |
55 | * be returned. | |
56 | */ | |
1e59de90 TL |
57 | public int key(final ByteBuffer key) { |
58 | assert (isOwningHandle()); | |
59 | final int result; | |
60 | if (key.isDirect()) { | |
61 | result = keyDirect0(nativeHandle_, key, key.position(), key.remaining()); | |
62 | } else { | |
63 | result = keyByteArray0( | |
64 | nativeHandle_, key.array(), key.arrayOffset() + key.position(), key.remaining()); | |
65 | } | |
f67539c2 TL |
66 | key.limit(Math.min(key.position() + result, key.limit())); |
67 | return result; | |
68 | } | |
69 | ||
70 | /** | |
71 | * <p>Return the value for the current entry. The underlying storage for | |
72 | * the returned slice is valid only until the next modification of | |
73 | * the iterator.</p> | |
74 | * | |
75 | * <p>REQUIRES: !AtEnd() && !AtStart()</p> | |
76 | * @return value for the current entry. | |
77 | */ | |
78 | public byte[] value() { | |
79 | assert (isOwningHandle()); | |
80 | return value0(nativeHandle_); | |
81 | } | |
82 | ||
83 | /** | |
84 | * <p>Return the value for the current entry. The underlying storage for | |
85 | * the returned slice is valid only until the next modification of | |
86 | * the iterator.</p> | |
87 | * | |
88 | * <p>REQUIRES: {@link #isValid()}</p> | |
89 | * | |
90 | * @param value the out-value to receive the retrieved value. | |
91 | * It is using position and limit. Limit is set according to value size. | |
92 | * Supports direct buffer only. | |
93 | * @return The size of the actual value. If the return value is greater than the | |
94 | * length of {@code value}, then it indicates that the size of the | |
95 | * input buffer {@code value} is insufficient and partial result will | |
96 | * be returned. | |
97 | */ | |
1e59de90 TL |
98 | public int value(final ByteBuffer value) { |
99 | assert (isOwningHandle()); | |
100 | final int result; | |
101 | if (value.isDirect()) { | |
102 | result = valueDirect0(nativeHandle_, value, value.position(), value.remaining()); | |
103 | } else { | |
104 | result = valueByteArray0( | |
105 | nativeHandle_, value.array(), value.arrayOffset() + value.position(), value.remaining()); | |
106 | } | |
f67539c2 TL |
107 | value.limit(Math.min(value.position() + result, value.limit())); |
108 | return result; | |
109 | } | |
110 | ||
111 | @Override protected final native void disposeInternal(final long handle); | |
112 | @Override final native boolean isValid0(long handle); | |
113 | @Override final native void seekToFirst0(long handle); | |
114 | @Override final native void seekToLast0(long handle); | |
115 | @Override final native void next0(long handle); | |
116 | @Override final native void prev0(long handle); | |
20effc67 | 117 | @Override final native void refresh0(long handle) throws RocksDBException; |
f67539c2 TL |
118 | @Override final native void seek0(long handle, byte[] target, int targetLen); |
119 | @Override final native void seekForPrev0(long handle, byte[] target, int targetLen); | |
120 | @Override final native void status0(long handle) throws RocksDBException; | |
1e59de90 TL |
121 | @Override |
122 | final native void seekDirect0(long handle, ByteBuffer target, int targetOffset, int targetLen); | |
123 | @Override | |
124 | final native void seekForPrevDirect0( | |
125 | long handle, ByteBuffer target, int targetOffset, int targetLen); | |
126 | @Override | |
127 | final native void seekByteArray0( | |
128 | final long handle, final byte[] target, final int targetOffset, final int targetLen); | |
129 | @Override | |
130 | final native void seekForPrevByteArray0( | |
131 | final long handle, final byte[] target, final int targetOffset, final int targetLen); | |
f67539c2 TL |
132 | |
133 | private native byte[] key0(long handle); | |
134 | private native byte[] value0(long handle); | |
135 | ||
136 | private native int keyDirect0(long handle, ByteBuffer buffer, int bufferOffset, int bufferLen); | |
1e59de90 | 137 | private native int keyByteArray0(long handle, byte[] buffer, int bufferOffset, int bufferLen); |
f67539c2 | 138 | private native int valueDirect0(long handle, ByteBuffer buffer, int bufferOffset, int bufferLen); |
1e59de90 | 139 | private native int valueByteArray0(long handle, byte[] buffer, int bufferOffset, int bufferLen); |
f67539c2 | 140 | } |