@Override public byte[] generateCaptchaImage(String captchaKey) throws AccountCaptchaException { String text = captchaMap.get(captchaKey); if (text == null) { throw new AccountCaptchaException("Captch key" + captchaKey + " not found!"); } BufferedImage image = producer.createImage(text); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(image, "jpg", out); } catch (IOException e) { throw new AccountCaptchaException("Failed to write captcha stream!", e); } return out.toByteArray(); }