All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bytezone.dm3270.orders.TextOrder Maven / Gradle / Ivy

Go to download

This is a trimmed down version of https://github.com/dmolony/dm3270 to be used as TN3270 client library

There is a newer version: 0.9.1
Show newest version
package com.bytezone.dm3270.orders;

import com.bytezone.dm3270.display.DisplayScreen;
import com.bytezone.dm3270.display.Pen;
import com.bytezone.dm3270.utilities.Dm3270Utility;

public class TextOrder extends Order {

  public TextOrder(byte[] buffer, int ptr, int max) {
    int dataLength = getDataLength(buffer, ptr, max);
    this.buffer = new byte[dataLength];
    System.arraycopy(buffer, ptr, this.buffer, 0, dataLength);
  }

  private int getDataLength(byte[] buffer, int offset, int max) {
    int ptr = offset + 1;
    int length = 1;
    while (ptr < max) {
      byte value = buffer[ptr++];
      for (byte orderValue : orderValues) {
        if (value == orderValue) {
          return length;
        }
      }
      length++;
    }

    return length;
  }

  @Override
  public boolean isText() {
    return true;
  }

  @Override
  public void process(DisplayScreen screen) {
    Pen pen = screen.getPen();
    for (byte b : buffer) {
      pen.write(b);
    }
  }

  @Override
  public String toString() {
    return buffer.length == 0 ? "" : "Text: [" + Dm3270Utility.getString(buffer) + "]";
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy