diff options
author | kitfox | 2008-02-28 07:46:15 +0100 |
---|---|---|
committer | kitfox | 2008-02-28 07:46:15 +0100 |
commit | 9551fc304e04f5014746eb4631aadf7953b46a83 (patch) | |
tree | d82236a587003b328960914fddc9bd4b39626a2e /src/main/java/com/kitfox/svg/xml/Base64OutputStream.java | |
parent | Updated color parsing to handle rgb percentages (diff) | |
download | svg-salamander-core-9551fc304e04f5014746eb4631aadf7953b46a83.tar.gz svg-salamander-core-9551fc304e04f5014746eb4631aadf7953b46a83.tar.xz svg-salamander-core-9551fc304e04f5014746eb4631aadf7953b46a83.zip |
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
Diffstat (limited to 'src/main/java/com/kitfox/svg/xml/Base64OutputStream.java')
-rwxr-xr-x | src/main/java/com/kitfox/svg/xml/Base64OutputStream.java | 90 |
1 files changed, 90 insertions, 0 deletions
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); + } +} |