Package com.google.appengine.api.files

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


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


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

      blobstoreService.serve(blobKey, range, response);
   }

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

    return getFileService().createNewBlobFile(MIME_TYPE, abbrev(fileDescription));
  }

  private static byte[] slurp(BlobKey blobKey) throws IOException {
    FileReadChannel in = getFileService().openReadChannel(
        new AppEngineFile(AppEngineFile.FileSystem.BLOBSTORE, blobKey.getKeyString()),
        false);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteBuffer buf = ByteBuffer.allocate(BUFFER_BYTES);
    while (true) {
      int bytesRead = in.read(buf);
View Full Code Here

      throw new IOException("Failed to get blob key for " + finalizedBlobFile, e);
    }
  }

  private BlobKey dump(String fileDescription, byte[] bytes) throws IOException {
    AppEngineFile file = newFile(fileDescription);
    OutputStream out = openForFinalWrite(file);
    out.write(bytes);
    out.close();
    BlobKey blobKey = getBlobKey(file);
    // We verify if what's in the file matches what we wanted to write -- the
View Full Code Here

  }

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

                byte[] bytes = response.getContent();
                if (expectedBytes != null) {
                  Assert.check(expectedBytes == bytes.length, "Expected %s bytes, got %s: %s",
                      expectedBytes, bytes.length, prettyBytes(bytes));
                }
                final AppEngineFile file = dump(mimeType, filename, ByteBuffer.wrap(bytes));
                log.info("Wrote file " + file);
                BlobKey blobKey =
                    // NOTE(ohler): When running locally with unapplied jobs
                    // enabled, getBlobKey() sometimes returns null here even
                    // though it shouldn't, according to its documentation.  So
View Full Code Here

  private BlobKey findBlob(String keyOrFilePath) {
    BlobKey candidateKey;
    if (keyOrFilePath.startsWith("/blobstore/")) {
      candidateKey = FileServiceFactory.getFileService()
          .getBlobKey(new AppEngineFile(keyOrFilePath));
    } else {
      candidateKey = new BlobKey(keyOrFilePath);
    }
    if (new BlobInfoFactory().loadBlobInfo(candidateKey) != null) {
      return candidateKey;
View Full Code Here

  // TODO(ohler): Find out if the Files API already has a way to do this.
  public static AppEngineFile getReadHandle(AppEngineFile file) {
    if (file.getFileSystem() == AppEngineFile.FileSystem.BLOBSTORE) {
      // TODO(ohler): Replace FileServiceImpl.getBlobFile() with this, or
      // understand why all the other work it's doing is needed.
      return new AppEngineFile(file.getFileSystem(), getBlobKey(file).getKeyString());
    } else {
      // TODO(ohler): Figure out what needs to happen for bigstore files.
      return file;
    }
  }
View Full Code Here

              assertEquals(6, files.size());
              for (String file : files) {
                ByteBuffer buf = ByteBuffer.allocate(8);
                FileReadChannel ch =
                    FileServiceFactory.getFileService().openReadChannel(
                        new AppEngineFile(file), false);
                assertEquals(8, ch.read(buf));
                assertEquals(-1, ch.read(ByteBuffer.allocate(1)));
                ch.close();
                buf.flip();
                assertTrue(expected.remove(Marshallers.getLongMarshaller().fromBytes(buf)));
View Full Code Here

TOP

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

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.