Package com.google.appengine.api.files

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


  private static AppEngineFile dump(@Nullable String mimeType, String downloadFilename,
      ByteBuffer bytes) throws IOException {
    bytes.rewind();
    AppEngineFile file = newBlob(mimeType, downloadFilename);
    FileWriteChannel out = getFileService().openWriteChannel(file, true);
    while (bytes.hasRemaining()) {
      out.write(bytes);
    }
    out.closeFinally();
    // Verify if what's in the file matches what we wanted to write -- the Files
    // API is still experimental and I've seen it misbehave.
    bytes.rewind();
    byte[] expected = getBytes(bytes);
    byte[] actual = slurp(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);
    blobSize = new BlobInfoFactory().loadBlobInfo(blobKey).getSize();
  }
View Full Code Here

  public long length() {
    return file.getLength();
  }

  private void writeAll() throws IOException {
    FileWriteChannel writer = file.openWriteChannel();
    ByteBuffer toWrite = ByteBuffer.wrap(bytes);
    writer.write(toWrite);
    writer.closeFinally();
  }
View Full Code Here

    public static AppEngineFile withWriter(AppEngineFile file , Map<String, Object> options, Closure<?> closure) throws FileNotFoundException, FinalizationException, LockException, IOException {
        boolean locked = isLocked(options);
        boolean closeFinally = isFinalize(options);
        String encoding = (String) (options.containsKey("encoding") ? options.get("encoding") : "UTF-8");

        FileWriteChannel writeChannel = FileServiceFactory.getFileService().openWriteChannel(file, locked);
        PrintWriter writer = new PrintWriter(Channels.newWriter(writeChannel, encoding));

        IOGroovyMethods.withWriter(writer, closure);

        if (closeFinally) {
            writeChannel.closeFinally();
        } else {
            writeChannel.close();
        }

        return file;
    }
View Full Code Here

     */
    public static AppEngineFile withOutputStream(AppEngineFile file, Map<String, Object> options, Closure<?> closure) throws FileNotFoundException, FinalizationException, LockException, IOException {
        boolean locked = isLocked(options);
        boolean closeFinally = isFinalize(options);

        FileWriteChannel writeChannel = FileServiceFactory.getFileService().openWriteChannel(file, locked);
        OutputStream stream = Channels.newOutputStream(writeChannel);

        IOGroovyMethods.withStream(stream, closure);

        if (closeFinally) {
            writeChannel.closeFinally();
        } else {
            writeChannel.close();
        }

        return file;
    }
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();
    if (blobKey != null)
      try {
        deleteBlobKey(blobKey);
      } catch (IOException e) {
        // some error in deleting blob, google app issue
View Full Code Here

    Image newImage = imagesService.applyTransform(crop, oldImage);
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("image/jpg");
    byte[] data = newImage.getImageData();

    FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
    // This time we write to the channel directly
    writeChannel.write(ByteBuffer.wrap(data));
    // Now finalize
    writeChannel.closeFinally();
    //if(blobKey !=null) //delete the existing blob first -- GOT ERROR here....
    //    blobstoreService.delete(blobKey);
    // Now read from the file using the Blobstore API
    blobKey = fileService.getBlobKey(file);
    String[] json = {blobKey.getKeyString()};
View Full Code Here

  //======================HELPER METHODS==================================
  private String createImage() throws IOException, FileNotFoundException,
      FinalizationException, LockException {
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("text/plain");
    FileWriteChannel writeChannel = fileService
        .openWriteChannel(file, true);
    PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel,
        "UTF8"));
    out.println("Hello");
    out.close();
    writeChannel.closeFinally();

    BlobKey bk = fileService.getBlobKey(file);
    String imageKeyStr = bk.getKeyString();
    return imageKeyStr;
  }
View Full Code Here

  }

  public BlobKey writeJpegImage(byte[] bytes) throws IOException{
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("image/jpeg");
    FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
    OutputStream out = (Channels.newOutputStream(writeChannel));
    out.write(bytes);
    out.close();
    writeChannel.closeFinally();
   
    return fileService.getBlobKey(file);
  }
View Full Code Here

  }
  private BlobKey persistBlob() throws IOException, FileNotFoundException,
      FinalizationException, LockException {
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("image/jpeg");
    FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
    PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
    out.println("Hello");
    out.close();
    writeChannel.closeFinally();
   
    BlobKey bk = fileService.getBlobKey(file);
    return bk;
  }
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.