title: How to fetch the file list from gcs?
body: <p>Following google's <a href="https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/getstarted" rel="nofollow">Getting Started</a> I use following code to get the list of all files in a remote directory</p>
  
  <pre><code>class GCSFileStorage {
      String bucket = "bucket_name";
      String remoteDirectoryPath = "remote/path";
      int fetchBlockSize = 1024 * 1024;
      GcsService gcsService =
        GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
  
      List&lt;String&gt; list() {
          List&lt;String&gt; filenames = new List();
          ListResult listResult = gcsService.list(bucket, ListOptions.DEFAULT);
          while (listResult.hasNext()) {
              ListItem listItem = listResult.next();
              filenames += listItem.getName();
          }
          return filenames;
      }
  }
  
  GCSFileStorage gcs = new GCSFileStorage();
  gcs.list();
  </code></pre>
  
  <p>But this code fails with an exception:</p>
  
  <pre><code>java.io.IOException: com.google.appengine.tools.cloudstorage.RetriesExhaustedException:
  ...
  Caused by: java.io.IOException: java.lang.NullPointerException
  ...
  Caused by: java.lang.NullPointerException
      at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.&lt;init&gt;(LocalRawGcsService.java:123)
      at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.getInstance(LocalRawGcsService.java:184)
  </code></pre>
  
  <p>I suspect that I somehow should authorize in gcs and this may be the reason of failure. However I haven't found proper way to init everything that gcs needs for work.</p>