fix BASE64EncoderStream : must pad on flush instead of close

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@29 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2007-02-20 13:41:56 +00:00
parent 29e5c570aa
commit 612c486540
1 changed files with 8 additions and 6 deletions

View File

@ -46,12 +46,12 @@ public class BASE64EncoderStream extends FilterOutputStream {
/** /**
* The internal buffer of encoded output bytes. * The internal buffer of encoded output bytes.
**/ **/
private byte output[] = new byte[4]; private byte[] output = new byte[4];
/** /**
* The internal buffer of input bytes to be encoded. * The internal buffer of input bytes to be encoded.
**/ **/
private byte input[] = new byte[3]; private byte[] input = new byte[3];
/** /**
* The index of the next position in the internal buffer of input bytes * The index of the next position in the internal buffer of input bytes
@ -100,6 +100,11 @@ public class BASE64EncoderStream extends FilterOutputStream {
maxLineLength = max; maxLineLength = max;
} }
public void flush() throws IOException {
pad();
out.flush();
}
/** /**
* Completes the encoding of data, padding the input data if necessary * Completes the encoding of data, padding the input data if necessary
* to end the input on a multiple of 4 bytes, writes a terminating * to end the input on a multiple of 4 bytes, writes a terminating
@ -111,12 +116,9 @@ public class BASE64EncoderStream extends FilterOutputStream {
public void close() throws IOException { public void close() throws IOException {
try { try {
flush(); flush();
} } catch (IOException ignored) {
catch (IOException ignored) {
} }
// Make sure the number of bytes output is a multiple of three.
pad();
// Add a terminating CRLF sequence. // Add a terminating CRLF sequence.
out.write('\r'); out.write('\r');