use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-blobstore-google-cloud by sonatype-nexus-community.
the class GoogleCloudBlobStore method doCreate.
@Override
protected Blob doCreate(final InputStream blobData, final Map<String, String> headers, @Nullable final BlobId blobId) {
return createInternal(headers, destination -> {
try (InputStream data = blobData) {
MetricsInputStream input = new MetricsInputStream(data);
uploader.upload(storage, getConfiguredBucketName(), destination, input);
return input.getMetrics();
}
}, blobId);
}
use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-public by sonatype.
the class S3BlobStore method doCreate.
@Override
@Timed
@MonitoringBlobStoreMetrics(operationType = UPLOAD)
protected Blob doCreate(final InputStream blobData, final Map<String, String> headers, @Nullable final BlobId blobId) {
return create(headers, destination -> {
try (InputStream data = blobData) {
MetricsInputStream input = new MetricsInputStream(data);
uploader.upload(s3, getConfiguredBucket(), destination, input);
return input.getMetrics();
}
}, blobId);
}
use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-public by sonatype.
the class FileBlobStoreConcurrencyIT method readContentAndValidateMetrics.
/**
* Read all the content from a blob, and compare it with the metrics on file in the blob store.
*
* @throws RuntimeException if there is any deviation
*/
private void readContentAndValidateMetrics(final BlobId blobId, final InputStream inputStream, final BlobMetrics metadataMetrics) throws NoSuchAlgorithmException, IOException {
final MetricsInputStream measured = new MetricsInputStream(inputStream);
ByteStreams.copy(measured, nullOutputStream());
checkEqual("stream length", metadataMetrics.getContentSize(), measured.getSize(), blobId);
checkEqual("SHA1 hash", metadataMetrics.getSha1Hash(), measured.getMessageDigest(), blobId);
}
use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-public by sonatype.
the class SimpleFileOperations method create.
@Override
public StreamMetrics create(final Path path, final InputStream data) throws IOException {
checkNotNull(path);
checkNotNull(data);
// Ensure path exists for new blob
Path dir = path.getParent();
checkNotNull(dir, "Null parent for path: %s", path);
DirectoryHelper.mkdir(dir);
final MetricsInputStream input = new MetricsInputStream(data);
try {
try (final OutputStream output = Files.newOutputStream(path, StandardOpenOption.CREATE_NEW)) {
ByteStreams.copy(input, output);
}
} finally {
// FIXME: Revisit closing stream which is passed in as parameter, this should be the responsibility of the caller
data.close();
}
return input.getMetrics();
}
Aggregations