String[] extraFieldValues = new String[3];
int jarSize;
String locale;
String prof;
int space;
RandomAccessStream jarOutputStream = null;
OutputStream outputStream = null;
parsedUrl = new HttpUrl(info.jarUrl);
if (parsedUrl.authority == null && info.jadUrl != null) {
// relative URL, add the JAD URL as the base
try {
parsedUrl.addBaseUrl(info.jadUrl);
} catch (IOException e) {
postInstallMsgBackToProvider(
OtaNotifier.INVALID_JAD_MSG);
throw new InvalidJadException(
InvalidJadException.INVALID_JAR_URL);
}
url = parsedUrl.toString();
// The JAR URL saved to storage MUST be absolute
info.jarUrl = url;
} else {
url = info.jarUrl;
}
jarOutputStream = new RandomAccessStream();
jarOutputStream.connect(filename,
RandomAccessStream.READ_WRITE_TRUNCATE);
outputStream = jarOutputStream.openOutputStream();
prof = System.getProperty(MICROEDITION_PROFILES);
space = prof.indexOf(' ');
if (space != -1) {
prof = prof.substring(0, space);
}
extraFieldKeys[0] = "User-Agent";
extraFieldValues[0] = "Profile/" + prof
+ " Configuration/" +
System.getProperty(MICROEDITION_CONFIG);
extraFieldKeys[1] = "Accept-Charset";
extraFieldValues[1] = "UTF-8, ISO-8859-1";
/* locale can be null */
locale = System.getProperty(MICROEDITION_LOCALE);
if (locale != null) {
extraFieldKeys[2] = "Accept-Language";
extraFieldValues[2] = locale;
}
try {
state.beginTransferDataStatus = DOWNLOADING_JAR;
state.transferStatus = DOWNLOADED_1K_OF_JAR;
jarSize = downloadResource(url, extraFieldKeys, extraFieldValues,
acceptableTypes, true, true, outputStream, null,
InvalidJadException.INVALID_JAR_URL,
InvalidJadException.JAR_SERVER_NOT_FOUND,
InvalidJadException.JAR_NOT_FOUND,
InvalidJadException.INVALID_JAR_TYPE);
return jarSize;
} catch (InvalidJadException ije) {
switch (ije.getReason()) {
case InvalidJadException.INVALID_JAR_URL:
case InvalidJadException.JAR_SERVER_NOT_FOUND:
case InvalidJadException.JAR_NOT_FOUND:
case InvalidJadException.INVALID_JAR_TYPE:
postInstallMsgBackToProvider(
OtaNotifier.INVALID_JAR_MSG);
break;
default:
// for safety/completeness.
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"Installer InvalidJadException: " + ije.getMessage());
}
break;
}
throw ije;
} finally {
try {
jarOutputStream.disconnect();
} catch (Exception e) {
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_AMS,
"disconnect threw a Exception");
}