use of net.technicpack.launchercore.exception.PermissionDeniedException in project LauncherV3 by TechnicPack.
the class Download method run.
@Override
@SuppressWarnings("unused")
public void run() {
try {
HttpURLConnection conn = Utils.openHttpConnection(url);
int response = conn.getResponseCode();
int responseFamily = response / 100;
if (responseFamily == 3) {
String redirUrlText = conn.getHeaderField("Location");
if (redirUrlText != null && !redirUrlText.isEmpty()) {
URL redirectUrl = null;
try {
redirectUrl = new URL(redirUrlText);
} catch (MalformedURLException ex) {
throw new DownloadException("Invalid Redirect URL: " + url, ex);
}
conn = Utils.openHttpConnection(redirectUrl);
response = conn.getResponseCode();
responseFamily = response / 100;
}
}
if (responseFamily != 2) {
throw new DownloadException("The server issued a " + response + " response code.");
}
InputStream in = getConnectionInputStream(conn);
size = conn.getContentLengthLong();
outFile = new File(outPath);
outFile.delete();
try (ReadableByteChannel rbc = Channels.newChannel(in);
FileOutputStream fos = new FileOutputStream(outFile)) {
fos.getChannel().lock();
stateChanged();
Thread progress = new MonitorThread(Thread.currentThread(), rbc);
progress.start();
fos.getChannel().transferFrom(rbc, 0, size > 0 ? size : Integer.MAX_VALUE);
in.close();
rbc.close();
progress.interrupt();
synchronized (timeoutLock) {
if (isTimedOut) {
return;
}
}
if (size > 0) {
long fileLength = outFile.length();
if (size == fileLength) {
result = Result.SUCCESS;
} else {
throw new DownloadException("File size doesn't match. Expected " + size + ", got " + fileLength);
}
} else {
result = Result.SUCCESS;
}
}
} catch (ClosedByInterruptException ex) {
result = Result.FAILURE;
return;
} catch (PermissionDeniedException e) {
exception = e;
result = Result.PERMISSION_DENIED;
} catch (OverlappingFileLockException e) {
exception = e;
result = Result.LOCK_FAILED;
} catch (DownloadException e) {
exception = e;
result = Result.FAILURE;
} catch (Exception e) {
exception = e;
e.printStackTrace();
}
}
Aggregations