EPPrinterInfo.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package epson.print;
  2. import org.json.JSONException;
  3. import org.json.JSONObject;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.Serializable;
  8. public class EPPrinterInfo implements Serializable {
  9. static final long serialVersionUID = -4712510101292698959L;
  10. public String printerAccessKey = "";
  11. public String printerEmailAddress = "";
  12. public String printerID = "";
  13. public String printerIP = "";
  14. public int printerLocation = 0;
  15. public String printerName = "";
  16. public String printerSerialNo = "";
  17. public String scannerID = "";
  18. public String userDefName = "";
  19. public void writeJSON(FileOutputStream fileOutputStream) throws JSONException, IOException {
  20. JSONObject jSONObject = new JSONObject();
  21. jSONObject.put("printerName", printerName);
  22. jSONObject.put("printerID", printerID);
  23. jSONObject.put("printerIP", printerIP);
  24. String str = printerSerialNo;
  25. if (str == null) {
  26. str = "";
  27. }
  28. jSONObject.put("printerSerialNo", str);
  29. jSONObject.put("printerLocation", printerLocation);
  30. jSONObject.put("printerEmailAddress", printerEmailAddress);
  31. jSONObject.put("printerAccessKey", printerAccessKey);
  32. jSONObject.put("userDefName", userDefName);
  33. jSONObject.put("scannerID", scannerID);
  34. fileOutputStream.write(jSONObject.toString().getBytes());
  35. }
  36. public void readJSON(FileInputStream fileInputStream) throws JSONException, IOException {
  37. byte[] bArr = new byte[fileInputStream.available()];
  38. fileInputStream.read(bArr);
  39. JSONObject jSONObject = new JSONObject(new String(bArr));
  40. printerName = jSONObject.getString("printerName");
  41. printerID = jSONObject.getString("printerID");
  42. printerIP = jSONObject.getString("printerIP");
  43. printerSerialNo = jSONObject.getString("printerSerialNo");
  44. printerLocation = jSONObject.getInt("printerLocation");
  45. printerEmailAddress = jSONObject.getString("printerEmailAddress");
  46. printerAccessKey = jSONObject.getString("printerAccessKey");
  47. userDefName = jSONObject.getString("userDefName");
  48. try {
  49. scannerID = jSONObject.getString("scannerID");
  50. } catch (JSONException e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. }