|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.less4j.Simple
public class Simple
A few utilities too simple for language experts, but damn usefull for application developers.
Copyright © 2006 Laurent A.V. Szyster
| Field Summary | |
|---|---|
static char[] |
ALPHANUMERIC
The strictly alphanumeric set of ASCII characters, usefull for ubiquitous identifiers on any devices and in any languages, including American English and all phone slangs. |
static java.lang.String |
encoding
The default 8 bit encoding for UNICODE strings |
static int |
fioBufferSize
The maximum block size for many file system. |
static int |
netBufferSize
Sixteen Kilobytes (16384 8-bit bytes) represent 3,4 pages of 66 lines and 72 columns of ASCII characters. |
| Constructor Summary | |
|---|---|
Simple()
|
|
| Method Summary | |
|---|---|
static void |
associate(java.lang.Object[] namespace,
java.util.Map object)
|
static java.lang.String |
decode(byte[] bytes,
java.lang.String encoding)
|
static byte[] |
encode(java.lang.String unicode,
java.lang.String encoding)
Encode a unicode string in the given characterset
encoding or use the default if a
UnsupportedEncodingException was throwed. |
static java.util.Iterator |
iterator(java.lang.Object[] objects)
A convenience to iterate around a "primitive" array. |
static java.util.Iterator |
itermap(java.util.Map map,
java.lang.Object[] keys)
|
static java.lang.String |
join(java.lang.Object separator,
java.util.Iterator iter)
If you miss Python's join, here it is ;-)
Synopsis
... |
static java.lang.StringBuffer |
join(java.lang.Object separator,
java.util.Iterator iter,
java.lang.StringBuffer sb)
If you miss Python's join, here it is ;-)
Synopsis
... |
static java.lang.String |
password(int length)
Generate a random password of a given length, using
only US ASCII characters. |
static java.lang.String |
read(java.io.BufferedReader br)
|
static java.lang.String |
read(java.lang.String name)
Try to read a complete file into a String. |
static java.lang.String |
read(java.net.URL url)
|
static int |
recv(java.io.InputStream is,
byte[] buffer,
int off)
|
static java.util.Iterator |
split(java.lang.String splitted,
char splitter)
Returns an Iterator that splits a string with a single
character as fast an lean as possible in Java (without a PCRE and
for a maybe too simple use case). |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static char[] ALPHANUMERIC
public static final java.lang.String encoding
public static int fioBufferSize
public static int netBufferSize
Sixteen Kilobytes (16384 8-bit bytes) represent 3,4 pages of 66 lines and 72 columns of ASCII characters. Much more information than what most of us can digest in a few minutes. It's a reasonable maximum to set for an application web interface updated by its user every few seconds.
Also, 16KB happens to be the defacto standard buffer size for TCP peers and networks since it's the maximum UDP datagram size in use. Which makes anything smaller than this limit a better candidate for the lowest possible IP network latency.
Finally, sixteen KB buffers can hold more than 65 thousand concurrent responses in one GB of RAM, a figure between one and two orders of magnitude larger than what you can reasonably expect from a J2EE container running some commodity hardware. At an average speed of 0.5 millisecond per concurrent request/response 16KB buffers sums up to 36MBps, less than 1Gbps.
So, that sweet sixteen spot is also a safe general maximum for a web 2.0 application controller that needs to keep lean on RAM and wants the fastest possible network and the smallest possible imbalance between input and output.
| Constructor Detail |
|---|
public Simple()
| Method Detail |
|---|
public static void associate(java.lang.Object[] namespace,
java.util.Map object)
public static java.lang.String decode(byte[] bytes,
java.lang.String encoding)
bytes - encoding -
public static byte[] encode(java.lang.String unicode,
java.lang.String encoding)
unicode string in the given characterset
encoding or use the default if a
UnsupportedEncodingException was throwed.
unicode - the String to encodeencoding - the character set name
bytepublic static java.util.Iterator iterator(java.lang.Object[] objects)
...
Iterator iter = Simple.iterator(new Object[]{x, y, z});
Usefull to iterate through final arrays, a prime construct in web
application controllers where check lists and filter sets made of
primitive array abound (usually to enforce business rules).
objects - the array to iterate through
public static java.util.Iterator itermap(java.util.Map map,
java.lang.Object[] keys)
public static java.lang.String join(java.lang.Object separator,
java.util.Iterator iter)
join, here it is ;-)
...
Iterator iter = Simple.iterator(new Object[]{"A", "B", "C"});
String joined = Simple.join(", ", iter)
...
separator - iter -
public static java.lang.StringBuffer join(java.lang.Object separator,
java.util.Iterator iter,
java.lang.StringBuffer sb)
join, here it is ;-)
...
Iterator iter = Simple.iterator(new Object[]{"A", "B", "C"});
StringBuffer joined = Simple.join(", ", iter, new StringBuffer())
...
separator - iter - sb - public static java.lang.String password(int length)
Generate a random password of a given length, using
only US ASCII characters.
length - of the password to generate
length characters
public static java.lang.String read(java.io.BufferedReader br)
throws java.io.IOException
br -
java.io.IOExceptionpublic static java.lang.String read(java.lang.String name)
Usage:
String resource = fileRead("my.xml");
Note that since it does not throw exceptions, this method can
be used to load static class String members, piggy-backing the
class loader to fetch text resources at runtime.
This convenience allows the servlet controller to cache resources when it is initialized.
name - the file's name
String or nullpublic static java.lang.String read(java.net.URL url)
url -
public static int recv(java.io.InputStream is,
byte[] buffer,
int off)
throws java.io.IOException
is - buffer - off -
java.io.IOException
public static java.util.Iterator split(java.lang.String splitted,
char splitter)
Iterator that splits a string with a single
character as fast an lean as possible in Java (without a PCRE and
for a maybe too simple use case).
splitted - the String to splitsplitter - the char used to split input
- Returns:
- an
Iterator of String
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||