本文整理汇总了Java中com.google.cloud.storage.Blob.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java Blob.getSize方法的具体用法?Java Blob.getSize怎么用?Java Blob.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.storage.Blob
的用法示例。
在下文中一共展示了Blob.getSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isBlobEligible
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
private boolean isBlobEligible(Blob blob, long minTimeStamp) {
String blobName = blob.getName();
String prefixToMatch = blobName.substring(
GcsUtil.normalizePrefix(gcsOriginConfig.commonPrefix).length(), blobName.length());
return blob.getSize() > 0 && blob.getUpdateTime() > minTimeStamp
&& antPathMatcher.match(gcsOriginConfig.prefixPattern, prefixToMatch);
}
示例2: get
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
@VisibleForTesting
void get(Blob blob, File file) throws IOException, TransferFailedException
{
final Resource resource = new Resource(blob.getName().substring(getBaseId().getName().length()));
final long size = blob.getSize();
try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
raf.setLength(size);
}
fireGetInitiated(resource, file);
try (
final ReadChannel readChannel = blob.reader();
final FileChannel fileChannel = FileChannel.open(
file.toPath(),
StandardOpenOption.WRITE,
StandardOpenOption.READ
);
) {
fireGetStarted(resource, file);
final ByteBuffer byteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size);
long readSize = 0;
long priorStart = 0;
do {
final int mySize = readChannel.read(byteBuffer);
if (mySize == -1) {
throw new TransferFailedException(String.format("Premature EOS after [%s] of [%s] bytes", readSize, size));
}
readSize += mySize;
if (priorStart != byteBuffer.position()) {
final ByteBuffer rob = byteBuffer.duplicate();
rob.position((int) priorStart).limit(byteBuffer.position());
final byte[] bytes = ByteBuffer
.allocate((int) (byteBuffer.position() - priorStart))
.put(rob)
.array();
final TransferEvent event = new TransferEvent(
this,
resource,
TransferEvent.TRANSFER_PROGRESS,
TransferEvent.REQUEST_GET
);
fireTransferProgress(event, bytes, bytes.length);
priorStart = byteBuffer.position();
}
} while (readSize < size);
fireGetCompleted(resource, file);
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("Fetched [%s] bytes for [%s]", readSize, blob));
}
}
}
示例3: doGetContentSize
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
/**
* Gets the size of the file content
*
* @return The file size
* @throws Exception
*/
@Override protected long doGetContentSize() throws Exception {
Blob blob = getBlob();
return blob != null ? blob.getSize() : 0;
}