For a long time to display epub files on the device

We display the epub file on the screen through our application. The file is saved in SDCard and the following logic that we use to receive data files from SDCard and display on the screen. But it takes a long time to load content on the screen. Any problems with my code? please help friends.

 File rootDir = Environment.getExternalStorageDirectory();
   EpubReader epubReader = new EpubReader();
   try {
        book = epubReader.readEpub(new FileInputStream("/sdcard/forbook.epub"));
        Toast.makeText(getApplicationContext(), "Book : " + book, Toast.LENGTH_LONG).show();
    } catch (FileNotFoundException e) {
        Toast.makeText(getApplicationContext(), "File Not Found" + book, Toast.LENGTH_LONG).show();
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Toast.makeText(getApplicationContext(), "IO Found" + book, Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
   Spine spine = book.getSpine(); 
   List<SpineReference> spineList = spine.getSpineReferences() ;
   int count = spineList.size();
   StringBuilder string = new StringBuilder();
   String linez = null;
    for (int i = 0; count > i; i++) {
       Resource res = spine.getResource(i);

       try {
           InputStream is = res.getInputStream();
           BufferedReader reader = new BufferedReader(new InputStreamReader(is));
           try {
               String line;
            while ((line = reader.readLine()) != null) {
                   linez =   string.append(line + "\n").toString();
                    //linez=line.toString();
               }

           } catch (IOException e) {e.printStackTrace();}

           //do something with stream
       } catch (IOException e) {
           e.printStackTrace();
       }

   }
  final String mimeType = "text/html";
  final String encoding = "UTF-8";
  webView.loadDataWithBaseURL("", linez, mimeType, encoding,null);

}

Please help me friends.

+1
source share
2 answers

An ePub is nothing more than a zip file with several HTML files inside. Often in each section / section of the book there will be one file (resource).

What you are doing right now is a cycle through the backbone of a book, loading all the resources, when you can probably display a maximum of 1 on the screen at a time.

, , .

+2

, StringBuilder - . -, , try-catch. -, . , :

    StringBuilder string = new StringBuilder();
    Resource res;
    InputStream is;
    BufferedReader reader;
    String line;
    for (int i = 0; count > i; i++) {
        res = spine.getResource(i);
        try {
            is = res.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is));
            while ((line = reader.readLine()) != null) {
                string.append(line + "\n");
            }

            // do something with stream
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    ...
    webView.loadDataWithBaseURL("", string.toString(), mimeType, encoding, null);

, , , , Traceview AsyncTask .

+2

All Articles