protected void markInUse() throws IOException { for (String id : new ArrayList<String>(inUse.keySet())) { mark(id); } }
/** * Set the referenceKey from Base64 encoded byte array * @param encodedKey base64 encoded key */ public void setReferenceKeyEncoded(String encodedKey) { setReferenceKey(BaseEncoding.base64().decode(encodedKey)); }
@Override public boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception { return (chunkIds.size() == countDeleteChunks(chunkIds, maxLastModifiedTime)); }
@Override public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws IOException { if (isMarkEnabled()) { mark(blobId); } else { if (level > 0) { byte[] block = readBlock(digest, 0); idStream = new ByteArrayInputStream(block); } else { long readPos = pos - pos % blockSize; byte[] block = readBlock(digest, readPos); ByteArrayInputStream in = new ByteArrayInputStream(block); IOUtils.skipFully(in, pos - readPos);
@Override public long getBlobLength(String blobId) throws IOException { if (isMarkEnabled()) { mark(blobId);
@Override public String writeBlob(InputStream in) throws IOException { try { ByteArrayOutputStream idStream = new ByteArrayOutputStream(); convertBlobToId(in, idStream, 0, 0); byte[] id = idStream.toByteArray(); // System.out.println(" write blob " + StringUtils.convertBytesToHex(id)); String blobId = StringUtils.convertBytesToHex(id); usesBlobId(blobId); statsCollector.uploadCompleted(blobId); return blobId; } finally { try { in.close(); } catch (IOException e) { // ignore } } }
storeBlock(digest, level, Arrays.copyOf(block, blockLen)); statsCollector.uploaded(System.nanoTime() - start, TimeUnit.NANOSECONDS, blockLen); convertBlobToId(new ByteArrayInputStream(idBlock), idStream, level + 1, totalLength); count = 1; convertBlobToId(new ByteArrayInputStream(idBlock), idStream, level + 1, totalLength);
/** * Returns the reference key of this data store. Synchronized to * control concurrent access to the cached {@link #referenceKey} value. * * @return reference key */ private synchronized byte[] getReferenceKey() { if (referenceKey == null) { referenceKey = getOrCreateReferenceKey(); } return referenceKey; }
byte[] readBlock(byte[] digest, long pos) { BlockId id = new BlockId(digest, pos); return load(id).data; }
@Override public String getBlobId(@NotNull String reference) { checkNotNull(reference, "BlobId must be specified"); int colon = reference.indexOf(':'); if (colon != -1) { String blobId = reference.substring(0, colon); if (reference.equals(getReference(blobId))) { return blobId; } log.debug("Possibly invalid reference as blobId does not match {}", reference); } return null; }
@Override public String getReference(@NotNull String blobId) { checkNotNull(blobId, "BlobId must be specified"); try { Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); byte[] hash = mac.doFinal(blobId.getBytes("UTF-8")); return blobId + ':' + BaseEncoding.base32Hex().encode(hash); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } catch (InvalidKeyException e) { throw new IllegalStateException(e); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
if (level > 0) { queue.add(StringUtils.convertBytesToHex(digest)); byte[] block = readBlock(digest, 0); idStream = new ByteArrayInputStream(block); streamsStack.push(idStream);
@Override public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws IOException { if (isMarkEnabled()) { mark(blobId); } else { if (level > 0) { byte[] block = readBlock(digest, 0); idStream = new ByteArrayInputStream(block); } else { long readPos = pos - pos % blockSize; byte[] block = readBlock(digest, readPos); ByteArrayInputStream in = new ByteArrayInputStream(block); IOUtils.skipFully(in, pos - readPos);
@Override public long getBlobLength(String blobId) throws IOException { if (isMarkEnabled()) { mark(blobId);
@Override public String writeBlob(InputStream in) throws IOException { try { ByteArrayOutputStream idStream = new ByteArrayOutputStream(); convertBlobToId(in, idStream, 0, 0); byte[] id = idStream.toByteArray(); // System.out.println(" write blob " + StringUtils.convertBytesToHex(id)); String blobId = StringUtils.convertBytesToHex(id); usesBlobId(blobId); statsCollector.uploadCompleted(blobId); return blobId; } finally { try { in.close(); } catch (IOException e) { // ignore } } }
storeBlock(digest, level, Arrays.copyOf(block, blockLen)); statsCollector.uploaded(System.nanoTime() - start, TimeUnit.NANOSECONDS, blockLen); convertBlobToId(new ByteArrayInputStream(idBlock), idStream, level + 1, totalLength); count = 1; convertBlobToId(new ByteArrayInputStream(idBlock), idStream, level + 1, totalLength);
/** * Returns the reference key of this data store. Synchronized to * control concurrent access to the cached {@link #referenceKey} value. * * @return reference key */ private synchronized byte[] getReferenceKey() { if (referenceKey == null) { referenceKey = getOrCreateReferenceKey(); } return referenceKey; }
byte[] readBlock(byte[] digest, long pos) { BlockId id = new BlockId(digest, pos); return load(id).data; }