Acme
Class Utils

java.lang.Object
  extended by Acme.Utils

public class Utils
extends Object


Nested Class Summary
static class Utils.DummyPrintStream
           
static class Utils.SimpleBuffer
           
static interface Utils.ThreadFactory
           
static class Utils.ThreadPool
           
 
Field Summary
protected static char[] BASE64ARRAY
           
static int COPY_BUF_SIZE
           
protected static byte[] DECODABET
          Translates a Base64 value to either its 6-bit reconstruction value or a negative number indicating some other meaning.
static Class[] EMPTY_CLASSES
           
static Enumeration EMPTY_ENUMERATION
           
static Object[] EMPTY_OBJECTS
           
protected static byte EQUALS_SIGN
          The equals sign (=) as a byte.
protected static byte EQUALS_SIGN_ENC
           
static String ISO_8859_1
           
protected static byte WHITE_SPACE_ENC
           
 
Constructor Summary
Utils()
           
 
Method Summary
static String base64Decode(String _s, String _enc)
          base 64 decoding
static String base64Encode(byte[] _bytes)
          base 64 encoding, array of bytes converted to bytes using specified encoding
static String base64Encode(String _s, String _enc)
          base 64 encoding, string converted to bytes using specified encoding
static String calculateClassPath(ClassLoader cl)
          calculate local file based class path for class loader if possible (servlet classes must be located there)
static String canonicalizePath(String path)
           
static String[] copyOf(String[] original, int newLength)
           
static String[] copyOfRange(String[] original, int from, int newLength)
           
static void copyStream(InputStream in, OutputStream out, long maxLen)
           
static void copyStream(Reader in, OutputStream out, String charSet)
           
static void copyStream(Reader in, Writer out)
           
static byte[] decode(byte[] source, int off, int len)
          Very low-level access to decoding ASCII characters in the form of a byte array.
static String decode(String s, String enc)
          Decodes URL encoded string including newly introduced JavaScript encoding with %uxxxx chars
static byte[] decode64(String s)
          Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it.
static String htmlEncode(String s, boolean encodeWS)
           
static float isGzipAccepted(String contentEncoding)
           
static String lsDateStr(Date date)
           
static void main(String[] args)
           
static boolean match(String pattern, String string)
           
static int matchSpan(String pattern, String string)
           
static Map parsePostData(long len, InputStream is, String encoding, String[] cachedStream)
           
static Hashtable parseQueryString(String query, String encoding)
           
static String[] splitStr(String str)
           
static String[] splitStr(String str, char delim)
           
static String[] splitStr(String str, String quotes)
           
static String toFile(URL url)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPY_BUF_SIZE

public static final int COPY_BUF_SIZE
See Also:
Constant Field Values

ISO_8859_1

public static final String ISO_8859_1
See Also:
Constant Field Values

EMPTY_CLASSES

public static final Class[] EMPTY_CLASSES

EMPTY_OBJECTS

public static final Object[] EMPTY_OBJECTS

EMPTY_ENUMERATION

public static final Enumeration EMPTY_ENUMERATION

BASE64ARRAY

protected static final char[] BASE64ARRAY

DECODABET

protected static final byte[] DECODABET
Translates a Base64 value to either its 6-bit reconstruction value or a negative number indicating some other meaning.


WHITE_SPACE_ENC

protected static final byte WHITE_SPACE_ENC
See Also:
Constant Field Values

EQUALS_SIGN_ENC

protected static final byte EQUALS_SIGN_ENC
See Also:
Constant Field Values

EQUALS_SIGN

protected static final byte EQUALS_SIGN
The equals sign (=) as a byte.

See Also:
Constant Field Values
Constructor Detail

Utils

public Utils()
Method Detail

lsDateStr

public static String lsDateStr(Date date)

parseQueryString

public static Hashtable parseQueryString(String query,
                                         String encoding)

parsePostData

public static Map parsePostData(long len,
                                InputStream is,
                                String encoding,
                                String[] cachedStream)
                         throws IOException
Throws:
IOException

decode

public static String decode(String s,
                            String enc)
                     throws UnsupportedEncodingException
Decodes URL encoded string including newly introduced JavaScript encoding with %uxxxx chars

Parameters:
s - encoded string
enc - source encoding
Returns:
decoded string or original if no decoding required
Throws:
UnsupportedEncodingException

htmlEncode

public static String htmlEncode(String s,
                                boolean encodeWS)

isGzipAccepted

public static float isGzipAccepted(String contentEncoding)

match

public static boolean match(String pattern,
                            String string)

matchSpan

public static int matchSpan(String pattern,
                            String string)

splitStr

public static String[] splitStr(String str)

splitStr

public static String[] splitStr(String str,
                                char delim)

splitStr

public static String[] splitStr(String str,
                                String quotes)

copyOf

public static String[] copyOf(String[] original,
                              int newLength)

copyOfRange

public static String[] copyOfRange(String[] original,
                                   int from,
                                   int newLength)

canonicalizePath

public static String canonicalizePath(String path)

copyStream

public static void copyStream(InputStream in,
                              OutputStream out,
                              long maxLen)
                       throws IOException
Throws:
IOException

copyStream

public static void copyStream(Reader in,
                              Writer out)
                       throws IOException
Throws:
IOException

copyStream

public static void copyStream(Reader in,
                              OutputStream out,
                              String charSet)
                       throws IOException
Throws:
IOException

base64Encode

public static final String base64Encode(String _s,
                                        String _enc)
base 64 encoding, string converted to bytes using specified encoding

Parameters:
String - _s original string to encode
String - encoding, can be null, then iso-8859-1 used
Returns:
String result of encoding as iso-8859-1 string
return null in case of invalid encoding or original string null
Throws:
no - exceptions

base64Encode

public static final String base64Encode(byte[] _bytes)
base 64 encoding, array of bytes converted to bytes using specified encoding

Parameters:
String - _s original string to encode
String - encoding, can be null, then iso-8859-1 used
Returns:
String result of encoding as iso-8859-1 string
Throws:
NullPointerException - if input parameter is null

base64Decode

public static final String base64Decode(String _s,
                                        String _enc)
base 64 decoding

Parameters:
encoded - string
encoding - used to get string bytes
Returns:
result of encoding, or null if encoding invalid or string null, or string is invalid base 64 encoding

decode

public static byte[] decode(byte[] source,
                            int off,
                            int len)
Very low-level access to decoding ASCII characters in the form of a byte array. Does not support automatically gunzipping or any other "fancy" features.

Parameters:
source - The Base64 encoded data
off - The offset of where to begin decoding
len - The length of characters to decode
Returns:
decoded data
Since:
1.3

decode64

public static byte[] decode64(String s)
Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it.

Parameters:
s - the string to decode
Returns:
the decoded data
Since:
1.4

calculateClassPath

public static String calculateClassPath(ClassLoader cl)
calculate local file based class path for class loader if possible (servlet classes must be located there)

Parameters:
cl - class loader
Returns:
class path in string

toFile

public static final String toFile(URL url)

main

public static void main(String[] args)


Copyright © 2012. All Rights Reserved.