`
- 浏览:
190353 次
- 性别:
-
java 代码
-
-
-
-
-
- package sun.misc;
-
- import java.io.*;
- import java.nio.ByteBuffer;
-
-
-
-
- public abstract class CharacterDecoder
- {
-
- public CharacterDecoder()
- {
- }
-
- protected abstract int bytesPerAtom();
-
- protected abstract int bytesPerLine();
-
- protected void decodeBufferPrefix(PushbackInputStream pushbackinputstream, OutputStream outputstream)
- throws IOException
- {
- }
-
- protected void decodeBufferSuffix(PushbackInputStream pushbackinputstream, OutputStream outputstream)
- throws IOException
- {
- }
-
- protected int decodeLinePrefix(PushbackInputStream pushbackinputstream, OutputStream outputstream)
- throws IOException
- {
- return bytesPerLine();
- }
-
- protected void decodeLineSuffix(PushbackInputStream pushbackinputstream, OutputStream outputstream)
- throws IOException
- {
- }
-
- protected void decodeAtom(PushbackInputStream pushbackinputstream, OutputStream outputstream, int i)
- throws IOException
- {
- throw new CEStreamExhausted();
- }
-
- protected int readFully(InputStream inputstream, byte abyte0[], int i, int j)
- throws IOException
- {
- for(int k = 0; k < j; k++)
- {
- int l = inputstream.read();
- if(l == -1)
- return k != 0 ? k : -1;
- abyte0[k + i] = (byte)l;
- }
-
- return j;
- }
-
- public void decodeBuffer(InputStream inputstream, OutputStream outputstream)
- throws IOException
- {
- int j = 0;
- PushbackInputStream pushbackinputstream = new PushbackInputStream(inputstream);
- decodeBufferPrefix(pushbackinputstream, outputstream);
- try
- {
- do
- {
- int k = decodeLinePrefix(pushbackinputstream, outputstream);
- int i;
- for(i = 0; i + bytesPerAtom() < k; i += bytesPerAtom())
- {
- decodeAtom(pushbackinputstream, outputstream, bytesPerAtom());
- j += bytesPerAtom();
- }
-
- if(i + bytesPerAtom() == k)
- {
- decodeAtom(pushbackinputstream, outputstream, bytesPerAtom());
- j += bytesPerAtom();
- } else
- {
- decodeAtom(pushbackinputstream, outputstream, k - i);
- j += k - i;
- }
- decodeLineSuffix(pushbackinputstream, outputstream);
- } while(true);
- }
- catch(CEStreamExhausted cestreamexhausted)
- {
- decodeBufferSuffix(pushbackinputstream, outputstream);
- }
- }
-
- public byte[] decodeBuffer(String s)
- throws IOException
- {
- byte abyte0[] = new byte[s.length()];
- s.getBytes(0, s.length(), abyte0, 0);
- ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte0);
- ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
- decodeBuffer(((InputStream) (bytearrayinputstream)), ((OutputStream) (bytearrayoutputstream)));
- return bytearrayoutputstream.toByteArray();
- }
-
- public byte[] decodeBuffer(InputStream inputstream)
- throws IOException
- {
- ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
- decodeBuffer(inputstream, ((OutputStream) (bytearrayoutputstream)));
- return bytearrayoutputstream.toByteArray();
- }
-
- public ByteBuffer decodeBufferToByteBuffer(String s)
- throws IOException
- {
- return ByteBuffer.wrap(decodeBuffer(s));
- }
-
- public ByteBuffer decodeBufferToByteBuffer(InputStream inputstream)
- throws IOException
- {
- return ByteBuffer.wrap(decodeBuffer(inputstream));
- }
- }
-
-
-
-
-
-
-
- package sun.misc;
-
- import java.io.*;
-
-
-
-
- public class BASE64Decoder extends CharacterDecoder
- {
-
- public BASE64Decoder()
- {
- decode_buffer = new byte[4];
- }
-
- protected int bytesPerAtom()
- {
- return 4;
- }
-
- protected int bytesPerLine()
- {
- return 72;
- }
-
- protected void decodeAtom(PushbackInputStream pushbackinputstream, OutputStream outputstream, int i)
- throws IOException
- {
- byte byte0 = -1;
- byte byte1 = -1;
- byte byte2 = -1;
- byte byte3 = -1;
- if(i < 2)
- throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
- int j;
- do
- {
- j = pushbackinputstream.read();
- if(j == -1)
- throw new CEStreamExhausted();
- } while(j == 10 || j == 13);
- decode_buffer[0] = (byte)j;
- j = readFully(pushbackinputstream, decode_buffer, 1, i - 1);
- if(j == -1)
- throw new CEStreamExhausted();
- if(i > 3 && decode_buffer[3] == 61)
- i = 3;
- if(i > 2 && decode_buffer[2] == 61)
- i = 2;
- switch(i)
- {
- case 4:
- byte3 = pem_convert_array[decode_buffer[3] & 0xff];
-
-
- case 3:
- byte2 = pem_convert_array[decode_buffer[2] & 0xff];
-
-
- case 2:
- byte1 = pem_convert_array[decode_buffer[1] & 0xff];
- byte0 = pem_convert_array[decode_buffer[0] & 0xff];
-
-
- default:
- switch(i)
- {
- case 2:
- outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));
- break;
-
- case 3:
- outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));
- outputstream.write((byte)(byte1 << 4 & 0xf0 | byte2 >>> 2 & 0xf));
- break;
-
- case 4:
- outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));
- outputstream.write((byte)(byte1 << 4 & 0xf0 | byte2 >>> 2 & 0xf));
- outputstream.write((byte)(byte2 << 6 & 0xc0 | byte3 & 0x3f));
- break;
- }
- break;
- }
- }
-
- private static final char pem_array[] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
- 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
- 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
- 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
- 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', '+', '/'
- };
- private static final byte pem_convert_array[];
- byte decode_buffer[];
-
- static
- {
- pem_convert_array = new byte[256];
- for(int i = 0; i < 255; i++)
- pem_convert_array[i] = -1;
-
- for(int j = 0; j < pem_array.length; j++)
- pem_convert_array[pem_array[j]] = (byte)j;
-
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
sun公司的base64解码编码,里面附带使用说明,尤其是在eclipse下如何使用
BASE64Encoder.jar是用于java、android项目中Base64数据加解密工具,简单易用
sun.misc.BASEDecoder、sun.misc.BASEEncoder等 在编码解码是用到的工具类,导入jar包之后,就可以正常使用此类
Kotlin Base64编解码类,可以对AES/DES的加密密文作编码和解码,防止出现加解密出错的问题。 encrypt before size: 16 encrypt after size: 24 使用DES作加密解密时,咱们会发现加密后的密码变长了,这样会直接导致...
包含sun.misc.编码解码、org.apache.commons.codec.binary.Base64编码解码、自定义的、myBase64Encode/Dencode 以及对对几种方式的区别
网上经常有用编码、解码来传图片的例子。但是都使用的是sun.misc.BASE64Encoder和sun.misc.BASE64Dncoder。虽然在rt.jar中,但是是内部使用的。 所以建议使用apache的commons-codec。
Java中实现图片转Base64,Base64转图片。SSM中直接使用Spring的jar包实现,Android客户端上传的base64会无法解码,使用这个Jar包可以解决这个问题。
Sun公司提供的Base64转码/解码工具,包含jar包和源代码。 Sun公司提供的Base64转码/解码工具,包含jar包和源代码。
密文经过sun 内部的Base64Encoder编码成为字符串后返回密文字符串。解密的时候先使用Base64Decoder先解码密文,然后再解密。 数字签名也是同样道理。 该工具在jre7以及以上的环境能够更好的运行。 使用范例: ...
在 OS X 上,您可能想要创建一个指向 /Applications/HashCalc.app/Contents/MacOS/HashCalc 的链接文件,以便您可以输入 hashcalc path/file 第二个选项卡上还有一个 Base64 文本编码器和解码器作为便利工具。...
这是一份关于2.1版JavaServletAPI的说明文档,作为对这本文档的补充,你可以到http://java.sun.com/products/servlet/index.html下面下载Javadoc格式的文档。 谁需要读这份文档 这份文档描述了JavaServletAPI的最新...