diff app/src/main/java/org/tn5250j/framework/tn5250/tnvt.java @ 445:8fa8e73e2f5c

update to tn5250j version 0.7.7, svn r1270
author Carl Byington <carl@five-ten-sg.com>
date Mon, 04 Jan 2016 15:52:25 -0800
parents d29cce60f393
children 5ce5235adde6
line wrap: on
line diff
--- a/app/src/main/java/org/tn5250j/framework/tn5250/tnvt.java	Thu Dec 03 12:33:34 2015 -0800
+++ b/app/src/main/java/org/tn5250j/framework/tn5250/tnvt.java	Mon Jan 04 15:52:25 2016 -0800
@@ -300,9 +300,7 @@
 
             producer = new DataStreamProducer(this, bin, dsq, abyte0);
             pthread = new Thread(producer);
-            //         pthread.setPriority(pthread.MIN_PRIORITY);
             pthread.setPriority(Thread.NORM_PRIORITY);
-            //          pthread.setPriority(Thread.NORM_PRIORITY / 2);
             pthread.start();
 
             try {
@@ -576,7 +574,6 @@
         //       row - first ##
         //       column - second ##
         //       F3 - Help Aid Key
-        //      System.out.println("Help request sent");
         baosp.write(screen52.getCurrentRow());
         baosp.write(screen52.getCurrentCol());
         baosp.write(AID_HELP);
@@ -609,8 +606,6 @@
         // bit 5 - SRQ system request
         // bit 6 - TRQ Test request key
         // bit 7 - HLP
-
-        //      System.out.println("Attention key sent");
         try {
             Log.i(TAG, "sendAttentionKey() writeGDS()");
             writeGDS(0x40, 0, null);
@@ -831,7 +826,7 @@
             ScreenPlanes planes = screen52.getPlanes();
             c = planes.getChar(str);
             boolean waitFor = !(c == 'a');
-            StringBuffer command = new StringBuffer();
+            StringBuilder command = new StringBuilder();
 
             for (int i = str + 1; i < 132; i++) {
                 c = planes.getChar(i);
@@ -877,7 +872,7 @@
      * @param scan
      *            if true, scanning is enabled; disabled otherwise.
      *
-     * @see scan4Cmd()
+     * @see #scan()
      */
     public void setScanningEnabled(boolean scan) {
         this.scan = scan;
@@ -899,10 +894,9 @@
      * second character in the datastream (the zero position allows to
      * devisualize the scan stream). If the sequence <code>#!</code> is
      * encountered and if this sequence is <strong>not </strong> followed by a
-     * blank character, the {@link parseCommand(ScreenChar[])}is called.
+     * blank character, the {@link parseCommand()}is called.
      */
     private void scan() {
-        //     System.out.println("Checking command : " +
         // screen52.screen[1].getChar() + screen52.screen[2].getChar());
         //      ScreenChar[] screen = screen52.screen;
         ScreenPlanes planes = screen52.getPlanes();
@@ -1080,8 +1074,8 @@
                     strpccmd();
                 }
             }
-            catch (Exception exd) {
-                Log.w(TAG, " tnvt.run: " + exd.getMessage());
+            catch (RuntimeException e) {
+                Log.w(TAG, " tnvt.run: " + e.getMessage());
                 exd.printStackTrace();
             }
 
@@ -1109,32 +1103,27 @@
     private final void readScreen() throws IOException {
         int rows = screen52.getRows();
         int cols = screen52.getColumns();
-        byte abyte0[] = new byte[rows * cols];
-        fillScreenArray(abyte0, rows, cols);
+        byte screenArray[] = new byte[rows * cols];
+        fillScreenArray(screenArray, rows, cols);
         Log.i(TAG, "readScreen() writeGDS()");
-        writeGDS(0, 0, abyte0);
-        abyte0 = null;
+        writeGDS(0, 0, screenArray);
     }
 
-    private final void fillScreenArray(byte[] sa, int rows, int cols) {
-        int la = 32;
-        int sac = 0;
-        int len = rows * cols;
+    private final void fillScreenArray(byte[] sa) {
         ScreenPlanes planes = screen52.planes;
 
         try {
-            for (int y = 0; y < len; y++) { // save the screen data
-                if (planes.isAttributePlace(y)) {
-                    la = planes.getCharAttr(y);
-                    sa[sac++] = (byte) la;
+            for (int i = 0; i < sa.length; i++) { // save the screen data
+                if (planes.isAttributePlace(i)) {
+                    sa[i] = (byte) planes.getCharAttr(i);
                 }
                 else {
                     //  The characters on screen are in unicode
-                    char ch = planes.getChar(y);
+                    char ch = planes.getChar(i);
                     byte byteCh;
                     if (isDataUnicode(ch)) byteCh = codePage.uni2ebcdic(ch);
                     else                   byteCh = (byte) ch;
-                    sa[sac++] = byteCh;
+                    sa[i] = byteCh;
                 }
             }
         }
@@ -1144,20 +1133,18 @@
         }
     }
 
-    private final void fillRegenerationBuffer(ByteArrayOutputStream sc, int rows, int cols)
-    throws IOException {
+	private byte[] createRegenerationBuffer(int len) throws IOException {
         int la = 32;
         int sac = 0;
-        int len = rows * cols;
         ScreenPlanes planes = screen52.planes;
         byte[] sa = new byte[len];
 
         try {
             boolean guiExists = sfParser != null && sfParser.isGuisExists();
 
-            for (int y = 0; y < len; y++) { // save the screen data
+            for (int i = 0; i < len; i++) { // save the screen data
                 if (guiExists) {
-                    byte[] guiSeg = sfParser.getSegmentAtPos(y);
+                    byte[] guiSeg = sfParser.getSegmentAtPos(i);
 
                     if (guiSeg != null) {
                         //Log.i(TAG," gui saved at " + y + " - " + screen52.getRow(y) + "," +
@@ -1170,18 +1157,16 @@
                         sa[sac++] = (byte)0x04;
                         sa[sac++] = (byte)0x11;
                         sac += guiSeg.length;
-                        //y--;
-                        //               continue;
                     }
                 }
 
-                if (planes.isAttributePlace(y)) {
-                    la = planes.getCharAttr(y);
+                if (planes.isAttributePlace(i)) {
+                    la = planes.getCharAttr(i);
                     sa[sac++] = (byte) la;
                 }
                 else {
                     //  The characters on screen are in unicode
-                    char ch = planes.getChar(y);
+                    char ch = planes.getChar(i);
                     byte byteCh;
                     if (isDataUnicode(ch)) byteCh = codePage.uni2ebcdic(ch);
                     else                   byteCh = (byte) ch;
@@ -1193,57 +1178,42 @@
             Log.i(TAG, exc.getMessage());
             exc.printStackTrace();
         }
-
-        sc.write(sa);
+        return sa;
     }
 
     public final void saveScreen() throws IOException {
         ByteArrayOutputStream sc = new ByteArrayOutputStream();
-        sc.write(4);
-        sc.write(0x12); // 18
-        sc.write(0); // 18
-        sc.write(0); // 18
-        sc.write((byte) screen52.getRows()); // store the current size
-        sc.write((byte) screen52.getColumns()); //    ""
+		sc.write(new byte[] {4, 0x12, 0, 0});
+        sc.write((byte) screen52.getRows());    // store the current size
+        sc.write((byte) screen52.getColumns()); // ""
         int cp = screen52.getCurrentPos(); // save off current position
-        // fix below submitted by Mitch Blevins
-        //int cp = screen52.getScreenFields().getCurrentFieldPos();
-        // save off current position
-        sc.write((byte)(cp >> 8 & 0xff));  //    ""
-        sc.write((byte)(cp & 0xff));  //    ""
+        sc.write((byte)(cp >> 8 & 0xff));  // ""
+        sc.write((byte)(cp & 0xff));       // ""
         sc.write((byte)(screen52.homePos >> 8 & 0xff));  // save home pos
-        sc.write((byte)(screen52.homePos & 0xff));  //    ""
-        int rows = screen52.getRows(); // store the current size
-        int cols = screen52.getColumns(); //    ""
-        //      byte[] sa = new byte[rows * cols];
-        fillRegenerationBuffer(sc, rows, cols);
-        //      fillScreenArray(sa, rows, cols);
-        //
-        //      sc.write(sa);
-        //      sa = null;
+        sc.write((byte)(screen52.homePos & 0xff));       // ""
+		sc.write(createRegenerationBuffer(screen52.getRows() * screen52.getColumns()));
         int sizeFields = screen52.getScreenFields().getSize();
-        sc.write((byte)(sizeFields >> 8 & 0xff));  //    ""
-        sc.write((byte)(sizeFields & 0xff));  //    ""
+        sc.write((byte)(sizeFields >> 8 & 0xff));  // save number of fields
+        sc.write((byte)(sizeFields & 0xff));       // ""
 
         if (sizeFields > 0) {
             int x = 0;
             int s = screen52.getScreenFields().getSize();
-            ScreenField sf = null;
 
             while (x < s) {
-                sf = screen52.getScreenFields().getField(x);
-                sc.write((byte) sf.getAttr()); // attribute
+                ScreenField sf = screen52.getScreenFields().getField(x);
+                sc.write((byte) sf.getAttr());      // attribute
                 int sp = sf.startPos();
-                sc.write((byte)(sp >> 8 & 0xff));  //    ""
-                sc.write((byte)(sp & 0xff));  //    ""
+                sc.write((byte)(sp >> 8 & 0xff));   // position
+                sc.write((byte)(sp & 0xff));        // ""
 
                 if (sf.mdt)
                     sc.write((byte) 1);
                 else
                     sc.write((byte) 0);
 
-                sc.write((byte)(sf.getLength() >> 8 & 0xff));  //    ""
-                sc.write((byte)(sf.getLength() & 0xff));  //    ""
+                sc.write((byte)(sf.getLength() >> 8 & 0xff));
+                sc.write((byte)(sf.getLength() & 0xff));
                 sc.write((byte) sf.getFFW1() & 0xff);
                 sc.write((byte) sf.getFFW2() & 0xff);
                 sc.write((byte) sf.getFCW1() & 0xff);
@@ -1252,8 +1222,6 @@
                 Log.d(TAG, sf.toString());
                 x++;
             }
-
-            sf = null;
         }
 
         // The following two lines of code looks to have caused all sorts of
@@ -1269,8 +1237,6 @@
         catch (IOException ioe) {
             Log.w(TAG, ioe.getMessage());
         }
-
-        sc = null;
         Log.d(TAG, "Save Screen end ");
     }
 
@@ -1886,7 +1852,6 @@
                     //break;
 
                     default: // all others must be output to screen
-                        //Log.d(TAG,"all others must be output to screen");
                         byte byte0 = bk.getByteOffset(-1);
 
                         if (isAttribute(byte0)) {
@@ -1926,7 +1891,6 @@
         }
         catch (Exception e) {
             Log.w(TAG, "write to display " + e.getMessage());
-            e.printStackTrace();
         }
 
         ;
@@ -2057,12 +2021,10 @@
             pendingUnlock = false;
 
         if (resetMDT || resetMDTAll || nullMDT || nullAll) {
-            ScreenField sf;
             int f = screen52.getScreenFields().getSize();
 
             for (int x = 0; x < f; x++) {
-                sf = screen52.getScreenFields().getField(x);
-
+                ScreenField sf = screen52.getScreenFields().getField(x);
                 if (!sf.isBypassField()) {
                     if ((nullMDT && sf.mdt) || nullAll) {
                         sf.setFieldChar((char) 0x0);
@@ -2073,8 +2035,6 @@
                 if (resetMDTAll || (resetMDT && !sf.isBypassField()))
                     sf.resetMDT();
             }
-
-            sf = null;
         }
     }
 
@@ -2154,8 +2114,8 @@
     //  The first 32 characters are non displayable characters
     //  This is normally the inverse of isDataEBCDIC (That's why there is a
     //  check on 255 -> 0xFFFF
-    private boolean isDataUnicode(int byte0) {
-        return (((byte0 < 0) || (byte0 >= 32)) && (byte0 != 0xFFFF));
+    private boolean isDataUnicode(int data) {
+        return (((data < 0) || (data >= 32)) && (data != 0xFFFF));
     }
 
     private void writeStructuredField() {
@@ -2379,8 +2339,7 @@
                                     break;
 
                                 case TIMING_MARK: // 6   rfc860
-                                    //                        System.out.println("Timing Mark Received and notifying " +
-                                    //                        "the server that we will not do it");
+                                    Log.d(TAG, "Timing Mark Received and notifying the server that we will not do it.");
                                     baosp.write(IAC);
                                     baosp.write(WONT);
                                     baosp.write(TIMING_MARK);
@@ -2570,7 +2529,7 @@
             return devName;
         }
         else {
-            StringBuffer sb = new StringBuffer(devName + devSeq);
+            StringBuilder sb = new StringBuilder(devName + devSeq);
             int ei = 1;
 
             while (sb.length() > 10) {