Skip to content
Merged
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 @@ -155,13 +155,4 @@ public byte decodeBuffer(String inputString)[] throws IOException {
decodeBuffer(inStream, outStream);
return (outStream.toByteArray());
}

/**
* Decode the contents of the inputstream into a buffer.
*/
public byte decodeBuffer(InputStream in)[] throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
decodeBuffer(in, outStream);
return (outStream.toByteArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,4 @@ public void encodeBuffer(byte aBuffer[], OutputStream aStream) throws IOExceptio
encodeBuffer(inStream, aStream);
}

/**
* A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded
* buffer.
*/
public String encodeBuffer(byte aBuffer[]) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
try {
encodeBuffer(inStream, outStream);
} catch (Exception IOException) {
// This should never happen.
return null;
}
return (outStream.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.jupiter.api.Test;

class BASE64EncoderTest {
private BASE64Encoder encoder = new BASE64Encoder();

@Test
void testEncodingDate() {
void testEncodingDate() throws IOException {
var plain = "Thu 16 Dec 20:37:57 UTC 2021";
var buffer = new ByteArrayOutputStream();

var encoded = encoder.encodeBuffer(plain.getBytes());
encoder.encodeBuffer(plain.getBytes(), buffer);
var encoded = buffer.toString();

assertThat(encoded).isEqualTo("VGh1IDE2IERlYyAyMDozNzo1NyBVVEMgMjAyMQ==" + System.lineSeparator());
}
Expand Down
Loading