From 71bd11c7468e1cbccc58069e70c176c67fb8de53 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 21 Jul 2021 12:34:35 +0200 Subject: Replaced StandardCharsets with Charset.forName java.nio.charset.StandardCharsets is available on API level >= 19. See https://developer.android.com/reference/java/nio/charset/StandardCharsets. java.nio.charset.Charset is there since java 1.4. --- .../java/org/uic/barcode/asn1/uper/StringCoder.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/main/java/org/uic/barcode/asn1/uper/StringCoder.java') 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 + ")"); } -- cgit v1.2.3