summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-10-19 15:19:29 +0200
committerGitHub <noreply@github.com>2021-10-19 15:19:29 +0200
commitc4bb941ec4669e94153a1425e371c59635bc19ee (patch)
tree528a98796cd304b4d9f1b81e23d47cf9c465cee9 /src/main
parentUpdate uicRailTicketData_v3.0.0.asn (diff)
parentReplaced StandardCharsets with Charset.forName (diff)
downloadUIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.tar
UIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.tar.gz
UIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.tar.bz2
UIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.tar.lz
UIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.tar.xz
UIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.tar.zst
UIC-barcode-c4bb941ec4669e94153a1425e371c59635bc19ee.zip
Diffstat (limited to '')
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/Document2.txt34
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/StringCoder.java20
-rw-r--r--src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java6
3 files changed, 13 insertions, 47 deletions
diff --git a/src/main/java/org/uic/barcode/asn1/uper/Document2.txt b/src/main/java/org/uic/barcode/asn1/uper/Document2.txt
deleted file mode 100644
index 176ec23..0000000
--- a/src/main/java/org/uic/barcode/asn1/uper/Document2.txt
+++ /dev/null
@@ -1,34 +0,0 @@
- if (restrictionAnnotation.value() == CharacterRestriction.UTF8String) {
- // UTF8 length
- BitBuffer stringbuffer = ByteBitBuffer.createInfinite();
-
- //char array replaced - begin
- byte[] stringasbytearray = string.getBytes(StandardCharsets.UTF_8);
-
- for (byte b: stringasbytearray){
- UperEncoder.encodeConstrainedInt(stringbuffer, byte & 0xff, 0, 255);
- }
- //char array replaced - end
-
- stringbuffer.flip();
- if (stringbuffer.limit() % 8 != 0) {
- throw new AssertionError("utf8 encoding resulted not in multiple of 8 bits");
- }
- int numOctets = (stringbuffer.limit() + 7) / 8; // Actually +7 is not needed here,
- // since we already checked with %8.
- int position1 = bitbuffer.position();
- UperEncoder.encodeLengthDeterminant(bitbuffer, numOctets);
- UperEncoder.logger.debug(String.format("UTF8String %s, length %d octets, encoded as %s", string, numOctets, bitbuffer.toBooleanStringFromPosition(position1)));
- int position2 = bitbuffer.position();
- for (int i = 0; i < stringbuffer.limit(); i++) {
- bitbuffer.put(stringbuffer.get());
- }
- UperEncoder.logger.debug(String.format("UTF8String %s, encoded length %d octets, value bits: %s", string, numOctets, bitbuffer.toBooleanStringFromPosition(position2)));
- return;
-
-
-
-
-
-
-new String(bytearray, StandardCharsets.UTF_8)); \ No newline at end of file
diff --git a/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java b/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java
index fe06e3d..c842480 100644
--- a/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java
+++ b/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java
@@ -5,7 +5,7 @@ import java.lang.reflect.Field;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
-import java.nio.charset.StandardCharsets;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -87,7 +87,7 @@ class StringCoder implements Decoder, Encoder {
BitBuffer stringbuffer = ByteBitBuffer.createInfinite();
//char array replaced - begin
- byte[] stringasbytearray = string.getBytes(StandardCharsets.UTF_8);
+ byte[] stringasbytearray = string.getBytes(Charset.forName("UTF-8"));
for (byte b: stringasbytearray){
UperEncoder.encodeConstrainedInt(stringbuffer, b & 0xff, 0, 255);
@@ -179,7 +179,7 @@ class StringCoder implements Decoder, Encoder {
}
byte[] contentBytes = UperEncoder.bytesFromCollection(content);
UperEncoder.logger.debug(String.format("Content bytes (hex): %s", UperEncoder.hexStringFromBytes(contentBytes)));
- String resultStr = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(contentBytes)).toString();
+ String resultStr = Charset.forName("UTF-8").decode(ByteBuffer.wrap(contentBytes)).toString();
UperEncoder.logger.debug(String.format("Decoded as %s", resultStr));
T result = UperEncoder.instantiate(classOfT, resultStr);
return result;
@@ -211,7 +211,7 @@ class StringCoder implements Decoder, Encoder {
}
UperEncoder.encodeConstrainedInt(
bitbuffer,
- StandardCharsets.US_ASCII.encode(CharBuffer.wrap(new char[] { c })).get() & 0xff,
+ Charset.forName("US-ASCII").encode(CharBuffer.wrap(new char[] { c })).get() & 0xff,
0,
127);
return;
@@ -219,7 +219,7 @@ class StringCoder implements Decoder, Encoder {
if (restriction.alphabet() != DefaultAlphabet.class) {
throw new UnsupportedOperationException("alphabet for UTF8 is not supported yet.");
}
- ByteBuffer buffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(new char[] { c }));
+ ByteBuffer buffer = Charset.forName("UTF-8").encode(CharBuffer.wrap(new char[] { c }));
for (int i = 0; i < buffer.limit(); i++) {
UperEncoder.encodeConstrainedInt(bitbuffer, buffer.get() & 0xff, 0, 255);
}
@@ -249,7 +249,7 @@ class StringCoder implements Decoder, Encoder {
} else {
UperEncoder.encodeConstrainedInt(
bitbuffer,
- StandardCharsets.US_ASCII.encode(CharBuffer.wrap(new char[] { c }))
+ Charset.forName("US-ASCII").encode(CharBuffer.wrap(new char[] { c }))
.get() & 0xff,
0,
126);
@@ -258,7 +258,7 @@ class StringCoder implements Decoder, Encoder {
} else {
UperEncoder.encodeConstrainedInt(
bitbuffer,
- StandardCharsets.US_ASCII.encode(CharBuffer.wrap(new char[] { c }))
+ Charset.forName("US-ASCII").encode(CharBuffer.wrap(new char[] { c }))
.get() & 0xff,
0,
126);
@@ -280,7 +280,7 @@ class StringCoder implements Decoder, Encoder {
}
byte charByte = (byte) UperEncoder.decodeConstrainedInt(bitqueue, UperEncoder.newRange(0, 127, false));
byte[] bytes = new byte[] { charByte };
- String result = StandardCharsets.US_ASCII.decode(ByteBuffer.wrap(bytes)).toString();
+ String result = Charset.forName("US-ASCII").decode(ByteBuffer.wrap(bytes)).toString();
if (result.length() != 1) {
throw new AssertionError("decoded more than one char (" + result + ")");
}
@@ -307,7 +307,7 @@ class StringCoder implements Decoder, Encoder {
} else { // Encode normally
byte charByte = (byte) UperEncoder.decodeConstrainedInt(bitqueue, UperEncoder.newRange(0, 126, false));
byte[] bytes = new byte[] { charByte };
- String result = StandardCharsets.US_ASCII.decode(ByteBuffer.wrap(bytes)).toString();
+ String result = Charset.forName("US-ASCII").decode(ByteBuffer.wrap(bytes)).toString();
if (result.length() != 1) { throw new AssertionError(
"decoded more than one char (" + result + ")");
}
@@ -316,7 +316,7 @@ class StringCoder implements Decoder, Encoder {
} else { // Encode normally
byte charByte = (byte) UperEncoder.decodeConstrainedInt(bitqueue, UperEncoder.newRange(0, 126, false));
byte[] bytes = new byte[] { charByte };
- String result = StandardCharsets.US_ASCII.decode(ByteBuffer.wrap(bytes)).toString();
+ String result = Charset.forName("US-ASCII").decode(ByteBuffer.wrap(bytes)).toString();
if (result.length() != 1) {
throw new AssertionError("decoded more than one char (" + result + ")");
}
diff --git a/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java b/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java
index 549a2e7..2d403e4 100644
--- a/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java
+++ b/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java
@@ -7,7 +7,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
+import java.nio.charset.Charset;
import org.uic.barcode.staticFrame.ticketLayoutBarcode.FormatType;
import org.uic.barcode.staticFrame.ticketLayoutBarcode.LayoutElement;
@@ -43,7 +43,7 @@ public class UTLAYDataRecord extends DataRecord {
for (int i = 0; i < length; i++){
bytes[i] = byteData[i + offset];
}
- return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
+ return Charset.forName("UTF-8").decode(ByteBuffer.wrap(bytes)).toString();
}
/**
@@ -59,7 +59,7 @@ public class UTLAYDataRecord extends DataRecord {
for (int i = 0; i < length; i++){
bytes[i] = byteData[i + offset];
}
- return StandardCharsets.ISO_8859_1.decode(ByteBuffer.wrap(bytes)).toString();
+ return Charset.forName("ISO-8859-1").decode(ByteBuffer.wrap(bytes)).toString();
}
/**