From 9551fc304e04f5014746eb4631aadf7953b46a83 Mon Sep 17 00:00:00 2001 From: kitfox Date: Thu, 28 Feb 2008 06:46:15 +0000 Subject: Added Base64 stream codecs. Added Main-Class attribute to generated jars. git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@52 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b --- .../com/kitfox/svg/xml/Base64OutputStream.java | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 src/main/java/com/kitfox/svg/xml/Base64OutputStream.java (limited to 'src/main/java/com/kitfox/svg/xml/Base64OutputStream.java') diff --git a/src/main/java/com/kitfox/svg/xml/Base64OutputStream.java b/src/main/java/com/kitfox/svg/xml/Base64OutputStream.java new file mode 100755 index 0000000..db167de --- /dev/null +++ b/src/main/java/com/kitfox/svg/xml/Base64OutputStream.java @@ -0,0 +1,90 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.kitfox.svg.xml; + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * + * @author kitfox + */ +public class Base64OutputStream extends FilterOutputStream +{ + int buf; + int numBytes; + int numChunks; + + public Base64OutputStream(OutputStream out) + { + super(out); + } + + public void flush() throws IOException + { + out.flush(); + } + + public void close() throws IOException + { + switch (numBytes) + { + case 1: + buf <<= 4; + out.write(getBase64Byte(1)); + out.write(getBase64Byte(0)); + out.write('='); + out.write('='); + break; + case 2: + buf <<= 2; + out.write(getBase64Byte(2)); + out.write(getBase64Byte(1)); + out.write(getBase64Byte(0)); + out.write('='); + break; + case 3: + out.write(getBase64Byte(3)); + out.write(getBase64Byte(2)); + out.write(getBase64Byte(1)); + out.write(getBase64Byte(0)); + break; + default: + assert false; + } + + out.close(); + } + + public void write(int b) throws IOException + { + buf = (buf << 8) | (0xff & b); + numBytes++; + + if (numBytes == 3) + { + out.write(getBase64Byte(3)); + out.write(getBase64Byte(2)); + out.write(getBase64Byte(1)); + out.write(getBase64Byte(0)); + + numBytes = 0; + numChunks++; + if (numChunks == 16) + { +// out.write('\r'); +// out.write('\n'); + numChunks = 0; + } + } + } + + public byte getBase64Byte(int index) + { + return Base64Util.encodeByte((buf >> (index * 6)) & 0x3f); + } +} -- cgit v1.2.3-55-g7522