Package com.google.appengine.api.files

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


    }
    long length;
    if (entity.getProperty(FILE_LENGTH_PROP) != null) {
      length = (Long) entity.getProperty(FILE_LENGTH_PROP);
    } else {
      AppEngineFile file = nameToAppEngineFile(filename);
      length = FILES.stat(file).getLength();
    }
    return new GcsFileMetadata(filename, options, null, length, creationTime);
  }
View Full Code Here


      if (offset >= meta.getLength()) {
        return Futures.immediateFailedFuture(new BadRangeException(
            "The requested range cannot be satisfied. bytes=" + Long.toString(offset) + "-"
            + Long.toString(offset + dst.remaining()) + " the file is only " + meta.getLength()));
      }
      AppEngineFile file = nameToAppEngineFile(filename);
      try (FileReadChannel readChannel = FILES.openReadChannel(file, false)) {
        readChannel.position(offset);
        int read = 0;
        while (read != -1 && dst.hasRemaining()) {
          read = readChannel.read(dst);
View Full Code Here

      GcsFilename sourceFileName = new GcsFilename(dest.getBucketName(), filename);
      GcsFileMetadata meta = getObjectMetadata(sourceFileName, timeoutMillis);
      if (meta == null) {
        throw new FileNotFoundException(this + ": No such file: " + filename);
      }
      AppEngineFile file = nameToAppEngineFile(sourceFileName);
      try (FileReadChannel readChannel = FILES.openReadChannel(file, false)) {
        readChannel.position(0);
        while (readChannel.read(chunk) != -1) {
          chunk.flip();
          token = append(token, chunk);
View Full Code Here

    if (meta == null) {
      throw new FileNotFoundException(this + ": No such file: " + source);
    }
    ByteBuffer chunk = ByteBuffer.allocate(1024);
    Token token = beginObjectCreation(dest, GcsFileOptions.getDefaultInstance(), timeoutMillis);
    AppEngineFile file = nameToAppEngineFile(source);
    try (FileReadChannel readChannel = FILES.openReadChannel(file, false)) {
      readChannel.position(0);
      while (readChannel.read(chunk) != -1) {
        chunk.flip();
        token = append(token, chunk);
View Full Code Here

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

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

    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

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

      }
     
      // 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);
     
      // step 3 : send result back to client
      BlobUploadResult result = AutoBeanUtil.newBlobUploadResult(Status.SUCCESS, fileName, rawData.length);
      resultStr = AutoBeanUtil.encode(BlobUploadResult.class, result);
    } catch (FileUploadException e) {
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.