Interface CaptchaRenderer

All Known Implementing Classes:
AudioCaptchaRenderer, Base64CaptchaRenderer, GifCaptchaRenderer, ImageCaptchaRenderer

public interface CaptchaRenderer
Captcha Renderer - Interface for CAPTCHA rendering 验证码渲染器 - 验证码渲染接口

This interface defines the contract for rendering CAPTCHAs to various outputs.

此接口定义了将验证码渲染到各种输出的契约。

Features | 主要功能:

  • Multiple output format support - 多种输出格式支持
  • Stream-based rendering - 基于流的渲染

Usage Examples | 使用示例:

CaptchaRenderer renderer = new ImageCaptchaRenderer();
renderer.render(captcha, outputStream);

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No (captcha and stream must not be null) - 空值安全: 否(验证码和流不能为null)
Since:
JDK 25, opencode-base-captcha V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • render

      void render(Captcha captcha, OutputStream out) throws IOException
      Renders the CAPTCHA to an output stream. 将验证码渲染到输出流。
      Parameters:
      captcha - the CAPTCHA | 验证码
      out - the output stream | 输出流
      Throws:
      IOException - if rendering fails | 如果渲染失败
    • renderToBytes

      byte[] renderToBytes(Captcha captcha)
      Renders the CAPTCHA to a byte array. 将验证码渲染到字节数组。
      Parameters:
      captcha - the CAPTCHA | 验证码
      Returns:
      the rendered bytes | 渲染的字节
    • renderToBase64

      String renderToBase64(Captcha captcha)
      Renders the CAPTCHA to a Base64 string. 将验证码渲染到 Base64 字符串。
      Parameters:
      captcha - the CAPTCHA | 验证码
      Returns:
      the Base64 string | Base64 字符串
    • getContentType

      String getContentType()
      Gets the content type of the rendered output. 获取渲染输出的内容类型。
      Returns:
      the content type | 内容类型
    • image

      static CaptchaRenderer image()
      Creates an image renderer. 创建图像渲染器。
      Returns:
      the renderer | 渲染器
    • gif

      static CaptchaRenderer gif()
      Creates a GIF renderer. 创建 GIF 渲染器。
      Returns:
      the renderer | 渲染器
    • base64

      static CaptchaRenderer base64()
      Creates a Base64 renderer. 创建 Base64 渲染器。
      Returns:
      the renderer | 渲染器
    • audio

      static CaptchaRenderer audio()
      Creates an audio renderer. 创建音频渲染器。
      Returns:
      the renderer | 渲染器