Retrologic Systems Retrologic Systems Retrologic Systems
RetroGuard for Java Obfuscation
  RetroGuard  |  CAPTCHA  |  Contracting  |  Resellers  |  Contact

Java Library Integration


Prev   Contents   Next

Java library access is available in RetroCapture Pro only.

RetroCapture can be accessed directly from your Java web-application as a library. Just include retrocapture.jar in the classpath when running your application. The currently accessible library methods are listed below:

  /** Create a new Capture generator with its default styles. */
  public Capture() throws Exception

  /** Load style definitions from this script file. */
  public void loadStyleFile(File scriptFile) throws Exception

  /** Generate a passphrase for this named style. */
  public String generatePassphrase(String styleName) throws IOException

  /** Generate a GIF capture image for this passphrase as a bytearray. */
  public byte[] generateImageBytes(String styleName, String passphrase) throws IOException

The class Example.java below shows how to access RetroCapture Pro as a library. Copy the example code to a file named Example.java, then compile:

    javac -cp retrocapture.jar Example.java

and run:

    java -cp retrocapture.jar:. Example

This example will generate a single RetroCapture image as example.gif and output the corresponding passphrase to stdout.

Example.java


/* 
 * RetroCapture -- example of how to generate a CAPTCHA GIF image as bytes.
 */

import com.retrologic.cap.Capture;
import java.io.File;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;

public class Example {

    public static void main(String[] args) throws Exception {

        // create a RetroCapture generator; it can be used to generate many images
        Capture capture = new Capture();

        // load some custom styles
        File styleFile = new File("mystyles.cap");
        capture.loadStyleFile(styleFile);

        // generate a suitable passphrase and use it to create an image
        String customStyle = "mystyle";
        String passphrase = capture.generatePassphrase(customStyle);
        byte[] gifImage = capture.generateImageBytes(customStyle, passphrase);

        // as a test, write the passphrase to stdout and write the image to file
        System.out.println(passphrase);
        OutputStream os = 
            new BufferedOutputStream(
                new FileOutputStream(
                    new File("example.gif")));
        os.write(gifImage);
        os.close();
    }
}

Prev   Contents   Next
 Copyright © 1998-2007 Retrologic Systems. retroguard | captcha | contracting | resellers | site map | contact
 All rights reserved. site terms | privacy policy