| Author |
Topics |
Replies |
Views |
Last Updated |
|
|
HostJ2ME.com Search Proxy |
8 |
760 |
August 26, 2009 12:36 PM |
Provides search results for the OSM client by aggregating results from Google, Bing, Wikipedia, and Yahoo using the respective search APIs.
Example Usage:
SearchAgent agent = new SearchAgent(); Query query = new Query(); query.addHeader("user-agent","MySearchClient")); query.setTerm("volvo xc60"); query.setTypes(FileRecord.TYPE_ALL);
List providers = new ArrayList(); providers.add("yahoo"); providers.add("live"); providers.add("google"); providers.add("googlevideo"); providers.add("wikipedia");
BasicUIListable results = agent.find(query,5*1000,100,providers.toArray(new String[0]));
for ( SearchResult record : results.items(pn,ps) ) { System.out.println(record.getTitle()); }
Contact me if you need the full source code
|
|
|
Need help |
0 |
672 |
June 14, 2009 7:57 AM |
I downloaded the application but,when opening it,I'm told 'invalid code,get key name' Please advise
|
|
|
Midlet Icon Extractor |
0 |
1219 |
January 21, 2009 12:13 PM |
HostJ2ME.com uses the code below to extract application icons from Midlet jars and display them in the HostJ2ME.com midlet directory.
package com.astrientlabs.hostj2me.util;
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile;
import com.astrientlabs.files.AstrientFile; import com.astrientlabs.util.Strings;
public class IconExtractor { private String MANIFEST = "META-INF/MANIFEST.MF"; public byte[] extract(String path) throws ZipException, IOException { return extract(new File(path)); } public byte[] extract(File jarFile) throws ZipException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ZipFile zipFile = new ZipFile(jarFile); try { /*for ( Enumeration? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) { System.out.println(e.nextElement().getName()); }*/ ZipEntry entry = zipFile.getEntry(MANIFEST);
InputStream is = zipFile.getInputStream(entry); if ( is != null ) { Properties props = new Properties(); props.load(is); String iconFile = props.getProperty("MIDlet-Icon"); if ( Strings.isNull(iconFile) ) { props.list(System.out); String midlet1 = props.getProperty("MIDlet-1"); if ( !Strings.isNull(midlet1) ) { String[] parts = midlet1.split(","); if ( parts.length > 2 ) { iconFile = parts[1].trim(); if ( iconFile.startsWith("/") ) { iconFile = iconFile.substring(1); } } } } if ( iconFile != null ) { ZipEntry iconEntry = zipFile.getEntry(iconFile); if ( iconEntry != null ) { FileOutputStream fos = new FileOutputStream("/tmp/icon.png"); InputStream zis = zipFile.getInputStream(iconEntry); int r = 0; byte[] buffer = new byte[4*1024]; while( (r = zis.read(buffer)) != -1 ) { baos.write(buffer,0,r); fos.write(buffer,0,r); } fos.close(); zis.close(); } } } } finally { zipFile.close(); } return baos.toByteArray(); } public static void main(String[] args) { File jarFile = new File("/projects/workspace/cliqmobile/builds/cliqmobile.jar"); IconExtractor extractor = new IconExtractor(); try { byte[] data = extractor.extract(jarFile); System.out.println(data.length + " " + AstrientFile.fileType(data)); } catch (ZipException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.exit(0); } }
|
|
|
Java Utility for perfrorming DNS Blacklist lookups. For more information on DNSBL see http://en.wikipedia.org/wiki/DNSBL
|
0 |
1396 |
January 16, 2009 12:43 PM |
package com.astrientlabs.net.dns;
import java.util.ArrayList; import java.util.Hashtable; import java.util.List;
import javax.naming.Context; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext;
import com.astrientlabs.prefs.Preferences;
public class DNSBL { private static String[] RECORD_TYPES = { "A", "TXT" }; private DirContext ictx; private List lookupServices = new ArrayList(); public DNSBL() throws NamingException { StringBuilder dnsServers = new StringBuilder(""); List nameservers = sun.net.dns.ResolverConfiguration.open().nameservers(); for( Object dns : nameservers ) { dnsServers.append("dns://").append(dns).append(" "); } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); env.put("com.sun.jndi.dns.timeout.initial", Preferences.system.get("dns.timeout","4000")); env.put("com.sun.jndi.dns.timeout.retries", Preferences.system.get("dns.retry","1")); env.put(Context.PROVIDER_URL,Preferences.system.get("dns.url",dnsServers.toString())); ictx = new InitialDirContext(env); } public void addLookupService(String service) { lookupServices.add(service); } public void check(String ip) throws DNSBLException { String[] parts = ip.split("\\."); StringBuilder buffer = new StringBuilder();
for (int i = 0; i parts.length; i++) { buffer.insert(0, '.'); buffer.insert(0, parts[i]); } ip = buffer.toString();
Attribute attribute; Attributes attributes; String lookupHost; for ( String service : lookupServices ) { lookupHost = ip + service; try { attributes = ictx.getAttributes(lookupHost, RECORD_TYPES); attribute = attributes.get("TXT"); if ( attribute != null ) { throw new DNSBLException(lookupHost + ": " + attribute.get()); } } catch (NameNotFoundException e) { //this is good //LogWriter.system.log(getClass(),e); } catch (NamingException e) { //LogWriter.system.log(getClass(),e); } } } public static void main (String[] args) { try { DNSBL dnsBL = new DNSBL(); dnsBL.addLookupService("blackholes.easynet.nl"); dnsBL.addLookupService("cbl.abuseat.org"); dnsBL.addLookupService("proxies.blackholes.wirehub.net"); dnsBL.addLookupService("bl.spamcop.net"); dnsBL.addLookupService("sbl.spamhaus.org"); dnsBL.addLookupService("dnsbl.njabl.org"); dnsBL.addLookupService("list.dsbl.org"); dnsBL.addLookupService("multihop.dsbl.org"); dnsBL.addLookupService("cbl.abuseat.org"); try { dnsBL.check("201.223.47.44"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } try { dnsBL.check("38.100.193.183"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } try { dnsBL.check("189.94.149.137"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } try { dnsBL.check("220.227.113.25"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } } catch (Exception e) { e.printStackTrace(); } System.exit(0); } } class DNSBLException extends Exception {
public DNSBLException() { super(); }
public DNSBLException(String message, Throwable cause) { super(message, cause); }
public DNSBLException(String message) { super(message); }
public DNSBLException(Throwable cause) { super(cause); } }
|
|
|
Line Wrapping Utility for Drawing Strings on a Canvas |
1 |
2900 |
January 29, 2007 3:14 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.text;
import java.util.Enumeration; import java.util.NoSuchElementException;
import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics;
public class LineEnumeration implements Enumeration { private Font font;
private String text; private int width; private int position; private int length; private int start = 0;
public LineEnumeration(Font font, String text, int width) { this.font = font; this.text = text; this.width = width; this.length = text.length(); }
public boolean hasMoreElements() { return (position (length - 1)); }
public Object nextElement() throws NoSuchElementException { try { int next = next();
String s = text.substring(start, next); start = next;
if (text.length() - 1 > start && (text.charAt(start) == ' ' || text.charAt(start) == '\n')) { position++; start++; }
return s; } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(e.getMessage()); } catch (Exception e) { throw new NoSuchElementException(e.getMessage()); } }
private int next() { int i = position; int lastBreak = -1;
for (; i length && font.stringWidth(text.substring(position, i)) = width; i++) { if (text.charAt(i) == ' ') { lastBreak = i; } else if (text.charAt(i) == '\n') { lastBreak = i; break; } }
if (i == length) { position = i; } else if (lastBreak == position) { position++; } else if (lastBreak position) { position = i; } else { position = lastBreak; }
return position; }
public int writeTo(Graphics g, int startx, int starty, int maxY, Font font) { int fontHeight = font.getHeight() + 1;
while (hasMoreElements() && starty maxY) { g.drawString(String.valueOf(nextElement()).trim(), startx, starty, Graphics.TOP | Graphics.LEFT); starty += fontHeight; }
return starty; }
public void reset() { start = 0; position = 0; } }
|
|
|
download reporting |
1 |
1928 |
September 30, 2008 3:26 AM |
I need to know how the hostj2me server manages to log the mobile configuration, profile,and the model number of the phone which downloads a mobile application from its server....How is it possible to query the phone OTA.......
|
|
|
I need some code post on this |
2 |
2133 |
November 14, 2007 4:16 AM |
I wrote a Time Table midlet using persistence storage API for university students to save course code with time. I want the midlet to alert the user when they have that particular course or some minutes before even when the midlet is closed. I need some code post on this. Thanks
|
|
|
J2ME: Getting a list of files in a directory (inside the .jar file) |
1 |
1544 |
March 26, 2007 11:04 AM |
Hi,
I have a problem which should be quite simple, but I haven't been able to work it out. I want to create a list of files inside a directory within the .jar file, but all the instructions I've seen for listing files within a directory assume you're using the fileConnection API and listing an external directory. I don't want to require JSR75, and I've got a feeling that that can't see inside the .jar file anyway.
I can load the files themselves with no problems, and my current solution is to create a text file with a list of all the files in the directory, but this is a nuisance to keep updating. So can someone give me some pointers about how to create a String[] with a list of files inside an internal directory?
|
|
|
Need some assistance |
1 |
1498 |
November 14, 2007 4:14 AM |
I wrote a Time Table midlet using persistence storage API for university students to save course code with time. I want the midlet to alert the user when they have that particular course or some minutes before even when the midlet is closed. I need assistance on this area. Kindly help me on this. Thanks
|
|
|
Paging utility for displaying lists in web UI |
0 |
1346 |
January 02, 2008 1:29 PM |
/* * Copyright (C) 2005 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 2005 */ package com.astrientlabs.webui;
import java.util.LinkedList; import java.util.List; import java.util.Random;
import com.astrientlabs.logging.LogWriter;
public class BasicUIListable extends LinkedList implements UIListable { /** * */ private static final long serialVersionUID = -7369036906003073472L; private int pageSize = 10; private int pageNumber = -1; private Random random = new Random(); public List getItems(int pageNumber) { int start = pageNumber * pageSize; int end = start + pageSize; return getItems(start,end); } public List items(int pageNumber, int pageSize) { int start = (pageNumber * pageSize); int end = start + pageSize; return getItems(start,end); } public List getItems(int start, int end) { try { if ( start > -1 && start size() ) { if ( end > size() ) { end = size(); }
return this.subList(start,end); } } catch (Exception e) { LogWriter.system.log(getClass(),e); } return this.subList(0,0);//(List)EMPTY_LIST; }
public void resetPageNumber() { pageNumber = -1; } public List next() { return getItems(++pageNumber); } public List current() { return ( pageNumber == -1 ) ? next() : getItems(pageNumber); } public List previous() { return getItems(--pageNumber); } /** * Returns the pageNumber. * @return int */ public int getPageNumber() { return pageNumber; }
/** * Returns the pageSize. * @return int */ public int getPageSize() { return pageSize; }
/** * Sets the pageNumber. * @param pageNumber The pageNumber to set */ public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; }
/** * Sets the pageSize. * @param pageSize The pageSize to set */ public void setPageSize(int pageSize) { this.pageSize = pageSize; }
public int totalPages() { int size = size(); int pageSize = getPageSize(); int total = size / pageSize; if ( (size % pageSize ) > 0 ) { total++; } return total; } public int totalPages(int pageSize) { int size = size();
int total = size / pageSize; if ( (size % pageSize ) > 0 ) { total++; } return total; } /* public synchronized void buildIndexes(Indexer indexer) { indexes.clear(); Object o; Object index; for ( Iterator iter = this.iterator(); iter.hasNext(); ) { o = iter.next(); index = indexer.index(indexes,this); } }*/ /* public static void main(String[] args) { BasicUIListable list = new BasicUIListable(); list.setPageSize(2); for(int i = 0; i 5;list.add(String.valueOf(i++))); for (String s : list) { System.out.println(s); } System.out.println("\n\n"); List l = list.getItems(2); for (String s : l) { System.out.println(s); } System.exit(0); }*/ public E random() { return this.get(random.nextInt(this.size())); } }
edited by hostj2me 1/2/08 1:31 PM
|
|
|
Detecting Soft Keys |
0 |
1595 |
November 06, 2007 3:17 PM |
Here is the pseudo code I use to determine the soft key assignments in most of my J2ME apps.
int KEY_SOFTKEY_LEFT = -6; int KEY_SOFTKEY_RIGHT = -7; if ( ...check needed ) { try { Class.forName("com.siemens.mp.game.Light"); KEY_SOFTKEY_RIGHT = -4; KEY_SOFTKEY_LEFT = -1; } catch (ClassNotFoundException ignore) { //ignore.printStackTrace(); try { Class.forName("com.mot.iden.customercare.CustomerCare"); KEY_SOFTKEY_RIGHT = -21; KEY_SOFTKEY_LEFT = -20; } catch (ClassNotFoundException ignore2) { //ignore2.printStackTrace(); try { Class.forName("com.motorola.phonebook.PhoneBookRecord"); KEY_SOFTKEY_RIGHT = -22; KEY_SOFTKEY_LEFT = -21; } catch (ClassNotFoundException ignore3) { if ( someCanvas.getKeyName(-21).equalsIgnoreCase("soft1") ) { KEY_SOFTKEY_LEFT = -21; } if ( someCanvas.getKeyName(-22).equalsIgnoreCase("soft2") ) { KEY_SOFTKEY_RIGHT = -22; } } } } }
|
|
|
MIDI Converter, Type 1 to Type 0 |
0 |
661 |
September 14, 2007 3:46 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 2005 */ package com.astrientlabs.audio;
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile;
import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiFileFormat; import javax.sound.midi.MidiSystem; import javax.sound.midi.Sequence; import javax.sound.midi.Track;
public class MidiConverter { public static boolean isType1(byte[] data) throws InvalidMidiDataException, IOException { return isType1(new ByteArrayInputStream(data)); }
public static boolean isType1(InputStream is) throws InvalidMidiDataException, IOException { MidiFileFormat format = MidiSystem.getMidiFileFormat(is); return (format.getType() == 1); }
public static byte[] convertToType(byte[] data, int maxTracks) throws InvalidMidiDataException, IOException { return convertToType0(new ByteArrayInputStream(data), maxTracks); }
public static byte[] convertToType0(InputStream is, int maxTracks) throws InvalidMidiDataException, IOException { Sequence sequence = MidiSystem.getSequence(is);
Track[] tracks = sequence.getTracks(); Track first = tracks[0]; Track track;
for (int i = 1; i tracks.length; i++) { track = tracks[i]; if (i maxTracks) for (int j = 0, stop = track.size(); j stop; first.add(track.get(j++))) ; sequence.deleteTrack(track); }
ByteArrayOutputStream os = new ByteArrayOutputStream(1024); MidiSystem.write(sequence, 0, os);
return os.toByteArray(); }
public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile(new File("G:/in.mid"), "r"); byte[] data = new byte[(int) raf.length()]; raf.readFully(data);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
if (isType1(bais)) { bais.reset(); data = convertToType0(bais, 8);
FileOutputStream fos = new FileOutputStream(new File("g:out.mid")); fos.write(data); fos.close(); // finally:) } } catch (Exception e) { e.printStackTrace(); } System.exit(0); } }
|
|
|
J2ME: E61 Key map file |
1 |
2019 |
March 22, 2007 6:04 PM |
32= 33=! 34=" 35=# 38=& 39=' 40=( 41=) 42=* 43=+ 44=,;. 45=- 46=.:_ 47=/ 48=0 49=1 50=2 51=3 52=4 53=5 54=6 55=7 56=8 57=9 61== 63=? 64=@ 95=_ 97=a" 98=b8 99=c) 100=d+ 101=e- 102=f4 103=g5 104=h6 105=i/ 106=j# 107=k 108=l 109=m0 110=n9 111=o= 112=p? 113=q! 114=r1 115=s@ 116=t2 117=u* 118=v7 119=w& 120=x( 121=y3 122=z' mode=0
|
|
|
BBC News | Technology | World Edition: Designing mobiles for the world |
0 |
1026 |
May 29, 2007 10:45 AM |
BBC News speaks to Jan Chipchase, principal human behavioural researcher at Nokia Design.
|
|
|
J2ME: How to tell if application was Push activated |
1 |
921 |
May 29, 2007 10:22 AM |
private boolean isPushActivated() { String[] connections = PushRegistry.listConnections(true); return ( connections != null && connections.length > 0 ) }
|