Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced apache commons base64 encoder/decoder with native java #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Base64;

import javax.xml.bind.annotation.XmlAccessOrder;
import javax.xml.bind.annotation.XmlAccessType;
Expand All @@ -12,8 +13,6 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;

import org.apache.commons.codec.binary.Base64;

/**
* A JAXB holder class for strings that could possibly contain invalid XML characters. If any invalid XML characters are found, the string will be base64
* encoded.
Expand Down Expand Up @@ -74,7 +73,7 @@ public String getValue() {

try {
incoming = value.getBytes("UTF-8");
byte[] decodedBytes = Base64.decodeBase64(incoming);
byte[] decodedBytes = Base64.getDecoder().decode(incoming);
decoded = new String(decodedBytes, Charset.forName("UTF-8"));
} catch (UnsupportedEncodingException e) {
// Should never happen with UTF-8!!! (but if it does we will be
Expand All @@ -91,7 +90,7 @@ public byte[] getValueAsBytes() {
try {
byte[] incoming = value.getBytes("UTF-8");
if (this.base64Encoded != null && this.base64Encoded.equals(Boolean.TRUE)) {
return Base64.decodeBase64(incoming);
return Base64.getDecoder().decode(incoming);
} else {
return incoming;
}
Expand All @@ -112,7 +111,7 @@ public void setValue(String value) {
if (XMLUtil.isValidXML(value)) {
this.value = value;
} else {
this.value = new String(Base64.encodeBase64(value.getBytes(UTF_8)), UTF_8);
this.value = new String(Base64.getEncoder().encode(value.getBytes(UTF_8)), UTF_8);
this.base64Encoded = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.MessageFormat;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import javax.xml.bind.JAXBContext;

import org.apache.commons.codec.binary.Base64;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void testPlainString() throws Exception {
public void testEncodedStringString() throws Exception {
TypedValue value = new TypedValue("encoded\0String");
String actual = serialize(value);
assertEquals(expected64("xs:string", new String(Base64.encodeBase64("encoded\0String".getBytes()))), actual);
assertEquals(expected64("xs:string", new String(Base64.getEncoder().encode("encoded\0String".getBytes()))), actual);
assertTrue(value.isBase64Encoded());
assertEquals("xs:string", value.getType());
}
Expand All @@ -71,7 +71,7 @@ public void testEncodedNoOpTypeString() throws Exception {
BaseType<String> type = new NoOpType("encoded\0String");
TypedValue value = new TypedValue(type);
String actual = serialize(value);
assertEquals(expected64("xs:string", new String(Base64.encodeBase64("encoded\0String".getBytes()))), actual);
assertEquals(expected64("xs:string", new String(Base64.getEncoder().encode("encoded\0String".getBytes()))), actual);
assertTrue(value.isBase64Encoded());
assertEquals("xs:string", value.getType());
}
Expand All @@ -81,7 +81,7 @@ public void testEncodedTypeString() throws Exception {
BaseType<String> type = new LcNoDiacriticsType("encoded\0String");
TypedValue value = new TypedValue(type);
String actual = serialize(value);
assertEquals(expected64("xs:string", new String(Base64.encodeBase64("encoded\0String".getBytes()))), actual);
assertEquals(expected64("xs:string", new String(Base64.getEncoder().encode("encoded\0String".getBytes()))), actual);
assertTrue(value.isBase64Encoded());
assertEquals("xs:string", value.getType());
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public void testByte() throws Exception {
public void testByteArray() throws Exception {
TypedValue value = new TypedValue(new byte[] {(byte) 1, (byte) 2, (byte) 3, (byte) 42});
String actual = serialize(value);
assertEquals(expected("xs:base64Binary", new String(Base64.encodeBase64((byte[]) value.getValue()))), actual);
assertEquals(expected("xs:base64Binary", new String(Base64.getEncoder().encode((byte[]) value.getValue()))), actual);
assertFalse(value.isBase64Encoded());
assertEquals("xs:base64Binary", value.getType());
}
Expand Down