title: How to download a file from Google Cloud Storage with Java?
body: <p>I'm developping an application that provides users with an interface where they can download files from our Google Cloud Storage. I wrote unit tests and I could connect to the storage and a file was downloaded. </p>
  
  <p>Now that I'm (almost) finished with my interface, I wanted to test the whole application. But now I notice I don't really download the file, I download a file with META data about the file I want to download. Something like:</p>
  
  <pre><code>{
   "kind": "storage#object",
   "id": "xxxxxxxxxxx/Homer.png/xxxxxxxxxxxx",
   "selfLink": "https://www.googleapis.com/storage/xxxxxxxxxxxxxxxx/Homer.png",
   "name": "Homer.png",
   "bucket": "xxxxxxxxxxxxxxx",
   "generation": "xxxxxxxxxxxxxxx",
   "metageneration": "1",
   "contentType": "image/png",
   "updated": "2014-07-17T08:37:28.026Z",
   "storageClass": "STANDARD",
   "size": "xxxxx",
   "md5Hash": "xxxxxxxxxxxxxxxxxxxxx",
   "mediaLink": "https://www.googleapis.com/download/storage/xxxxxxxxxxxxxxx/o/Homer.png?generation=xxxxxxxxxxxxxxxxx&amp;alt=media",
   "owner": {
    "entity": "user-xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "entityId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
   },
   "crc32c": "xxxxxxxxxx",
   "etag": "xxxxxxxxxxxxx"
  }
  </code></pre>
  
  <p>I'm wondering what I'm doing wrong, this is the code I'm using to download the file:</p>
  
  <pre><code>public byte[] getFileAsByteArray(String bucketName, String fileName)
          throws GoogleAppManagerException {
          Storage storage = null;
          try {
              storage = getStorage();
          } catch (GeneralSecurityException e) {
              throw new GoogleAppManagerException(SECURITY_EXCEPTION + e.getStackTrace(), e);
          } catch (IOException e) {
              throw new GoogleAppManagerException(IO_EXCEPTION + e.getStackTrace(), e);
          }
          Get get = null;
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          try {
              get = storage.objects().get(bucketName, fileName);
              get.executeAndDownloadTo(outputStream);
          } catch (IOException e1) {
              throw new GoogleAppManagerException(IO_EXCEPTION + e1.getStackTrace(), e1);
          }
          return outputStream.toByteArray();
      }
  </code></pre>