Use StringBuffer.append.  Don't use += of String for large Strings because
everytime you use += a new String is constructed and the previous String is
garbage Collected.  StringBuffer.append, on the other hand, truly appends
the String to the StringBuffer and no garbage collecting is done.  Hence it
is a lot faster compared to += for large Strings.

Eric R. Dunstan
2000 A.D.


>From: Kalyan Rizvanovich <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and
>     reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Servlets, Sockets and Whois
>Date: Thu, 11 May 2000 21:58:07 GMT
>
>Dear Gurus,
>I am writing a servlet in order to
>access WHOIS domain registration
>database. I've read all of the messages
>in this forum with respect to this
>technique, so please do not redirect me
>to them.
>When sending the request through a
>socket( OutputStream out = socket.getOutputStream();
>        String str = "kalyan.com";
>        byte buf[] = str.getBytes();
>        out.write(buf);) everything works fine,
>however when I try to get the data from the socket
>back (    InputStream in = s.getInputStream();
>          while ((c = in.read()) != -1) {
>            strRawResponse += (char)c;
>          } ) the process takes an enourmous amount of
>time and sometimes returns an error.
>Please advise me on how to approach this problem.
>Here is the full code:
>
>import java.net.*;
>import java.io.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>public
>class whoisSuccess2 extends HttpServlet {
>
>
>  public void init(ServletConfig config) throws ServletException {
>    super.init(config);
>  }
>
>    public void doGet (HttpServletRequest req, HttpServletResponse res)
>        throws ServletException, IOException
>    {
>
>        res.setContentType("text/html");
>  String dome = req.getParameter("dome");
>
>  ServletOutputStream output = res.getOutputStream();
>
>  int c;
>  Socket s = new Socket("rs.internic.net",43);
>  InputStream in = s.getInputStream();
>  OutputStream out = s.getOutputStream();
>  String str = "kalyan.com";
>  byte buf[] = str.getBytes();
>  out.write(buf);
>  String strRawResponse = "";
>
>
>  while ((c = in.read()) != -1) {
>     strRawResponse += (char)c;
>  }
>  output.println("<html>");
>  output.println("<head><title>Whois</title></head>");
>  output.println("<body>");
>  output.println(strRawResponse);
>  output.println("</body></html>");
>
>
>    }
>}
>
>________________________________________________________________________
>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
>http://java.sun.com/products/jsp/faq.html
>http://www.esperanto.org.nz/jsp/jspfaq.html
>http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to