/atlib/branches/location/at/proximity/gps/CustomReader.java
Java | 50 lines | 38 code | 12 blank | 0 comment | 5 complexity | cf8ea60e0e21f53f2d666ed818e66f65 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-2.1
- package at.proximity.gps;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.StringTokenizer;
- import javax.microedition.io.Connector;
- import javax.microedition.io.StreamConnection;
- import ocss.nmea.api.NMEAEvent;
- import ocss.nmea.api.NMEAReader;
- public class CustomReader extends NMEAReader {
- private final String URL = "socket://127.0.0.1:4444";
- public CustomReader(ArrayList al) {
- super(al);
- }
- public void read() {
- super.enableReading();
- try {
- StreamConnection scon = (StreamConnection) Connector.open(URL,
- Connector.READ_WRITE, true);
- System.out.println("Connecting to Server: " + URL);
- InputStream in = scon.openInputStream();
- StringBuffer sb = new StringBuffer();
- while (true) {
- int c = in.read();
- if (c == -1 || c == 0) {
- break;
- }
- sb.append((char) c);
- }
- super.fireDataRead(new NMEAEvent(this, sb.toString()));
- in.close();
- scon.close();
- } catch (IOException ioe) {
- System.err.println("Error Reading from: " + URL);
- ioe.printStackTrace();
- }
- }
- }