List of usage examples for org.apache.commons.io FileUtils copyURLToFile
public static void copyURLToFile(URL source, File destination) throws IOException
source
to a file destination
. From source file:main.java.vasolsim.common.GenericUtils.java
/** * exports an internal resource to an external file * * @param internalResource internal resource * @param externalResource external target file * * @return if the export was successful/*from w w w .jav a2s . c o m*/ */ public static boolean exportResource(URL internalResource, File externalResource) { try { FileUtils.copyURLToFile(internalResource, externalResource); } catch (IOException e) { return false; } return true; }
From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java
private BufferedReader getEnGensenReader() throws IOException { File dir = new File(TERM_EXTRACT_SCRIPTS_DIR); if (!dir.exists()) { dir.mkdir();//from w w w. j a v a 2 s . c o m } String taggerPath = TERM_EXTRACT_SCRIPTS_DIR + File.separator + TERM_EXTRACT_TAGGER_PL; File scriptFile = new File(taggerPath); if (!scriptFile.exists()) { URL url = DODDLE_OWL.class.getClassLoader() .getResource(Utils.RESOURCE_DIR + "TermExtractScripts/" + TERM_EXTRACT_TAGGER_PL); if (url != null) { FileUtils.copyURLToFile(url, scriptFile); // System.out.println("copy: " + scriptFile.getAbsolutePath()); } } ProcessBuilder processBuilder = new ProcessBuilder(PERL_EXE, taggerPath, STANFORD_PARSER_MODELS_HOME + File.separator + "tmpTagger.txt"); termExtractProcess = processBuilder.start(); return new BufferedReader(new InputStreamReader(termExtractProcess.getInputStream(), "UTF-8")); }
From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java
/** * @param text//w ww. j a v a2 s .co m * @param rt * @return * @throws IOException */ private BufferedReader getJaGenSenReader(String text) throws IOException { tmpFile = File.createTempFile("tmp", null); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), Japanese_Morphological_Analyzer_CharacterSet)); bw.write(text); bw.close(); tmpJapaneseMorphologicalAnalyzerFile = File.createTempFile("tmpJpMorphologicalAnalyzer", null); ProcessBuilder processBuilder = null; if (Japanese_Morphological_Analyzer.matches(".*mecab.*")) { processBuilder = new ProcessBuilder(Japanese_Morphological_Analyzer, "-o", tmpJapaneseMorphologicalAnalyzerFile.getAbsolutePath(), tmpFile.getAbsolutePath()); } else { processBuilder = new ProcessBuilder(Japanese_Morphological_Analyzer, "-i", "w", "-o", tmpJapaneseMorphologicalAnalyzerFile.getAbsolutePath(), tmpFile.getAbsolutePath()); } jaMorphologicalAnalyzerProcess = processBuilder.start(); String path = ""; String TERM_EXTRACT_EXE = TERM_EXTRACT_CHASEN_PL; if (Japanese_Morphological_Analyzer.matches(".*mecab.*")) { TERM_EXTRACT_EXE = TERM_EXTRACT_MECAB_PL; } File dir = new File(TERM_EXTRACT_SCRIPTS_DIR); if (!dir.exists()) { dir.mkdir(); } path = TERM_EXTRACT_SCRIPTS_DIR + File.separator + TERM_EXTRACT_EXE; File scriptFile = new File(path); if (!scriptFile.exists()) { URL url = DODDLE_OWL.class.getClassLoader() .getResource(Utils.RESOURCE_DIR + "TermExtractScripts/" + TERM_EXTRACT_EXE); if (url != null) { FileUtils.copyURLToFile(url, scriptFile); // System.out.println("copy: " + scriptFile.getAbsolutePath()); } } processBuilder = new ProcessBuilder(PERL_EXE, path, tmpJapaneseMorphologicalAnalyzerFile.getAbsolutePath()); termExtractProcess = processBuilder.start(); return new BufferedReader(new InputStreamReader(termExtractProcess.getInputStream(), Japanese_Morphological_Analyzer_CharacterSet)); }
From source file:hu.tbognar76.apking.ApKing.java
private boolean isLocalVersionGooglePlayImage(String packageName) { String fname = this.init.catalogHtml + "/" + this.init.catalogPic + "/" + packageName + ".png"; if (!this.init.isCatalogPicForced) { File t = new File(fname); if (t.exists()) { // System.out.println("------"+fname); if (t.length() > 1) { return true; }//from w w w. ja v a 2 s.c om return false; } else { // WORK TO DO BELOW } } Document doc = null; try { doc = Jsoup .connect("https://play.google.com/store/apps/details?id=" + URI.create(packageName) + "&hl=en") .get(); // Joni j, de nha nem // Elements img = doc.getElementsByClass("cover-image"); Elements img = doc.select("div.cover-container img"); String uu = "http:" + img.first().attr("src"); uu = uu.replace("http:https:", "https:"); uu = uu.replace("=w300", "=w120"); URL url = new URL(uu); FileUtils.copyURLToFile(url, new File(fname)); } catch (Exception e) { try { FileUtils.write(new File(fname), "-"); return false; } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return true; }
From source file:com.aurel.track.dbase.HandleHome.java
/** * Copies FAQ template structure from the WAR to TRACKPLUS_HOME if it does not exist there yet. * @return//from w w w .j a v a 2 s . c o m * @throws ServletException */ public static void copyFAQTemplates(ServletContext servletContext) throws ServletException { File faqTemplateDir = null; File faqDir = null; ZipFile templateZipFile = null; try { // First check if we have a configuration file pointed to by the environment URL templateURL = null; if (HandleHome.getTrackplus_Home() != null && !"".equals(HandleHome.getTrackplus_Home())) { faqTemplateDir = new File( HandleHome.getTrackplus_Home() + File.separator + "Faqs" + File.separator + "whc_template"); faqDir = new File(HandleHome.getTrackplus_Home() + File.separator + "Faqs"); if (!faqDir.exists() || !faqDir.isDirectory()) { if (faqDir != null && !faqDir.exists()) { faqDir.mkdirs(); } if (faqDir != null && !faqDir.canWrite()) { LOGGER.error(faqDir + " not writable to " + faqDir.getAbsolutePath() + " by user " + System.getProperty("user.name")); return; } } if (!faqTemplateDir.exists() || !faqTemplateDir.isDirectory()) { templateURL = PluginUtils.class.getResource("/resources/reportTemplates/whc_template.zip"); File faqTemplate = new File(HandleHome.getTrackplus_Home() + File.separator + "Faqs" + File.separator + "whc_template.zip"); FileUtils.copyURLToFile(templateURL, faqTemplate); templateZipFile = new ZipFile(faqTemplate); Enumeration<? extends ZipEntry> entries = templateZipFile.getEntries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(faqDir, entry.getName()); entryDestination.getParentFile().mkdirs(); if (!entryDestination.isDirectory()) { InputStream in = templateZipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } } } catch (Exception e) { LOGGER.error("Could not read " + templateZipFile + ". Ignoring. " + e.getMessage()); } }
From source file:eu.sisob.uma.extractors.adhoc.cvfilesinside.InternalCVFilesExtractor.java
/** * * @param input_file//from w w w. j a v a 2 s . com * @param results_dir * @param zip_output_file * @param output_file_2 * @param error_sw */ public static void download_files(File input_file, File results_dir, File zip_output_file, File output_file_2, StringWriter error_sw) { CSVReader reader = null; try { reader = new CSVReader(new FileReader(input_file), CSV_SEPARATOR); } catch (FileNotFoundException ex) { Logger.getRootLogger().error("Error reading " + input_file.getName() + " - " + ex.toString()); return; } int idStaffIdentifier = -1; int idName = -1; int idFirstName = -1; int idLastName = -1; int idInitials = -1; int idUnitOfAssessment_Description = -1; int idInstitutionName = -1; int idWebAddress = -1; int idResearchGroupDescription = -1; int idResearcherWebAddress = -1; int idResearcherWebAddressType = -1; int idResearcherWebAddressExt = -1; int idScoreUrl = -1; String[] nextLine; try { if ((nextLine = reader.readNext()) != null) { for (int i = 0; i < nextLine.length; i++) { String column_name = nextLine[i]; if (column_name.equals(FileFormatConversor.CSV_COL_ID)) idStaffIdentifier = i; else if (column_name.equals(FileFormatConversor.CSV_COL_NAME)) idName = i; else if (column_name.equals(FileFormatConversor.CSV_COL_FIRSTNAME)) idFirstName = i; else if (column_name.equals(FileFormatConversor.CSV_COL_LASTNAME)) idLastName = i; else if (column_name.equals(FileFormatConversor.CSV_COL_INITIALS)) idInitials = i; else if (column_name.equals(FileFormatConversor.CSV_COL_SUBJECT)) idUnitOfAssessment_Description = i; else if (column_name.equals(FileFormatConversor.CSV_COL_INSTITUTION_NAME)) idInstitutionName = i; else if (column_name.equals(FileFormatConversor.CSV_COL_INSTITUTION_URL)) idWebAddress = i; else if (column_name.equals(FileFormatConversor.CSV_COL_RESEARCHER_PAGE_URL)) idResearcherWebAddress = i; else if (column_name.equals(FileFormatConversor.CSV_COL_RESEARCHER_PAGE_TYPE)) idResearcherWebAddressType = i; else if (column_name.equals(FileFormatConversor.CSV_COL_RESEARCHER_PAGE_EXT)) idResearcherWebAddressExt = i; else if (column_name.equals(FileFormatConversor.CSV_COL_SCORE_URL)) idScoreUrl = i; } } } catch (Exception ex) { String error_msg = "Error reading headers of " + input_file.getName(); Logger.getRootLogger().error(error_msg + " - " + ex.toString()); if (error_sw != null) error_sw.append(error_msg + "\r\n"); return; } try { for (int i = 0; i < nextLine.length; i++) nextLine[i] = "\"" + nextLine[i] + "\""; FileUtils.write(output_file_2, StringUtil.join(Arrays.asList(nextLine), ";") + "\r\n", "UTF-8", false); } catch (IOException ex) { Logger.getLogger("root").error(ex.toString()); } if (idResearcherWebAddress != -1 && idResearcherWebAddressType != -1 && idResearcherWebAddressExt != -1) { Logger.getRootLogger().info("Going to downloads results files"); MessageDigest digest = null; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException ex) { } if (!results_dir.exists()) results_dir.mkdirs(); // File cv_results_dirs = new File(results_dir, "CV"); // if(!cv_results_dirs.exists()) // cv_results_dirs.mkdirs(); // // File pub_results_dirs = new File(results_dir, "PUB"); // if(!pub_results_dirs.exists()) // pub_results_dirs.mkdirs(); // // File homepage_results_dirs = new File(results_dir, "HOMEPAGE"); // if(!homepage_results_dirs.exists()) // homepage_results_dirs.mkdirs(); try { while ((nextLine = reader.readNext()) != null) { String url = nextLine[idResearcherWebAddress]; String ext = nextLine[idResearcherWebAddressExt]; String type = nextLine[idResearcherWebAddressType]; String id = nextLine[idStaffIdentifier]; try { Logger.getRootLogger().info("Downloading " + url); String filename = type + "_" + id + "_" + MD5(url) + "." + ext; File dest = null; // if(type.equals("CV")) // dest = new File(cv_results_dirs, filename); // else if(type.equals("PUB")) // dest = new File(pub_results_dirs, filename); // else if(type.equals("HOMEPAGE")) // dest = new File(homepage_results_dirs, filename); // else dest = new File(results_dir, filename); int max = 10; int num = 0; boolean download_finish = false; while (!download_finish) { try { Thread.sleep(200); URL fetched_url = Downloader.fetchURL(url); FileUtils.copyURLToFile(fetched_url, dest); download_finish = true; } catch (Exception ex) { Logger.getRootLogger().error("Error downloading " + url, ex); num++; } if (max <= num) throw new Exception("Error download time overflowed"); } nextLine[idResearcherWebAddress] = filename; try { for (int i = 0; i < nextLine.length; i++) nextLine[i] = "\"" + nextLine[i] + "\""; FileUtils.write(output_file_2, StringUtil.join(Arrays.asList(nextLine), ";") + "\r\n", "UTF-8", true); } catch (Exception ex) { Logger.getLogger("root").error(ex.toString()); } } catch (Exception ex) { Logger.getRootLogger().error("Error manage downloading " + url, ex); } } } catch (Exception ex) { Logger.getRootLogger().error("Error reading " + input_file.getName() + " " + ex.getMessage()); } ZipFile zf; try { zf = new ZipFile(zip_output_file); zf.createZipFileFromFolder(results_dir, new ZipParameters(), false, 0); } catch (Exception ex) { Logger.getRootLogger().error("Error zipping results from " + input_file.getName()); } } else { Logger.getRootLogger().error("Headers incorrect " + input_file.getName()); } }
From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java
private void writeHTML(String xmlName, String outfileBasename) { if (!OutputFormat.toLowerCase().contains("html")) return;/*from ww w.j a v a 2 s .com*/ String htmlfileName = outfileBasename + ".html"; if (OutputFormat.toLowerCase().contains("framehtml")) { StatusBoard.getStatusBoard().statusChanged(STATUS_WRITE_FRAMEHTML); transformationParameters.put("outputdir", outfileBasename); File outDir = new File(outputDirectory); File xmlFile = new File(outDir, xmlName); transformationParameters.put("catalogXmlPath", xmlFile.toURI().toString()); if (xmlName != null && xmlName.length() > 0 && xslframeHtmlFileName != null && xslframeHtmlFileName.length() > 0) { xsltWrite(xmlName, xslframeHtmlFileName, htmlfileName); } File outputDir = new File(outDir, outfileBasename); File cssDestination = new File(outputDir, cssFileName); try { if (cssPath.toLowerCase().startsWith("http")) { URL css = new URL(cssPath + "/" + cssFileName); FileUtils.copyURLToFile(css, cssDestination); } else { File css = new File(cssPath + "/" + cssFileName); if (css.exists()) { FileUtils.copyFile(css, cssDestination); } else { result.addError(this, 18, css.getAbsolutePath()); return; } } } catch (Exception e) { result.addWarning(this, 16, cssFileName, cssPath, outputDir.getAbsolutePath()); } if (includeDiagrams) { /* * Copy content of temporary images folder to output folder */ File tmpImgDir = options.imageTmpDir(); try { FileUtils.copyDirectoryToDirectory(tmpImgDir, outputDir); } catch (IOException e) { result.addError(this, 28, tmpImgDir.getAbsolutePath(), outputDir.getAbsolutePath(), e.getMessage()); } } } else { StatusBoard.getStatusBoard().statusChanged(STATUS_WRITE_HTML); if (xmlName != null && xmlName.length() > 0 && xslhtmlfileName != null && xslhtmlfileName.length() > 0 && htmlfileName != null && htmlfileName.length() > 0) { xsltWrite(xmlName, xslhtmlfileName, htmlfileName); } } }
From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java
/** * Transforms the contents of the temporary feature catalogue xml and * inserts it into a specific place (denoted by a placeholder) of a docx * template file. The result is copied into a new output file. The template * file is not modified.// w w w.j a v a2 s. c o m * * @param xmlName * Name of the temporary feature catalogue xml file, located in * the output directory. * @param outfileBasename * Base name of the output file, without file type ending. */ private void writeDOCX(String xmlName, String outfileBasename) { if (!OutputFormat.toLowerCase().contains("docx")) return; StatusBoard.getStatusBoard().statusChanged(STATUS_WRITE_DOCX); ZipHandler zipHandler = new ZipHandler(); String docxfileName = outfileBasename + ".docx"; try { // Setup directories File outDir = new File(outputDirectory); File tmpDir = new File(outDir, "tmpdocx"); File tmpinputDir = new File(tmpDir, "input"); File tmpoutputDir = new File(tmpDir, "output"); // get docx template // create temporary file for the docx template copy File docxtemplate_copy = new File(tmpDir, "docxtemplatecopy.tmp"); // populate temporary file either from remote or local URI if (docxTemplateFilePath.toLowerCase().startsWith("http")) { URL templateUrl = new URL(docxTemplateFilePath); FileUtils.copyURLToFile(templateUrl, docxtemplate_copy); } else { File docxtemplate = new File(docxTemplateFilePath); if (docxtemplate.exists()) { FileUtils.copyFile(docxtemplate, docxtemplate_copy); } else { result.addError(this, 19, docxtemplate.getAbsolutePath()); return; } } /* * Unzip the docx template to tmpinputDir and tmpoutputDir The * contents of the tmpinputdir will be used as input for the * transformation. The transformation result will overwrite the * relevant files in the tmpoutputDir. */ zipHandler.unzip(docxtemplate_copy, tmpinputDir); zipHandler.unzip(docxtemplate_copy, tmpoutputDir); /* * Get hold of the styles.xml file from which the transformation * will get relevant information. The path to this file will be used * as a transformation parameter. */ File styleXmlFile = new File(tmpinputDir, "word/styles.xml"); if (!styleXmlFile.canRead()) { result.addError(null, 301, styleXmlFile.getName(), "styles.xml"); return; } /* * Get hold of the temporary feature catalog xml file. The path to * this file will be used as a transformation parameter. */ File xmlFile = new File(outDir, xmlName); if (!styleXmlFile.canRead()) { result.addError(null, 301, styleXmlFile.getName(), xmlName); return; } /* * Get hold of the input document.xml file (internal .xml file from * the docxtemplate). It will be used as the source for the * transformation. */ File indocumentxmlFile = new File(tmpinputDir, "word/document.xml"); if (!indocumentxmlFile.canRead()) { result.addError(null, 301, indocumentxmlFile.getName(), "document.xml"); return; } /* * Get hold of the output document.xml file. It will be used as the * transformation target. */ File outdocumentxmlFile = new File(tmpoutputDir, "word/document.xml"); if (!outdocumentxmlFile.canWrite()) { result.addError(null, 307, outdocumentxmlFile.getName(), "document.xml"); return; } /* * Prepare the transformation. */ transformationParameters.put("styleXmlPath", styleXmlFile.toURI().toString()); transformationParameters.put("catalogXmlPath", xmlFile.toURI().toString()); transformationParameters.put("DOCX_PLACEHOLDER", DOCX_PLACEHOLDER); /* * Execute the transformation. */ this.xsltWrite(indocumentxmlFile, xsldocxfileName, outdocumentxmlFile); if (includeDiagrams) { /* * === Process image information === */ /* * 1. Copy content of temporary images folder to output folder */ File mediaDir = new File(tmpoutputDir, "word/media"); FileUtils.copyDirectoryToDirectory(options.imageTmpDir(), mediaDir); /* * 2. Create image information file. The path to this file will * be used as a transformation parameter. */ Document imgInfoDoc = createDocument(); imgInfoDoc.appendChild(imgInfoDoc.createComment("Temporary file containing image metadata")); Element imgInfoRoot = imgInfoDoc.createElement("images"); imgInfoDoc.appendChild(imgInfoRoot); addAttribute(imgInfoDoc, imgInfoRoot, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); List<ImageMetadata> imageList = new ArrayList<ImageMetadata>(imageSet); Collections.sort(imageList, new Comparator<ImageMetadata>() { @Override public int compare(ImageMetadata o1, ImageMetadata o2) { return o1.getId().compareTo(o2.getId()); } }); for (ImageMetadata im : imageList) { Element e1 = imgInfoDoc.createElement("image"); addAttribute(imgInfoDoc, e1, "id", im.getId()); addAttribute(imgInfoDoc, e1, "relPath", im.getRelPathToFile()); imgInfoRoot.appendChild(e1); } Properties outputFormat = OutputPropertiesFactory.getDefaultMethodProperties("xml"); outputFormat.setProperty("indent", "yes"); outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount", "2"); if (encoding != null) outputFormat.setProperty("encoding", encoding); File relsFile = new File(tmpDir, "docx_relationships.tmp.xml"); try { OutputStream fout = new FileOutputStream(relsFile); OutputStream bout = new BufferedOutputStream(fout); OutputStreamWriter outputXML = new OutputStreamWriter(bout, outputFormat.getProperty("encoding")); Serializer serializer = SerializerFactory.getSerializer(outputFormat); serializer.setWriter(outputXML); serializer.asDOMSerializer().serialize(imgInfoDoc); outputXML.close(); } catch (Exception e) { String m = e.getMessage(); if (m != null) { result.addError(m); } e.printStackTrace(System.err); } /* * 3. Apply transformation to relationships file */ /* * Get hold of the input relationships file (internal file from * the docx template). It will be used as the source for the * transformation. */ File inRelsXmlFile = new File(tmpinputDir, "word/_rels/document.xml.rels"); if (!inRelsXmlFile.canRead()) { result.addError(null, 301, inRelsXmlFile.getName(), "document.xml.rels"); return; } /* * Get hold of the output relationships file. It will be used as * the transformation target. */ File outRelsXmlFile = new File(tmpoutputDir, "word/_rels/document.xml.rels"); if (!outRelsXmlFile.canWrite()) { result.addError(null, 307, outRelsXmlFile.getName(), "document.xml.rels"); return; } /* * Prepare the transformation. */ transformationParameters.put("imageInfoXmlPath", relsFile.toURI().toString()); /* * Execute the transformation. */ this.xsltWrite(inRelsXmlFile, xsldocxrelsfileName, outRelsXmlFile); } /* * === Create the docx result file === */ // Get hold of the output docx file (it will be overwritten or // initialized). File outFile = new File(outDir, docxfileName); /* * Zip the temporary output directory and copy it to the output docx * file. */ zipHandler.zip(tmpoutputDir, outFile); /* * === Delete the temporary directory === */ try { FileUtils.deleteDirectory(tmpDir); } catch (IOException e) { result.addWarning(this, 20, e.getMessage()); } result.addResult(getTargetID(), outputDirectory, docxfileName, null); } catch (Exception e) { String m = e.getMessage(); if (m != null) { result.addError(m); } e.printStackTrace(System.err); } }
From source file:net.zyuiop.fastsurvival.updater.Updater.java
public void doUpdate(CommandSender sender) { checkForUpdates();//from w w w .j a v a 2s . c om if (!updates) { sender.sendMessage(ChatColor.GOLD + "The plugin is already up to date =)"); return; } File plugin = FastSurvival.instance.getFile(); String[] path = StringUtils.split(downloadUrl.getFile(), "/"); Bukkit.getLogger().info("Current plugin : " + plugin.getAbsolutePath()); File target = new File(plugin.getParentFile(), path[path.length - 1]); sender.sendMessage(ChatColor.YELLOW + "[Updater] Starting download of " + target.getName()); try { FileUtils.copyURLToFile(downloadUrl, target); } catch (IOException e) { e.printStackTrace(); sender.sendMessage(ChatColor.YELLOW + "[Updater] " + ChatColor.RED + "Failed to download the new version. Check the log for more information."); return; } sender.sendMessage(ChatColor.YELLOW + "[Updater] Download finished, applying update.."); Plugin outdated = FastSurvival.instance; FastSurvival.instance = null; Bukkit.getServer().getPluginManager().disablePlugin(outdated); outdated.getPluginLoader().disablePlugin(outdated); if (!plugin.delete()) { plugin.deleteOnExit(); Bukkit.getLogger().info("Delete failed / Scheduled delete on exit."); } Bukkit.reload(); sender.sendMessage( ChatColor.YELLOW + "[Updater] " + ChatColor.GREEN + "The plugin was updated successfully !"); sender.sendMessage(ChatColor.YELLOW + "[Updater] " + ChatColor.YELLOW + "FastSurvival is now at version " + ChatColor.GREEN + targetVersion); }
From source file:no.dusken.aranea.admin.control.EditExternalPageController.java
/** * get 15 last feedentries from the given url. * * @param feedurl - url to a rss-feed//from w w w. ja v a2s .c o m * @return list with feedentries */ private SyndFeed getFeedEntries(String feedurl) { File feedFile = new File(cacheDirectory + "/" + feedurl); // check if the file is too old, and download if that is the case if (!feedFile.exists() || System.currentTimeMillis() - feedFile.lastModified() > 100000) { try { FileUtils.copyURLToFile(new URL(feedurl), new File(cacheDirectory + "/" + feedurl)); } catch (IOException e) { // log, continue using the old file and hope the best log.error("Could not download rss", e); } } SyndFeed feed = null; try { SyndFeedInput input = new SyndFeedInput(); feed = input.build(new XmlReader(feedFile)); feed.setEncoding("UTF-8"); } catch (FeedException e) { log.error("Could not parse feed", e); } catch (IOException e) { log.error("Could not read rss file", e); } if (feed != null) { return feed; } else { return null; } }