![JAR search and dependency download from the Maven repository](/logo.png)
fr.w3blog.zpl.model.ZebraUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zebra-zpl Show documentation
Show all versions of zebra-zpl Show documentation
Java Api for Zepra Zpl generator
package fr.w3blog.zpl.model;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.List;
/**
* Utilities to print zpl
*
* @author ttropard
*
*/
public class ZebraUtils {
/**
* Function to print code Zpl
*
* @param zpl
* code Zpl to print
* @param ip
* ip adress
* @param port
* port
* @throws ZebraPrintException
* if zpl could not be printed
*/
public static void printZpl(String zpl, String ip, int port) throws ZebraPrintException {
Socket clientSocket = null;
try {
try {
clientSocket = new Socket(ip, port);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(zpl);
clientSocket.close();
} finally {
if (clientSocket != null) {
clientSocket.close();
}
}
} catch (IOException e1) {
throw new ZebraPrintException("Cannot print label on this printer : " + ip + ":" + port, e1);
}
}
/**
* Fonction to print zebraLabel
*
* @param zebraLabel
* zebraLabel
* @param ip
* ip adress
* @param port
* port
* @throws ZebraPrintException
* if zpl could not be printed
*/
public static void printZpl(ZebraLabel zebraLabel, String ip, int port) throws ZebraPrintException {
printZpl(zebraLabel.getZplCode(), ip, port);
}
/**
* Fonction to print zebraLabel
*
* @param zebraLabels
* list of zebra labels
* @param ip
* ip adress
* @param port
* port
* @throws ZebraPrintException
* if zpl could not be printed
*/
public static void printZpl(List zebraLabels, String ip, int port) throws ZebraPrintException {
StringBuilder zpl = new StringBuilder();
for (ZebraLabel zebraLabel : zebraLabels) {
zpl.append(zebraLabel.getZplCode());
}
printZpl(zpl.toString(), ip, port);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy