summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-03-29 17:07:46 +0200
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-03-29 17:07:46 +0200
commit91942fcafe79e292e73ca0f09c0225614e7ed2b4 (patch)
tree0b32dc5507c307ce021642e422e24e742810a426 /src/main
parentexclude classpath (diff)
downloadUIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.tar
UIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.tar.gz
UIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.tar.bz2
UIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.tar.lz
UIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.tar.xz
UIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.tar.zst
UIC-barcode-91942fcafe79e292e73ca0f09c0225614e7ed2b4.zip
Diffstat (limited to '')
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/IntCoder.java42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java b/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java
index 87b561b..5964a64 100644
--- a/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java
+++ b/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java
@@ -223,11 +223,11 @@ class IntCoder implements Encoder, Decoder {
} else if (classOfT == BigInteger.class) {
return (T) resultValue;
} else if (classOfT == Long.class) {
- return (T) Long.valueOf(resultValue.longValueExact());
+ return (T) bigToLong(resultValue);
} else if (classOfT == Integer.class) {
- return (T) Integer.valueOf(resultValue.intValueExact());
+ return (T) bigToInteger(resultValue);
} else if (classOfT == Short.class) {
- return (T) Short.valueOf(resultValue.shortValueExact());
+ return (T) bigToShort(resultValue);
}
} catch (Exception e){
UperEncoder.logger.debug(String.format("INTEGER Decoded as %s is too big for data type", resultValue));
@@ -235,6 +235,42 @@ class IntCoder implements Encoder, Decoder {
return null;
}
+ private Long bigToLong(BigInteger b) {
+
+ Long l = b.longValue();
+
+ if (BigInteger.valueOf(l).equals(b)) {
+ return l;
+ } else {
+ throw new ArithmeticException("BigInteger To Long failed");
+ }
+
+ }
+
+ private Integer bigToInteger(BigInteger b) {
+
+ Integer l = b.intValue();
+
+ if (BigInteger.valueOf(l).equals(b)) {
+ return l;
+ } else {
+ throw new ArithmeticException("BigInteger To Integer failed");
+ }
+
+ }
+
+ private Short bigToShort(BigInteger b) {
+
+ Short l = b.shortValue();
+
+ if (BigInteger.valueOf(l).equals(b)) {
+ return l;
+ } else {
+ throw new ArithmeticException("BigInteger To Short failed");
+ }
+
+ }
+
@SuppressWarnings("unchecked")
@Override
public <T> T getDefault(Class<T> classOfT, Annotation[] extraAnnotations) {