Skip to content

Commit

Permalink
#249 Remove commons-codec dependency in favor of JDK's own Base64 cod…
Browse files Browse the repository at this point in the history
…ec (#250)

- switches to `java.util.Base64` instead of `org.apache.commons.codec.binary.Base64`
- removes (hard) dependency commons-codec from `dkpro-jwpl-revisionmachine`
  • Loading branch information
mawiesne authored Oct 30, 2023
1 parent 1bd5437 commit 600d287
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
12 changes: 4 additions & 8 deletions dkpro-jwpl-revisionmachine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
<groupId>org.dkpro.jwpl</groupId>
<artifactId>dkpro-jwpl-api</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

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

import org.dkpro.jwpl.revisionmachine.common.exceptions.ConfigurationException;
import org.dkpro.jwpl.revisionmachine.common.exceptions.DecodingException;
import org.dkpro.jwpl.revisionmachine.difftool.config.ConfigurationKeys;
Expand Down Expand Up @@ -499,8 +498,7 @@ public void setInput(final byte[] input)
* if an error occurs while reading the stream
*/
public void setInput(final InputStream input, final boolean binary)
throws IOException
{
throws IOException {

if (!binary) {

Expand All @@ -518,12 +516,14 @@ public void setInput(final InputStream input, final boolean binary)
v = input.read();
}

Base64.Decoder decoder = Base64.getDecoder();

if (zipFlag) {
r = new BitReader(inflateInput(
Base64.decodeBase64(buffer.toString()), 0));
decoder.decode(buffer.toString()), 0));
}
else {
r = new BitReader(Base64.decodeBase64(buffer.toString()));
r = new BitReader(decoder.decode(buffer.toString()));
}
}
else {
Expand Down Expand Up @@ -570,17 +570,16 @@ public void setInput(final InputStream input, final boolean binary)
* @throws DecodingException
* if the decoding fails
*/
public void setInput(final String input)
throws DecodingException
{
public void setInput(final String input) throws DecodingException {

boolean zipFlag = input.charAt(0) == '_';
Base64.Decoder decoder = Base64.getDecoder();
if (zipFlag) {
r = new BitReader(inflateInput(
Base64.decodeBase64(input.substring(1)), 0));
decoder.decode(input.substring(1)), 0));
}
else {
byte[] data = Base64.decodeBase64(input);
byte[] data = decoder.decode(input);
if (data == null) {

for (int i = 0; i < input.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Iterator;
import java.util.zip.Deflater;

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

import org.dkpro.jwpl.revisionmachine.common.exceptions.ConfigurationException;
import org.dkpro.jwpl.revisionmachine.common.exceptions.EncodingException;
import org.dkpro.jwpl.revisionmachine.difftool.config.ConfigurationKeys;
Expand All @@ -33,9 +32,6 @@

/**
* The RevisionApi class contains methods to encode the diff information.
*
*
*
*/
public class RevisionEncoder
implements RevisionEncoderInterface
Expand Down Expand Up @@ -278,11 +274,11 @@ private void encodeDelete(final DiffPart part)
*/
@Override
public String encodeDiff(final RevisionCodecData codecData, final Diff diff)
throws UnsupportedEncodingException, EncodingException
{
throws UnsupportedEncodingException, EncodingException {

String sEncoding;
byte[] bData = encode(codecData, diff);
Base64.Encoder encoder = Base64.getEncoder();
if (MODE_ZIP_COMPRESSION) {

Deflater compresser = new Deflater();
Expand All @@ -302,14 +298,14 @@ public String encodeDiff(final RevisionCodecData codecData, final Diff diff)
output = stream.toByteArray();

if (bData.length + 1 < output.length) {
sEncoding = Base64.encodeBase64String(bData);
sEncoding = encoder.encodeToString(bData);
}
else {
sEncoding = "_" + Base64.encodeBase64String(output);
sEncoding = "_" + encoder.encodeToString(output);
}
}
else {
sEncoding = Base64.encodeBase64String(bData);
sEncoding = encoder.encodeToString(bData);
}

return sEncoding;
Expand Down

0 comments on commit 600d287

Please sign in to comment.