code: public void write(String data) throws IOException {
          if (!open) {
              throw new IllegalStateException("Stream has already been closed.");
          }
  
          String buffer = pattern.matcher(residual + data).replaceAll("");
          int usableLength = buffer.length() - buffer.length() % 4;
          stream.write(Base64.decode((buffer.substring(0, usableLength))));
          residual = buffer.substring(usableLength);
      }
docs: Add Base64-encoded characters to be decoded. This is not a trivial
  operation for two reasons: any characters that are not valid for
  Base64-encoding must be ignored, and we can only decode groups of 4
  characters. So, when data is received, we remove any invalid characters
  and then strip off any trailing characters that don't fit in the
  4-character groups. Those trailing characters will be prefixed to the
  next set of data, and hopefully we will have none left over when the
  writer is closed.
  
  @throws IllegalStateException
  if called after close().
  @throws IOException
  from the inner OutputStream.