2013年2月21日木曜日

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

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

翻訳元はこちらです。

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

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

第1回はこちら、第2回はこちら、第3回はこちら
第4回はこちら、第5回はこちら、第6回はこちら
第7回はこちら、第8回はこちら、第9回はこちら
第10回はこちら、第11回はこちら、第12回はこちら
第13回はこちらです。

Quotas and Limits - クォータと制限

Cloud Storageは、豊富な無料試用クォータを提供する従量制有料サービスです。無料クォータを超えた場合は、Cloud Storage料金表に基づいて課金されます。

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

2013年2月8日金曜日

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

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

翻訳元はこちらです。

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

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

第1回はこちら、第2回はこちら、第3回はこちら
第4回はこちら、第5回はこちら、第6回はこちら
第7回はこちら、第8回はこちら、第9回はこちら
第10回はこちら、第11回はこちら、第12回はこちらです。

  • アプリケーションをデプロイします。
    Eclipseから
    • EclipseのツールバーにあるGoogleアイコンをクリックします。
    • ドロップダウンメニューのDeploy to App Engineをクリックします。
    • App Engine project settings...をクリックします。
    • Application IDをダイアログのDeploymentセクションに入力して、OKボタンをクリックします。
    • メールアドレスとパスワードを入力して、Deployをクリックします。
    コマンドラインから: アプリケーションのコードとファイルをappcfg.cmd(Windows)またはappcfg.sh(Mac OS X,Linux)という名前のSDKに含まれているコマンドを使ってアップロードすることができます。 AppCfgは、App Engineのアプリケーション用の対話型多目的ツールです。コマンドは、アクション名、アプリケーションのwar/ディレクトリへのパス、その他のオプションを引数とします。App Engineにアプリケーションのコードをアップロードするには、アップデートアクションを使用します。 Windowsでアップロードを行うには:
    ..\appengine-java-sdk\bin\appcfg.cmd update war
    
    Mac OS XまたはLinuxでアップロードを行うには:
    ../appengine-java-sdk/bin/appcfg.sh update war
    
    Googleアカウントのユーザー名とパスワードをプロンプトに入力してください。
  • http://application-id.appspot.comでアプリケーションを参照してください。

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

2013年2月1日金曜日

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

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

翻訳元はこちらです。

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

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

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

  • 以下のコードでGuestbookServlet.javaのdoGet()メソッドを上書きして、BACKETNAMEとFILENAMEをあなたのバケット及びファイル名に書き換えます。
    /**
     * Copyright 2011 Google Inc. All Rights Reserved.
     * Create, Write, Read, and Finalize Cloud Storage objects.
     * Access your app at: http://myapp.appspot.com/
    **/
    
    @SuppressWarnings("serial")
    /**
     * Copyright 2011 Google Inc. All Rights Reserved.
     * Create, Write, Read, and Finalize Cloud Storage objects.
     * Access your app at: http://myapp.appspot.com/
    **/
    
    @SuppressWarnings("serial")
    public class GuestbookServlet extends HttpServlet {
       public static final String BUCKETNAME = "YOUR_BUCKET_NAME";
       public static final String FILENAME = "YOUR_FILE_NAME";
    
      @Override
      public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, world from java");
        FileService fileService = FileServiceFactory.getFileService();
        GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
           .setBucket(BUCKETNAME)
           .setKey(FILENAME)
           .setMimeType("text/html")
           .setAcl("public_read")
           .addUserMetadata("myfield1", "my field value");
        AppEngineFile writableFile =
             fileService.createNewGSFile(optionsBuilder.build());
        // Open a channel to write to it
         boolean lock = false;
         FileWriteChannel writeChannel =
             fileService.openWriteChannel(writableFile, lock);
         // Different standard Java ways of writing to the channel
         // are possible. Here we use a PrintWriter:
         PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
         out.println("The woods are lovely dark and deep.");
         out.println("But I have promises to keep.");
         // Close without finalizing and save the file path for writing later
         out.close();
         String path = writableFile.getFullPath();
         // Write more to the file in a separate request:
         writableFile = new AppEngineFile(path);
         // Lock the file because we intend to finalize it and
         // no one else should be able to edit it
         lock = true;
         writeChannel = fileService.openWriteChannel(writableFile, lock);
         // This time we write to the channel directly
         writeChannel.write(ByteBuffer.wrap
                   ("And miles to go before I sleep.".getBytes()));
    
         // Now finalize
         writeChannel.closeFinally();
         resp.getWriter().println("Done writing...");
    
         // At this point, the file is visible in App Engine as:
         // "/gs/BUCKETNAME/FILENAME"
         // and to anybody on the Internet through Cloud Storage as:
         // (http://storage.googleapis.com/BUCKETNAME/FILENAME)
         // We can now read the file through the API:
         String filename = "/gs/" + BUCKETNAME + "/" + FILENAME;
         AppEngineFile readableFile = new AppEngineFile(filename);
         FileReadChannel readChannel =
             fileService.openReadChannel(readableFile, false);
         // Again, different standard Java ways of reading from the channel.
         BufferedReader reader =
                 new BufferedReader(Channels.newReader(readChannel, "UTF8"));
         String line = reader.readLine();
         resp.getWriter().println("READ:" + line);
    
        // line = "The woods are lovely, dark, and deep."
         readChannel.close();
      }
    }
    

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