public static boolean downloadOCSSWInstaller() { if (isOcsswInstalScriptDownloadSuccessful()) { return ocsswInstalScriptDownloadSuccessful; } try { URL website = new URL(OCSSW_INSTALLER_URL); ReadableByteChannel rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream(TMP_OCSSW_INSTALLER); fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.close(); (new File(TMP_OCSSW_INSTALLER)).setExecutable(true); ocsswInstalScriptDownloadSuccessful = true; } catch (MalformedURLException malformedURLException) { handleException("URL for downloading install_ocssw.py is not correct!"); } catch (FileNotFoundException fileNotFoundException) { handleException( "ocssw installation script failed to download. \n" + "Please check network connection or 'seadas.ocssw.root' variable in the 'seadas.config' file. \n" + "possible cause of error: " + fileNotFoundException.getMessage()); } catch (IOException ioe) { handleException( "ocssw installation script failed to download. \n" + "Please check network connection or 'seadas.ocssw.root' variable in the \"seadas.config\" file. \n" + "possible cause of error: " + ioe.getLocalizedMessage()); } finally { return ocsswInstalScriptDownloadSuccessful; } }
public static void updateOCSSWRoot(String installDir) { FileWriter fileWriter = null; try { final FileReader reader = new FileReader(new File(RuntimeContext.getConfig().getConfigFilePath())); final BufferedReader br = new BufferedReader(reader); StringBuilder text = new StringBuilder(); String line; boolean isOCSSWRootSpecified = false; while ((line = br.readLine()) != null) { if (line.startsWith("seadas.ocssw.root")) { line = "seadas.ocssw.root = " + installDir; isOCSSWRootSpecified = true; } text.append(line); text.append("\n"); } // Append "seadas.ocssw.root = " + installDir + "\n" to the runtime config file if it is not // exist if (!isOCSSWRootSpecified) { text.append("seadas.ocssw.root = " + installDir + "\n"); } fileWriter = new FileWriter(new File(RuntimeContext.getConfig().getConfigFilePath())); fileWriter.write(text.toString()); if (fileWriter != null) { fileWriter.close(); } ocsswRoot = installDir; } catch (IOException ioe) { handleException(ioe.getMessage()); } }