本文整理汇总了Java中jetbrains.exodus.ArrayByteIterable类的典型用法代码示例。如果您正苦于以下问题:Java ArrayByteIterable类的具体用法?Java ArrayByteIterable怎么用?Java ArrayByteIterable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArrayByteIterable类属于jetbrains.exodus包,在下文中一共展示了ArrayByteIterable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContributions
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@Override
public int getContributions(ProjectFacade project, UserFacade user, String path) {
if (user.getEmail() != null) {
Environment env = getEnv(project.getId().toString());
Store store = getStore(env, CONTRIBUTIONS_STORE);
return env.computeInReadonlyTransaction(new TransactionalComputable<Integer>() {
@Override
public Integer compute(Transaction tx) {
byte[] contributionKey = getContributionKey(user.getEmail(), path);
byte[] bytes = getBytes(store.get(tx, new ArrayByteIterable(contributionKey)));
if (bytes != null)
return ByteBuffer.wrap(bytes).getInt();
else
return 0;
}
});
} else {
return 0;
}
}
示例2: deleteFile
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
/**
* Deletes existing file with the specified {@code path}.
*
* @param txn {@linkplain Transaction} instance
* @param path file path
* @return deleted {@linkplain File} or {@code null} if no file with specified {@code path}exists.
* @see File
*/
@Nullable
public File deleteFile(@NotNull final Transaction txn, @NotNull final String path) {
final ArrayByteIterable key = StringBinding.stringToEntry(path);
final ByteIterable fileMetadata;
try (Cursor cursor = pathnames.openCursor(txn)) {
fileMetadata = cursor.getSearchKey(key);
if (fileMetadata != null) {
cursor.deleteCurrent();
}
}
if (fileMetadata != null) {
final File result = new File(path, fileMetadata);
// at first delete contents
try (ClusterIterator iterator = new ClusterIterator(this, txn, result)) {
while (iterator.hasCluster()) {
iterator.deleteCurrent();
iterator.moveToNext();
}
}
return result;
}
return null;
}
示例3: getClusterConverter
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@Override
@Nullable ClusterConverter getClusterConverter() {
return new ClusterConverter() {
@NotNull
@Override
public ByteIterable onRead(@NotNull final ByteIterable raw) {
final int length = raw.getLength();
int decompressedLength = length * 3 + 500;
final byte[] result = new byte[decompressedLength];
decompressedLength = new SnappyDecompressor().decompress(
raw.getBytesUnsafe(), 0, length, result, 0, decompressedLength);
return new ArrayByteIterable(result, decompressedLength);
}
@NotNull
@Override
public ByteIterable onWrite(@NotNull final ByteIterable source) {
final int sourceLength = source.getLength();
int compressedLength = sourceLength + sourceLength / 5 + 50;
final byte[] compressed = new byte[compressedLength];
compressedLength = new SnappyCompressor().compress(
source.getBytesUnsafe(), 0, sourceLength, compressed, 0, compressedLength);
return new ArrayByteIterable(compressed, compressedLength);
}
};
}
示例4: testBindings
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
public void testBindings() {
final ArrayByteIterable entry0 = PropertyKey.propertyKeyToEntry(new PropertyKey(15, 71));
final ArrayByteIterable entry1 = PropertyKey.propertyKeyToEntry(new PropertyKey(16, 24));
final ArrayByteIterable entry2 = PropertyKey.propertyKeyToEntry(new PropertyKey(128, 24));
final ArrayByteIterable entry3 = PropertyKey.propertyKeyToEntry(new PropertyKey(245, 71));
Assert.assertTrue(ByteIterableUtil.compare(entry0, entry1) < 0);
Assert.assertTrue(ByteIterableUtil.compare(entry0, entry2) < 0);
Assert.assertTrue(ByteIterableUtil.compare(entry0, entry3) < 0);
Assert.assertTrue(ByteIterableUtil.compare(entry1, entry2) < 0);
Assert.assertTrue(ByteIterableUtil.compare(entry1, entry3) < 0);
Assert.assertTrue(ByteIterableUtil.compare(entry1, entry0) > 0);
Assert.assertTrue(ByteIterableUtil.compare(entry2, entry3) < 0);
Assert.assertTrue(ByteIterableUtil.compare(entry2, entry1) > 0);
Assert.assertTrue(ByteIterableUtil.compare(entry2, entry0) > 0);
}
示例5: get
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@Nullable
@Override
public ByteIterable get(@NotNull final ByteIterable key) {
try (ITreeCursor cursor = treeNoDuplicates.openCursor()) {
final ByteIterable value = cursor.getSearchKeyRange(getEscapedKeyWithSeparator(key));
if (value != null && value != ByteIterable.EMPTY) {
int keyLength = CompressedUnsignedLongByteIterable.getInt(value);
if (key.getLength() == keyLength) {
final ByteIterable noDupKey = new UnEscapingByteIterable(cursor.getKey());
final byte[] noDupKeyBytes = noDupKey.getBytesUnsafe();
if (ByteIterableUtil.compare(key.getBytesUnsafe(), keyLength, noDupKeyBytes, keyLength) == 0) {
return new ArrayByteIterable(Arrays.copyOfRange(noDupKeyBytes,
keyLength + 1, // skip separator
noDupKey.getLength()));
}
}
}
return null;
}
}
示例6: getAllStoreNames
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@NotNull
List<String> getAllStoreNames() {
final ITree tree = this.tree;
if (tree.getSize() == 0) {
return Collections.emptyList();
}
final List<String> result = new ArrayList<>();
final ITreeCursor cursor = tree.openCursor();
while (cursor.getNext()) {
final ArrayByteIterable key = new ArrayByteIterable(cursor.getKey());
if (isStringKey(key)) {
final String storeName = StringBinding.entryToString(key);
if (!EnvironmentImpl.isUtilizationProfile(storeName)) {
result.add(storeName);
}
}
}
return result;
}
示例7: get
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@Override
@Nullable
public ByteIterable get(@NotNull final Transaction txn, @NotNull final ByteIterable key) {
final ITree tree = ((TransactionBase) txn).getTree(this);
final long treeRootAddress = tree.getRootAddress();
final StoreGetCache storeGetCache;
// if neither tree is empty nor mutable and StoreGetCache is on
if (treeRootAddress != Loggable.NULL_ADDRESS && (storeGetCache = environment.getStoreGetCache()) != null) {
ByteIterable result = storeGetCache.tryKey(treeRootAddress, key);
if (result != null) {
return result == NULL_CACHED_VALUE ? null : result;
}
result = tree.get(key);
storeGetCache.cacheObject(treeRootAddress, key, result == null ? NULL_CACHED_VALUE : new ArrayByteIterable(result));
return result;
}
return tree.get(key);
}
示例8: hasNextImpl
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
private boolean hasNextImpl() {
while (!current.hasNext()) {
currentAddress += read;
final int alignment = ((int) currentAddress) & (log.getCachePageSize() - 1);
final long alignedAddress = currentAddress - alignment;
final ArrayByteIterable page = log.cache.getPageIterable(log, alignedAddress);
final int readBytes = page.getLength();
if (readBytes <= alignment) { // alignment is >= 0 for sure
read = 0;
offset = 0;
return false;
}
read = readBytes - alignment;
current = page.iterator(alignment);
offset = current.getOffset();
}
return true;
}
示例9: putRandomKeyValue
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
private void putRandomKeyValue(Store primary,
Store secondary,
Transaction txn,
int keysCount,
int valuesCount,
Persistent23TreeMap.MutableMap<Integer, Integer> testMap) {
final int key = rnd.nextInt(keysCount);
final ArrayByteIterable keyEntry = IntegerBinding.intToCompressedEntry(key);
final int value = rnd.nextInt(valuesCount);
testMap.put(key, value);
final ArrayByteIterable valueEntry = IntegerBinding.intToCompressedEntry(value);
final ByteIterable oldValue = primary.get(txn, keyEntry);
primary.put(txn, keyEntry, valueEntry);
if (oldValue != null) {
try (Cursor cursor = secondary.openCursor(txn)) {
Assert.assertTrue(cursor.getSearchBoth(oldValue, keyEntry));
Assert.assertTrue(cursor.deleteCurrent());
}
}
secondary.put(txn, valueEntry, keyEntry);
}
示例10: deleteRandomKey
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
private void deleteRandomKey(Store primary,
Store secondary,
Transaction txn,
int keysCount,
Persistent23TreeMap.MutableMap<Integer, Integer> testMap) {
final int key = rnd.nextInt(keysCount);
testMap.remove(key);
final ArrayByteIterable keyEntry = IntegerBinding.intToCompressedEntry(key);
final ByteIterable oldValue = primary.get(txn, keyEntry);
primary.delete(txn, keyEntry);
if (oldValue != null) {
try (Cursor cursor = secondary.openCursor(txn)) {
Assert.assertTrue(cursor.getSearchBoth(oldValue, keyEntry));
Assert.assertTrue(cursor.deleteCurrent());
}
}
}
示例11: registerNewUser
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
private static void registerNewUser(final Environment env, final Store users, final Store emails, final String username, final String email) {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final ArrayByteIterable usernameEntry = stringToEntry(username);
final ArrayByteIterable emailEntry = stringToEntry(email);
final boolean exists;
try (Cursor usersCursor = users.openCursor(txn)) {
exists = usersCursor.getSearchBoth(usernameEntry, emailEntry);
if (!exists) {
users.put(txn, usernameEntry, emailEntry);
}
}
if (!exists) {
try (Cursor emailsCursor = emails.openCursor(txn)) {
if (emailsCursor.getSearchBoth(emailEntry, usernameEntry)) {
throw new ExodusException("It can't be: users & emails are inconsistent!");
}
emails.put(txn, emailEntry, usernameEntry);
}
}
System.out.println((exists ? "User is already registered: " : "New user registered: ") + username + " " + email);
}
});
}
示例12: join
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
public static ByteIterable join(ByteIterable p1, ByteIterable p2) {
int length;
byte[] bytes;
byte[] p1bytes = p1.getBytesUnsafe();
if (p1.getLength() > 65535)
throw new IllegalArgumentException();
length = 2 + p1.getLength() + (p2 == null ? 0 : p2.getLength());
bytes = new byte[length];
bytes[0] = (byte) (p1.getLength() >> 8);
bytes[1] = (byte) (p1.getLength() & 0xFF);
System.arraycopy(p1bytes, 0, bytes, 2, p1.getLength());
if (p2 != null) {
byte[] p2bytes = p2.getBytesUnsafe();
System.arraycopy(p2bytes, 0, bytes, 2 + p1.getLength(), p2.getLength());
}
return new ArrayByteIterable(bytes);
}
示例13: visit
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@Override
public void visit(User user, PullRequest request) {
Environment env = getEnv(request.getTargetProject().getId().toString());
Store store = getStore(env, PULL_REQUEST_STORE);
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(Transaction txn) {
store.put(txn, new StringPairByteIterable(user.getUUID(), request.getUUID()),
new ArrayByteIterable(longToBytes(System.currentTimeMillis()+1000L)));
}
});
}
示例14: updateContribution
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
private void updateContribution(Transaction txn, Store contributionsStore, String email, String path) {
ArrayByteIterable contributionKey =
new ArrayByteIterable(getContributionKey(email, path));
byte[] contributionBytes =
getBytes(contributionsStore.get(txn, contributionKey));
int contributions;
if (contributionBytes != null)
contributions = ByteBuffer.wrap(contributionBytes).getInt() + 1;
else
contributions = 1;
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
byteBuffer.putInt(contributions);
contributionsStore.put(txn, contributionKey,
new ArrayByteIterable(byteBuffer.array()));
}
示例15: getChildren
import jetbrains.exodus.ArrayByteIterable; //导入依赖的package包/类
@Override
public Set<ObjectId> getChildren(Project project, final ObjectId parent) {
Environment env = getEnv(project.getId().toString());
final Store store = getStore(env, COMMITS_STORE);
return env.computeInReadonlyTransaction(new TransactionalComputable<Set<ObjectId>>() {
@Override
public Set<ObjectId> compute(Transaction txn) {
Set<ObjectId> children = new HashSet<>();
byte[] keyBytes = new byte[20];
parent.copyRawTo(keyBytes, 0);
byte[] valueBytes = getBytes(store.get(txn, new ArrayByteIterable(keyBytes)));
if (valueBytes != null) {
if (valueBytes.length % 20 == 0) {
for (int i=0; i<valueBytes.length/20; i++) {
children.add(ObjectId.fromRaw(valueBytes, i*20));
}
} else {
/*
* skip the leading byte, which tells whether or not the commit
* has been processed
*/
for (int i=0; i<(valueBytes.length-1)/20; i++) {
children.add(ObjectId.fromRaw(valueBytes, i*20+1));
}
}
}
return children;
}
});
}