Package com.google.appengine.api.files

Examples of com.google.appengine.api.files.FileWriteChannel


  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);
    blobSize = new BlobInfoFactory().loadBlobInfo(blobKey).getSize();
  }
View Full Code Here


    }
  }
 
  private static void saveBlob(String blobName, String contentType, byte[] data) throws IOException {
    log.info("saving blob " + blobName);
    FileWriteChannel blobChannel = newBlobChannel(blobName, contentType);
   
    OutputStream ostream = Channels.newOutputStream(blobChannel);
    ostream.write(data);
    ostream.flush();
    blobChannel.closeFinally();
  }
View Full Code Here

  public void setObject(String bucketName, String fileName, byte[] data) throws IOException {
    setObject(bucketName, fileName, getMimeType(fileName), DEFAULT_ACL, DEFAULT_CACHE, data, DEFAULT_ENCODING);
  }
 
  public void setObject(String bucketName, String fileName, String mimeType, String permission, String cacheControl, byte[] data, String encoding) throws IOException {
    FileWriteChannel writeChannel = null;
   
    try{
      writeChannel = createWritableFile(bucketName,fileName,mimeType,permission,cacheControl);
      writeChannel.write(ByteBuffer.wrap(data), encoding);
    } catch (IOException e) {
      logger.warning("IOException: " + e);
      e.printStackTrace();
      throw e;
    } finally {
      try {
        if(writeChannel != null && writeChannel.isOpen()) writeChannel.closeFinally();
      } catch (IllegalStateException e) {
        logger.warning("IllegalStateException: " + e);
      } catch (IOException e) {
        logger.warning("IOException: " + e);
      }
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()));

    // Now finalize
    writeChannel.closeFinally();
    return fileService.getBlobKey(file);
  }
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();
    BlobKey key = fileService.getBlobKey(file);
    return key.getKeyString();
  }
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);
      if (servingURL != null) {
        this.url = servingURL;
      }
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);
     
      // step 3 : send result back to client
      BlobUploadResult result = AutoBeanUtil.newBlobUploadResult(Status.SUCCESS, fileName, rawData.length);
View Full Code Here

        FileService fileService = FileServiceFactory.getFileService();
        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("\"");
            writer.print(memo.getCreatedAt());
            writer.print("\"");
            writer.print("\t");
            writer.print("\"");
            writer.print(memo.getAuthor().getEmail());
            writer.print("\"");
            writer.print("\t");
            writer.print("\"");
            writer.print(memo.getMemo());
            writer.print("\"");
            writer.println();
        }
        writer.close();
        writeChannel.closeFinally();
        return fileService.getBlobKey(file);
    }
View Full Code Here

        input.close();
        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);
        // test@example.com というユーザがログイン中、という状態を作っておく。
        TestEnvironment environment =
            (TestEnvironment) ApiProxy.getCurrentEnvironment();
        environment.setEmail("test@example.com");
View Full Code Here

   }

   protected String storeBytesInternal(String mimeType, byte[] bytes) throws IOException
   {
      AppEngineFile file = fileService.createNewBlobFile(mimeType);
      FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
      try
      {
         writeChannel.write(ByteBuffer.wrap(bytes));
      }
      finally
      {
         writeChannel.closeFinally();
      }
      BlobKey blobKey = fileService.getBlobKey(file);
      return blobKey.getKeyString();
   }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.files.FileWriteChannel

Copyright © 2018 www.massapicom. 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.