/Users/lyon/j4p/src/security/BASE64Encoder.java
|
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4 // Source File Name: BASE64Encoder.java
5
6 package security;
7
8 import java.io.IOException;
9 import java.io.OutputStream;
10
11 // Referenced classes of package sun.misc:
12 // CharacterEncoder
13
14 public class BASE64Encoder
15 extends CharacterEncoder {
16
17 public BASE64Encoder() {
18 }
19
20 protected int bytesPerAtom() {
21 return 3;
22 }
23
24 protected int bytesPerLine() {
25 return 57;
26 }
27
28 protected void encodeAtom(
29 OutputStream outStream,
30 byte data[],
31 int offset,
32 int len)
33 throws IOException {
34 if (len == 1) {
35 byte a = data[offset];
36 byte b = 0;
37 //byte c = 0;
38 outStream.write(
39 pem_array[a >>> 2 & 0x3f]);
40 outStream.write(pem_array[(a << 4 &
41 0x30) +
42 (b >>> 4 &
43 0xf)]);
44 outStream.write(61);
45 outStream.write(61);
46 } else if (len == 2) {
47 byte a = data[offset];
48 byte b = data[offset + 1];
49 byte c = 0;
50 outStream.write(
51 pem_array[a >>> 2 & 0x3f]);
52 outStream.write(pem_array[(a << 4 &
53 0x30) +
54 (b >>> 4 &
55 0xf)]);
56 outStream.write(pem_array[(b << 2 &
57 0x3c) +
58 (c >>> 6 &
59 3)]);
60 outStream.write(61);
61 } else {
62 byte a = data[offset];
63 byte b = data[offset + 1];
64 byte c = data[offset + 2];
65 outStream.write(
66 pem_array[a >>> 2 & 0x3f]);
67 outStream.write(pem_array[(a << 4 &
68 0x30) +
69 (b >>> 4 &
70 0xf)]);
71 outStream.write(pem_array[(b << 2 &
72 0x3c) +
73 (c >>> 6 &
74 3)]);
75 outStream.write(pem_array[c & 0x3f]);
76 }
77 }
78
79 private static final char pem_array[] = {
80 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
81 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
82 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
83 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
84 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
85 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
86 '8', '9', '+', '/'
87 };
88
89 }
90