Package com.google.appengine.api.files

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


  }

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


        .build(), new Verifier<List<AppEngineFile>>() {
      @Override
      public void verify(MapReduceResult<List<AppEngineFile>> result) throws Exception {
        assertEquals(1, result.getOutputResult().size());
        assertEquals(10, result.getCounters().getCounter(CounterNames.MAPPER_CALLS).getValue());
        AppEngineFile file = result.getOutputResult().get(0);
        FileReadChannel ch = FileServiceFactory.getFileService().openReadChannel(file, false);
        BufferedReader reader =
            new BufferedReader(Channels.newReader(ch, US_ASCII.newDecoder(), -1));
        String line = reader.readLine();
        List<String> strings = Arrays.asList(line.split(","));
View Full Code Here

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

      .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

    logger.info("deleting " + strKeys.size() + " blobs...");

    List<AppEngineFile> files = new ArrayList<AppEngineFile>();
    for (String key : strKeys) {
      // also delete the Google Cloud Storage file (if exists)
      files.add(new AppEngineFile("/gs/cl-test-grid-logs/" + key));
    }
    // TODO: spawn multiple threads to speed-up blob deletion
    fileService.delete(files.toArray(new AppEngineFile[files.size()]));
  }
View Full Code Here

      return;
    }

    final String key = req.getParameter("key");
    String filename = "/gs/cl-test-grid-logs/" + key;
    AppEngineFile file = new AppEngineFile(filename);
    FileReadChannel readChannel = null;
    InputStream inputStream = null;
    try {
      final boolean lock = false;
      readChannel = FileServiceFactory.getFileService().openReadChannel(file, lock);
View Full Code Here

    return createWritableFile( bucketName, fileName,  getMimeType(fileName), DEFAULT_ACL, DEFAULT_CACHE);
  }
 
  public FileWriteChannel createWritableFile(String bucketName, String fileName, String mimeType, String permission, String cacheControl) throws IOException {
    GSFileOptionsBuilder optionsBuilder = null;
    AppEngineFile writableFile = null;
    String path = null;
   
    if(Utils.isEmpty(bucketName)||Utils.isEmpty(fileName)){
      logger.warning("bucketName : " + bucketName + " fileName : " + fileName);
      throw new IOException("Invalid Bucket or File name!");
    }
   
    optionsBuilder = new GSFileOptionsBuilder();
    optionsBuilder.setBucket(bucketName);
    optionsBuilder.setKey(fileName);
    optionsBuilder.setMimeType(mimeType);
    optionsBuilder.setAcl(permission);
    optionsBuilder.setCacheControl(cacheControl);
     
    writableFile = this.fileService.createNewGSFile(optionsBuilder.build());
    path = writableFile.getFullPath();
    writableFile = new AppEngineFile(path);
    //logger.info(path+" isWritable:"+writableFile.isWritable());
    return fileService.openWriteChannel(writableFile, true);
  }
View Full Code Here

 
  public byte[] getObject(String bucketName, String filename)
  { 
    byte[] data = new byte [16384]; //switch to dynamic array
    boolean lockForRead = false;
    AppEngineFile readableFile = new AppEngineFile("/gs/"+bucketName+filename);
   
    FileReadChannel readChannel;
    try {
      readChannel = fileService.openReadChannel(readableFile, lockForRead);
      DataInputStream reader = new DataInputStream(Channels.newInputStream(readChannel));
View Full Code Here

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

    e.setUnindexedProperty(FILE_LENGTH_PROP, stats.getLength());
    DATASTORE.put(null, e);
  }

  private AppEngineFile nameToAppEngineFile(GcsFilename filename) {
    return new AppEngineFile(
        AppEngineFile.FileSystem.GS, filename.getBucketName() + "/" + filename.getObjectName());
  }
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.