Package com.google.appengine.api.files

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


    super.tearDown();
  }

  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


    ostream.flush();
    blobChannel.closeFinally();
  }

  private static FileWriteChannel newBlobChannel(String blobName, String contentType) throws IOException {
    FileService fileService = FileServiceFactory.getFileService();

    GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
      .setBucket("cl-test-grid-logs")
      .setKey(blobName)
      .setAcl("public-read")
      .setContentEncoding("gzip");
    if (contentType != null) {
      optionsBuilder.setMimeType(contentType);
    }

    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);
  }
View Full Code Here

  public BlobKey toBlobstore(Blob imageData) throws IOException {
    if (null == imageData)
      return null;

    // Get a file service
    FileService fileService = FileServiceFactory.getFileService();

    // 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

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        if (blobKeys != null && blobKeys.size() > 0) {
          for (BlobKey blobKey : blobKeys) {
            b = blobService.fetchData(blobKey, 0, 20);
            if (b.length > 0) {
              FileService fileService = FileServiceFactory
                  .getFileService();
              AppEngineFile file = fileService
                  .getBlobFile(blobKey);
              FileReadChannel readChannel = fileService
                  .openReadChannel(file, false);
              InputStream is = Channels
                  .newInputStream(readChannel);
              int nRead;
              byte[] buffer = new byte[10240];
View Full Code Here

public class GAEFileService {
 
  public static String createFile(String contentType, String fileName, byte[] content)
      throws FileNotFoundException, FinalizationException, LockException, IOException {
    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

    BlobInfoFactory infoFactory = new BlobInfoFactory();
    BlobKey blobKey = new BlobKey(key);
    BlobInfo blobInfo = infoFactory.loadBlobInfo(blobKey);
    if(blobInfo==null) notFound();
    response.setContentTypeIfNotSet(blobInfo.getContentType());
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.getBlobFile(blobKey);
    boolean lock = false;
    FileReadChannel readChannel = fileService.openReadChannel(file, lock);
    InputStream inputStream = Channels.newInputStream(readChannel);
    renderBinary(inputStream);
  }
View Full Code Here

  /**
   * @param url the url to set
   */
  public void setUrl(String url) {
    URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
    FileService fileService = FileServiceFactory.getFileService();
    ImagesService imagesService = ImagesServiceFactory.getImagesService();

    HTTPResponse fetchResponse;
    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;
      }
      else {
View Full Code Here

          stream.close();
        }
      }
     
      // step 2 : save file into blobstore
      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

        Datastore.delete(deleteKeyList);
        Datastore.delete(minutesKey);
    }

    public static BlobKey exportAsTSV(Minutes minutes) throws IOException {
        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

        byte[] imageBytes = new byte[(int) testImageFile.length()];
        DataInputStream input =
            new DataInputStream(new FileInputStream(testImageFile));
        input.readFully(imageBytes);
        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");
        int beforeCount = tester.count(Profile.class);
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.