Package com.ccc.barcode
Class CameraServer
java.lang.Object
com.ccc.barcode.CameraServer
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
QueueCameraServer
This server will pull in images and barcodes from all cameras
configured in client mode.
Below is a simple server for displaying barcodes from scans.
public class BarcodePrintCameraServer extends CameraServer {
public BarcodePrintCameraServer(InetSocketAddress address, ConnectionList connectionList) throws IOException {
super(address);
}
@Override
protected void onMessage(CameraConnection connection, CameraScanResult result) {
System.out.println(result.getBarcode());
}
}
It's also easy to save images. Below is a server that saves scan images to a temporary directory as bitmap files.
public class ImageSaveCameraServer extends CameraServer {
private Path targetDirectory;
public ImageSaveCameraServer(InetSocketAddress address, ConnectionList connectionList) throws IOException {
super(address);
targetDirectory = Files.createTempDirectory("barcode-sink");
}
@Override
protected void onMessage(CameraConnection connection, CameraScanResult result) {
try {
Path target = Files.createTempFile(targetDirectory, null, ".bmp");
String writerName = "BMP";
boolean isWriter = ImageIO.write(result.getImage(), writerName, target.toFile());
if (!isWriter) {
System.out.println("Could not use writer: " + writerName);
return;
}
System.out.println("Saved image to file: " + target);
} catch (IOException e) {
System.out.println("Could not print file: " + e);
}
}
}
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCameraServer(InetSocketAddress address) Construct a server that will listen on the given address. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidonConnect(CameraInfo connection) Called every time a new camera connects.protected voidonDisconnect(CameraInfo connection) Called every time a camera disconnects.protected voidonMessage(CameraInfo connection, CameraScanResult result) Called every time a camera receives a message.voidrun()Starts the server.
-
Field Details
-
address
-
-
Constructor Details
-
CameraServer
Construct a server that will listen on the given address.
-
-
Method Details
-
onConnect
Called every time a new camera connects.- Parameters:
connection- Information on the camera.
-
onDisconnect
Called every time a camera disconnects.- Parameters:
connection- Information on the camera.
-
onMessage
Called every time a camera receives a message.- Parameters:
connection- Information on the camera.result- Information from the scan.
-
run
public void run()Starts the server. This can be called directly, but a developer can run it in the background as a thread.// Listen for camera on port 8080. Thread cameraServerThread = new Thread(new CameraServer(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 8080))); cameraServerThread.start();
-