forked from dmolony/dm3270
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying charset when creating terminal client to support mul…
…tiple charsets Additionally move other utility methods to buffer (where they are better fit) and site to application package which provides better cohesion
- Loading branch information
1 parent
8c95ab0
commit 398fd6d
Showing
55 changed files
with
399 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: java | ||
dist: trusty | ||
jdk: oraclejdk8 | ||
cache: | ||
directories: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.bytezone.dm3270; | ||
|
||
import com.bytezone.dm3270.buffers.Buffer; | ||
import java.nio.charset.UnsupportedCharsetException; | ||
|
||
public enum Charset { | ||
CP1025, | ||
CP1026, | ||
CP1047, | ||
CP1140, | ||
CP1141, | ||
CP1142, | ||
CP1143, | ||
CP1144, | ||
CP1145, | ||
CP1146, | ||
CP1147, | ||
CP1148, | ||
CP1149, | ||
CP1153, | ||
CP1154, | ||
CP1166, | ||
CP1377, | ||
CP850, | ||
CP870, | ||
CP930, | ||
CP931, | ||
CP935, | ||
CP937, | ||
CP939; | ||
|
||
private char[] charsMapping; | ||
private java.nio.charset.Charset charset; | ||
|
||
public synchronized void load() throws UnsupportedCharsetException { | ||
if (charset != null) { | ||
return; | ||
} | ||
charset = java.nio.charset.Charset.forName(name()); | ||
byte[] baseBytes = new byte[256]; | ||
for (int i = 0; i < 256; i++) { | ||
baseBytes[i] = (byte) i; | ||
} | ||
charsMapping = new String(baseBytes, charset).toCharArray(); | ||
} | ||
|
||
public char getChar(byte value) { | ||
return charsMapping[value & 0xFF]; | ||
} | ||
|
||
public String getString(byte[] buffer) { | ||
return new String(buffer, charset); | ||
} | ||
|
||
public String getString(byte[] buffer, int offset, int length) { | ||
return new String(buffer, | ||
offset + length > buffer.length ? buffer.length - offset - 1 : offset, | ||
length, charset); | ||
} | ||
|
||
public String toHex(byte[] b) { | ||
return toHex(b, 0, b.length); | ||
} | ||
|
||
public String toHex(byte[] b, int offset, int length) { | ||
StringBuilder text = new StringBuilder(); | ||
for (int ptr = offset, max = offset + length; ptr < max; ptr += Buffer.HEX_LINE_SIZE) { | ||
StringBuilder hexLine = new StringBuilder(); | ||
StringBuilder textLine = new StringBuilder(); | ||
for (int linePtr = 0; linePtr < Buffer.HEX_LINE_SIZE && ptr + linePtr < max; linePtr++) { | ||
int val = b[ptr + linePtr] & 0xFF; | ||
hexLine.append(String.format("%02X ", val)); | ||
if (val < 0x40 || val == 0xFF) { | ||
textLine.append('.'); | ||
} else { | ||
textLine.append(new String(b, ptr + linePtr, 1, charset)); | ||
} | ||
} | ||
text.append(String.format("%04X %-48s %s%n", ptr, hexLine.toString(), textLine.toString())); | ||
} | ||
return text.length() > 0 ? text.substring(0, text.length() - 1) : text.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/com/bytezone/dm3270/utilities/Site.java → ...com/bytezone/dm3270/application/Site.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.