Package com.google.appengine.api.files

Examples of com.google.appengine.api.files.FileService.openWriteChannel()


  protected void createFile(String record, int recordsCount)
      throws IOException, FileNotFoundException, FinalizationException, LockException {
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile blobFile = fileService.createNewBlobFile("application/bin");
    FileWriteChannel writeChannel = fileService.openWriteChannel(blobFile, true);
    for (int i = 0; i < recordsCount; i++) {
      writeChannel.write(ByteBuffer.wrap(record.getBytes()));
    }
    writeChannel.closeFinally();
    blobKey = fileService.getBlobKey(blobFile);
View Full Code Here


    }

    AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());

    boolean lockForWrite = true; // We want to lock it, because we are going to call closeFinally in the end
    return fileService.openWriteChannel(writableFile, lockForWrite);
  }

  /* ======== ID Generation ========= */

  private static final Random random = new Random(asLong(SecureRandom.getSeed(8)));
View Full Code Here

    // Create a new Blob file with mime-type "image/png"
    AppEngineFile file = fileService.createNewBlobFile("image/jpeg");// png

    // Open a channel to write to it
    boolean lock = true;
    FileWriteChannel writeChannel = fileService
        .openWriteChannel(file, lock);

    // This time we write to the channel directly
    writeChannel.write(ByteBuffer.wrap(imageData.getBytes()));
View Full Code Here

    FileService fileService = FileServiceFactory.getFileService();
    // Create a new Blob file with mime-type "text/plain"
    AppEngineFile file = fileService.createNewBlobFile(contentType, fileName);
    // Open a channel to write to it
    boolean lock = true;
    FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
    // Different standard Java ways of writing to the channel
    // are possible. Here we use a PrintWriter:
    writeChannel.write(ByteBuffer.wrap(content));
    // Now finalize
    writeChannel.closeFinally();
View Full Code Here

    try {
      fetchResponse = fetchService.fetch(new URL(url));
      Image originalImage = ImagesServiceFactory.makeImage(fetchResponse.getContent());

      AppEngineFile file = fileService.createNewBlobFile("image/" + originalImage.getFormat());
      FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
      ByteBuffer buffer = ByteBuffer.wrap(originalImage.getImageData());
      writeChannel.write(buffer);
      writeChannel.closeFinally();
      BlobKey key = fileService.getBlobKey(file);
      String servingURL = imagesService.getServingUrl(key);
View Full Code Here

      FileService fileService = FileServiceFactory.getFileService();
      // TODO : make mimetype configurable by user
      AppEngineFile file = fileService.createNewBlobFile("text/plain", fileName);
     
      // Open a channel to write to it
      FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
      writeChannel.write(ByteBuffer.wrap(rawData));     
      writeChannel.closeFinally();
     
      logger.info("Uploaded file name : " + fileName + " path : " + file.getFullPath() + " with size = " + rawData.length);
     
View Full Code Here

        AppEngineFile file =
            fileService.createNewBlobFile(
                "text/tab-separated-values",
                minutes.getTitle());
        FileWriteChannel writeChannel =
            fileService.openWriteChannel(file, true);
        PrintWriter writer =
            new PrintWriter(Channels.newWriter(writeChannel, "utf-8"));
        List<Memo> list = MemoService.list(minutes.getKey());
        for (Memo memo : list) {
            writer.print("\"");
View Full Code Here

        FileService fileService = FileServiceFactory.getFileService();
        AppEngineFile file =
            fileService
                .createNewBlobFile("images/gif", testImageFile.getName());
        FileWriteChannel writeChannel =
            fileService.openWriteChannel(file, true);
        OutputStream output = Channels.newOutputStream(writeChannel);
        output.write(imageBytes);
        output.close();
        writeChannel.closeFinally();
        BlobKey blobKey = fileService.getBlobKey(file);
View Full Code Here

    super.setUp();
    helper.setUp();

    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile blobFile = fileService.createNewBlobFile("application/bin");
    FileWriteChannel writeChannel = fileService.openWriteChannel(blobFile, true);
    for (int i = 0; i < RECORDS_COUNT; i++) {
      writeChannel.write(ByteBuffer.wrap(RECORD.getBytes()));
    }
    writeChannel.closeFinally();
    blobKey = fileService.getBlobKey(blobFile);
View Full Code Here

  private BlobKey getBlobKeyImage(BlobKey blobKey, byte[] data)
      throws IOException {
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("image/jpg");

    FileWriteChannel writeChannel = fileService
        .openWriteChannel(file, true);
    // This time we write to the channel directly
    writeChannel.write(ByteBuffer.wrap(data));
    // Now finalize
    writeChannel.closeFinally();
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.