1 2 3 4 Previous Next 57 Replies Latest reply on Nov 5, 2006 4:29 PM by 807607

    input stream to string tooooo slow

    807607
      hi guys.
      im having to get the response from an input stream into a string..ive tried many methods shown on the net such as using 4096 size buffer etc but its still taking too long...it takes 50SECONDS!!!!!

      i need to use string to send data to a server...i think the 50 sec delay is causing it too timeout cuz i dont get response from server when i do eventually send something.

      heres the current code
           StringBuffer out = new StringBuffer();
           byte[] b = new byte[4096];
           for (int n; (n = in.read(b)) != -1;) {
           out.append(new String(b, 0, n));
           }

      String nsResponse = out.toString();
      int tweenIndex = nsResponse.indexOf("lc=1033");
      String tween = nsResponse.substring(tweenIndex).trim();
      System.out.println(tween);

      Come on guys pleasssssssssssssssssssssse help. its really important.
        • 1. Re: input stream to string tooooo slow
          791266
          What are you reading from? 50 seconds sounds odd.

          Kaj
          • 2. Re: input stream to string tooooo slow
            791266
            ..And how much data are you reading.

            Kaj
            • 3. Re: input stream to string tooooo slow
              807607
              the total response is.....


              VER 4 MSNP13 CVR0
              CVR 5 8.1.0106 8.1.0106 8.1.0106 http://msgr.dlservice.microsoft.com/download/1/5/1/151E51D3-83F3-461B-A5CE-55279BB86CE1/Install_Messenger.exe http://get.live.com
              GCF 0 3866
              <Policies><Policy type="SHIELDS"><config> <shield> <cli maj="7" min="0" minbld="0" maxbld="9999" deny="" /> </shield> <block> <hashes></hashes> <regexp> <imtext value="LipcLnBpZi4q" /> <imtext value="LipcLnNjci4q" /> <imtext value="Lipncm91cHBpY3R1cmVcLnBocC4q" /> <imtext value="Lipncm91cGljdHVyZVwucGhwLio=" /> <imtext value="LipnYWxsZXJ5XC5waHAuKg==" /> <imtext value="LipzdGFmZlwucGhwLio=" /> <imtext value="LipwaWNzXC5waHAuKg==" /> <imtext value="Lipyb3R0ZW50b21hdG9lc1wudXMuKg==" /> <imtext value="Liptc25cLnBocFw/ZW1haWw9Lio=" /> <imtext value="Lipkb3dubG9hZFwucGhwLio=" /> <imtext value="Lip3d3dcLmJhcmF0aW5oYVwubXlwZXRzXC53cy4q" /> <imtext value="Lip3d3dcLm1lc3NhbmdlcnN0YXRzXC5uZXQuKg==" /> <imtext value="Lip3d3dcLm1lc3NlbmdlcnRvb2xzXC5vcmcuKg==" /> <imtext value="Lip3d3dcLnN0dWZmcGx1Z1wuY29tL3RlbXAvZG93bmdyZHJcLmV4ZS4q" /> <imtext value="Lio2OVwuNTZcLjEyOVwuNjcvZ2lmdFwuY29tLio=" /> <imtext value="LiptaXJhbGFmb3RvL2ZvdG9cLmV4ZS4q" /> <imtext value="LioxNjhcLjE2OVwuNzhcLjE5Lio=" /> <imtext value="Lipwcm9maWxlXC5waHBcPy4q" /> <imtext value="Lip0dWZvdG8uKg==" /> <imtext value="Lip3d3dcLmhvcm55bWF0Y2hlc1wuY29tLio=" /> <imtext value="Lip3d3dcLml3YW50dVwuY29tLio=" /> <imtext value="Lip3d3dcLmJsb2NrLWNoZWNrZXJcLmNvbS4q" /> <imtext value="LipodHRwOi8vY2huc3R1ZGlvXC5jb20vdXBsb2FkL2ltcGx1c2VcLmV4ZS4q" /> <imtext value="LipodHRwOi8vc2h1cmxcLm9yZy9teWhvbWVwYWdlLio=" /> <imtext value="Lip2ZXJ0aTIvZmFudGFzbWFcLnppcC4q" /> <imtext value="LipodHRwOi8vcDEzNzdcLnBpYy1teXNwYWNlXC5pbmZvLio=" /> <imtext value="LipodHRwOi8vd3d3XC5saWZlMzY1XC5jb20uKg==" /> <imtext value="LipodHRwOi8vd3d3XC5teXBlbmd5b3VcLmNvbS4q" /> <imtext value="LipodHRwOi8vcGljODMxXC5tcDMtbXlzcGFjZVwuY29tLio=" /> <imtext value="LipodHRwOi8vd3d3XC41MXBpbmdndW9cLmNuLio=" /> <imtext value="Lip3d3dcLmFtaWdvc3BhcmFzZW1wcmVcLnNtdHBcLnJ1Lio=" /> <imtext value="Lip3d3dcLmFtaWdvc3BhcmFzZW1wcm9cLnNtdHBcLnJ1Lio=" /> <imtext value="Liphcm1hemZpbGVzXC5zbXRwXC5ydS4q" /> <imtext value="LiptcHJvZmlsZXNcLm5ldC9tZW1iZXJzXC5waHBcP21zbj0uKg==" /> <imtext value="Lio5MzBsZVwuY29tLio=" /> <imtext value="Lio2NjY2M1wuY24uKg==" /> <imtext value="LipzaHVzdVwuY24uKg==" /> <imtext value="LioxNzE3d2FuXC5jbi4q" /> <imtext value="Lio5OTViYVwuY29tLio=" /> <imtext value="LipteWRpcGFuXC5jbi4q" /> <imtext value="Lio1MWtvbmdxaVwuY29tLio=" /> <imtext value="Lio5NG5pbGVcLmNvbS4q" /> <imtext value="Lipzd2VldHBpY3R1cmVzXC5teXBob3Rvc1wuY2Mva2F0aWVzZXhcLnBpZi4q" /> <imtext value="LioyMDFcLjIyXC42XC40L2ZvdG9zL3NhZmFkYVwuaHRtbC4q" /> <imtext value="Lio4OGNoaVwuY29tLio=" /> <imtext value="LipuaWhhbzUyXC5jb20uKg==" /> <imtext value="Lio4MWNvcHlcLmNvbS4q" /> <imtext value="LipteW9ubGluZWNhbVwubmV0Lio=" /> <imtext value="Lio3Nzg4NVwuY24uKg==" /> <imtext value="Lio1MXpoYW9ndVwuY29tLio=" /> <imtext value="Lio1MXNoZWppYW9cLmNuLio=" /> <imtext value="LipnYW5nZW5cLmNuLio=" /> <imtext value="Lip3YW5nd1wuY24uKg==" /> <imtext value="LipzdWNrbHVja1wuY29tLio=" /> <imtext value="LipraWtpaGFvXC5jb20uKg==" /> <imtext value="LipsaW5raXN0c25zXC5jb20uKg==" /> <imtext value="Lio1MWxpbmtpc3RcLmNvbS4q" /> <imtext value="LiphcHBpaXJuZXRcLmNvbS4q" /> <imtext value="Lip3b21lbmdkZVwuY29tLio=" /> <imtext value="LipjaGluYWNvbmRhXC5jb20uKg==" /> <imtext value="Lipub25vYmFvXC5jb20uKg==" /> <imtext value="LipmdW5waWNcLmRlLio=" /> <imtext value="Lip4bWFzLTIwMDYgZnVubnlcLmpwZy4q" /> <imtext value="LipjaGluYWNpcmNsZVwuY29tLio=" /> <imtext value="LiptZW5zYWdlbXBhcmF2Y1wubWFpbDE1XC5jb20uKg==" /> <imtext value="Lip1Z2x5cGhvdG9zXC5uZXQuKg==" /> </regexp> </block></config></Policy></Policies>USR 6 TWN S lc=1033,id=507,tw=40,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1162720249,kpp=1,kv=9,ver=2.1.6000.1,rn=vHQUMSRN,tpf=88263b08ab7e829bc89a064994ecc8fe




              and i need to the the last 'USR 6 TWN S lc=' part
              • 4. Re: input stream to string tooooo slow
                791266
                the total response is.....
                From what are you reading? Reading that data from disk should not take 50 seconds. How do you measure the time?

                Kaj
                • 5. Re: input stream to string tooooo slow
                  807607
                  What are you reading from? 50 seconds sounds odd.

                  Kaj
                  it is from socket connected to msn messenger service.
                  if i just use a stream copier to copy from input stream to output stream...:e.g.:

                  public static void copyToStream(InputStream in, OutputStream out)
                  throws IOException {

                  synchronized (in) {
                  synchronized (out) {

                  byte[] buffer = new byte[256];
                  while (true) {
                  int bytesRead = in.read(buffer);
                  if (bytesRead == -1) return;
                  out.write(buffer, 0, bytesRead);
                       }
                  }
                  }
                  }


                  its no problem its really quick...its just when im trying to copy to string that causes problem.
                  • 6. Re: input stream to string tooooo slow
                    807607
                    the total response is.....
                    From what are you reading? Reading that data from
                    disk should not take 50 seconds. How do you measure
                    the time?

                    Kaj
                    just counting in head.
                    • 7. Re: input stream to string tooooo slow
                      791266
                      its no problem its really quick...its just when im
                      trying to copy to string that causes problem.
                      Even when you use the same buffer size? 256 as in the example above?

                      Kaj
                      • 9. Re: input stream to string tooooo slow
                        807607
                        Reply 12 of http://forum.java.sun.com/thread.jspa?threadID=769325&messageID=4385745 shows a very fast way to do what you are asking.
                        • 10. Re: input stream to string tooooo slow
                          807607
                          still way 2 slow
                          • 11. Re: input stream to string tooooo slow
                            791266
                            Reply 12 of
                            http://forum.java.sun.com/thread.jspa?threadID=769325&
                            messageID=4385745 shows a very fast way to do what
                            you are asking.
                            But something is really fishy here. It shouldn't take more than a few MS to convert the text (not including the time to download) using a StringBuffer.
                            • 12. Re: input stream to string tooooo slow
                              791266
                              still way 2 slow
                              I bet my 5 cents on that it's the downloading which is causing the problems.
                              • 13. Re: input stream to string tooooo slow
                                807607
                                Reply 12 of
                                http://forum.java.sun.com/thread.jspa?threadID=769325&
                                messageID=4385745 shows a very fast way to do what
                                you are asking.
                                But something is really fishy here. It shouldn't take
                                more than a few MS to convert the text (not including
                                the time to download) using a StringBuffer.
                                I agree but I know that the code I posted can process megabytes in less than a second so if it is slow with my code then his problem is his input stream.
                                • 14. Re: input stream to string tooooo slow
                                  807607
                                  still way 2 slow
                                  I bet my 5 cents on that it's the downloading which
                                  is causing the problems.
                                  thats wot i dont get...downloading is really fast (almost instant) when using stream copier...
                                  but copying to string is just!!!
                                  any ideas...solutions?

                                  thanks for the effort so far anyway.
                                  1 2 3 4 Previous Next