org.bouncycastle.mime.encoding.Base64OutputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-jdk15on Show documentation
Show all versions of bcpkix-jdk15on Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.5 to JDK 1.8. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
package org.bouncycastle.mime.encoding;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.util.encoders.Base64;
public class Base64OutputStream
extends FilterOutputStream
{
byte[] buffer = new byte[54];
int bufOff;
public Base64OutputStream(OutputStream stream)
{
super(stream);
}
public void write(int b)
throws IOException
{
doWrite((byte)b);
}
public void write(byte[] buf, int bufOff, int len)
throws IOException
{
for (int i = 0; i != len; i++)
{
doWrite(buf[bufOff + i]);
}
}
public void write(byte[] buf)
throws IOException
{
write(buf, 0, buf.length);
}
public void close()
throws IOException
{
if (bufOff > 0)
{
Base64.encode(buffer, 0, bufOff, out);
}
out.close();
}
private void doWrite(byte b)
throws IOException
{
buffer[bufOff++] = b;
if (bufOff == buffer.length)
{
Base64.encode(buffer, 0, buffer.length, out);
out.write('\r');
out.write('\n');
bufOff = 0;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy