Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Addition of InputStream in DeviceConnection Class #544

Open
madhura365 opened this issue Oct 10, 2024 · 0 comments
Open

Comments

@madhura365
Copy link

I've been utilizing your Android thermal POS printing library for my projects, and I'm impressed with its functionality and ease of use.

I have a suggestion for a small enhancement that could greatly benefit users like myself. I've noticed that the current DeviceConnection class provides robust support for sending data (OutputStream) to the device. However, for certain use cases, having the ability to receive data (InputStream) from the device would be invaluable.

Here's a proposed modification to the DeviceConnection class:

`public abstract class DeviceConnection {
protected OutputStream outputStream;
protected InputStream inputStream; // New addition
protected byte[] data;

public DeviceConnection() {
    this.outputStream = null;
    this.inputStream = null; // Initialize inputStream
    this.data = new byte[0];
}

// Existing methods...

/**
 * Read data from the device.
 */
public byte[] read(int length) throws EscPosConnectionException {
    if (!this.isConnected() || this.inputStream == null) {
        throw new EscPosConnectionException("Unable to read data from device.");
    }
    try {
        byte[] buffer = new byte[length];
        int bytesRead = this.inputStream.read(buffer);
        if (bytesRead == -1) {
            throw new EscPosConnectionException("End of stream reached unexpectedly.");
        }
        return Arrays.copyOf(buffer, bytesRead);
    } catch (IOException e) {
        e.printStackTrace();
        throw new EscPosConnectionException(e.getMessage());
    }
}

// Other methods...

public abstract DeviceConnection connect() throws EscPosConnectionException;
public abstract DeviceConnection disconnect();

// Existing methods...

/**
 * Check if InputStream is open.
 *
 * @return true if is connected
 */
public boolean isInputConnected() {
    return this.inputStream != null;
}

/**
 * Set InputStream for the device connection.
 */
public void setInputStream(InputStream inputStream) {
    this.inputStream = inputStream;
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant