Package com.google.appengine.api.files

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


  @Override
  public void setUp() throws Exception {
    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


  }

  /* to store and return the blobkey */
  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
      }
    // Now read from the file using the Blobstore API
    return (BlobKey) fileService.getBlobKey(file);
  }
View Full Code Here

    BlobKey blobKey = new BlobKey(strBlobKey);
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
    Transform crop = ImagesServiceFactory.makeCrop(dblX1, dblY1, dblX2, dblY2);
    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()};
    jsonRet = new Gson().toJson(json);
    res.setContentType("application/json");
    res.setCharacterEncoding("utf-8");
    res.getWriter().write(jsonRet);
View Full Code Here

    assertFalse(json.contains("three"));
  }
  //======================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

    entity.setProperty(blobField, null);
    save(entity);
  }

  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

        AppEngineFile file = getAppEngineFile(blobKey);
        return getFileContents(file);
    }

    private AppEngineFile getAppEngineFile(BlobKey blobKey) {
        FileService fileService = FileServiceFactory.getFileService();
        return fileService.getBlobFile(blobKey);
    }
View Full Code Here

            .addClass(UploadHandlerServlet.class)
            .addClass(BlobserviceServeServlet.class);
    }

    protected BlobKey writeNewBlobFile(String text) throws IOException {
        FileService fileService = FileServiceFactory.getFileService();
        AppEngineFile file = fileService.createNewBlobFile("text/plain", "uploadedText.txt");
        FileWriteChannel channel = fileService.openWriteChannel(file, true);
        try {
            channel.write(ByteBuffer.wrap(text.getBytes()));
        } finally {
            channel.closeFinally();
        }
        return fileService.getBlobKey(file);
    }
View Full Code Here

            Key key = ds.put(entity);

            entity = ds.get(key);
            log.info(entity.toString());

            FileService fs = FileServiceFactory.getFileService();
            AppEngineFile file = fs.createNewBlobFile("qwertfile");
            FileWriteChannel fwc = fs.openWriteChannel(file, false);
            try {
                log.info("b_l = " + fwc.write(ByteBuffer.wrap("qwert".getBytes())));
            } finally {
                fwc.close();
            }
View Full Code Here

TOP

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

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.