使Xodus能够保存到Google Cloud Storage的必要步骤是什么?

时间:2018-09-11 06:32:27

标签: java xodus

Google云存储通过一组API提供云文件存储,例如:

上传 InputStream content = new ByteArrayInputStream("Hello, World!".getBytes(UTF_8)); Blob blob = bucket.create(blobName, content, "text/plain"); 下载: private void run(Storage storage, String bucketName, String objectName, Path downloadTo) throws IOException { BlobId blobId = BlobId.of(bucketName, objectName); Blob blob = storage.get(blobId); if (blob == null) { System.out.println("No such object"); return; } PrintStream writeTo = System.out; if (downloadTo != null) { writeTo = new PrintStream(new FileOutputStream(downloadTo.toFile())); } if (blob.getSize() < 1_000_000) { // Blob is small read all its content in one request byte[] content = blob.getContent(); writeTo.write(content); } else { // When Blob size is big or unknown use the blob's channel reader. try (ReadChannel reader = blob.reader()) { WritableByteChannel channel = Channels.newChannel(writeTo); ByteBuffer bytes = ByteBuffer.allocate(64 * 1024); while (reader.read(bytes) > 0) { bytes.flip(); channel.write(bytes); bytes.clear(); } } } if (downloadTo == null) { writeTo.println(); } else { writeTo.close(); } }

这可以用作Xodus存储器而不是本地文件系统吗?使Xodus在这种云环境中工作需要采取哪些步骤?

0 个答案:

没有答案