/** * @see net.sourceforge.squirrel_sql.client.update.xmlbeans.UpdateXmlSerializer#readChannelBean(net.sourceforge.squirrel_sql.fw.util.FileWrapper) */ public ChannelXmlBean readChannelBean(FileWrapper fileWrapper) throws FileNotFoundException, IOException { ChannelXmlBean result = null; BufferedInputStream is = null; try { is = new BufferedInputStream(new FileInputStream(fileWrapper.getAbsolutePath())); result = readChannelBean(is); } finally { _iou.closeInputStream(is); } return result; }
_iou.copyBytes(fis, os); _iou.closeInputStream(fis);
@Override public void copySplashImage() throws IOException { // The user.dir property on the Mac is /Applications/SQuirreLSQL.app/Contents/Resources/Java String squirrelHome = System.getProperty("user.dir"); String jarFilename = squirrelHome + "/update/downloads/core/squirrel-sql.jar"; String resourceName = "splash.jpg"; String pathToIconsDir = squirrelHome + "/icons"; String destinationFile = pathToIconsDir + "/" + resourceName; File iconsDir = new File(pathToIconsDir); if (!iconsDir.exists()) { logInfo("Icons directory ("+pathToIconsDir+") doesn't exist, so attempting to create it."); boolean result = iconsDir.mkdir(); if (!result) { s_log.error("Failed to create icons directory ("+pathToIconsDir+")"); } } logInfo("Copying splash.jpg from jarfile ("+jarFilename+") to "+destinationFile); ioutils.copyResourceFromJarFile(jarFilename, resourceName, destinationFile); }
/** * Updates the launch script with changes made necessary by the new release. * * @throws IOException * if an I/O error occurs */ @Override public void updateLaunchScript() throws IOException { // 1. determine which script(s) to fix. List<String> launchScriptLocations = getLaunchScriptLocations(); for (String launchScript : launchScriptLocations) { logInfo("Applying updates to launch script: " + launchScript); // 2. Get the lines from the file, applying the line fixers List<String> lines = ioutils.getLinesFromFile(launchScript, scriptLineFixers); // 3. Write the fixed lines back out to the file. ioutils.writeLinesToFile(launchScript, lines); } }
/** * @see net.sourceforge.squirrel_sql.client.update.UpdateUtil#downloadHttpUpdateFile(java.lang.String, int, * java.lang.String, java.lang.String, long, long) */ public String downloadHttpUpdateFile(final String host, final int port, final String fileToGet, final String destDir, final long fileSize, final long checksum, final IProxySettings proxySettings) throws Exception { URL url = _iou.constructHttpUrl(host, port, fileToGet); String result = null; FileWrapper resultFile = _fileWrapperFactory.create(destDir, _pathUtils.getFileFromPath(fileToGet)); result = resultFile.getAbsolutePath(); if (s_log.isDebugEnabled()) { s_log.debug("downloadHttpFile: writing http response body to file: " + resultFile); } int totalLength = _iou.downloadHttpFile(url, resultFile, proxySettings); verifySize(url, fileSize, totalLength); return result; }
_iou.closeOutputStream(fos); _iou.closeInputStream(fis); _iou.closeInputStream(zis);
/** * @see net.sourceforge.squirrel_sql.client.update.UpdateUtil#getCheckSum(java.io.File) */ public long getCheckSum(FileWrapper f) { String absPath = f.getAbsolutePath(); Long result = -1L; if (fileChecksumMap.containsKey(absPath)) { result = fileChecksumMap.get(absPath); } else { try { result = _iou.getCheckSum(f); } catch (IOException e) { s_log.error("getCheckSum: failed to compute the checksum for file (" + f.getAbsolutePath() + "): " + e.getMessage(), e); } // -1 is stored if the checksum operation failed. This will ensure that comparison with any other // file's checksum will be different - even if they happen to be the same file. fileChecksumMap.put(absPath, result); } return result; }
_iou.copyFile(from, toFile);
/** * Updates the launch script with changes made necessary by the new release. * * @throws IOException * if an I/O error occurs */ @Override public void updateLaunchScript() throws IOException { // 1. determine which script(s) to fix. List<String> launchScriptLocations = getLaunchScriptLocations(); for (String launchScript : launchScriptLocations) { logInfo("Applying updates to launch script: " + launchScript); // 2. Get the lines from the file, applying the line fixers List<String> lines = ioutils.getLinesFromFile(launchScript, scriptLineFixers); // 3. Write the fixed lines back out to the file. ioutils.writeLinesToFile(launchScript, lines); } }
/** * @see net.sourceforge.squirrel_sql.client.update.UpdateUtil#downloadHttpUpdateFile(java.lang.String, int, * java.lang.String, java.lang.String, long, long) */ public String downloadHttpUpdateFile(final String host, final int port, final String fileToGet, final String destDir, final long fileSize, final long checksum, final IProxySettings proxySettings) throws Exception { URL url = _iou.constructHttpUrl(host, port, fileToGet); String result = null; FileWrapper resultFile = _fileWrapperFactory.create(destDir, _pathUtils.getFileFromPath(fileToGet)); result = resultFile.getAbsolutePath(); if (s_log.isDebugEnabled()) { s_log.debug("downloadHttpFile: writing http response body to file: " + resultFile); } int totalLength = _iou.downloadHttpFile(url, resultFile, proxySettings); verifySize(url, fileSize, totalLength); return result; }
_iou.closeOutputStream(fos); _iou.closeInputStream(fis); _iou.closeInputStream(zis);
/** * @see net.sourceforge.squirrel_sql.client.update.UpdateUtil#getCheckSum(java.io.File) */ public long getCheckSum(FileWrapper f) { String absPath = f.getAbsolutePath(); Long result = -1L; if (fileChecksumMap.containsKey(absPath)) { result = fileChecksumMap.get(absPath); } else { try { result = _iou.getCheckSum(f); } catch (IOException e) { s_log.error("getCheckSum: failed to compute the checksum for file (" + f.getAbsolutePath() + "): " + e.getMessage(), e); } // -1 is stored if the checksum operation failed. This will ensure that comparison with any other // file's checksum will be different - even if they happen to be the same file. fileChecksumMap.put(absPath, result); } return result; }
_iou.copyFile(from, toFile);
ioUtil.closeOutputStream(fos);
/** * @see net.sourceforge.squirrel_sql.client.update.xmlbeans.UpdateXmlSerializer#readChannelBean(net.sourceforge.squirrel_sql.fw.util.FileWrapper) */ public ChannelXmlBean readChannelBean(FileWrapper fileWrapper) throws FileNotFoundException, IOException { ChannelXmlBean result = null; BufferedInputStream is = null; try { is = new BufferedInputStream(new FileInputStream(fileWrapper.getAbsolutePath())); result = readChannelBean(is); } finally { _iou.closeInputStream(is); } return result; }
_iou.copyBytes(fis, os); _iou.closeInputStream(fis);
artifact.setVersion(version); artifact.setSize(a.length()); artifact.setChecksum(_iou.getCheckSum(a)); module.addArtifact(artifact);
@Override public void copySplashImage() throws IOException { // The user.dir property on the Mac is /Applications/SQuirreLSQL.app/Contents/Resources/Java String squirrelHome = System.getProperty("user.dir"); String jarFilename = squirrelHome + "/update/downloads/core/squirrel-sql.jar"; String resourceName = "splash.jpg"; String pathToIconsDir = squirrelHome + "/icons"; String destinationFile = pathToIconsDir + "/" + resourceName; File iconsDir = new File(pathToIconsDir); if (!iconsDir.exists()) { logInfo("Icons directory ("+pathToIconsDir+") doesn't exist, so attempting to create it."); boolean result = iconsDir.mkdir(); if (!result) { s_log.error("Failed to create icons directory ("+pathToIconsDir+")"); } } logInfo("Copying splash.jpg from jarfile ("+jarFilename+") to "+destinationFile); ioutils.copyResourceFromJarFile(jarFilename, resourceName, destinationFile); }
/** * @see net.sourceforge.squirrel_sql.client.update.xmlbeans.UpdateXmlSerializer#readChangeListBean(net.sourceforge.squirrel_sql.fw.util.FileWrapper) */ public ChangeListXmlBean readChangeListBean(FileWrapper file) throws FileNotFoundException { XMLDecoder bis = null; FileInputStream fis = null; Object result = null; try { fis = new FileInputStream(new File(file.getAbsolutePath())); bis = new XMLDecoder(new BufferedInputStream(fis)); result = bis.readObject(); } finally { _iou.closeInputStream(fis); if (bis != null) { bis.close(); } } return (ChangeListXmlBean) result; }