/** * Copies the 20 bytes of this objcetid's internal SHA-1 hash into {@code target}, starting at * {@code target}'s index zero. * * @pre {@code 0 <= length <= 20} * @pre {@code target.length >= 20} * @param target the byte array where to copy the 20 bytes of this SHA-1 hash sequence. */ public void getRawValue(byte[] target) { getRawValue(target, NUM_BYTES); }
/** * Copies the 20 bytes of this objcetid's internal SHA-1 hash into {@code target}, starting at * {@code target}'s index zero. * * @pre {@code 0 <= length <= 20} * @pre {@code target.length >= 20} * @param target the byte array where to copy the 20 bytes of this SHA-1 hash sequence. */ public void getRawValue(byte[] target) { getRawValue(target, NUM_BYTES); }
/** * @return a raw byte array of the hash code for this object id. Changes to the returned array * do not affect this object. */ public byte[] getRawValue() { byte[] raw = new byte[NUM_BYTES]; getRawValue(raw); return raw; }
@Override protected InputStream getRawInternal(ObjectId id, boolean failIfNotFound) throws IllegalArgumentException { byte[] bytes = getRawInternal(id.getRawValue()); if (bytes != null) { return new ByteArrayInputStream(bytes); } if (failIfNotFound) { throw new IllegalArgumentException("Object does not exist: " + id); } return null; }
@Override public void funnel(RevObject object) throws IOException { out.write(object.getId().getRawValue()); serializer.write(object, out); }
@Override public void funnel(RevObject object) throws IOException { OutputStream out = getCurrentTarget(); out.write(object.getId().getRawValue()); serializer.write(object, out); out.flush(); }
@Override public boolean exists(ObjectId commitId) { byte[] key = commitId.getRawValue(); try (RocksDBReference dbRef = dbhandle.getReference()) { int size = dbRef.db().get(key, NODATA); return size != RocksDB.NOT_FOUND; } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public boolean exists(ObjectId id) { checkOpen(); checkNotNull(id, "argument id is null"); try (RocksDBReference dbRef = dbhandle.getReference()) { return exists(dbRef, bulkReadOptions, id.getRawValue()); } }
@Override public void delete(ObjectId objectId) { checkNotNull(objectId, "argument objectId is null"); checkWritable(); byte[] key = objectId.getRawValue(); try (RocksDBReference dbRef = dbhandle.getReference()) { dbRef.db().delete(key); } catch (RocksDBException e) { throw new RuntimeException(e); } }
public static void writeTag(RevTag tag, DataOutput out) throws IOException { out.write(tag.getCommitId().getRawValue()); out.writeUTF(tag.getName()); out.writeUTF(tag.getMessage()); writePerson(tag.getTagger(), out); }
@Override public void delete(ObjectId objectId) { checkNotNull(objectId, "argument objectId is null"); checkWritable(); byte[] key = objectId.getRawValue(); try (RocksDBReference dbRef = dbhandle.getReference()) { dbRef.db().remove(key); } catch (RocksDBException e) { throw Throwables.propagate(e); } }
public void writeCommit(RevCommit commit, DataOutput data) throws IOException { data.write(commit.getTreeId().getRawValue()); final int nParents = commit.getParentIds().size(); writeUnsignedVarInt(nParents, data); for (ObjectId pId : commit.getParentIds()) { data.write(pId.getRawValue()); } writePerson(commit.getAuthor(), data); writePerson(commit.getCommitter(), data); data.writeUTF(commit.getMessage()); }
@Override public void objectToEntry(@Nullable ObjectId object, TupleOutput output) { if (null == object || object.isNull()) { output.write(0); } else { output.write(ObjectId.NUM_BYTES); output.write(object.getRawValue()); } } }
@Override public boolean exists(ObjectId commitId) { Preconditions.checkNotNull(commitId, "id"); DatabaseEntry key = new DatabaseEntry(commitId.getRawValue()); DatabaseEntry data = new DatabaseEntry(); // tell db not to retrieve data data.setPartial(0, 0, true); final LockMode lockMode = LockMode.READ_UNCOMMITTED; Transaction transaction = null; OperationStatus status = graphDb.get(transaction, key, data, lockMode); return SUCCESS == status; }
private void putNodeInternal(final ObjectId id, final NodeData node) throws IOException { byte[] key = id.getRawValue(); byte[] data = BINDING.objectToEntry(node); try (RocksDBReference dbRef = dbhandle.getReference()) { dbRef.db().put(key, data); } catch (RocksDBException e) { propagate(e); } }
@Override public void addIndexedTree(IndexInfo index, ObjectId originalTree, ObjectId indexedTree) { byte[] indexTreeLookupId = computeIndexTreeLookupId(index.getId(), originalTree); try (RocksDBReference dbRef = dbhandle.getReference()) { dbRef.db().put(indexMappingsColumn, indexTreeLookupId, indexedTree.getRawValue()); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public void addIndexedTree(IndexInfo index, ObjectId originalTree, ObjectId indexedTree) { byte[] indexTreeLookupId = computeIndexTreeLookupId(index.getId(), originalTree); try (RocksDBReference dbRef = dbhandle.getReference()) { dbRef.db().put(indexMappingsColumn, indexTreeLookupId, indexedTree.getRawValue()); } catch (RocksDBException e) { throw Throwables.propagate(e); } }
@Override public void writeBucket(final int index, final Bucket bucket, DataOutput data, Envelope envBuff) throws IOException { writeUnsignedVarInt(index, data); data.write(bucket.getObjectId().getRawValue()); envBuff.setToNull(); bucket.expand(envBuff); writeBounds(envBuff,data); }
@Test public void testGetRawValue() { ObjectId oid = ObjectId.valueOf("ff68b74766e20cca000000000000000000000000"); byte[] raw = new byte[ObjectId.NUM_BYTES]; oid.getRawValue(raw); byte[] oidRaw = oid.getRawValue(); for (int i = 0; i < ObjectId.NUM_BYTES; i++) { assertEquals(oidRaw[i], raw[i]); } }
@Test public void testGetRawValue2() { byte bytes[] = new byte[] { (byte) 0xff, (byte) 0x68, (byte) 0xb7, (byte) 0x47, (byte) 0x66, (byte) 0xe2, (byte) 0x0c, (byte) 0xca, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ObjectId id1 = ObjectId.valueOf("ff68b74766e20cca000000000000000000000000"); byte bytes2[] = id1.getRawValue(); assertTrue(Arrays.equals(bytes, bytes2)); }