Package com.google.appengine.api.files

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


      @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(","));
        assertEquals(10, strings.size());
View Full Code Here


    }

    public InputStream getInputStream() throws IOException {
      if (file == null)
        return null;
      FileReadChannel channel = fileService.openReadChannel(file, false);
      return Channels.newInputStream(channel);
    }
View Full Code Here

    }

    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);
      inputStream = Channels.newInputStream(readChannel);
View Full Code Here

 
    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));
      reader.readFully(data);
      readChannel.close();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (LockException e) {
      // TODO Auto-generated catch block
View Full Code Here

            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

    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

  private static AppEngineFile newFile(String fileDescription) throws IOException {
    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);
      if (bytesRead < 0) {
        break;
      }
      Preconditions.checkState(bytesRead != 0, "0 bytes read: %s", buf);
      out.write(buf.array(), 0, bytesRead);
View Full Code Here

      throws IOException {
    return getFileService().createNewBlobFile(mimeType, downloadFilename);
  }

  private static byte[] slurp(AppEngineFile file) throws IOException {
    FileReadChannel in = getFileService().openReadChannel(file, false);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteBuffer buf = ByteBuffer.allocate(BUFFER_BYTES);
    while (true) {
      buf.clear();
      int bytesRead = in.read(buf);
      if (bytesRead < 0) {
        break;
      }
      out.write(buf.array(), 0, bytesRead);
    }
View Full Code Here

            assertEquals(1, outputResult.size());
            for (List<String> files : outputResult) {
              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)));
              }
            }
            assertTrue(expected.isEmpty());
View Full Code Here

     * @throws FileNotFoundException
     */
    public static AppEngineFile withReader(AppEngineFile file, Map<String, Object> options, Closure<?> closure) throws FileNotFoundException, LockException, IOException {
        String encoding = (String) (options.containsKey("encoding") ? options.get("encoding") : "UTF-8");

        FileReadChannel readChannel = FileServiceFactory.getFileService().openReadChannel(file, isLocked(options));
        BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, encoding));

        IOGroovyMethods.withReader(reader, closure);
        readChannel.close();

        return file;
    }
View Full Code Here

TOP

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

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.