안녕하세요.
다운로드를 구현중인데 다운로드를 중지하였을때 close시
close에서 약간의 딜레이가 발생합니다.
이게 사람이 인지할정도로 2초정도나 딜레이가 발생하는데 원인을 모르겠습니다..
아래 소스코드 첨부합니다.
long totalSize = 0; //누적 패킷량
URL url = null;
InputStream inputStream = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
File mFile = new File(StoragePath.EXTERNAL_ROOT_PATH + "/" + fileName); //키비폴더에 파일을 저장한다.
try {
url = new URL(targetUrl);
Log.i("Download", targetUrl);
inputStream = url.openStream();
bis = new BufferedInputStream(inputStream, 1024);
fos = new FileOutputStream(mFile);
bos = new BufferedOutputStream(fos);
} catch(Exception e) {Log.i("ERR", "" + e.toString());}
int dataLength = 0;
byte[] buff = new byte[65536];
try {
while((dataLength = bis.read(buff)) != -1) {
Log.i("Download", "length : " + dataLength);
if(mDownloadStateFlag != true) {
Log.i("Download", "다운로드 상태가 아니므로 루프탈출");
break;
}
bos.write(buff, 0, dataLength);
bos.flush();
totalSize += dataLength;
mPercent = (int)((totalSize * 100) / maxSize);
Log.i("Download", "totalSize : " + totalSize + "max size : " + maxSize + "퍼센트 = " + mPercent);
}
// bos.close();
// bis.close();
bos = null;
bis = null;
}catch(Exception ee) {
//타임아웃 처리해야함..
Log.i("Download", "" + ee.toString());
return false;
}
조언 부탁드립니다.