| Forum Details |
Topics |
Posts |
| Categories |
| |
| 464 member(s) |
| 438,127 hit(s) |
| 14 categories |
| 48 topics |
| 26 messages |
| 0 online |
|
| Author |
Topics |
Replies |
Views |
Last Updated |
|
|
J2ME: replaceAll for Strings |
0 |
675 |
May 28, 2007 4:25 PM |
public static String replaceAll(String text, String old, String newString) { int next = text.indexOf(old); if ( next == -1 ) { return text; } else { StringBuffer buffer = new StringBuffer(text.substring(0,next)); buffer.append(newString); int current = next+old.length(), stop = text.length(); for ( ; current stop && (next = text.indexOf(old,current)) != -1; ) { buffer.append(text.substring(current, next)); buffer.append(newString); current = next+old.length(); } if ( current stop ) { buffer.append(text.substring(current)); } return buffer.toString(); } }
|
|
|
Unix: Show machine configuration |
0 |
831 |
May 09, 2007 12:41 PM |
|
|
|
J2ME: Split a string by character, StringTokenizer |
0 |
1146 |
March 05, 2007 12:51 PM |
public static Vector split(String s, char c) { Vector parts = new Vector(); if ( s != null ) { int lastfound = 0; int pos = 0; while ( (lastfound = s.indexOf(c,pos)) != - 1 ) { parts.addElement(s.substring(pos,lastfound)); pos = lastfound+1; } if ( pos < s.length() ) parts.addElement(s.substring(pos)); } return parts; }
edited by hostj2me 4/28/07 9:43 PM
|
|
|
Venture Beat: Social capitalism |
0 |
1211 |
April 09, 2007 3:12 PM |
Today is Good Friday.
Appropriate time, perhaps, to point out the latest column, by attorney Jay Parkhill, which looks at social capitalism, its two basic models, and why some companies in this area are likely to succeed while others are not.
|
|
|
HostJ2ME.com Image proxy servlet source code |
0 |
607 |
April 02, 2007 12:34 AM |
package com.astrientlabs.biz.web;
import java.awt.image.renderable.ParameterBlock; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL;
import javax.media.jai.Interpolation; import javax.media.jai.JAI; import javax.media.jai.RenderedOp; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
import com.astrientlabs.files.AstrientFile; import com.astrientlabs.logging.LogWriter; import com.astrientlabs.lpa.CachingFileStore; import com.astrientlabs.misc.ApiKey; import com.astrientlabs.util.Strings; import com.astrientlabs.web.WebServlet; import com.astrientlabs.webstats.StatRecorder; import com.sun.media.jai.codec.FileSeekableStream; import com.sun.media.jai.codec.JPEGEncodeParam;
public class ImageProxyServlet extends WebServlet { /** * */ private static final long serialVersionUID = -7462909049956679674L; private static final CachingFileStore fileStore = new CachingFileStore("/tmp/j2me/imageproxy"); private static final long maxFileSize = 1024L * 1024L * 10; public void _doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { URL u = null; HttpURLConnection con = null; try { StatRecorder.record(request); String heightString = request.getParameter("h"); String widthString = request.getParameter("w"); String url = request.getParameter("u"); String format = Strings.ifNull(request.getParameter("f"), "JPEG"); //String auth = Strings.ifNull(request.getParameter("auth"), "public");
String apiKey = request.getParameter("key"); ApiKey.testValid(apiKey);
LogWriter.system.log(ImageProxyServlet.class, apiKey + " Requested file " + url);
u = new URL(url); con = (HttpURLConnection) u.openConnection();
String id = "F" + u.getHost().hashCode() + "." + u.getPath().hashCode();
String path = fileStore.getLocation(id, "orig"); File f = new File(path);
if (con.getContentLength() != -1 && con.getContentLength() > maxFileSize) { response.sendError(HttpURLConnection.HTTP_ENTITY_TOO_LARGE, "requested resource is too large"); return; }
if ( /*!Preferences.system.getBoolean("imgproxy.caching",false) ||*/ (!f.exists() || f.lastModified() con.getLastModified() || f.length() == 0 || con.getContentLength() != f.length()) ) { LogWriter.system.log(ImageProxyServlet.class, "downloading updated image"); fileStore.invalidate(id, "orig"); fileStore.add(id, "orig", new byte[0]);
InputStream is = u.openStream(); FileOutputStream fos = new FileOutputStream(f); try { int r; int read = 0; byte[] buffer = new byte[4*1024]; while ((r = is.read(buffer)) != -1) { fos.write(buffer, 0, r); read += r; if (read > maxFileSize) { response.sendError(HttpURLConnection.HTTP_ENTITY_TOO_LARGE, "requested resource is too large"); return; } } fos.flush(); } finally { if (is != null) is.close(); try { fos.close(); } catch (Exception e) { } } }
String newFilePath = format.toUpperCase().hashCode() + "." + heightString + "." + widthString;
path = fileStore.getLocation(id, newFilePath); File newFile = new File(path);
if (!newFile.exists() || newFile.lastModified() f.lastModified() || newFile.length() == 0) { fileStore.invalidate(id, newFilePath); FileSeekableStream stream = new FileSeekableStream(f); RenderedOp image = JAI.create("stream", stream);
scale(image, format, path, widthString, heightString); image.dispose(); }
try { response.setContentType(AstrientFile.fileType(new FileSeekableStream(newFile))); } catch (Exception e) { LogWriter.system.log(ImageProxyServlet.class, e); }
fileStore.writeTo(response.getOutputStream(), id, newFilePath); } catch (Exception e) { LogWriter.system.log(ImageProxyServlet.class, e); response.sendError(HttpURLConnection.HTTP_NO_CONTENT, e.getMessage()); } finally { if ( con != null ) { try { con.disconnect(); } catch (Exception ignored) { } } } }
public void scale(RenderedOp image, String format, String location, String widthString, String heightString) { int width = (widthString == null) ? image.getWidth() : Integer.parseInt(widthString); int height = (heightString == null) ? image.getHeight() : Integer.parseInt(heightString);
try { /*boolean landscape = (image.getWidth() > image.getHeight()); if (landscape && (height > width)) { int tmpi = height; height = width; width = tmpi; }*/
double cw = width / (1.0 * image.getWidth()); double ch = height / (1.0 * image.getHeight());
double scale; if (cw ch) { scale = cw; } else { scale = ch; }
if (scale > 1.0) scale = 1.0;
Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC); ParameterBlock params = new ParameterBlock(); params.addSource(image); params.add(new Float(scale)); params.add(new Float(scale)); params.add(0.0F); params.add(0.0F); params.add(interp);
RenderedOp image1 = JAI.create("scale", params);
if (format.equalsIgnoreCase("JPEG")) { JPEGEncodeParam param = new JPEGEncodeParam(); param.setQuality(1.2F); RenderedOp op = JAI.create("filestore", image1, location, format, param); op.dispose(); } else { RenderedOp op = JAI.create("filestore", image1, location, format); op.dispose(); }
} finally { } } }
|
|
|
alarm:clock: Sequoia Invests $11.5M in Micro-finance Fund |
0 |
1265 |
March 31, 2007 6:58 PM |
Sequoia is getting some nice TV coverage today on MSNBC's Closing Bell for its $11.5M investment in Indian Microfinance bank SKS. SKS says it is now one of the fastest growing Microfinance institutions in the world and the first for-profit microfinance lengder. The company says it grew by 160% with a 99% on-time repayment rate last year. SKS currently provides loans to its 600K members in 7,200 villages in rural India.
SKS says that the new capital will go towards giving loans to over 5M poor families by 2010. SKS estimates that its loans have a return on equity of 23%. In fact, 23% is the standard interest rate for its loans, which seems to us like loan sharking but we understand the poverty level folks that get these loans don't have many other options.
Sequoia's investment includes an exit clause. In the next three to five years, SKS will either have an initial public offering or be acquired.
Here's an interesting quote from another SKS investor: â??Established markets never took poor people seriously. They neglected the obvious business opportunity. The larger banks and some of the larger institutions have not gone into this business systematically. This creates an...
edited by hostj2me 3/31/07 7:00 PM
|
|
|
Yahoo! News: Wireless and Mobile: Wireless piggybacking case sets precedent: experts
(AFP)
|
1 |
1173 |
March 26, 2007 12:19 PM |
>AFP - When 17-year-old Garyl Tan Jia Luo piggybacked on his neighbour's unsecured wireless Internet network to chat online, he could not have imagined that in doing so he would make Asian legal history.
>
|
|
|
BBC News | Technology | World Edition: Injunction in Vonage patent row |
1 |
1134 |
March 26, 2007 12:00 PM |
A US judge bans internet phone firm Vonage from using patents owned by US phone giant Verizon.
|
|
|
alarm:clock: Mobile's AdMob Pours $15M From Top Shelf Investors |
1 |
1149 |
March 26, 2007 11:49 AM |
Sequoia seems to be enamoured of its AdBrite investment as AdMob looks a lot like AdBrite. Like AdBrite, AdMob is an open marketplace where any publisher can sell his mobile ad inventory. When we first covered AdMob, we were taken aback by their claims of ads served. The number keeps getting bigger as it claims over 1.6B ads served in less than a year and it now says it has more than 1200 publishers. Today, San Mateo's AdMob has raised $15M in Series B funding led by Accel Partners led the deal and joined by return backer Sequoia Capital. To some extent, Admob competes with Screentonic, Medio, ThirdScreen Media as well as Google. AdMob's leadership is provided by Omar Hamoui, CEO and Founder. He previously founded Fotochatter: a mobile to mobile image sharing network that he ran for 11 months from March 2005 – January 2006. Before that he ran HerBabyShower for 2 years and GoPix for a bit over a year. CEO Omar Hamoui Bangs The Gang To Celebrate 1B ads served We have to say we are impressed with the maturity of the company's ad server. AdMob lets advertisers target by country, language, carrier, phone brand, phone... >
>
|
|
|
y!p! Source Code Available |
0 |
492 |
March 21, 2007 6:04 PM |
The complete y!p! Yahoo Image Search Java ME (J2ME) example client source code is now available. You can download it and find out more details here:
http://www.hostj2me.com/appdetails.html?id=1557
There is a video walkthrough here:
http://worlddeveloper.org/files/1877/yipi.wmv
|
|
|
Property File Parser and Persistent Settings Object for Midlets |
2 |
1042 |
January 29, 2007 3:09 PM |
/* * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Astrient Labs, LLC * www.astrientlabs.com * rashid@astrientlabs.com * Rashid Mayes 2006 */ package com.astrientlabs.prefs;
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Hashtable;
import javax.microedition.rms.RecordEnumeration; import javax.microedition.rms.RecordStore; import javax.microedition.rms.RecordStoreNotFoundException;
import com.astrientlabs.log.Logger;
public class PropertyMap extends Hashtable { public static final char RECORD_DELIMITER = '=';
private PropertyMap parent; private String name;
public PropertyMap(String name) { this.name = name; }
public PropertyMap(PropertyMap parent, String name) { this.name = name; this.parent = parent; }
public void initialize() { InputStream is = null;
try { is = getClass().getResourceAsStream("/config/" + name + ".properties"); parse(is); } catch (IOException e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (Exception e) { } } }
public void parse(InputStream is) throws IOException { int b; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((b = is.read()) != -1) { if (b == '\n') { addLine(new String(baos.toByteArray()).trim()); baos.reset(); } else { if (b != '\n' && b != '\r') baos.write(b); } }
if (baos.size() != 0) { addLine(new String(baos.toByteArray()).trim()); } }
private void addLine(String line) { if (line.charAt(0) != '#') { int ii = line.indexOf(RECORD_DELIMITER); if (ii != -1 && ii != (line.length() - 1)) { put(line.substring(0, ii), line.substring(ii + 1)); } } }
public void delete() { String recordStoreName = "props-" + name; try { RecordStore.deleteRecordStore(recordStoreName); } catch (RecordStoreNotFoundException e) { } catch (Exception e) { Logger.instance.log("propertyMap.delete()", e); } }
public void read() { String recordStoreName = "props-" + name; RecordStore preferenceDB = null;
try { preferenceDB = RecordStore.openRecordStore(recordStoreName, false); RecordEnumeration renum = preferenceDB.enumerateRecords(null, null, false);
while (renum.hasNextElement()) { addLine(new String(renum.nextRecord())); } } catch (RecordStoreNotFoundException e) { } catch (Exception e) { Logger.instance.log("propertyMap.read()", e); } finally { try { if (preferenceDB != null) { preferenceDB.closeRecordStore(); } } catch (Exception e) { } } }
public void write() { String recordStoreName = "props-" + name; RecordStore recordStore = null;
try { delete();
if (!isEmpty()) { recordStore = RecordStore.openRecordStore(recordStoreName, true);
Object key; byte[] bytes;
StringBuffer buffer = new StringBuffer(); Enumeration keys = keys(); while (keys.hasMoreElements()) { key = keys.nextElement(); buffer.append(key); buffer.append(RECORD_DELIMITER); buffer.append(get(key));
bytes = buffer.toString().getBytes();
recordStore.addRecord(bytes, 0, bytes.length); buffer.setLength(0); } }
Logger.instance.log("propertyMap.write()", name + " saved to " + recordStoreName); } catch (Exception e) { Logger.instance.log("propertyMap.write().1", e); } finally { try { if (recordStore != null) { recordStore.closeRecordStore(); } } catch (Exception e) { Logger.instance.log("propertyMap.write().2", e); } } }
//TODO: only strings public Object put(Object arg0, Object arg1) { return super.put(arg0.toString(), arg1.toString()); }
public String get(String name) { String value = (String) super.get(name); if (value == null) { return (parent == null) ? null : parent.get(name); } else { return value; } }
public String get(String name, String def) { String value = get(name); return (value == null) ? def : String.valueOf(value); }
public boolean getBoolean(String name, boolean def) { String value = get(name); return (value == null) ? def : value.equalsIgnoreCase("true"); }
public int getInt(String name, int def) { String value = get(name); if (value != null) { try { if (value.startsWith("-")) { return -1 * Integer.parseInt(value.substring(1)); } else { return Integer.parseInt(value); } } catch (Exception e) { } }
return def; }
public int getInt(String name, int def, int r) { String value = get(name); if (value != null) { try { if (value.startsWith("-")) { return -1 * Integer.parseInt(value.substring(1), r); } else { return Integer.parseInt(value, r); } } catch (Exception e) { } }
return def; } }
|
|
|
J2ME: Persistent Properties Utility |
0 |
482 |
March 16, 2007 11:53 AM |
/* * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Astrient Labs, LLC * www.astrientlabs.com * rashid@astrientlabs.com * Rashid Mayes 2006 */ package com.astrientlabs.prefs;
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Hashtable;
import javax.microedition.rms.RecordEnumeration; import javax.microedition.rms.RecordStore; import javax.microedition.rms.RecordStoreNotFoundException;
import com.astrientlabs.log.Logger;
public class PropertyMap extends Hashtable { public static final char RECORD_DELIMITER = '='; private PropertyMap parent; private String name; public PropertyMap(String name) { this.name = name; } public PropertyMap(PropertyMap parent, String name) { this.name = name; this.parent = parent; } public void initialize() { InputStream is = null;
try { is = getClass().getResourceAsStream("/config/"+name+".properties"); parse(is); } catch (IOException e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (Exception e) { } } } public void parse(InputStream is) throws IOException { int b; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((b = is.read()) != -1) { if (b == '\n') { addLine(new String(baos.toByteArray()).trim()); baos.reset(); } else { if (b != '\n' && b != '\r') baos.write(b); } }
if (baos.size() != 0) { addLine(new String(baos.toByteArray()).trim()); } }
private void addLine(String line) { if (line.charAt(0) != '#') { int ii = line.indexOf(RECORD_DELIMITER); if (ii != -1 && ii != (line.length() - 1)) { put(line.substring(0, ii), line.substring(ii + 1)); } } } public void delete() { String recordStoreName = "props-"+name; try { RecordStore.deleteRecordStore(recordStoreName); } catch (RecordStoreNotFoundException e) { } catch (Exception e) { Logger.instance.log("propertyMap.delete()",e); } } public void read() { String recordStoreName = "props-"+name; RecordStore preferenceDB = null; try { preferenceDB = RecordStore.openRecordStore(recordStoreName, false); RecordEnumeration renum = preferenceDB.enumerateRecords(null, null, false);
while (renum.hasNextElement()) { addLine(new String(renum.nextRecord())); } } catch (RecordStoreNotFoundException e) { } catch (Exception e) { Logger.instance.log("propertyMap.read()",e); } finally { try { if (preferenceDB != null) { preferenceDB.closeRecordStore(); } } catch (Exception e) { } } }
public void write() { String recordStoreName = "props-"+name; RecordStore recordStore = null;
try { delete(); if (!isEmpty()) { recordStore = RecordStore.openRecordStore(recordStoreName, true);
Object key; byte[] bytes;
StringBuffer buffer = new StringBuffer(); Enumeration keys = keys(); while (keys.hasMoreElements()) { key = keys.nextElement(); buffer.append(key); buffer.append(RECORD_DELIMITER); buffer.append(get(key));
bytes = buffer.toString().getBytes();
recordStore.addRecord(bytes, 0, bytes.length); buffer.setLength(0); } } Logger.instance.log("propertyMap.write()",name + " saved to " + recordStoreName); } catch (Exception e) { Logger.instance.log("propertyMap.write().1",e); } finally { try { if (recordStore != null) { recordStore.closeRecordStore(); } } catch (Exception e) { Logger.instance.log("propertyMap.write().2",e); } } }
//TODO: only strings public Object put(Object arg0, Object arg1) { return super.put(arg0.toString(), arg1.toString()); }
public String get(String name) { String value = (String) super.get(name); if ( value == null ) { return (parent == null) ? null : parent.get(name); } else { return value; } }
public String get(String name, String def) { String value = get(name); return (value == null) ? def : String.valueOf(value); }
public boolean getBoolean(String name, boolean def) { String value = get(name); return (value == null) ? def : value.equalsIgnoreCase("true"); }
public int getInt(String name, int def) { String value = get(name); if (value != null) { try { if (value.startsWith("-")) { return -1 * Integer.parseInt(value.substring(1)); } else { return Integer.parseInt(value); } } catch (Exception e) { } } return def; } public int getInt(String name, int def, int r) { String value = get(name); if (value != null) { try { if (value.startsWith("-")) { return -1 * Integer.parseInt(value.substring(1),r); } else { return Integer.parseInt(value,r); } } catch (Exception e) { } } return def; } }
|
|
|
J2ME: Logger, remote logging utility from w!k! |
2 |
968 |
March 15, 2007 11:32 AM |
/* * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Astrient Labs, LLC * www.astrientlabs.com * rashid@astrientlabs.com * Rashid Mayes 2006 */ package com.astrientlabs.log;
import java.io.DataInputStream; import java.io.DataOutputStream; import java.util.Calendar; import java.util.Vector;
import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection;
import com.astrientlabs.midlet.Wiki; import com.astrientlabs.threads.Semaphore;
public class Logger implements Runnable { public static final Logger instance = new Logger(15,"w!k!","astrient:1e4e4d:-1985900"); private static int sequenceNumberMajor = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); private static int sequenceNumberMinor; private int flush; private int protocolID = 1; private String applicationName; private String APIKey; private Semaphore semaphore = new Semaphore(0); private Vector messages = new Vector(); private Thread thread = null; private boolean running = false; private LogListener logListener; public Logger(int flush, String applicationName, String APIKey) { this.flush = flush; this.applicationName = applicationName; this.APIKey = APIKey; (thread = new Thread(this)).start(); } public void setListener(LogListener logListener) { this.logListener = logListener; } public void log(String source, Throwable t) { log(source, t + ": " + t.getClass().getName() + ": " + t.getMessage()); } public void log(String source, String message) { log(source + ": " + message); } public void log(Throwable t) { t.printStackTrace(); log(t.getClass().getName() + " " + t.getMessage()); } public void log(String message) { //TODO: uncomment for debug System.out.println(message); if ( logListener != null ) logListener.log(message); messages.addElement(new LogMessage(message)); if ( messages.size() > flush ) { semaphore.release(); } } public void flush() { semaphore.release(); } public void run() { while ( thread != null ) { semaphore.acquire(); if ( !running ) { running = true; try { uploadMessages(); } finally { running = false; } } } } protected void uploadMessages() { int count = messages.size(); if ( count > 0 ) { HttpConnection c = null; DataInputStream dis = null; DataOutputStream dos = null; String url = Wiki.instance.getAppProperty("server"); if ( url == null ) url = "http://www.hostj2me.com/applog"; try { c = (HttpConnection) Connector.open(url,Connector.READ_WRITE); c.setRequestMethod(HttpConnection.POST); dos = c.openDataOutputStream(); dos.writeLong(protocolID); dos.writeUTF(APIKey); dos.writeUTF(applicationName); dos.writeInt(count); LogMessage message; for (int i = 0; i count; i++ ) { message = (LogMessage)messages.firstElement(); messages.removeElement(message); dos.writeLong(message.timeStamp); dos.writeUTF("SEQN: " + sequenceNumberMajor + "." + (sequenceNumberMinor++)); dos.writeUTF(message.message); } dos.flush(); dis = c.openDataInputStream(); dis.readInt(); //response code, 0 = OK } catch (Throwable e) { e.printStackTrace(); } finally { if (dis != null) { try { dis.close(); } catch (Exception e) { } } if (dos != null) { try { dos.close(); } catch (Exception e) { } } if (c != null) { try { c.close(); } catch (Exception e) { } } } } } public void stop() { semaphore.release(); thread = null; } }
edited by hostj2me 3/15/07 11:33 AM
|
|
|
MIFOS |
0 |
691 |
March 13, 2007 9:53 PM |
Mifos looks like a promising project. It is using open-source development to create a micro-finance platform.
More information at the link below.
http://www.mifos.org
|
|
|
HostJ2me.com Tips & Tricks |
3 |
1062 |
March 10, 2007 11:37 AM |
Share how you use Hostj2me.com and your experience with its features
|
|