Skip to content

Commit 75d790e

Browse files
committed
Removing deprecated commons codec API calls
1 parent 1093721 commit 75d790e

3 files changed

Lines changed: 31 additions & 13 deletions

File tree

src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,10 @@ public void close() throws IOException {
845845
//buffering seems not to help
846846
//bufferedOutputStream = new BufferedOutputStream(new Base64OutputStream(ivSplittingOutputStream, false), 8192 * 5);
847847
ReplaceableOuputStream replaceableOuputStream = new ReplaceableOuputStream(ivSplittingOutputStream); //NOPMD
848-
OutputStream base64OutputStream = new Base64OutputStream(replaceableOuputStream, false); //NOPMD
848+
OutputStream base64OutputStream = Base64OutputStream.builder() //NOPMD
849+
.setOutputStream(replaceableOuputStream)
850+
.setEncode(false)
851+
.get();
849852
ivSplittingOutputStream.setParentOutputStream(replaceableOuputStream);
850853
OutputStreamWriter outputStreamWriter = //NOPMD
851854
new OutputStreamWriter(base64OutputStream,

src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import javax.xml.stream.XMLStreamConstants;
4141
import javax.xml.stream.XMLStreamException;
4242

43+
import org.apache.commons.codec.binary.Base64;
4344
import org.apache.commons.codec.binary.Base64OutputStream;
4445
import org.apache.xml.security.algorithms.JCEMapper;
4546
import org.apache.xml.security.encryption.XMLCipherUtil;
@@ -175,12 +176,14 @@ public void init(OutputProcessorChain outputProcessorChain) throws XMLSecurityEx
175176
symmetricCipher.init(Cipher.ENCRYPT_MODE, encryptionPartDef.getSymmetricKey(), parameterSpec);
176177

177178
characterEventGeneratorOutputStream = new CharacterEventGeneratorOutputStream();
178-
Base64OutputStream base64EncoderStream = null; //NOPMD
179+
Base64OutputStream.Builder builder = Base64OutputStream.builder()
180+
.setOutputStream(characterEventGeneratorOutputStream)
181+
.setEncode(true);
179182
if (XMLUtils.isIgnoreLineBreaks()) {
180-
base64EncoderStream = new Base64OutputStream(characterEventGeneratorOutputStream, true, 0, null);
181-
} else {
182-
base64EncoderStream = new Base64OutputStream(characterEventGeneratorOutputStream, true);
183+
builder.setBaseNCodec(Base64.builder().setLineLength(0).setLineSeparator(null).get());
183184
}
185+
186+
Base64OutputStream base64EncoderStream = builder.get(); //NOPMD
184187
base64EncoderStream.write(iv);
185188

186189
OutputStream outputStream = new CipherOutputStream(base64EncoderStream, symmetricCipher); //NOPMD

src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ public class TransformBase64Decode extends TransformIdentity {
4343

4444
@Override
4545
public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
46-
super.setOutputStream(new Base64OutputStream(
47-
new FilterOutputStream(outputStream) {
46+
OutputStream base64OutputStream = Base64OutputStream.builder() //NOPMD
47+
.setOutputStream(new FilterOutputStream(outputStream) {
4848
@Override
4949
public void close() throws IOException {
5050
//do not close the parent output stream!
5151
super.flush();
5252
}
53-
},
54-
false)
55-
);
53+
})
54+
.setEncode(false)
55+
.get();
56+
super.setOutputStream(base64OutputStream);
5657
}
5758

5859
@Override
@@ -96,7 +97,11 @@ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
9697
public void transform(Object object) throws XMLStreamException {
9798
if (base64OutputStream == null) {
9899
byteArrayOutputStream = new UnsyncByteArrayOutputStream();
99-
base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
100+
base64OutputStream =
101+
Base64OutputStream.builder()
102+
.setOutputStream(byteArrayOutputStream)
103+
.setEncode(false)
104+
.get();
100105
}
101106
try {
102107
base64OutputStream.write((byte[]) object);
@@ -139,7 +144,10 @@ public void doFinal() throws XMLStreamException {
139144
public void transform(Object object) throws XMLStreamException {
140145
if (base64OutputStream == null) {
141146
byteArrayOutputStream = new UnsyncByteArrayOutputStream();
142-
base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
147+
base64OutputStream = Base64OutputStream.builder()
148+
.setOutputStream(byteArrayOutputStream)
149+
.setEncode(false)
150+
.get();
143151
}
144152
try {
145153
base64OutputStream.write((byte[]) object);
@@ -177,7 +185,11 @@ public void transform(InputStream inputStream) throws XMLStreamException {
177185
if (getOutputStream() != null) {
178186
super.transform(inputStream);
179187
} else {
180-
super.transform(new Base64InputStream(inputStream, false));
188+
InputStream base64InputStream = Base64InputStream.builder() //NOPMD
189+
.setInputStream(inputStream)
190+
.setEncode(false)
191+
.get();
192+
super.transform(base64InputStream);
181193
}
182194
}
183195

0 commit comments

Comments
 (0)