Qishu Archives
A shared entry for product documents, interface references, engineering notes, and release-ready delivery records.
Java SDK
NIB SDK integration guide for Java, Android, network printing, and Bluetooth printing.
The Java SDK is suitable for Android applications, JVM tools, network printers, and classic Bluetooth connections. During integration, first wrap the real connection as a Device, then let templates build a Script or send bytes directly through the write pipeline.
Maven modules
Section titled “Maven modules”The Maven group is com.boxliy.nib.
| Module | Purpose |
|---|---|
nib |
Standard aggregate edition, suitable for product integration. |
nib-core |
Device, Script, WritePipeline, receive sources, and query dispatch. |
nib-esc-boxliy, nib-tspl-boxliy, nib-cpcl-boxliy |
Boxliy dialect builders and response parsers. |
nib-esc, nib-tspl, nib-cpcl |
Aryten-compatible dialects. |
nib-esc-lin8inch, nib-tspl-lin8inch |
Lin8inch dialects. |
nib-network |
TCP/IP network printer connection. |
nib-bluetooth |
Java classic Bluetooth abstraction. |
| Android classic adapter | Android classic Bluetooth adapter source exists in the repository. Whether it is delivered as an independent module depends on the actual delivery version. |
No confirmed Java BLE module was found in the source. If Android BLE is required, confirm it from the delivery version or project adapter layer, and do not infer BLE support from the classic Bluetooth module.
Core objects
Section titled “Core objects”Device is the minimal device contract:
public interface Device { String name(); boolean connected(); void write(byte[] data) throws IOException; byte[] read(int timeoutMs) throws IOException; void close() throws IOException;}Script stores built bytes and provides binary(), hex(), base64(), string(), and length(). WritePipeline handles chunked writes. WriteOptions configures ChunkPolicy, WriteMode, cancellation, timeout, and backpressure, and returns WriteResult.
The default chunk size comes from NibDefaults.CHUNK_SIZE, currently 1024 bytes.
First print
Section titled “First print”Java EscBoxliy does not have a text() method. Use raw(...) for normal text:
import com.boxliy.nib.core.Device;import com.boxliy.nib.esc.EscBoxliy;
Device device = Device.none();
EscBoxliy.of(device) .reset() .raw("NIB SDK\r\n") .feed(2) .write();Device.none() is suitable for testing script generation and does not connect to a real printer. In real projects, pass in a Device returned by a network, classic Bluetooth, or Android classic connection.
When you need to build a script before writing:
import com.boxliy.nib.core.WriteOptions;import com.boxliy.nib.core.WritePipeline;import com.boxliy.nib.core.WriteResult;import com.boxliy.nib.tspl.TsplAryten;
byte[] data = TsplAryten.of() .size(40, 30) .cls() .text(20, 20, "NIB SDK") .print(1) .build() .binary();
WriteResult result = WritePipeline.write( device, data, WriteOptions.defaults(), null);Network printing
Section titled “Network printing”nib-network provides Network.connect(...):
import com.boxliy.nib.core.Device;import com.boxliy.nib.network.Network;
Device device = Network.connect("192.168.1.50", 9100);The default connection timeout is 10000 ms. You can also call Network.connect(host, port, timeoutMs). Before network printing, confirm host, port, timeout, retry, and logging strategy. Logs can record endpoints and byte lengths, but should not record sensitive print content.
Android and classic Bluetooth
Section titled “Android and classic Bluetooth”The Java repository confirms nib-bluetooth and includes Android classic adapter source. Android classic integration usually needs to:
- Request Bluetooth permissions according to the Android version.
- Scan for or select a paired device.
- Establish a classic Bluetooth socket.
- Wrap it as a
Device. - Generate a
Scriptwith a dialect builder. - Send it through builder
write()orWritePipeline.write(...). - Close the connection when the page is destroyed or the session ends.
Do not put permissions, lifecycle, or reconnect logic inside print templates.
Receiving, querying, and parsing
Section titled “Receiving, querying, and parsing”Core provides ReceiveSource, PollingReceiveSource, CallbackReceiveSource, ReceiveListener, QueryDispatcher, PendingQuery, and ResponseMatcher.
Boxliy dialect parser names:
| Dialect | Parser |
|---|---|
| ESC | EscResponseParser |
| TSPL | TsplResponseParser |
| CPCL | CpclResponseParser |
Queries such as status, battery, model, and serial number should be handled centrally in the session layer, with reasonable timeouts for the device firmware.
Methods and Commands
The tables below list the public entry points integration teams usually need. Builder methods generate printer commands; actual availability still depends on the ESC, TSPL, CPCL, or Lin8inch command family supported by the target firmware.
Core, Connection, and Writing
| Object | Method / Command | Purpose | Parameters |
|---|---|---|---|
Device / Script | name(), connected(), write(data), read(timeoutMs), close(), binary(), hex(), base64(), string(), length() | Abstracts the real printer connection for templates, write pipelines, and query handling. | `timeoutMs` is the read timeout; `Script` is used to inspect or store built bytes. |
WritePipeline / WriteOptions | write(device, data, options, listener), withChunkPolicy(), withMode(), withCancellationToken(), withTimeout(), withBackpressure() | Writes built bytes to a device with chunking, timeout, cancellation, and flow-control rules. | `ChunkPolicy.fixed(size)` controls chunking; listener receives `WriteProgress`; returns `WriteResult`. |
PrinterDiscovery / PrinterConnector | scan(), stop(), connect(printer, options), disconnect(), state() | Scans, connects, and disconnects printers so platform connections can be unified under NIB core. | `ConnectionOptions` contains transport, timeoutMs, and autoReconnect. |
ReceiveSource / QueryDispatcher | start(listener), stop(), accept(data), receive(data), query(matcher, timeoutMs), cancel(), shutdown() | Routes device responses into listeners or query dispatchers for status, battery, model, and similar queries. | `ResponseMatcher` returns a matched result; `PendingQuery` can `get()` with or without timeout. |
Command Builders
| Object | Method / Command | Purpose | Parameters |
|---|---|---|---|
EscBoxliy / EscAryten | of(), newLine(), location(), image(), line(), cut(), feed(), lineRow(), lineDot(), backLineDot(), enable(), wakeup(), position(), stopJob(), setBTType(), lineDotCut(), thickness(), learnLabelGap(), paperType(), batteryVolume(), info(), model(), version(), printerVersion(), sn(), state(), status(), name(), mac(), reset(), raw(), imageGray(), build(), write(), clear() | Builds ESC/Boxliy commands for receipt, portable, and ESC-compatible printers. | `of` accepts device/charset; `raw` accepts a template and args; `write(chunkSize, progress)` writes directly. |
TsplBoxliy / TsplAryten | of(), size(), gap(), bline(), continuous(), label(), direction(), codePage(), speed(), density(), reference(), offset(), shift(), gapSensor(), ribbon(), cut(), tear(), peel(), detect(), readState(), status(), state(), realtimeStatus(), sn(), sns(), version(), versions(), model(), models(), batteryVolume(), cls(), text(), barcode(), qrcode(), dmatrix(), line(), box(), circle(), ellipse(), image(), print(), raw(), build(), write(), clear() | Builds TSPL label commands for templates with paper size, coordinates, barcodes, and QR codes. | Coordinates and sizes are ints; enums include Direction, Mirror, CodePage, Font, Rotation, BarcodeType, and QrLevel. |
CpclBoxliy / CpclAryten | of(), begin(), pageWidth(), feed(), gapSense(), barSense(), paperType(), text(), barcode(), qrcode(), line(), box(), bold(), underline(), waterMark(), inverseLine(), image(), form(), print(), status(), realtimeStatus(), sn(), model(), version(), batteryVolume(), raw(), build(), write(), clear() | Builds CPCL label commands for page setup, text, lines, barcodes, and images. | Page, text, barcode, QR, line, box, and image parameters follow CPCL commands; `PaperType` controls gap/bar sensing. |
EscLin8inch | of(), batteryLevel(), extendedModel(), bootVersion(), advancedDensity(), advancedDensityStatus(), grayMode(), mediaProfile(), mediaProfileStatus(), wirelessProvisioning(), wirelessProvisioningStatus(), compressedRasterTransport(), mediaTag(), mediaTagUid(), consumedMediaLength(), remainingMediaLength(), restoreLabelStartPosition(), alternateMotionProfile() | Adds Lin8inch telemetry, media, provisioning, and raster transport commands on top of ESC. | Lin8inch extensions are mainly for queries, media configuration, and WiFi provisioning; do not call them on unsupported models. |
TsplLin8inch | of(), automaticStatusFeedback(), printCompletion(), printerStatus(), firmwareVersion(), serialNumber(), macAddress(), deviceSpeed(), deviceSelfTest(), thermalStatus(), productId(), versionInfo(), selfTestPage(), modelSetting(), serialSetting(), versionSetting(), gbkCodepage(), utf8Codepage(), gapDetection(), configureStock(), configurePresentation(), twoColorRibbon(), directThermal() | Adds Lin8inch status feedback, media, ribbon, and presentation commands on top of TSPL. | Accepts booleans, speed, status flags, stock sensors, presentation mode, mark/gap, and offset. |
Response Parsing
| Object | Method / Command | Purpose | Parameters |
|---|---|---|---|
EscResponseParser / TsplResponseParser / CpclResponseParser | parse(raw), parse(query, raw) | Parses printer responses into status, battery, text, MAC, event, or unknown response objects. | `raw` is byte[]; response objects expose type, rawHex, statusFlags, isReady, batteryLevel, text, macAddress, and description. |
Practical recommendations
Section titled “Practical recommendations”- Confirm the dialect supported by the printer model before choosing
EscBoxliy,TsplBoxliy,CpclBoxliy, or Aryten/Lin8inch builders. - Android classic and JVM classic connection methods differ. The template layer should not depend on platform classes.
- Large images and continuous printing must validate chunk size on real devices.
- During obfuscation, keep the public SDK APIs required by the delivered package.