Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/tn5250/DataStreamProducer.java @ 416:07c1da90deab
avoid null pointer
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 27 Oct 2014 13:58:42 -0700 |
parents | 24186858750f |
children |
rev | line source |
---|---|
3 | 1 package org.tn5250j.framework.tn5250; |
2 | |
3 import java.io.BufferedInputStream; | |
4 import java.io.BufferedOutputStream; | |
5 import java.io.ByteArrayOutputStream; | |
6 import java.io.EOFException; | |
7 import java.io.FileNotFoundException; | |
8 import java.io.FileOutputStream; | |
9 import java.io.IOException; | |
10 import java.net.SocketException; | |
11 import java.util.concurrent.BlockingQueue; | |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
12 import java.util.Timer; |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
13 import java.util.TimerTask; |
3 | 14 |
15 import org.tn5250j.encoding.ICodePage; | |
72
8181cb01c64d
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
69
diff
changeset
|
16 |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
17 import android.util.Log; |
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
18 |
3 | 19 |
20 public class DataStreamProducer implements Runnable { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
21 private static final String TAG = "DataStreamProducer"; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
22 private tnvt vt; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
23 private BufferedInputStream bin; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
24 private ByteArrayOutputStream baosin; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
25 private Thread me; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
26 private byte[] saveStream; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
27 private final BlockingQueue<Object> dsq; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
28 private byte[] abyte2; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
29 private FileOutputStream fw; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
30 private BufferedOutputStream dw; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
31 private boolean dumpBytes = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
32 private ICodePage codePage; |
3 | 33 |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
34 |
3 | 35 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
36 public DataStreamProducer(tnvt vt, BufferedInputStream bin, BlockingQueue<Object> queue, byte[] init) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
37 this.bin = bin; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
38 this.vt = vt; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
39 baosin = new ByteArrayOutputStream(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
40 dsq = queue; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
41 abyte2 = init; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
42 } |
3 | 43 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
44 public void setInputStream(ByteArrayOutputStream is) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
45 baosin = is; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
46 } |
3 | 47 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
48 public final void run() { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
49 boolean done = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
50 me = Thread.currentThread(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
51 // load the first response screen |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
52 loadStream(abyte2, 0); |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
53 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
54 while (!done) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
55 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
56 byte[] abyte0 = readIncoming(); |
3 | 57 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
58 // WVL - LDC : 17/05/2004 : Device name negotiations send TIMING MARK |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
59 // Restructured to the readIncoming() method to return null |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
60 // on TIMING MARK. Don't process in that case (abyte0 == null)! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
61 if (abyte0 != null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
62 // WVL - LDC : 16/07/2003 : TR.000345 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
63 // When the socket has been closed, the reading returns |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
64 // no bytes (an empty byte arrray). |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
65 // But the loadStream fails on this, so we check it here! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
66 if (abyte0.length > 0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
67 loadStream(abyte0, 0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
68 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
69 // WVL - LDC : 16/07/2003 : TR.000345 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
70 // Returning no bytes means the input buffer has |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
71 // reached end-of-stream, so we do a disconnect! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
72 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
73 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
74 vt.disconnect(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
75 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
76 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
77 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
78 catch (SocketException se) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
79 Log.w(TAG, " DataStreamProducer thread interrupted and stopping " + se.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
80 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
81 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
82 catch (IOException ioe) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
83 Log.w(TAG, ioe.getMessage()); |
3 | 84 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
85 if (me.isInterrupted()) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
86 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
87 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
88 catch (Exception ex) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
89 Log.w(TAG, ex.getMessage()); |
3 | 90 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
91 if (me.isInterrupted()) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
92 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
93 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
94 } |
3 | 95 } |
96 | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
97 private final void loadStream(byte abyte0[], int i) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
98 int j = 0; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
99 int size = 0; |
3 | 100 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
101 if (saveStream == null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
102 j = (abyte0[i] & 0xff) << 8 | abyte0[i + 1] & 0xff; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
103 size = abyte0.length; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
104 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
105 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
106 size = saveStream.length + abyte0.length; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
107 byte[] inter = new byte[size]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
108 System.arraycopy(saveStream, 0, inter, 0, saveStream.length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
109 System.arraycopy(abyte0, 0, inter, saveStream.length, abyte0.length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
110 abyte0 = new byte[size]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
111 System.arraycopy(inter, 0, abyte0, 0, size); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
112 saveStream = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
113 inter = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
114 j = (abyte0[i] & 0xff) << 8 | abyte0[i + 1] & 0xff; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
115 Log.d(TAG, "partial stream found"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
116 } |
3 | 117 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
118 if (j > size) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
119 saveStream = new byte[abyte0.length]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
120 System.arraycopy(abyte0, 0, saveStream, 0, abyte0.length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
121 Log.d(TAG, "partial stream saved"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
122 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
123 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
124 byte abyte1[]; |
3 | 125 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
126 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
127 abyte1 = new byte[j + 2]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
128 System.arraycopy(abyte0, i, abyte1, 0, j + 2); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
129 dsq.put(abyte1); |
3 | 130 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
131 if (abyte0.length > abyte1.length + i) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
132 loadStream(abyte0, i + j + 2); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
133 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
134 catch (Exception ex) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
135 Log.w(TAG, "load stream error " + ex.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
136 // ex.printStackTrace(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
137 // dump(abyte0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
138 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
139 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
140 } |
3 | 141 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
142 public final byte[] readIncoming() |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
143 throws IOException { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
144 boolean done = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
145 boolean negotiate = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
146 baosin.reset(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
147 int j = -1; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
148 int i = 0; |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
149 Timer timer = new Timer("data.stream", true); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
150 TimerTask task = null; |
3 | 151 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
152 while (!done) { |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
153 if (bin.available() == 0) { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
154 task = new TimerTask() { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
155 public void run() { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
156 try { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
157 dsq.put(new Integer(0)); // trigger buffer.testChanged() |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
158 } |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
159 catch (Exception ex) { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
160 Log.w(TAG, "readIncoming error " + ex.getMessage()); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
161 } |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
162 } |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
163 }; |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
164 timer.schedule(task, 10); // 10 ms delay |
392
7ac1a0b02f44
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
219
diff
changeset
|
165 } |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
166 |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
167 i = bin.read(); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
168 |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
169 if (task != null) { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
170 task.cancel(); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
171 task = null; |
392
7ac1a0b02f44
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
219
diff
changeset
|
172 } |
3 | 173 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
174 // WVL - LDC : 16/07/2003 : TR.000345 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
175 // The inStream return -1 when end-of-stream is reached. This |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
176 // happens e.g. when the connection is closed from the AS/400. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
177 // So we stop in this case! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
178 // ==> an empty byte array is returned from this method. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
179 if (i == -1) { // nothing read! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
180 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
181 vt.disconnect(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
182 continue; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
183 } |
3 | 184 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
185 // We use the values instead of the static values IAC and EOR |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
186 // because they are defined as bytes. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
187 // |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
188 // The > if(i != 255 || j != 255) < is a hack for the double FF FF's |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
189 // that are being returned. I do not know why this is like this and |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
190 // can not find any documentation for it. It is also being returned |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
191 // on my Client Access tcp dump as well so they are handling it. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
192 // |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
193 // my5250 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
194 // 0000: 00 50 DA 44 C8 45 42 00 00 00 00 24 08 00 45 00 .P.D.EB....$..E. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
195 // 0010: 04 2A BC F9 00 00 40 06 D0 27 C1 A8 33 04 C1 A8 .*....@..'..3... |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
196 // 0020: 33 58 00 17 04 18 6F A2 83 CB 00 1E D1 BA 50 18 3X....o.......P. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
197 // 0030: 20 00 8A 9A 00 00 03 FF FF 12 A0 00 00 04 00 00 ............... |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
198 // --------------------------- || || ------------------------------------- |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
199 // 0040: 03 04 40 04 11 00 20 01 07 00 00 00 18 00 00 10 ..@... ......... |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
200 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
201 if (j == 255 && i == 255) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
202 j = -1; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
203 continue; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
204 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
205 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
206 baosin.write(i); |
3 | 207 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
208 // check for end of record EOR and IAC - FFEF |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
209 if (j == 255 && i == 239) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
210 done = true; |
3 | 211 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
212 // This is to check for the TELNET TIMING MARK OPTION |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
213 // rfc860 explains this in more detail. When we receive it |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
214 // we will negotiate with the server by sending a WONT'T TIMING-MARK |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
215 // This will let the server know that we processed the information |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
216 // and are just waiting for the user to enter some data so keep the |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
217 // socket alive. This is more or less a AYT (ARE YOU THERE) or not. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
218 if (i == 253 && j == 255) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
219 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
220 negotiate = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
221 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
222 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
223 j = i; |
3 | 224 } |
225 | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
226 // after the initial negotiation we might get other options such as |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
227 // timing marks ?????????????? do we ???????????? look at telnet spec |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
228 // yes we do. rfc860 explains about timing marks. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
229 // WVL - LDC : 17/05/2004 : Device name negotiations send TIMING MARK |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
230 // to existing device! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
231 // Handled incorrectly: we cannot continue processing the TIMING MARK DO |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
232 // after we have handled it in the vt.negotiate() |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
233 // We should not return the bytes; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
234 // ==> restructured to return null after negotiation! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
235 // Impacts the run method! Added the null check. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
236 byte[] rBytes = baosin.toByteArray(); |
3 | 237 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
238 if (dumpBytes) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
239 dump(rBytes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
240 } |
3 | 241 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
242 if (negotiate) { |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
243 if (bin.available() == 0) { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
244 task = new TimerTask() { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
245 public void run() { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
246 try { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
247 dsq.put(new Integer(0)); // trigger buffer.testChanged() |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
248 } |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
249 catch (Exception ex) { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
250 Log.w(TAG, "readIncoming error " + ex.getMessage()); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
251 } |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
252 } |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
253 }; |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
254 timer.schedule(task, 10); // 10 ms delay |
392
7ac1a0b02f44
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
219
diff
changeset
|
255 } |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
256 |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
257 // get the negotiation option |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
258 baosin.write(bin.read()); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
259 |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
260 if (task != null) { |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
261 task.cancel(); |
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
262 task = null; |
392
7ac1a0b02f44
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
219
diff
changeset
|
263 } |
394
24186858750f
add test buffer changed when input stream runs dry, similar to async test
Carl Byington <carl@five-ten-sg.com>
parents:
392
diff
changeset
|
264 |
3 | 265 vt.negotiate(rBytes); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
266 return null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
267 } |
3 | 268 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
269 return rBytes; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
270 } |
3 | 271 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
272 protected final void toggleDebug(ICodePage cp) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
273 if (codePage == null) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
274 codePage = cp; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
275 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
276 dumpBytes = !dumpBytes; |
3 | 277 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
278 if (dumpBytes) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
279 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
280 if (fw == null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
281 fw = new FileOutputStream("log.txt"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
282 dw = new BufferedOutputStream(fw); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
283 } |
3 | 284 } |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
285 catch (FileNotFoundException fnfe) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
286 Log.w(TAG, fnfe.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
287 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
288 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
289 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
290 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
291 if (dw != null) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
292 dw.close(); |
3 | 293 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
294 if (fw != null) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
295 fw.close(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
296 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
297 dw = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
298 fw = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
299 codePage = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
300 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
301 catch (IOException ioe) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
302 Log.w(TAG, ioe.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
303 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
304 } |
3 | 305 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
306 Log.i(TAG, "Data Stream output is now " + dumpBytes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
307 } |
3 | 308 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
309 public void dump(byte[] abyte0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
310 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
311 Log.i(TAG, "\n Buffer Dump of data from AS400: "); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
312 dw.write("\r\n Buffer Dump of data from AS400: ".getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
313 StringBuffer h = new StringBuffer(); |
3 | 314 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
315 for (int x = 0; x < abyte0.length; x++) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
316 if (x % 16 == 0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
317 System.out.println(" " + h.toString()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
318 dw.write((" " + h.toString() + "\r\n").getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
319 h.setLength(0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
320 h.append("+0000"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
321 h.setLength(5 - Integer.toHexString(x).length()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
322 h.append(Integer.toHexString(x).toUpperCase()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
323 System.out.print(h.toString()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
324 dw.write(h.toString().getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
325 h.setLength(0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
326 } |
3 | 327 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
328 char ac = codePage.ebcdic2uni(abyte0[x]); |
3 | 329 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
330 if (ac < ' ') |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
331 h.append('.'); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
332 else |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
333 h.append(ac); |
3 | 334 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
335 if (x % 4 == 0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
336 System.out.print(" "); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
337 dw.write((" ").getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
338 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
339 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
340 if (Integer.toHexString(abyte0[x] & 0xff).length() == 1) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
341 System.out.print("0" + Integer.toHexString(abyte0[x] & 0xff).toUpperCase()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
342 dw.write(("0" + Integer.toHexString(abyte0[x] & 0xff).toUpperCase()).getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
343 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
344 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
345 System.out.print(Integer.toHexString(abyte0[x] & 0xff).toUpperCase()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
346 dw.write((Integer.toHexString(abyte0[x] & 0xff).toUpperCase()).getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
347 } |
3 | 348 } |
349 | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
350 System.out.println(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
351 dw.write("\r\n".getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
352 dw.flush(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
353 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
354 catch (EOFException _ex) { } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
355 catch (Exception _ex) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
356 Log.w(TAG, "Cannot dump from host\n\r"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
357 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
358 } |
3 | 359 |
360 // public void dumpBytes() { | |
361 // byte shit[] = bk.buffer; | |
362 // for (int i = 0;i < shit.length;i++) | |
363 // System.out.println(i + ">" + shit[i] + "< - ascii - >" + getASCIIChar(shit[i]) + "<"); | |
364 // } | |
365 // | |
366 // public void dumpHexBytes(byte[] abyte) { | |
367 // byte shit[] = abyte; | |
368 // for (int i = 0;i < shit.length;i++) | |
369 // System.out.println(i + ">" + shit[i] + "< hex >" + Integer.toHexString((shit[i] & 0xff))); | |
370 // } | |
371 | |
98
16e023784917
protect both read calls with test for blocking
Carl Byington <carl@five-ten-sg.com>
parents:
72
diff
changeset
|
372 } |