本文整理了Java中com.google.cloud.storage.Blob.reader()
方法的一些代码示例,展示了Blob.reader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.reader()
方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:reader
[英]Returns a ReadChannel object for reading this blob's content.
Example of reading the blob's content through a reader.
try (ReadChannel reader = blob.reader()) }
}
Example of reading just a portion of the blob's content.
int start = 1;}
[中]返回用于读取此blob内容的ReadChannel对象。
通过读取器读取blob内容的示例。
try (ReadChannel reader = blob.reader()) }
}
仅读取blob内容的一部分的示例。
int start = 1;}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of reading the blob's content through a reader. */
// [TARGET reader(BlobSourceOption...)]
public void reader() throws IOException {
// [START reader]
try (ReadChannel reader = blob.reader()) {
ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);
while (reader.read(bytes) > 0) {
bytes.flip();
// do something with bytes
bytes.clear();
}
}
// [END reader]
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of reading just a portion of the blob's content. */
// [TARGET reader(BlobSourceOption...)]
// [VARIABLE 1]
// [VARIABLE 8]
public byte[] readContentRange(int start, int end) throws IOException {
// [START readContentRange]
try (ReadChannel reader = blob.reader()) {
reader.seek(start);
ByteBuffer bytes = ByteBuffer.allocate(end - start);
reader.read(bytes);
return bytes.array();
}
// [END readContentRange]
}
代码示例来源:origin: googleapis/google-cloud-java
/**
* Downloads this blob to the given file path using specified blob read options.
*
* @param path destination
* @param options blob read options
* @throws StorageException upon failure
*/
public void downloadTo(Path path, BlobSourceOption... options) {
try (OutputStream outputStream = Files.newOutputStream(path);
ReadChannel reader = reader(options)) {
WritableByteChannel channel = Channels.newChannel(outputStream);
ByteBuffer bytes = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE);
while (reader.read(bytes) > 0) {
bytes.flip();
channel.write(bytes);
bytes.clear();
}
} catch (IOException e) {
throw new StorageException(e);
}
}
代码示例来源:origin: google/data-transfer-project
InputStream getStream(UUID jobId, String keyName) {
String blobName = getDataKeyName(jobId, keyName);
Blob blob = bucket.get(blobName);
ReadChannel channel = blob.reader();
return Channels.newInputStream(channel);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testReader() throws Exception {
initializeExpectedBlob(2);
ReadChannel channel = createMock(ReadChannel.class);
expect(storage.getOptions()).andReturn(mockOptions);
expect(storage.reader(BLOB_INFO.getBlobId())).andReturn(channel);
replay(storage);
initializeBlob();
assertSame(channel, blob.reader());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testReaderWithDecryptionKey() throws Exception {
initializeExpectedBlob(2);
ReadChannel channel = createMock(ReadChannel.class);
expect(storage.getOptions()).andReturn(mockOptions);
expect(
storage.reader(
BLOB_INFO.getBlobId(), Storage.BlobSourceOption.decryptionKey(BASE64_KEY)))
.andReturn(channel)
.times(2);
replay(storage);
initializeBlob();
assertSame(channel, blob.reader(BlobSourceOption.decryptionKey(BASE64_KEY)));
assertSame(channel, blob.reader(BlobSourceOption.decryptionKey(KEY)));
}
代码示例来源:origin: com.google.cloud/google-cloud-storage
/**
* Downloads this blob to the given file path using specified blob read options.
*
* @param path destination
* @param options blob read options
* @throws StorageException upon failure
*/
public void downloadTo(Path path, BlobSourceOption... options) {
try (OutputStream outputStream = Files.newOutputStream(path);
ReadChannel reader = reader(options)) {
WritableByteChannel channel = Channels.newChannel(outputStream);
ByteBuffer bytes = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE);
while (reader.read(bytes) > 0) {
bytes.flip();
channel.write(bytes);
bytes.clear();
}
} catch (IOException e) {
throw new StorageException(e);
}
}
代码示例来源:origin: spring-cloud/spring-cloud-gcp
@Override
public InputStream getInputStream() throws IOException {
if (isBucket()) {
throw new IllegalStateException("Cannot open an input stream to a bucket: '" + this.location + "'");
}
else {
return Channels.newInputStream(throwExceptionForNullBlob(getBlob()).reader());
}
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-storage
@Override
public InputStream getInputStream() throws IOException {
if (isBucket()) {
throw new IllegalStateException("Cannot open an input stream to a bucket: '" + this.location + "'");
}
else {
return Channels.newInputStream(throwExceptionForNullBlob(getBlob()).reader());
}
}
代码示例来源:origin: ai.h2o/h2o-persist-gcs
final Blob blob = storageProvider.getStorage().get(gcsBlob.getBlobId());
return new InputStream() {
final ReadChannel reader = blob.reader();
内容来源于网络,如有侵权,请联系作者删除!