title: Remove Base64 prefix from InputStream
body: <p>I have a Base64 encoded Image String residing in a File Server. The encoded String has a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs" rel="nofollow">prefix</a> (ex: "data:image/png;base64,") for support in popular modern browsers (it's obtained via JavaScript's <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL" rel="nofollow">Canvas.toDataURL() method</a>). The client sends a request for the image to my server which verifies them and returns a stream of the Base64 encoded String. </p>
  
  <p>If the client is a web client, the image can be displayed as is within an <code>&lt;img&gt;</code> tag by setting the <code>src</code> to the Base64 encoded String. However, if the client is an Android client, the String needs to be decoded into a Bitmap without the prefix. Though, this can be done fairly easily.</p>
  
  <p><strong>The Problem:</strong>
  In order to simplify my code and not reinvent the wheel, I'm using an Image Library for the Android client to handle loading, displaying, and caching the images (Facebook's <a href="https://github.com/facebook/fresco" rel="nofollow">Fresco Library</a> to be exact). However, no library seems to support Base64 decoding (I want my cake and to eat it too). A solution I came up with is to decode the Base64 String on the server as it is being streamed to the client.</p>
  
  <p><strong>The Attempt:</strong></p>
  
  <pre><code>S3Object obj = s3Client.getObject(new GetObjectRequest(bucketName, keyName));
  Base64.Decoder decoder = Base64.getDecoder();
  //decodes the stream as it is being read
  InputStream stream = decoder.wrap(obj.getObjectContent());
  try{
      return new StreamingOutput(){
          @Override
          public void write(OutputStream output) throws IOException, WebApplicationException{
              int nextByte = 0;
              while((nextByte = stream.read()) != -1){
                  output.write(nextByte);
              }
              output.flush();
              output.close();
              stream.close();
          }
      };
  }catch(Exception e){
      e.printStackTrace();
  } 
  </code></pre>
  
  <p>Unfortunately, the Fresco library still has a problem displaying the image (with no stack traces!). As there doesn't seem to be an issue on my server when decoding the stream (no stack traces either), it leads me to believe that it must be an issue with the prefix. Which leaves me with a dilemma.</p>
  
  <p><strong>The Question:</strong> How do I remove the Base64 prefix from a Stream being sent to the client without storing and editing the entire Stream on the server? Is this possible?</p>