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

HttpURLConnection 다운로드 속도

0 추천

웹의 주소를 이용해서 파일을 다운받는 작업을 하고있습니다.(myUrl 변수)

현재 소스로 다운로드를 받았을 경우 370mb가 1분30초 정도 걸립니다.

원래 이 정도 속도가 평균적인것인지요..? 코드는 아래와 같이 작성했습니다.

HttpURLConnection conn = (HttpURLConnection) myUrl.openConnection();
conn.setRequestProperty("Accept-Encoding", "identity");// add
conn.setConnectTimeout(2000);
InputStream is = null;
int statusCode = conn.getResponseCode();
if (statusCode >= 200 && statusCode < 400) 
{
	is = conn.getInputStream();
} 
else 
{
is = conn.getErrorStream();
}
int fileSize = conn.getContentLength();// 다운받을 파일 크기
if (fileSize < 0) 
{
	conn.disconnect();
	downResult = 1;
} 
else 
{
byte[] data = new byte[1024];
is = conn.getInputStream();
File file = new File(localPath);
if (!file.exists()) 
{
	FileOutputStream fos = new FileOutputStream(file);
	int read;
	long total = 0;
	int progress = 0;
	for (;;) 
	{
	read = is.read(data);
	total += read;
	int progress_temp = (int) ((double) total / fileSize * 100);
	publishProgress("" + progress_temp);
	if (progress_temp % 10 == 0 && progress != progress_temp) 
	{
	  progress = progress_temp;
	}
	if (read <= 0) {
	 break;
	}
	fos.write(data, 0, read); 
	if(isCancelled())
	{
		return 4;
	}
}
is.close();
fos.close();
conn.disconnect();

 

 

다운로드하기 님이 2017년 7월 7일 질문

1개의 답변

+1 추천
370mb/90s 이니 약 4m bps 인데.. 코드 문제라기 보단 망이 최대  4m bps 정도만 지원하는 듯 합니다.

 

PS.

 byte[] data = new byte[1024]; 에서 1024 보다 큰 값을 넣으면,

반복을 약간 덜 해서,  일부 상황에선 약간 더 빠를 때가 있긴 합니다.
익명사용자 님이 2017년 7월 7일 답변
답변 감사합니다.
테스트할 땐 실내에서 와이파이를 사용하고 있습니다..^^
그럼 이 와이파이의 설정?지원속도가 그정도인가보네요.
궁금해서 속도측정어플로 테스트 해보니 다운로드:5m bps,업로드는:30m이네요 ㄷㄷ
...