cziegeler 02/01/04 05:25:36
Modified: src/scratchpad/org/apache/avalon/excalibur/source
SourceUtil.java
Log:
Reformatting code
Revision Changes Path
1.4 +46 -29
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceUtil.java
Index: SourceUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SourceUtil.java 4 Jan 2002 13:21:31 -0000 1.3
+++ SourceUtil.java 4 Jan 2002 13:25:36 -0000 1.4
@@ -20,9 +20,10 @@
* Utility class for source resolving.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/01/04 13:21:31 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/01/04 13:25:36 $
*/
-public final class SourceUtil {
+public final class SourceUtil
+{
private static final char [ ] alphabet = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
@@ -38,7 +39,8 @@
* BASE 64 encoding.
* See also RFC 1421
*/
- public static String encodeBASE64 ( String s ) {
+ public static String encodeBASE64 ( String s )
+ {
return encodeBASE64 ( s.getBytes ( ) );
}
@@ -46,7 +48,8 @@
* BASE 64 encoding.
* See also RFC 1421
*/
- public static String encodeBASE64 ( byte [ ] octetString ) {
+ public static String encodeBASE64 ( byte [ ] octetString )
+ {
int bits24;
int bits6;
@@ -55,7 +58,8 @@
int outIndex = 0;
int i = 0;
- while ( ( i + 3 ) <= octetString.length ) {
+ while ( ( i + 3 ) <= octetString.length )
+ {
// store the octets
bits24 = ( octetString [ i++ ] & 0xFF ) << 16;
bits24 |= ( octetString [ i++ ] & 0xFF ) << 8;
@@ -71,7 +75,8 @@
out [ outIndex++ ] = alphabet [ bits6 ];
}
- if ( octetString.length - i == 2 ) {
+ if ( octetString.length - i == 2 )
+ {
// store the octets
bits24 = ( octetString [ i ] & 0xFF ) << 16;
bits24 |= ( octetString [ i + 1 ] & 0xFF ) << 8;
@@ -85,7 +90,9 @@
// padding
out [ outIndex++ ] = '=';
- } else if ( octetString.length - i == 1 ) {
+ }
+ else if ( octetString.length - i == 1 )
+ {
// store the octets
bits24 = ( octetString [ i ] & 0xFF ) << 16;
@@ -107,19 +114,22 @@
static final int characterCaseDiff = ('a' - 'A');
/** Initialize the BitSet */
- static {
+ static
+ {
charactersDontNeedingEncoding = new BitSet(256);
int i;
- for (i = 'a'; i <= 'z'; i++) {
+ for (i = 'a'; i <= 'z'; i++)
+ {
charactersDontNeedingEncoding.set(i);
}
- for (i = 'A'; i <= 'Z'; i++) {
+ for (i = 'A'; i <= 'Z'; i++)
+ {
charactersDontNeedingEncoding.set(i);
}
- for (i = '0'; i <= '9'; i++) {
+ for (i = '0'; i <= '9'; i++)
+ {
charactersDontNeedingEncoding.set(i);
}
- charactersDontNeedingEncoding.set(' ');
charactersDontNeedingEncoding.set('-');
charactersDontNeedingEncoding.set('_');
charactersDontNeedingEncoding.set('.');
@@ -133,38 +143,45 @@
* @param s <code>String</code> to be translated.
* @return the translated <code>String</code>.
*/
- public static String encode(String s) {
- StringBuffer out = new StringBuffer(s.length());
- ByteArrayOutputStream buf = new ByteArrayOutputStream(32);
- OutputStreamWriter writer = new OutputStreamWriter(buf);
- for (int i = 0; i < s.length(); i++) {
+ public static String encode(String s)
+ {
+ final StringBuffer out = new StringBuffer( s.length() );
+ final ByteArrayOutputStream buf = new ByteArrayOutputStream( 32 );
+ final OutputStreamWriter writer = new OutputStreamWriter( buf );
+ for (int i = 0; i < s.length(); i++)
+ {
int c = (int)s.charAt(i);
- if (charactersDontNeedingEncoding.get(c)) {
- if (c == ' ') {
- out.append("%20");
- } else {
- out.append((char)c);
- }
- } else {
- try {
+ if (charactersDontNeedingEncoding.get(c))
+ {
+ out.append((char)c);
+ }
+ else
+ {
+ try
+ {
writer.write(c);
writer.flush();
- } catch(IOException e) {
+ }
+ catch(IOException e)
+ {
buf.reset();
continue;
}
byte[] ba = buf.toByteArray();
- for (int j = 0; j < ba.length; j++) {
+ for (int j = 0; j < ba.length; j++)
+ {
out.append('%');
char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
// converting to use uppercase letter as part of
// the hex value if ch is a letter.
- if (Character.isLetter(ch)) {
+ if (Character.isLetter(ch))
+ {
ch -= characterCaseDiff;
}
out.append(ch);
ch = Character.forDigit(ba[j] & 0xF, 16);
- if (Character.isLetter(ch)) {
+ if (Character.isLetter(ch))
+ {
ch -= characterCaseDiff;
}
out.append(ch);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>