1 |
/* Base64InputStream.java -- base-64 input stream. |
/* Base64InputStream.java -- base-64 input stream. |
2 |
Copyright (C) 2003 Free Software Foundation, Inc. |
Copyright (C) 2003, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
38 |
|
|
39 |
package gnu.java.io; |
package gnu.java.io; |
40 |
|
|
41 |
|
import java.io.ByteArrayInputStream; |
42 |
|
import java.io.ByteArrayOutputStream; |
43 |
import java.io.FilterInputStream; |
import java.io.FilterInputStream; |
44 |
import java.io.IOException; |
import java.io.IOException; |
45 |
import java.io.InputStream; |
import java.io.InputStream; |
92 |
eof = false; |
eof = false; |
93 |
} |
} |
94 |
|
|
95 |
|
// Class method. |
96 |
|
// ------------------------------------------------------------------------ |
97 |
|
|
98 |
|
/** |
99 |
|
* Decode a single Base-64 string to a byte array. |
100 |
|
* |
101 |
|
* @param base64 The Base-64 encoded data. |
102 |
|
* @return The decoded bytes. |
103 |
|
* @throws IOException If the given data do not compose a valid Base-64 |
104 |
|
* sequence. |
105 |
|
*/ |
106 |
|
public static byte[] decode(String base64) throws IOException |
107 |
|
{ |
108 |
|
Base64InputStream in = |
109 |
|
new Base64InputStream(new ByteArrayInputStream(base64.getBytes())); |
110 |
|
ByteArrayOutputStream out = |
111 |
|
new ByteArrayOutputStream((int) (base64.length() / 0.666)); |
112 |
|
byte[] buf = new byte[1024]; |
113 |
|
int len; |
114 |
|
while ((len = in.read(buf)) != -1) |
115 |
|
out.write(buf, 0, len); |
116 |
|
return out.toByteArray(); |
117 |
|
} |
118 |
|
|
119 |
// Instance methods. |
// Instance methods. |
120 |
// ------------------------------------------------------------------------ |
// ------------------------------------------------------------------------ |
121 |
|
|