bin noch nicht so die Leuchte in Java
kann mir jemand sagen was an diesem Script ausschnitt falsch ist bzw. es Korrigieren?
Code:
for (int i = 0; i < urlList.length; i++) {
if (skip[i] != 0) {
percentage = (initialPercentage + fileSizes[i] * 45 / totalSizeDownload);
}
else
{
try
{
md5s.remove(getFileName(urlList[i]));
md5s.store(new FileOutputStream(versionFile), "md5 hashes for downloaded files");
} catch (Exception e) {
e.printStackTrace();
}
int unsuccessfulAttempts = 0;
int maxUnsuccessfulAttempts = 3;
boolean downloadFile = true;
while (downloadFile) {
downloadFile = false;
URLConnection urlconnection = urlList[i].openConnection();
String etag = "";
if ((urlconnection instanceof HttpURLConnection)) {
urlconnection.setRequestProperty("Cache-Control", "no-cache");
urlconnection.connect();
etag = urlconnection.getHeaderField("ETag");
etag = etag.substring(1, etag.length() - 1);
}
String currentFile = getFileName(urlList[i]);
InputStream inputstream = getJarInputStream(currentFile, urlconnection);
FileOutputStream fos = new FileOutputStream(path + currentFile);
long downloadStartTime = System.currentTimeMillis();
int downloadedAmount = 0;
int fileSize = 0;
String downloadSpeedMessage = "";
MessageDigest m = MessageDigest.getInstance("MD5");
int bufferSize;
while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1)
{
int bufferSize;
fos.write(buffer, 0, bufferSize);
m.update(buffer, 0, bufferSize);
currentSizeDownload += bufferSize;
fileSize += bufferSize;
percentage = (initialPercentage + currentSizeDownload * 45 / totalSizeDownload);
subtaskMessage = ("Retrieving: " + currentFile + " " + currentSizeDownload * 100 / totalSizeDownload + "%");
downloadedAmount += bufferSize;
long timeLapse = System.currentTimeMillis() - downloadStartTime;
if (timeLapse >= 1000L) {
float downloadSpeed = downloadedAmount / (float)timeLapse;
downloadSpeed = (int)(downloadSpeed * 100.0F) / 100.0F;
downloadSpeedMessage = " @ " + downloadSpeed + " KB/sec";
downloadedAmount = 0;
downloadStartTime += 1000L;
}
subtaskMessage += downloadSpeedMessage;
}
inputstream.close();
fos.close();
String md5 = new BigInteger(1, m.digest()).toString(16);
while (md5.length() < 32) {
md5 = "0" + md5;
}
boolean md5Matches = true;
if (etag != null) {
md5Matches = md5.equals(etag);
}
if ((urlconnection instanceof HttpURLConnection)) {
if ((md5Matches) && ((fileSize == fileSizes[i]) || (fileSizes[i] <= 0)))
{
try {
md5s.setProperty(getFileName(urlList[i]), etag);
md5s.store(new FileOutputStream(versionFile), "md5 hashes for downloaded files");
} catch (Exception e) {
e.printStackTrace();
}
} else {
unsuccessfulAttempts++;
if (unsuccessfulAttempts < maxUnsuccessfulAttempts) {
downloadFile = true;
currentSizeDownload -= fileSize;
} else {
throw new Exception("failed to download " + currentFile);
}
}
}
}
}
}
Code:
if (skip[i] != 0) {
gruß
Regen.






