The following demonstrates how to use Java language to download random data from a SwiftRNG device when used with 64 bit Entropy Server for Windows. The following code will only work when running SwiftRNG Entropy Server. This is the recommended way for achieving maximum concurrent speed and performance. Before using the following examples make sure the SwiftRNG device is plugged into one of USB ports available.

A sample source code for retrieving an array of 10 random bytes from SwiftRNG device when using Entropy Server for Windows

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;

/**
 * 
 * A sample Java application that demonstrates how to connect to Entropy Server
 * in Windows for retrieving random bytes from SwiftRNG device.
 * 
 *
 */
public class TestSwiftRNGPipe {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RandomAccessFile pipe = null;
		try {
			// Connect to Entropy Server pipe
			pipe = new RandomAccessFile("\\\\.\\pipe\\SwiftRNG", "rw");
			// Send request to Entropy Server pipe to retrieve 10 random bytes
			pipe.write(createPipeRequest(10));
			// Read 10 random bytes from the response
			byte[] bytesToReceive = new byte[10];
			int retrievedCount = pipe.read(bytesToReceive);
			System.out.println("retrieved : " + retrievedCount
					+ " random bytes from entropy server: ");
			for (int i = 0; i < retrievedCount; i++) {
				System.out.println("random byte " + i + ": "
						+ bytesToReceive[i]);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (pipe != null) {
				try {
					pipe.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * Create a request for Entropy Server
	 * 
	 * @param byteCount
	 * @return
	 */
	private static byte[] createPipeRequest(int byteCount) {
		byte[] commandBytes = new byte[8];
		byte[] bytes = ByteBuffer.allocate(4).putInt(byteCount).array();
		int d = 4;
		for (int i = 3; i >= 0; i--) {
			commandBytes[d++] = bytes[i];
		}
		return commandBytes;
	}
}