phần mềm của mình là dowload java Swing chạy tới 99 phần trăm là bị đứng đối với file pdf file exe thì được
giúp mình fix lỗi này với


dưới đây là 1 số link demo bạn text rồi fix dùm mình với
http://www.rarlab.com/rar/wrar521vn.exe
http://www.tutorialspoint.com/java/pdf/index.pdf
dowload code tại
http://www.mediafire.com/download/70xu6v2qabt4ai9/IDM2.zip
mọi người giúp mình fix lỗi này với
code chính của phần mềm

package Model;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Observable;

import View.Common;

public class Downloads extends Observable implements Common {
private int size;
private String url;
private int status;
private int downloading;
private int complete;
private String save;
int start = 0;
int end = 0;
boolean resume = false;
private URL link;
ArrayList<Length> space = new ArrayList<>();

public Downloads() {

}

public Downloads(String url, String save) throws IOException {
this.url = url;
this.save = save;
downloading = 0;
loanding();
}

public void loanding() {
Thread loading = new Thread(new Runnable() {

@Override
public void run() {
try {
if (resume == false) {
link = new URL(url);
HttpURLConnection connect = (HttpURLConnection) link
.openConnection();
try {
size = Integer.parseInt(connect
.getHeaderField("Content-length"));
} catch (Exception e) {
status = ERRORS;
e.printStackTrace();
} finally {

changed();
}
connect.disconnect();
}
if (size > 0) {
if (resume == false) {
int length = size / PART;
end = length;
for (int i = 0; i < PART; i++) {
space.add(new Length(start, end, start));
if (end >= size)
break;
start += length;
end += length;

}
}
int countPart = 0;
for (int i = 0; i < PART; i++) {
if (space.get(i).getStart() < space.get(i).getEnd()) {
download(space.get(i).getStart(),
space.get(i).getEnd(), countPart)
.start();
}
countPart++;
}
} else {
start = ERRORS;
}
} catch (IOException e) {
status = ERRORS;
e.printStackTrace();
} finally {
changed();
}

}
});

loading.start();
}

public Thread download(final int start, final int end, final int count) {
Thread download = new Thread() {

@Override
public void run() {
resume = false;
if (start < end) {
try {
HttpURLConnection connect = (HttpURLConnection) link
.openConnection();
connect.setRequestProperty("Range", "bytes=" + start
+ "-" + end);
// connect.setRequestProperty("http.proxyHost", null);
connect.connect();
BufferedInputStream is = new BufferedInputStream(
connect.getInputStream());
// InputStream is = connect.getInputStream();
RandomAccessFile output = new RandomAccessFile(save,
"rw");
output.seek(start);
int byteReader = start;
int buffer_size = (end - byteReader) > BUFFER_MAX_SIZE ? BUFFER_MAX_SIZE
: (end - byteReader);
byte[] buffer = new byte[buffer_size];
int i = 0;
while (status == DOWNLOADING) {
if ((i = is.read(buffer)) != 0) {
if (i != -1) {
output.write(buffer, 0, i);
byteReader += i;
space.get(count).setStart(byteReader);
getDownloading();
buffer_size = (end - byteReader) > BUFFER_MAX_SIZE ? BUFFER_MAX_SIZE
: (end - byteReader);
buffer = new byte[buffer_size];
changed();
}
} else {
break;
}
}
if (getDownloading() == size) {
status = COMPLETE;
changed();
}
connect.disconnect();
is.close();
output.close();
} catch (ConnectException e) {
status = ERRORS;
System.out.println(count + " " + start + " " + end);
e.printStackTrace();
} catch (IOException e) {
status = ERRORS;
e.printStackTrace();
}
}
}
};

return download;
}

private int getDownloading() {
int process = 0;
synchronized (space) {

for (int i = 0; i < PART; i++) {
process += (space.get(i).getStart() - space.get(i).getFlag());
}
}
return downloading = process;
}

public String getSave() {
return save;
}

public int getProcess() {
return (int) (((float) downloading / size) * 100);
}

public String getName() {
String name = "";
for (int i = save.length(); i >= 0; i--) {
name = save.substring(i, save.length());
if (name.startsWith("\\") == true)
break;
}
return name;
}

public int getSize() {
return size;
}

public void changed() {
setChanged();
notifyObservers();
}

public int getStatus() {
return status;
}

public void setStatus(int status) {
this.status = status;
}

public void pause() {
status = WAITING;
new Thread(new Runnable() {

@Override
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
resume = true;
status = PAUSED;
changed();

}
}).start();

}

public void resume() {
if (resume == true) {
status = DOWNLOADING;
changed();
resume = true;
loanding();
}
}

public void cancel() {
status = CANCELLED;
changed();
}

public boolean checkHTTP(String url) {
if (url.startsWith("http://") || url.startsWith("https://"))
return true;
else
return false;
}
}