Android Open Source - PictureBookReader Download File






From Project

Back to project page PictureBookReader.

License

The source code is released under:

GNU General Public License

If you think the Android project PictureBookReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.uyghurdev.avaroid.picturebookreader;
/*from w w  w  . j  av a 2s.c  o m*/
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Environment;

public class DownloadFile {
  String url_con;
  String saved_name;
  int filesize;
  public int downloaddsize;
  Context m_cxt;
  URL m_uri;
  private String SDPATH;
  private String fileName;
  public ProgressDialog progressBar;

  DownloadFile(Context cxt, String url_c, String fileName,
      ProgressDialog _progressBar) {
    this.m_cxt = cxt;
    this.url_con = url_c;
    this.progressBar = _progressBar;
    this.SDPATH = Environment.getExternalStorageDirectory()
        + Configs.SDPath;
    this.m_cxt = cxt;
    this.fileName = fileName;
  }

  public void downloadfile() throws Throwable {
    URL url;
    File file = new File(SDPATH, fileName);
    url = new URL(url_con);
    long startTime = System.currentTimeMillis();
    HttpURLConnection ucon;
    ucon = (HttpURLConnection) url.openConnection();
    ucon.setRequestMethod("GET");
    ucon.setDoOutput(true);
    ucon.connect();
    filesize = ucon.getContentLength();
    InputStream is = ucon.getInputStream();
    BufferedInputStream inStream = new BufferedInputStream(is, 5 * 1024);
    FileOutputStream outStream = new FileOutputStream(file);
    byte[] buff = new byte[1024];
    int len;
    while ((len = inStream.read(buff)) != -1) {
      downloaddsize += len;
      getDownloadedSize(downloaddsize);
      int i = (int) ((float) downloaddsize * 100 / (float) filesize);
      progressBar.setProgress(i);
      outStream.write(buff, 0, len);

    }
    outStream.flush();
    outStream.close();
    inStream.close();
    System.out.println("download completed in "
        + ((System.currentTimeMillis() - startTime) / 1000) + " sec");

  }

  public void getDownloadedSize(int i) {
    downloaddsize = i;

  }

  public int setDownloadedSize() {
    return downloaddsize;
  }

}

//
// public class DownloadFile {
//
// private static final int BUFFER_SIZE = 1024;
// private URL url;
// private byte[] buffer;
// private String urlStr;
// public int downloadedSize;
// public int fileSize;
// public int getFile;
// private HttpURLConnection con = null;
// private Boolean finished = false;
// private String SDPATH;
// private String fileName;
// Context cxt;
//
// public DownloadFile(Context _cxt, String urlStr, String fileName) {
// this.urlStr = urlStr;
// this.SDPATH = Environment.getExternalStorageDirectory()
// + Configs.SDPath;
// this.cxt=_cxt;
// this.fileName = fileName;
// File file = new File(SDPATH, fileName);
// try {
// url = new URL(urlStr);
// con = (HttpURLConnection) url.openConnection();
// con.setRequestMethod("GET");
// con.setDoOutput(true);
// con.connect();
// fileSize=con.getContentLength();
//
// } catch (MalformedURLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// catch (IOException e) {
// e.printStackTrace();
// }
//
//
// }
//
// public int start() {
//
// try {
//
// File file = new File(SDPATH, fileName);
// url = new URL(urlStr);
// con = (HttpURLConnection) url.openConnection();
// con.setRequestMethod("GET");
// con.setDoOutput(true);
// con.connect();
// FileOutputStream fileOutput = new FileOutputStream(file);
// InputStream inputStream = con.getInputStream();
//
// downloadedSize = 0;
// buffer = new byte[BUFFER_SIZE];
// int bufferLength = 0;
// do {
// bufferLength = inputStream.read(buffer);
// if (bufferLength == -1) {
// break;
// }
// fileOutput.write(buffer, 0, bufferLength);
// downloadedSize += bufferLength;
// finished = false;
// } while (true); // close the output stream when done
//
// fileOutput.close();
// inputStream.close();
// finished = true;
// } catch (MalformedURLException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// return downloadedSize;
//
//
//
// }
//
// public Boolean isFinish() {
// return finished;
// }
//
// public int getCur() {
// // TODO Auto-generated method stub
// return downloadedSize;
// }
//
// public int getFileLength() {
// return fileSize;
// }
//
// public String getFileName(String Url) {
// int fileNameStart = Url.lastIndexOf("/");
// return Url.substring(fileNameStart);
//
// }
//
// public boolean isFileExist(String fileName) {
// File file = new File(SDPATH + fileName);
// return file.exists();
// }
//
// }





Java Source Code List

net.uyghurdev.avaroid.picturebookreader.About.java
net.uyghurdev.avaroid.picturebookreader.BookText.java
net.uyghurdev.avaroid.picturebookreader.Book.java
net.uyghurdev.avaroid.picturebookreader.BookmarkData.java
net.uyghurdev.avaroid.picturebookreader.Configs.java
net.uyghurdev.avaroid.picturebookreader.CurlMesh.java
net.uyghurdev.avaroid.picturebookreader.CurlPage.java
net.uyghurdev.avaroid.picturebookreader.CurlRenderer.java
net.uyghurdev.avaroid.picturebookreader.CurlView.java
net.uyghurdev.avaroid.picturebookreader.DecompressReader.java
net.uyghurdev.avaroid.picturebookreader.Decompresser.java
net.uyghurdev.avaroid.picturebookreader.DownloadFile.java
net.uyghurdev.avaroid.picturebookreader.FileCache.java
net.uyghurdev.avaroid.picturebookreader.GetOnlineBookInfo.java
net.uyghurdev.avaroid.picturebookreader.ImageLoader.java
net.uyghurdev.avaroid.picturebookreader.JSONManager.java
net.uyghurdev.avaroid.picturebookreader.LocalBook.java
net.uyghurdev.avaroid.picturebookreader.MemoryCache.java
net.uyghurdev.avaroid.picturebookreader.NetWorkOperator.java
net.uyghurdev.avaroid.picturebookreader.OnlineBookAdapter.java
net.uyghurdev.avaroid.picturebookreader.OnlineBooks.java
net.uyghurdev.avaroid.picturebookreader.OnlineGBookAdapter.java
net.uyghurdev.avaroid.picturebookreader.PlayOrder1.java
net.uyghurdev.avaroid.picturebookreader.ReadBook.java
net.uyghurdev.avaroid.picturebookreader.RecentBooksAdapter.java
net.uyghurdev.avaroid.picturebookreader.RecentGBooksAdapter.java
net.uyghurdev.avaroid.picturebookreader.Splash.java
net.uyghurdev.avaroid.picturebookreader.Utils.java
net.uyghurdev.avaroid.picturebookreader.XMLContent.java
net.uyghurdev.avaroid.picturebookreader.XMLHandler.java