code: public static void writeToStream(BitMatrix matrix, String format, OutputStream stream, MatrixToImageConfig config) 
        throws IOException {  
      BufferedImage image = toBufferedImage(matrix, config);
      if (!ImageIO.write(image, format, stream)) {
        throw new IOException("Could not write an image of format " + format);
      }
    }
docs: As {@link #writeToStream(BitMatrix, String, OutputStream)}, but allows customization of the output.
  
  @param matrix {@link BitMatrix} to write
  @param format image format
  @param stream {@link OutputStream} to write image to
  @param config output configuration
  @throws IOException if writes to the stream fail