/** * Returns the {@link Blob} with the given blobId. * * @param blobId the blobId of the blob. * @return the blob. */ public Blob getBlobFromBlobId(String blobId){ return new BlobStoreBlob(blobStore, blobId); }
@Override public String serialize(Blob blob) { if (blob instanceof BlobStoreBlob) { BlobStoreBlob bsb = (BlobStoreBlob) blob; BlobStore bsbBlobStore = bsb.getBlobStore(); //see if the blob has been created from another store if (bsbBlobStore != null && bsbBlobStore.equals(blobStore)) { return bsb.getBlobId(); } } String id; String reference = blob.getReference(); if(reference != null){ id = blobStore.getBlobId(reference); if(id != null){ return id; } } try { id = createBlob(blob.getNewStream()).getBlobId(); } catch (IOException e) { throw new IllegalStateException(e); } return id; } };
@Override public void collectReferences(ReferenceCollector collector) { int referencesFound = 0; Iterator<ReferencedBlob> blobIterator = null; try { blobIterator = nodeStore.getReferencedBlobsIterator(); while (blobIterator.hasNext()) { ReferencedBlob refBlob = blobIterator.next(); Blob blob = refBlob.getBlob(); referencesFound++; // TODO this mode would also add in memory blobId // Would that be an issue if (blob instanceof BlobStoreBlob) { collector.addReference(((BlobStoreBlob) blob).getBlobId(), refBlob.getId()); } else { // TODO Should not rely on toString. Instead obtain // secure reference and convert that to blobId using // blobStore collector.addReference(blob.toString(), refBlob.getId()); } } } finally { Utils.closeIfCloseable(blobIterator); } log.debug("Total blob references found (including chunk resolution) [{}]", referencesFound); } }
@Override public void collectReferences(ReferenceCollector collector) { int referencesFound = 0; Iterator<ReferencedBlob> blobIterator = null; try { blobIterator = nodeStore.getReferencedBlobsIterator(); while (blobIterator.hasNext()) { ReferencedBlob refBlob = blobIterator.next(); Blob blob = refBlob.getBlob(); referencesFound++; // TODO this mode would also add in memory blobId // Would that be an issue if (blob instanceof BlobStoreBlob) { collector.addReference(((BlobStoreBlob) blob).getBlobId(), refBlob.getId()); } else { // TODO Should not rely on toString. Instead obtain // secure reference and convert that to blobId using // blobStore collector.addReference(blob.toString(), refBlob.getId()); } } } finally { Utils.closeIfCloseable(blobIterator); } log.debug("Total blob references found (including chunk resolution) [{}]", referencesFound); } }
/** * Returns the {@link Blob} with the given blobId. * * @param blobId the blobId of the blob. * @return the blob. */ public Blob getBlobFromBlobId(String blobId){ return new BlobStoreBlob(blobStore, blobId); }
@Override public String serialize(Blob blob) { if (blob instanceof BlobStoreBlob) { BlobStoreBlob bsb = (BlobStoreBlob) blob; BlobStore bsbBlobStore = bsb.getBlobStore(); //see if the blob has been created from another store if (bsbBlobStore != null && bsbBlobStore.equals(blobStore)) { return bsb.getBlobId(); } } String id; String reference = blob.getReference(); if(reference != null){ id = blobStore.getBlobId(reference); if(id != null){ return id; } } try { id = createBlob(blob.getNewStream()).getBlobId(); } catch (IOException e) { throw new IllegalStateException(e); } return id; } };
private Blob getBlob(String blobId) { if (blobStore != null) { return new BlobStoreBlob(blobStore, blobId); } throw new IllegalStateException("Attempt to read external blob with blobId [" + blobId + "] " + "without specifying BlobStore"); }
@Override public Blob deserialize(String value) { if (value.startsWith(PREFIX)) { return base64.deserialize(value.substring(PREFIX.length())); } return new BlobStoreBlob(blobStore, value); }
@Override public Blob deserialize(String value) { if (value.startsWith(PREFIX)) { return base64.deserialize(value.substring(PREFIX.length())); } return new BlobStoreBlob(blobStore, value); }
@Override public Blob deserialize(String value) { if (value.startsWith(PREFIX)) { return base64.deserialize(value.substring(PREFIX.length())); } return new BlobStoreBlob(blobStore, value); }
@Override @NotNull public BlobStoreBlob createBlob(InputStream inputStream) throws IOException { return new BlobStoreBlob(blobStore, blobStore.writeBlob(inputStream)); }
@Override @NotNull public BlobStoreBlob createBlob(InputStream inputStream) throws IOException { return new BlobStoreBlob(blobStore, blobStore.writeBlob(inputStream)); }
/** * Returns the {@link Blob} with the given reference. Note that this method is meant to * be used with secure reference obtained from Blob#reference which is different from blobId * * @param reference the reference of the blob. * @return the blob. */ @Override public Blob getBlob(@NotNull String reference) { String blobId = blobStore.getBlobId(reference); if(blobId != null){ return new BlobStoreBlob(blobStore, blobId); } LOG.debug("No blobId found matching reference [{}]", reference); return null; }
@Override public Blob getBlob(@NotNull String reference) { //Use of 'reference' here is bit overloaded. In terms of NodeStore API //a blob reference refers to the secure reference obtained from Blob#getReference() //However in SegmentStore terminology a blob is referred via 'external reference' //That 'external reference' would map to blobId obtained from BlobStore#getBlobId if (blobStore != null) { String blobId = blobStore.getBlobId(reference); if (blobId != null) { return new BlobStoreBlob(blobStore, blobId); } return null; } throw new IllegalStateException("Attempt to read external blob with blobId [" + reference + "] " + "without specifying BlobStore"); }
/** * Returns the {@link Blob} with the given reference. Note that this method is meant to * be used with secure reference obtained from Blob#reference which is different from blobId * * @param reference the reference of the blob. * @return the blob. */ @Override public Blob getBlob(@NotNull String reference) { String blobId = blobStore.getBlobId(reference); if(blobId != null){ return new BlobStoreBlob(blobStore, blobId); } LOG.debug("No blobId found matching reference [{}]", reference); return null; }
@Override public Blob deserialize(String value) { if (errorBlob(value)){ return new ErrorBlob(value); } return new BlobStoreBlob(dataStore, value); }
@Nullable @Override public Blob completeBlobUpload(@NotNull String uploadToken) throws IllegalArgumentException { if (delegate instanceof DataRecordAccessProvider) { try { DataRecord record = ((DataRecordAccessProvider) delegate).completeDataRecordUpload(uploadToken); return new BlobStoreBlob(this, record.getIdentifier().toString()); } catch (DataStoreException | DataRecordUploadException e) { log.warn("Unable to complete direct upload for upload token {}", uploadToken, e); } } return null; }
@Override public Blob deserialize(String value) { if (errorBlob(value)){ return new ErrorBlob(value); } return new BlobStoreBlob(dataStore, value); }
@Override public Blob deserialize(String value) { if (errorBlob(value)){ return new ErrorBlob(value); } return new BlobStoreBlob(dataStore, value); }
@Nullable @Override public Blob completeBlobUpload(@NotNull String uploadToken) throws IllegalArgumentException { if (delegate instanceof DataRecordAccessProvider) { try { DataRecord record = ((DataRecordAccessProvider) delegate).completeDataRecordUpload(uploadToken); return new BlobStoreBlob(this, record.getIdentifier().toString()); } catch (DataStoreException | DataRecordUploadException e) { log.warn("Unable to complete direct upload for upload token {}", uploadToken, e); } } return null; }