PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/atlib/branches/location/at/proximity/gps/CustomReader.java

http://ambienttalk.googlecode.com/
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
  1. package at.proximity.gps;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.util.ArrayList;
  5. import java.util.StringTokenizer;
  6. import javax.microedition.io.Connector;
  7. import javax.microedition.io.StreamConnection;
  8. import ocss.nmea.api.NMEAEvent;
  9. import ocss.nmea.api.NMEAReader;
  10. public class CustomReader extends NMEAReader {
  11. private final String URL = "socket://127.0.0.1:4444";
  12. public CustomReader(ArrayList al) {
  13. super(al);
  14. }
  15. public void read() {
  16. super.enableReading();
  17. try {
  18. StreamConnection scon = (StreamConnection) Connector.open(URL,
  19. Connector.READ_WRITE, true);
  20. System.out.println("Connecting to Server: " + URL);
  21. InputStream in = scon.openInputStream();
  22. StringBuffer sb = new StringBuffer();
  23. while (true) {
  24. int c = in.read();
  25. if (c == -1 || c == 0) {
  26. break;
  27. }
  28. sb.append((char) c);
  29. }
  30. super.fireDataRead(new NMEAEvent(this, sb.toString()));
  31. in.close();
  32. scon.close();
  33. } catch (IOException ioe) {
  34. System.err.println("Error Reading from: " + URL);
  35. ioe.printStackTrace();
  36. }
  37. }
  38. }