BOS/BIS получает прогресс

У меня есть загрузка с BufferedInputStream и BufferedOutputStream, и теперь я хочу получить прогресс в процентах от этой загрузки.

Как это получить??

     BufferedInputStream bis = null;
     BufferedOutputStream bos = null;
     try
     {
        URL url = new URL( sb.toString() );
        URLConnection urlc = url.openConnection();

        bos = new BufferedOutputStream( urlc.getOutputStream() );
        bis = new BufferedInputStream( new FileInputStream( source ) );

        int i;
        int progress = 0;
        while ((i = bis.read()) != -1)
        {
           bos.write( i );
           //how to get the progress here?!

        }
     }
     finally
     {
        if (bis != null)
           try
           {
              bis.close();
           }
           catch (IOException ioe)
           {
              ioe.printStackTrace();
           }
        if (bos != null)
           try
           {
              bos.close();
           }
           catch (IOException ioe)
           {
              ioe.printStackTrace();
           }

     }

1 ответ

Нет проблем. Ты можешь использовать CountingInputStream а также CountingOutputStream фантики для этих целей. Смотрите библиотеку Apache Commons IO 2.5.

Другие вопросы по тегам