마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

스트림 close시 딜레이가 생깁니다..

0 추천

안녕하세요.

다운로드를 구현중인데 다운로드를 중지하였을때 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;
}
 
조언 부탁드립니다.
갸아악 (21,260 포인트) 님이 2015년 4월 1일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...