Examples of GcsOutputChannel


Examples of com.google.appengine.tools.cloudstorage.GcsOutputChannel

   * If the request path is /gcs/Foo/Bar this will be interpreted as
   * a request to create a GCS file named Bar in bucket Foo.
   */
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    GcsOutputChannel outputChannel =
        gcsService.createOrReplace(getFileName(req), GcsFileOptions.getDefaultInstance());
    copy(req.getInputStream(), Channels.newOutputStream(outputChannel));
  }
View Full Code Here

Examples of com.google.appengine.tools.cloudstorage.GcsOutputChannel

        .mimeType("text/html")
        .acl("public-read")
        .addUserMetadata("myfield1", "my field value")
        .build();

    GcsOutputChannel writeChannel = gcsService.createOrReplace(filename, options);
    PrintWriter writer = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
    writer.println("The woods are lovely dark and deep.");
    writer.println("But I have promises to keep.");
    writer.flush();

    writeChannel.waitForOutstandingWrites();

    writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes("UTF8")));

    writeChannel.close();
    resp.getWriter().println("Done writing...");


    GcsInputChannel readChannel = null;
    BufferedReader reader = null;
View Full Code Here

Examples of com.google.appengine.tools.cloudstorage.GcsOutputChannel

   *
   * Notice at the end closing the ObjectOutputStream is not done in a finally block.
   * See below for why.
   */
  private void writeObjectToFile(GcsFilename fileName, Object content) throws IOException {
    GcsOutputChannel outputChannel =
        gcsService.createOrReplace(fileName, GcsFileOptions.getDefaultInstance());
    @SuppressWarnings("resource")
    ObjectOutputStream oout =
        new ObjectOutputStream(Channels.newOutputStream(outputChannel));
    oout.writeObject(content);
View Full Code Here

Examples of com.google.appengine.tools.cloudstorage.GcsOutputChannel

   * finally.This is intentional. Because the file only exists for reading if close is called, if
   * there is an exception thrown while writing the file won't ever exist. (This way there is no
   * need to worry about cleaning up partly written files)
   */
  private void writeToFile(GcsFilename fileName, byte[] content) throws IOException {
    @SuppressWarnings("resource")
    GcsOutputChannel outputChannel =
        gcsService.createOrReplace(fileName, GcsFileOptions.getDefaultInstance());
    outputChannel.write(ByteBuffer.wrap(content));
    outputChannel.close();
  }
View Full Code Here

Examples of com.google.appengine.tools.cloudstorage.GcsOutputChannel

    em.close();
    RosieRecordsService rrs = new RosieRecordsService();
    GcsFilename filename = new GcsFilename(BUCKETNAME, "RosieConversion_" + (new Date()).toString());
    GcsFileOptions options = new GcsFileOptions.Builder().mimeType("text/html").acl("public-read").build();
        //.addUserMetadata("myfield1", "my field value").build();
    GcsOutputChannel writeChannel;
    try {
      writeChannel = gcsService.createOrReplace(filename, options);
      // You can write to the channel using the standard Java methods.
      // Here we use a PrintWriter:
      PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
      for (Long id_count = id_min; id_count <= id_max;  id_count++) {
        //write record value as a new line in Google Cloud Storage object
        rr = rrs.getRosieRecords(Long.valueOf(id_count));
        if (rr.getUsed() != 1) {
          log.info("writing out rosie record id: " + id_count);
          out.print(rr.getValue());
          out.flush();
          rrs.setRosieRecordsUsed(id_count);
        }
      }
      log.info("Done writing...");
      writeChannel.close();
    } catch (IOException e) {
      log.info("problem writing to GCS");
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of com.google.appengine.tools.cloudstorage.GcsOutputChannel

            .contentDisposition("Content-Disposition: attachment")
            .mimeType("text/html")
            .addUserMetadata("userKey", "UserMetadata")
            .build();

        GcsOutputChannel writeChannel = gcsService.createOrReplace(filename, option);
        try (PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"))) {
            out.println(CONTENT);
            out.flush();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.