2013年1月4日金曜日

Google Cloud Storageのドキュメント - Java API概要 その8

Google Cloud StorageのJava APIの概要についての
ドキュメントを翻訳しています。

翻訳元はこちらです。

このドキュメントは、Google App Engineアプリケーションから
Google Cloud Storageの機能を呼び出す方法について
説明しています。

現在は試験的運用中なので、今後変更があるかもしれません。

第1回はこちら、第2回はこちら、第3回はこちら
第4回はこちら、第5回はこちら、第6回はこちら
第7回はこちらです。

Opening and Writing to the Object - オブジェクトのオープン及び書き込み

オブジェクトに書き込むためには、書き込みチャネルをオープンしなければなりません:
// Open a channel for writing
boolean lockForWrite = false; // Do you want to exclusively lock this object?
FileWriteChannel writeChannel = fileService.openWriteChannel(writableFile, lockForWrite);

次に、標準的なJavaの方法を使ってオブジェクトに書き込むことができます:
// For this example, we write to the object using the PrintWriter
PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
out.println("The woods are lovely and deep.");
out.println("But I have promises too keep.");

// Close the object without finalizing.
out.close();

/**
 * You can write to this file again, later, by saving the file path.
 * It is not possible to read the file until you finalize it.
 * Once you finalize a file, it is not possible to write to it.
 */

// Save the file path
String path = writableFile.getFullPath();

// Lock the file so no one else can access it at the same time
lockForWrite = true;

// Write to the unfinalized file again in a separate request
writableFile = new AppEngineFile(path);
writeChannel = fileService.openWriteChannel(writableFile, lockForWrite);
writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes()));

インストール不要・無料のKaede翻訳ツール:
http://kaedetrans-hrd.appspot.com/

0 件のコメント:

コメントを投稿