title: Stream decoding of Base64 data
body: <p>I have some large base64 encoded data (stored in snappy files in the hadoop filesystem).
  This data was originally gzipped text data.
  I need to be able to read chunks of this encoded data, decode it, and then flush it to a GZIPOutputStream. </p>
  
  <p>Any ideas on how I could do this instead of loading the whole base64 data into an array and calling Base64.decodeBase64(byte[]) ?</p>
  
  <p>Am I right if I read the characters till the '\r\n' delimiter and decode it line by line?
  e.g. :</p>
  
  <pre><code>for (int i = 0; i &lt; byteData.length; i++) {
      if (byteData[i] == CARRIAGE_RETURN || byteData[i] == NEWLINE) {
         if (i &lt; byteData.length - 1 &amp;&amp; byteData[i + 1] == NEWLINE)
              i += 2;
         else 
              i += 1;
  
         byteBuffer.put(Base64.decodeBase64(record));
  
         byteCounter = 0;
         record = new byte[8192];
      } else {
          record[byteCounter++] = byteData[i];
      }
  }
  </code></pre>
  
  <p>Sadly, this approach doesn't give any human readable output.
  Ideally, I would like to stream read, decode, and stream out the data.</p>
  
  <p>Right now, I'm trying to put in an inputstream and then copy to a gzipout</p>
  
  <pre><code>byteBuffer.get(bufferBytes);
  
  InputStream inputStream = new ByteArrayInputStream(bufferBytes);
  inputStream = new GZIPInputStream(inputStream);
  IOUtils.copy(inputStream , gzipOutputStream);
  </code></pre>
  
  <p>And it gives me a 
  java.io.IOException: Corrupt GZIP trailer</p>