Acme
Class Utils

java.lang.Object
  extended by Acme.Utils

public class Utils
extends java.lang.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 java.lang.Class[] EMPTY_CLASSES
           
static java.util.Enumeration EMPTY_ENUMERATION
           
static java.lang.Object[] EMPTY_OBJECTS
           
protected static byte EQUALS_SIGN
          The equals sign (=) as a byte.
protected static byte EQUALS_SIGN_ENC
           
static java.lang.String ISO_8859_1
           
protected static byte WHITE_SPACE_ENC
           
 
Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String base64Decode(java.lang.String _s, java.lang.String _enc)
          base 64 decoding
static java.lang.String base64Encode(byte[] _bytes)
          base 64 encoding, array of bytes converted to bytes using specified encoding
static java.lang.String base64Encode(java.lang.String _s, java.lang.String _enc)
          base 64 encoding, string converted to bytes using specified encoding
static java.lang.String calculateClassPath(java.lang.ClassLoader cl)
          calculate local file based class path for class loader if possible (servlet classes must be located there)
static java.lang.String canonicalizePath(java.lang.String path)
           
static java.lang.String[] copyOf(java.lang.String[] original, int newLength)
           
static java.lang.String[] copyOfRange(java.lang.String[] original, int from, int newLength)
           
static void copyStream(java.io.InputStream in, java.io.OutputStream out, long maxLen)
           
static void copyStream(java.io.Reader in, java.io.OutputStream out, java.lang.String charSet)
           
static void copyStream(java.io.Reader in, java.io.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 java.lang.String decode(java.lang.String s, java.lang.String enc)
          Decodes URL encoded string including newly introduced JavaScript encoding with %uxxxx chars
static byte[] decode64(java.lang.String s)
          Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it.
static java.lang.String htmlEncode(java.lang.String s, boolean encodeWS)
           
static float isGzipAccepted(java.lang.String contentEncoding)
           
static java.lang.String lsDateStr(java.util.Date date)
           
static void main(java.lang.String[] args)
           
static boolean match(java.lang.String pattern, java.lang.String string)
           
static int matchSpan(java.lang.String pattern, java.lang.String string)
           
static java.util.Map parsePostData(long len, java.io.InputStream is, java.lang.String encoding, java.lang.String[] cachedStream)
           
static java.util.Hashtable parseQueryString(java.lang.String query, java.lang.String encoding)
           
static java.lang.String[] splitStr(java.lang.String str)
           
static java.lang.String[] splitStr(java.lang.String str, char delim)
           
static java.lang.String[] splitStr(java.lang.String str, java.lang.String quotes)
           
static java.lang.String toFile(java.net.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 java.lang.String ISO_8859_1
See Also:
Constant Field Values

EMPTY_CLASSES

public static final java.lang.Class[] EMPTY_CLASSES

EMPTY_OBJECTS

public static final java.lang.Object[] EMPTY_OBJECTS

EMPTY_ENUMERATION

public static final java.util.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 java.lang.String lsDateStr(java.util.Date date)

parseQueryString

public static java.util.Hashtable parseQueryString(java.lang.String query,
                                                   java.lang.String encoding)

parsePostData

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

decode

public static java.lang.String decode(java.lang.String s,
                                      java.lang.String enc)
                               throws java.io.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:
java.io.UnsupportedEncodingException

htmlEncode

public static java.lang.String htmlEncode(java.lang.String s,
                                          boolean encodeWS)

isGzipAccepted

public static float isGzipAccepted(java.lang.String contentEncoding)

match

public static boolean match(java.lang.String pattern,
                            java.lang.String string)

matchSpan

public static int matchSpan(java.lang.String pattern,
                            java.lang.String string)

splitStr

public static java.lang.String[] splitStr(java.lang.String str)

splitStr

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

splitStr

public static java.lang.String[] splitStr(java.lang.String str,
                                          java.lang.String quotes)

copyOf

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

copyOfRange

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

canonicalizePath

public static java.lang.String canonicalizePath(java.lang.String path)

copyStream

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

copyStream

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

copyStream

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

base64Encode

public static final java.lang.String base64Encode(java.lang.String _s,
                                                  java.lang.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 java.lang.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 java.lang.String base64Decode(java.lang.String _s,
                                                  java.lang.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(java.lang.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 java.lang.String calculateClassPath(java.lang.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 java.lang.String toFile(java.net.URL url)

main

public static void main(java.lang.String[] args)


Copyright © 2010. All Rights Reserved.