Thanks for the good information Miguel, I appreciate it even though I am aware of most of the code you are displaying below.
My original question was a more general one, regarding the porting of J2ME code into Android, something that has been an issue for many developers who have large chunks of code in J2ME that are not easy to rewrite. I didn't give much information about the overall goal so you are right, the small code segment I showed looked like a very small update that would have taken seconds actually to port and in fact modified to be done correctly (to avoid casting etc.). That particular piece of code is trying to open tcp sockets and use low lever streams to communicate. I have been porting a large peer-to-peer software baseline that has been running successfully under J2ME. In fact most of the code I imported in Android so far from J2ME has been working correctly and with very good performance results. The J2ME Polish project actually has ported the libs that I need in this case (including the javax.microedition) for the Android platform and that's what I have been using. So no, I am not "lazily" importing old code, I am importing current code that we need to run on Android. Logically if the places where this Connection class is used is in the hundreds, it made sense to be more efficient and try to use libs of J2ME ported in Android rather than changing all those places. Yes - not optimal but it is what it is. In summary, yes you and others have answered my original question, unless the trafeoffs are against it, it makes sense to always try to 'translate' everything that you run on Android using Android's API. Again thanks for the good pointers below On Sep 10, 7:26 pm, Miguel Morales <[email protected]> wrote: > Sounds like you're doing it wrong. One, try not to include any > foreign APIs/Jars unless you need it. Two, instead of trying to > lazily port old code, redo the functionality using the classes android > provides. > Casting is prone to bugs, if don't incorrectly, it can hide warnings > and errors. I don't know what it is you're trying to do there. > > You haven't explained what it is you're trying to do. Are you trying > to open a socket and communicate via low level streams or just http? > > I suspect what you're trying to do is really easy, and shouldn't have > taken more than a few minutes to update. > > You'll want to create an http url using the Url class: > > String mUrl = "http://whatever.com"; > URL url = new URL(mUrl); > > Then open a connection using URLConnection: > > URLConnection connection = url.openConnection(); > > You can then work with the stream directly using > connection.getInputStream(), or work with BufferedReader like: > BufferedReader in = new BufferedReader(new > InputStreamReader(connection.getInputStream()), 8); > > Grab the response to a string, not recommended, but if it's not a lot of data: > String line; > while ((line = in.readLine()) != null) > { > response = response + line;} > > in.close(); > > On Fri, Sep 10, 2010 at 2:56 PM, kypriakos <[email protected]> wrote: > > > Will do - thanks > > > On Aug 27, 7:05 am, "[email protected]" <[email protected]> > > wrote: > >> How about using a semi-automated service to convert J2ME to Android ? > >> Give it a try - free for eval purposes. Take a look atwww.upontek.com, > >> or send me your jar to [email protected] > > >> Thanks !!!! > > >> On 27 אוגוסט, 11:28, Indicator Veritatis <[email protected]> wrote: > > >> > Since Android does not include the javax.microedition package, one > >> > should not expect an exact equivalent. But we do have the > >> > org.apache.conn and org.apache.http.* packages; some of us think these > >> > are much better than anything in javax.microedition! > > >> > One should still expect to use a very little bit from java.net, e.g. > >> > the Url and Uri classes. > > >> > On Aug 26, 1:40 pm, kypriakos <[email protected]> wrote: > > >> > > Does anyone know the equivalent of these imports from J2ME to > >> > > Android? > > >> > > import javax.microedition.io.Connector; > >> > > import javax.microedition.io.HttpConnection; > >> > > import javax.microedition.io.SocketConnection; > >> > > import javax.microedition.io.StreamConnection; > > >> > > Also, I needed to import midpapi20.jar but I don't want to use > >> > > packages > >> > > outside Android into my app -- would I be able to find most of the > >> > > related packages in Android libs? > > >> > > Thanks very much-הסתר טקסט מצוטט- > > >> > -הראה טקסט מצוטט- > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected] > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > ~ Jeremiah:9:23-24 > Android 2D > MMORPG:http://developingthedream.blogspot.com/,http://diastrofunk.com,http://www.youtube.com/user/revoltingx -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

