Доброго времени суток! Получаю страницу и время ее скачивания следующим образом:
| Код | URLConnection conn; InputStreamReader is; BufferedReader in = null; StringBuilder htmlPage = null; try { URL url = new URL(site); conn = url.openConnection(); long startTime = System.currentTimeMillis(); is = new InputStreamReader(conn.getInputStream()); in = new BufferedReader(is); String inputLine; htmlPage = new StringBuilder(""); while ( (inputLine = in.readLine()) != null ) { htmlPage.append(inputLine); inputLine = null; } long endTime = System.currentTimeMillis(); System.out.println(endTime - startTime); } catch (MalformedURLException ex) { Logger.getLogger(DowloadSpeedPage.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(DowloadSpeedPage.class.getName()).log(Level.SEVERE, null, ex); } finally { conn = null; if (in != null) { try { in.close(); } catch (IOException ex) { throw new Exception("не удалось закрыть поток!"); } } }
|
Верно ли определяю время скачивания страницы? Как можно узнать размер скачиваемой страницы и среднюю скорость загрузки(например Кб/сек)? |