java 代码
- // Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2007-6-11 11:45:48
- // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
- // Decompiler options: packimports(3)
- // Source File Name: CharacterDecoder.java
- package sun.misc;
- import java.io.*;
- import java.nio.ByteBuffer;
- // Referenced classes of package sun.misc:
- // CEStreamExhausted
- 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));
- }
- }
- // Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2007-6-11 11:45:29
- // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
- // Decompiler options: packimports(3)
- // Source File Name: BASE64Decoder.java
- package sun.misc;
- import java.io.*;
- // Referenced classes of package sun.misc:
- // CharacterDecoder, CEFormatException, CEStreamExhausted
- 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: // '\004'
- byte3 = pem_convert_array[decode_buffer[3] & 0xff];
- // fall through
- case 3: // '\003'
- byte2 = pem_convert_array[decode_buffer[2] & 0xff];
- // fall through
- case 2: // '\002'
- byte1 = pem_convert_array[decode_buffer[1] & 0xff];
- byte0 = pem_convert_array[decode_buffer[0] & 0xff];
- // fall through
- default:
- switch(i)
- {
- case 2: // '\002'
- outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));
- break;
- case 3: // '\003'
- outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));
- outputstream.write((byte)(byte1 << 4 & 0xf0 | byte2 >>> 2 & 0xf));
- break;
- case 4: // '\004'
- 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;
- }
- }