3-Oct-03 (Created: 3-Oct-03) | More in 'CS-Java'

How to read from a url into a buffer


   public ConcreteElement getContent(RunData rundata)
      {

         BufferedReader br = null;
         try
         {
            //get a url
            URL url = new URL("http://216.187.231.34/akc/index.html");
            URLConnection con = url.openConnection();


            br = new BufferedReader ( new
              InputStreamReader(con.getInputStream()));

            String line = "";
            StringBuffer buf = new StringBuffer();
            while ((line = br.readLine()) != null)
              buf.append(line);

            return new JetspeedClearElement(buf.toString());
         }
         catch(Exception x)
         {
            AppObjects.log("Error:",x);
            return new JetspeedClearElement("Sorry there is an error");
         }
         finally
         {
            if (br != null)
               try {br.close();}catch (Exception x){}
         }
   }//eof-function