×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Unhappy BufferedReader issues

    Is there a command or at least an alternate command in J2ME for BufferedReader?

    I did go through the API documents and was unsuccessful.

    I am unable to use this in my code. I use JDK 1.3 and eclipse ME for coding.

    The suggestion eclipse offers is "Add JRE 1.6 to build path" , which I do not want.


    Kindly let me know what can be done.

    Thanks
    - Ashwin

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: BufferedReader issues

    No, this class doesn't exist, and there is no direct equivalent.

    What functionality do you want from this class?

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Re: BufferedReader issues

    Quote Originally Posted by grahamhughes View Post
    No, this class doesn't exist, and there is no direct equivalent.

    What functionality do you want from this class?

    Graham.

    Basically , i want to perform an OAuth authentication.

    Initially the consumer is presented with a key , he has to exchange the key to perform any action. So, when he presents the key , we need to verify it and authorize.

    Hope you are clear. Please let me know if you are confused/if you have any queries.

    - Ashwin

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: BufferedReader issues

    How does this relate to BufferedReader?

    Graham.

  5. #5
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Re: BufferedReader issues

    Quote Originally Posted by grahamhughes View Post
    How does this relate to BufferedReader?

    Graham.

    Well , I gave the rough approach of what am doing , am new to Java and J2ME - not good in putting things properly as of now. Sorry for that ! You can have a look at the code and suggest me.

    Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    import oauth.signpost.OAuth;
    import oauth.signpost.OAuthConsumer;
    import oauth.signpost.OAuthProvider;
    import oauth.signpost.basic.DefaultOAuthConsumer;
    import oauth.signpost.basic.DefaultOAuthProvider;
    import oauth.signpost.signature.SignatureMethod;
    
    
    public class Main {
    
        public static void main(String[] args) throws Exception {
        	OAuthConsumer consumer = new DefaultOAuthConsumer(
                    "YourConsumerKey",
                    "YourConsumerSecret",
                    SignatureMethod.HMAC_SHA1);
    
            OAuthProvider provider = new DefaultOAuthProvider(consumer,
                    "https://api.linkedin.com/uas/oauth/requestToken",
                    "https://api.linkedin.com/uas/oauth/accessToken",
                    "https://api.linkedin.com/uas/oauth/authorize");
    
            System.out.println("Fetching request token from LinkedIn...");
    
            // we do not support callbacks, thus pass OOB
            String authUrl = provider.retrieveRequestToken(OAuth.OUT_OF_BAND);
    
            System.out.println("Request token: " + consumer.getToken());
            System.out.println("Token secret: " + consumer.getTokenSecret());
    
            System.out.println("Now visit:\n" + authUrl
                    + "\n... and grant this app authorization");
            System.out.println("Enter the PIN code and hit ENTER when you're done:");
    
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String pin = br.readLine();
    
            System.out.println("Fetching access token from LinkedIn...");
    
            provider.retrieveAccessToken(pin);
    
            System.out.println("Access token: " + consumer.getToken());
            System.out.println("Token secret: " + consumer.getTokenSecret());
    
            URL url = new URL("http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url,headline)");
            HttpURLConnection request = (HttpURLConnection) url.openConnection();
    
            consumer.sign(request);
    
            System.out.println("Sending request to LinkedIn...");
            request.connect();
            String responseBody = convertStreamToString(request.getInputStream());
            
            System.out.println("Response: " + request.getResponseCode() + " "
                    + request.getResponseMessage() + "\n\n" + responseBody);
        }
        
        public static String convertStreamToString(InputStream is) {
            /*
             * To convert the InputStream to String we use the BufferedReader.readLine()
             * method. We iterate until the BufferedReader return null which means
             * there's no more data to read. Each line will appended to a StringBuilder
             * and returned as String.
             */
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();
     
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
     
            return sb.toString();
        }
    }
    This is the code in Java , need to convert it to J2ME. I've managed to change parts of it to make it compatible in J2ME , like say - I've modified the Http and URL part. Now, I need help and suggestions to implement the same for BufferedReader.

    Thanks
    -Ashwin

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: BufferedReader issues

    Do you have a J2ME version of the oauth.signpost library? Are you planning to convert the entire library?

    Graham.

  7. #7
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Re: BufferedReader issues

    Quote Originally Posted by grahamhughes View Post
    Do you have a J2ME version of the oauth.signpost library? Are you planning to convert the entire library?

    Graham.
    I don't have the J2ME version , need to use this only, is it possible ?

    - Ashwin

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: BufferedReader issues

    The J2SE version won't work on J2ME. I'm afraid you'll need to re-write the code for it, the same as you do with the sample code you're working on.

    Graham.

  9. #9
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Re: BufferedReader issues

    Quote Originally Posted by grahamhughes View Post
    The J2SE version won't work on J2ME. I'm afraid you'll need to re-write the code for it, the same as you do with the sample code you're working on.

    Graham.
    Yes Graham , I've partly succeeded with that. I am struck with this BufferedReader part for now. I am looking for alternatives in this aspect. I've made some changes and converted this J2SE part to J2ME as far as i can.

    - Ashwin

  10. #10
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: BufferedReader issues

    You can write a simple (inefficient) version of BufferedReader's readLine() method, just by reading characters into a StringBuffer, until you reach an end-of-line character. Read the specification very carefully, to match the behaviour. You can write your own BufferedReader class, if you like, but change the package name. You can't have your own classes in the java.io package, so you'll need to call it ashwin.io.BufferedReader, or something like that.

    Graham.

  11. #11
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Re: BufferedReader issues

    Quote Originally Posted by grahamhughes View Post
    You can write a simple (inefficient) version of BufferedReader's readLine() method, just by reading characters into a StringBuffer, until you reach an end-of-line character. Read the specification very carefully, to match the behaviour. You can write your own BufferedReader class, if you like, but change the package name. You can't have your own classes in the java.io package, so you'll need to call it ashwin.io.BufferedReader, or something like that.

    Graham.
    Fine , I'll try it out.

    Thanks
    - Ashwin

  12. #12
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,105
    Isn’t Java open source anymore?

  13. #13
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Bangalore
    Posts
    50

    Re: BufferedReader issues

    Hi Graham,

    http://code.google.com/p/oauth-signp...GettingStarted

    This is a tutorial or guidance to build the signpost part. My code was inspired from this link and written in Java.

    Can this now be built in J2ME ? There are some J2ME Oauth's as well.

    Awaiting your reply!

    Thanks
    - Ashwin

  14. #14
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: BufferedReader issues

    You will need a J2ME compatible library. The one you are looking will not work on J2ME.

    Graham.

Similar Threads

  1. GCCE issues
    By apsaarin in forum Symbian Tools & SDKs
    Replies: 18
    Last Post: 2010-06-18, 13:13
  2. Application is rejected by Symbian Signing, due to a couple of issues: Please help
    By mpurna in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 10
    Last Post: 2009-11-11, 15:30
  3. 3gp streaming issues
    By njahan in forum Streaming and Video
    Replies: 0
    Last Post: 2006-11-02, 19:05
  4. cannot find symbol BufferedReader
    By decisor in forum Mobile Java General
    Replies: 1
    Last Post: 2006-06-27, 12:21
  5. Series 60 graphics and sound issues
    By Teh_Architect in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2005-08-08, 11:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •