Skip to main content
Last updated April 12, 2011 04:34, by kmashint
Feedicon  

akmemobile Wiki

This code library helps fill gaps in Java ME / J2ME development. It provides helper classes for manipulating byte, character, and XML streams; working with files, property files, log files, arrays, dates, numbers, and strings; and covering gaps in Java ME Math with a port of C-library routines for IEEE-754.

Package-Class Tree:

  • akme.mobile.io
    • ByteBufferFast
    • CharArrayWriter
    • IoUtil
    • JsonBuffer
    • JsonTokenizer
    • JsonUtil
    • StringBufferFast
    • XmlBuffer
    • XmlReader
    • XmlSerializer
    • XmlTokenizer
    • XmlUtil
    • XmlWriter
  • akme.mobile.lang
    • NestableRuntimeException
  • akme.mobile.util
    • ArrayUtil
    • ClassUtil
    • DateUtil
    • IntList
    • Logger
    • MathUtil
    • MatrixUtil
    • NumberUtil
    • Properties
    • StringUtil

Sample code:

 
/** 
 * Pad the positive value with zeros to at most the given length (high-efficiency).
 * e.g. <code>pos += StringUtil.padZeroLeftFastMaxLength(result, pos, cal.get(Calendar.YEAR), 4);</code>
 * 
 * @return the given length.
 */
public static int padZeroLeftFastMaxLength(final char[] result, final int start, int value, final int length) {
	if (value < 0) throw new IllegalArgumentException(value + LESS_THAN_ZERO);
	for (int i=length; i-- > 0;) { result[start+i] = (char) (value%10 + '0'); value /= 10; }
	return length;
}

 /**
 * Check if the given URL exists.
 */
 public static final boolean exists(String url) {
  if (url == null) return false;
  try {
   if (url != null && url.startsWith("file:")) {
    FileConnection fcon = (FileConnection)Connector.open(url);
    final boolean result = fcon != null && fcon.exists();
    if (fcon != null) fcon.close();
    return result;
   } else {
    Connector.openInputStream(url).close();
    return true;
   }
  }
  catch (Exception ex) {
   return false;
  }
 }
 
 /**
 * Create a directory structure if it doesn't exist, may throw an IOException.
 */
 public static boolean createDirectoriesIfNeeded(String path) throws IOException {
  FileConnection fcon = null;
  for (int i=0, j=path.indexOf('/', path.indexOf("//")+2); 
    j<path.length() && j != -1; 
    i = j, j=path.indexOf('/', i+1)) {
  try {
   String dir = path.substring(i, j+1); 
   fcon = (FileConnection) Connector.open(dir, Connector.WRITE, true);
   if (fcon.exists()) {
    if (!fcon.isDirectory()) return false;
   } else {
    fcon.create();
    }
   }
   finally {
    closeQuiet(fcon);
   }
  }
  fcon = null;
  return true;
 }

 
 
Close
loading
Please Confirm
Close