Skip to content
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
5 changes: 5 additions & 0 deletions src/main/java/net/iharder/Base64.java
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,11 @@ public void flushBase64() throws java.io.IOException {
*/
@Override
public void close() throws java.io.IOException {
// 0. If the stream is already closed then invoking this method has no effect.
if (out == null) {
return;
}

// 1. Ensure that pending characters are written
flushBase64();

Expand Down
5 changes: 4 additions & 1 deletion src/test/java/net/iharder/Base64Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.iharder;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
Expand All @@ -25,7 +26,9 @@ private void runStreamTest(int length) throws Exception
byte[] data = createData(length);
ByteArrayOutputStream out_bytes = new ByteArrayOutputStream();
OutputStream out = new Base64.OutputStream(out_bytes);
out.write(data);
BufferedOutputStream bos = new BufferedOutputStream(out);
bos.write(data);
bos.close();
out.close();
byte[] encoded = out_bytes.toByteArray();
byte[] decoded = Base64.decode(encoded, 0, encoded.length,
Expand Down