List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:de.lightful.testflux.drools.DroolsRuleTestListener.java
private void addAllFilesFromDirectory(KnowledgeBuilder knowledgeBuilder, String directoryName, RulesBaseDirectory ruleBaseDirectory) { String baseDirectory = determineBaseDirectory(ruleBaseDirectory); File directory = fileFromBaseDirectory(directoryName, baseDirectory); if (!directory.exists()) { throw new TestFluxException("Directory " + directory.getAbsolutePath() + " given by @" + RuleSource.class.getSimpleName() + " must exist (but does not)."); }//ww w . j a v a2 s .c o m if (!directory.isDirectory()) { throw new TestFluxException("Directory " + directory.getAbsolutePath() + " given by @" + RuleSource.class.getSimpleName() + " must denote a directory (but does not)."); } Iterator<File> fileIterator = null; try { fileIterator = FileUtils.iterateFiles(directory, new String[] { "drl" }, false); } catch (Throwable t) { throw new TestFluxException("Caught " + t.getClass().getSimpleName() + ": " + t.getMessage()); } for (File file : IterableAdapter.makeFrom(fileIterator)) { addIndividualFile(knowledgeBuilder, file); } }
From source file:com.github.drochetti.javassist.maven.ClassTransformer.java
protected Iterator<String> iterateClassnames(final String dir) { final String[] extensions = { ".class" }; final File directory = new File(dir); // only files with extension '.class' and NOT with '$' - for ignoring nested classes // javassist doesn't support nested classes // @see http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/tutorial/tutorial2.html #4.7 Limitations ///*from w w w . ja va 2s. com*/ // Michael Haak: For me, working with nested classes works, so why not using all classes? final IOFileFilter fileFilter = new SuffixFileFilter(extensions); final IOFileFilter dirFilter = TrueFileFilter.INSTANCE; return ClassnameExtractor.iterateClassnames(directory, FileUtils.iterateFiles(directory, fileFilter, dirFilter)); }
From source file:de.crowdcode.movmvn.plugin.general.GeneralPlugin.java
private void moveFiles() { try {//from w w w .j a v a 2 s . c om context.logInfo("Move files..."); String projectSourceName = context.getProjectSourceName(); String projectTargetName = context.getProjectTargetName(); // Move files *.java from src -> src/main/java // Move files *.properties;*.txt;*.jpg -> src/main/resources // Move files *.java from test -> src/test/java // Move files *.properties;*.txt;*.jpg -> src/test/resources // Move files *.* from resources or resource -> src/main/resources // Move files from / to / but not .classpath, .project -> // src/main/resources // Move directory META-INF -> src/main/resources String[] extensionsJava = { "java" }; Iterator<File> fileIterator = FileUtils.iterateFiles(new File(projectSourceName + "/src"), extensionsJava, true); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); String nameResultAfterSrc = StringUtils.substringAfterLast(currentFile.getAbsolutePath(), "src\\"); nameResultAfterSrc = projectTargetName.concat("/src/main/java/").concat(nameResultAfterSrc); log.info("Target file: " + nameResultAfterSrc); File targetFile = new File(nameResultAfterSrc); FileUtils.copyFile(currentFile, targetFile, true); } // Check whether "resource" or "resources" exist? File directoryResources = new File(projectSourceName + "/resource"); File targetResourcesDir = new File(projectTargetName.concat("/src/main/resources")); if (directoryResources.exists()) { // Move the files FileUtils.copyDirectory(directoryResources, targetResourcesDir); } directoryResources = new File(projectSourceName + "/resources"); if (directoryResources.exists()) { // Move the files FileUtils.copyDirectory(directoryResources, targetResourcesDir); } // META-INF File directoryMetaInf = new File(projectSourceName + "/META-INF"); if (directoryMetaInf.exists()) { FileUtils.copyDirectoryToDirectory(directoryMetaInf, targetResourcesDir); } // Directory . *.txt, *.doc*, *.png, *.jpg -> src/main/docs File targetDocsDir = new File(projectTargetName.concat("/src/main/docs")); String[] extensionsRootDir = { "txt", "doc", "docx", "png", "jpg" }; fileIterator = FileUtils.iterateFiles(new File(projectSourceName), extensionsRootDir, false); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); FileUtils.copyFileToDirectory(currentFile, targetDocsDir); } // Directory . *.cmd, *.sh -> src/main/bin File targetBinDir = new File(projectTargetName.concat("/src/main/bin")); String[] extensionsRootBinDir = { "sh", "cmd", "properties" }; fileIterator = FileUtils.iterateFiles(new File(projectSourceName), extensionsRootBinDir, false); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); FileUtils.copyFileToDirectory(currentFile, targetBinDir); } } catch (IOException e) { log.info(e.getStackTrace().toString()); } }
From source file:com.ibm.soatf.component.jms.JmsComponent.java
/** * * @param objectName/* www .j a v a 2 s . c o m*/ * @return */ public Iterator<File> getGeneratedFilesIterator(String objectName) { String pattern = "*"; if (objectName != null) { pattern = objectName; } String filemask = new StringBuilder(jmsInterfaceConfig.getQueue().getName()).append(NAME_DELIMITER) .append(pattern).append(MESSAGE_SUFFIX).toString(); Iterator it = FileUtils.iterateFiles(workingDir, new WildcardFileFilter(filemask), TrueFileFilter.INSTANCE); return it; }
From source file:com.igormaznitsa.jute.JuteMojo.java
private static List<String> collectAllPotentialTestClassPaths(final Log log, final boolean verbose, final File rootFolder, final String[] includes, final String[] excludes) { final List<String> result = new ArrayList<String>(); final Iterator<File> iterator = FileUtils.iterateFiles(rootFolder, new IOFileFilter() { private final AntPathMatcher matcher = new AntPathMatcher(); @Override/* w w w. j a v a 2s .c om*/ public boolean accept(final File file) { if (file.isDirectory()) { return false; } final String path = file.getAbsolutePath(); boolean include = false; if (path.endsWith(".class")) { if (includes.length != 0) { for (final String patteen : includes) { if (matcher.match(patteen, path)) { include = true; break; } } } else { include = true; } if (include && excludes.length != 0) { for (final String pattern : excludes) { if (matcher.match(pattern, path)) { include = false; break; } } } } if (!include && verbose) { log.info("File " + path + " excluded"); } return include; } @Override public boolean accept(final File dir, final String name) { final String path = name; boolean include = false; if (includes.length != 0) { for (final String pattern : includes) { if (matcher.match(pattern, path)) { include = true; break; } } } else { include = true; } if (include && excludes.length != 0) { for (final String pattern : excludes) { if (matcher.match(pattern, path)) { include = false; break; } } } if (!include && verbose) { log.info("Folder " + name + " excluded"); } return include; } }, DirectoryFileFilter.DIRECTORY); while (iterator.hasNext()) { final String detectedFile = iterator.next().getAbsolutePath(); if (verbose) { log.info("Found potential test class : " + detectedFile); } result.add(detectedFile); } if (result.isEmpty()) { log.warn("No test files found in " + rootFolder.getAbsolutePath()); } return result; }
From source file:com.mindquarry.desktop.workspace.SVNTestBase.java
/** * Finds all files with a given pattern that can include wildcards. Will * recurse into subdirectories. Similar to 'find DIR -name "PATTERN"' on a * unix command line./* w w w .j av a2 s . co m*/ * * Example: findFiles(dir, "*.java") * * @param dir the directory to search for (including all subdirectories) * @param pattern a pattern that can contain "?" (single-char-wildcard) and * "*" (multi-char-wildcard) as wildcards * @return an Iterator containing File objects for all found files */ @SuppressWarnings("unchecked") public Iterator findFiles(File dir, String pattern) { return FileUtils.iterateFiles(dir, new WildcardFileFilter(pattern), TrueFileFilter.INSTANCE); }
From source file:edu.wustl.xipHost.avt2ext.AVTUtil.java
@SuppressWarnings("unchecked") public synchronized WG23DataModel getWG23DataModel(TargetElement targetElement) { if (targetElement == null) { return null; }// w w w . ja va2 s .c o m AvailableData availableData = new AvailableData(); ArrayOfPatient arrayOfPatient = new ArrayOfPatient(); List<org.nema.dicom.wg23.Patient> listPatients = arrayOfPatient.getPatient(); org.nema.dicom.wg23.Patient patient = new org.nema.dicom.wg23.Patient(); List<SubElement> subElements = targetElement.getSubElements(); //patientName is the same for all subElements, therefore it is sufficient to get it for the first element at index 0. Map<Integer, Object> dicomCriteria = subElements.get(0).getCriteria().getDICOMCriteria(); String patientName = dicomCriteria.get(new Integer(1048592)).toString(); //patientName patient.setName(patientName); ArrayOfObjectDescriptor arrayOfObjectDescPatient = new ArrayOfObjectDescriptor(); patient.setObjectDescriptors(arrayOfObjectDescPatient); ArrayOfStudy arrayOfStudy = new ArrayOfStudy(); List<org.nema.dicom.wg23.Study> listOfStudies = arrayOfStudy.getStudy(); List<ObjectLocator> objLocators = new ArrayList<ObjectLocator>(); if (targetElement.getTarget().equals(IterationTarget.PATIENT)) { String currentStudyInstanceUID = null; ArrayOfSeries arrayOfSeries = null; for (SubElement subElement : subElements) { String studyInstanceUID = subElement.getCriteria().getDICOMCriteria().get(new Integer(2097165)) .toString(); //studyInstanceUID String path = subElement.getPath(); IOFileFilter fileFilter = FileFilterUtils.trueFileFilter(); Iterator<File> files = FileUtils.iterateFiles(new File(path), fileFilter, null); if (currentStudyInstanceUID == null || !currentStudyInstanceUID.equalsIgnoreCase(studyInstanceUID)) { currentStudyInstanceUID = studyInstanceUID; org.nema.dicom.wg23.Study study = new org.nema.dicom.wg23.Study(); study.setStudyUID(studyInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDescStudy = new ArrayOfObjectDescriptor(); study.setObjectDescriptors(arrayOfObjectDescStudy); arrayOfSeries = new ArrayOfSeries(); List<org.nema.dicom.wg23.Series> listOfSeries = arrayOfSeries.getSeries(); org.nema.dicom.wg23.Series series = new org.nema.dicom.wg23.Series(); String seriesInstanceUID = subElement.getCriteria().getDICOMCriteria().get(new Integer(2097166)) .toString(); //seriesInstanceUID series.setSeriesUID(seriesInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDesc = new ArrayOfObjectDescriptor(); List<ObjectDescriptor> listObjectDescs = arrayOfObjectDesc.getObjectDescriptor(); //create list of objDescs and add them to each series while (files.hasNext()) { File file = files.next(); ObjectDescriptor objDesc = new ObjectDescriptor(); Uuid objDescUUID = new Uuid(); objDescUUID.setUuid(UUID.randomUUID().toString()); objDesc.setUuid(objDescUUID); //check mime type String mimeType = null; objDesc.setMimeType(mimeType); Uid uid = new Uid(); String classUID = ""; uid.setUid(classUID); objDesc.setClassUID(uid); String modCode = ""; Modality modality = new Modality(); modality.setModality(modCode); objDesc.setModality(modality); listObjectDescs.add(objDesc); ObjectLocator objLoc = new ObjectLocator(); objLoc.setUuid(objDescUUID); try { objLoc.setUri(file.toURI().toURL().toExternalForm()); //getURI from the iterator } catch (MalformedURLException e) { logger.error(e, e); } objLocators.add(objLoc); } series.setObjectDescriptors(arrayOfObjectDesc); listOfSeries.add(series); study.setSeries(arrayOfSeries); listOfStudies.add(study); } else { List<org.nema.dicom.wg23.Series> listOfSeries = arrayOfSeries.getSeries(); org.nema.dicom.wg23.Series series = new org.nema.dicom.wg23.Series(); String seriesInstanceUID = subElement.getCriteria().getDICOMCriteria().get(new Integer(2097166)) .toString(); //seriesInstanceUID series.setSeriesUID(seriesInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDesc = new ArrayOfObjectDescriptor(); List<ObjectDescriptor> listObjectDescs = arrayOfObjectDesc.getObjectDescriptor(); //create list of objDescs and add them to each series while (files.hasNext()) { File file = files.next(); ObjectDescriptor objDesc = new ObjectDescriptor(); Uuid objDescUUID = new Uuid(); objDescUUID.setUuid(UUID.randomUUID().toString()); objDesc.setUuid(objDescUUID); //check mime type objDesc.setMimeType("application/dicom"); Uid uid = new Uid(); String classUID = ""; uid.setUid(classUID); objDesc.setClassUID(uid); String modCode = ""; Modality modality = new Modality(); modality.setModality(modCode); objDesc.setModality(modality); listObjectDescs.add(objDesc); ObjectLocator objLoc = new ObjectLocator(); objLoc.setUuid(objDescUUID); try { objLoc.setUri(file.toURI().toURL().toExternalForm()); //getURI from the iterator } catch (MalformedURLException e) { logger.error(e, e); } objLocators.add(objLoc); } series.setObjectDescriptors(arrayOfObjectDesc); listOfSeries.add(series); } } patient.setStudies(arrayOfStudy); listPatients.add(patient); availableData.setPatients(arrayOfPatient); ArrayOfObjectDescriptor arrayOfObjectDescTopLevel = new ArrayOfObjectDescriptor(); availableData.setObjectDescriptors(arrayOfObjectDescTopLevel); } else if (targetElement.getTarget().equals(IterationTarget.STUDY)) { String studyInstanceUID = subElements.get(0).getCriteria().getDICOMCriteria().get(new Integer(2097165)) .toString(); //studyInstanceUID org.nema.dicom.wg23.Study study = new org.nema.dicom.wg23.Study(); study.setStudyUID(studyInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDescStudy = new ArrayOfObjectDescriptor(); study.setObjectDescriptors(arrayOfObjectDescStudy); ArrayOfSeries arrayOfSeries = new ArrayOfSeries(); List<org.nema.dicom.wg23.Series> listOfSeries = arrayOfSeries.getSeries(); for (SubElement subElement : subElements) { String seriesInstanceUID = subElement.getCriteria().getDICOMCriteria().get(new Integer(2097166)) .toString(); //seriesInstanceUID String path = subElement.getPath(); IOFileFilter fileFilter = FileFilterUtils.trueFileFilter(); Iterator<File> files = FileUtils.iterateFiles(new File(path), fileFilter, null); org.nema.dicom.wg23.Series series = new org.nema.dicom.wg23.Series(); series.setSeriesUID(seriesInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDesc = new ArrayOfObjectDescriptor(); List<ObjectDescriptor> listObjectDescs = arrayOfObjectDesc.getObjectDescriptor(); //create list of objDescs and add them to each series while (files.hasNext()) { File file = files.next(); ObjectDescriptor objDesc = new ObjectDescriptor(); Uuid objDescUUID = new Uuid(); objDescUUID.setUuid(UUID.randomUUID().toString()); objDesc.setUuid(objDescUUID); //check mime type objDesc.setMimeType("application/dicom"); Uid uid = new Uid(); String classUID = ""; uid.setUid(classUID); objDesc.setClassUID(uid); String modCode = ""; Modality modality = new Modality(); modality.setModality(modCode); objDesc.setModality(modality); listObjectDescs.add(objDesc); ObjectLocator objLoc = new ObjectLocator(); objLoc.setUuid(objDescUUID); try { objLoc.setUri(file.toURI().toURL().toExternalForm()); //getURI from the iterator } catch (MalformedURLException e) { logger.error(e, e); } objLocators.add(objLoc); } series.setObjectDescriptors(arrayOfObjectDesc); listOfSeries.add(series); } study.setSeries(arrayOfSeries); listOfStudies.add(study); patient.setStudies(arrayOfStudy); listPatients.add(patient); availableData.setPatients(arrayOfPatient); ArrayOfObjectDescriptor arrayOfObjectDescTopLevel = new ArrayOfObjectDescriptor(); availableData.setObjectDescriptors(arrayOfObjectDescTopLevel); } else if (targetElement.getTarget().equals(IterationTarget.SERIES)) { String studyInstanceUID = subElements.get(0).getCriteria().getDICOMCriteria().get(new Integer(2097165)) .toString(); //studyInstanceUID String path = subElements.get(0).getPath(); IOFileFilter fileFilter = FileFilterUtils.trueFileFilter(); Iterator<File> files = FileUtils.iterateFiles(new File(path), fileFilter, null); org.nema.dicom.wg23.Study study = new org.nema.dicom.wg23.Study(); study.setStudyUID(studyInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDescStudy = new ArrayOfObjectDescriptor(); study.setObjectDescriptors(arrayOfObjectDescStudy); ArrayOfSeries arrayOfSeries = new ArrayOfSeries(); List<org.nema.dicom.wg23.Series> listOfSeries = arrayOfSeries.getSeries(); org.nema.dicom.wg23.Series series = new org.nema.dicom.wg23.Series(); String seriesInstanceUID = subElements.get(0).getCriteria().getDICOMCriteria().get(new Integer(2097166)) .toString(); //seriesInstanceUID series.setSeriesUID(seriesInstanceUID); ArrayOfObjectDescriptor arrayOfObjectDesc = new ArrayOfObjectDescriptor(); List<ObjectDescriptor> listObjectDescs = arrayOfObjectDesc.getObjectDescriptor(); //create list of objDescs and add them to each series while (files.hasNext()) { File file = files.next(); ObjectDescriptor objDesc = new ObjectDescriptor(); Uuid objDescUUID = new Uuid(); objDescUUID.setUuid(UUID.randomUUID().toString()); objDesc.setUuid(objDescUUID); //check mime type objDesc.setMimeType("application/dicom"); Uid uid = new Uid(); String classUID = ""; uid.setUid(classUID); objDesc.setClassUID(uid); String modCode = ""; Modality modality = new Modality(); modality.setModality(modCode); objDesc.setModality(modality); listObjectDescs.add(objDesc); ObjectLocator objLoc = new ObjectLocator(); objLoc.setUuid(objDescUUID); try { objLoc.setUri(file.toURI().toURL().toExternalForm()); //getURI from the iterator } catch (MalformedURLException e) { logger.error(e, e); } objLocators.add(objLoc); } series.setObjectDescriptors(arrayOfObjectDesc); listOfSeries.add(series); study.setSeries(arrayOfSeries); listOfStudies.add(study); patient.setStudies(arrayOfStudy); listPatients.add(patient); availableData.setPatients(arrayOfPatient); ArrayOfObjectDescriptor arrayOfObjectDescTopLevel = new ArrayOfObjectDescriptor(); availableData.setObjectDescriptors(arrayOfObjectDescTopLevel); } WG23DataModelFileSystemImpl dataModel = new WG23DataModelFileSystemImpl(); dataModel.setAvailableData(availableData); ObjectLocator[] objLocs = new ObjectLocator[objLocators.size()]; objLocators.toArray(objLocs); dataModel.setObjectLocators(objLocs); WG23DataModel wg23DataModel = dataModel; return wg23DataModel; }
From source file:net.bpelunit.framework.control.deploy.activevos9.ActiveVOS9Deployment.java
private void scanForBPELFiles() throws DeploymentException { @SuppressWarnings("unchecked") Iterator<File> pddFiles = FileUtils.iterateFiles(tempDirectory, new String[] { "pdd" }, true); while (pddFiles.hasNext()) { File pddFile = pddFiles.next(); try {/*w w w . j a v a 2s . c o m*/ Document pddXml = XMLUtil.parseXML(new FileInputStream(pddFile)); Element pddRoot = pddXml.getDocumentElement(); String locationInBPR = pddRoot.getAttribute("location"); File bpelFile = new File(tempDirectory, locationInBPR); allProcesses.add(new BPELInfo(bpelFile, pddFile, pddXml)); } catch (FileNotFoundException e) { throw new DeploymentException("File could not be read: " + e.getMessage(), e); } catch (SAXException e) { throw new DeploymentException("XML file could not be parsed: " + e.getMessage(), e); } catch (IOException e) { throw new DeploymentException("XML file could not be read: " + e.getMessage(), e); } catch (ParserConfigurationException e) { throw new DeploymentException("XML file could not be parsed: " + e.getMessage(), e); } catch (JAXBException e) { throw new DeploymentException("BPEL file could not be parsed: " + e.getMessage(), e); } } }
From source file:eu.earthobservatory.org.StrabonEndpoint.QueryBean.java
/** * Processes the request made from the HTML visual interface of Strabon Endpoint. * /*from w w w . j a v a 2 s . c o m*/ * @param request * @param response * @throws ServletException * @throws IOException */ private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher; // check whether Update submit button was fired String reqFuncionality = (request.getParameter("submit") == null) ? "" : request.getParameter("submit"); if (reqFuncionality.equals("Update")) { // get the dispatcher for forwarding the rendering of the response dispatcher = request.getRequestDispatcher("/Update"); dispatcher.forward(request, response); } else { String query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); String format = request.getParameter("format"); String handle = request.getParameter("handle"); String maxLimit = request.getParameter("maxLimit"); // get stSPARQLQueryResultFormat from given format name TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format); if (query == null || format == null || queryResultFormat == null) { dispatcher = request.getRequestDispatcher("query.jsp"); request.setAttribute(ERROR, PARAM_ERROR); dispatcher.forward(request, response); } else { query = strabonWrapper.addLimit(query, maxLimit); if ("download".equals(handle)) { // download as attachment ServletOutputStream out = response.getOutputStream(); response.setContentType(queryResultFormat.getDefaultMIMEType()); response.setHeader("Content-Disposition", "attachment; filename=results." + queryResultFormat.getDefaultFileExtension() + "; " + queryResultFormat.getCharset()); try { strabonWrapper.query(query, format, out); response.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.print(ResponseMessages.getXMLHeader()); out.print(ResponseMessages.getXMLException(e.getMessage())); out.print(ResponseMessages.getXMLFooter()); } out.flush(); } else if (("map".equals(handle) || "map_local".equals(handle) || "timemap".equals(handle)) && (queryResultFormat == stSPARQLQueryResultFormat.KML || queryResultFormat == stSPARQLQueryResultFormat.KMZ)) { // show map (only valid for KML/KMZ) // get dispatcher dispatcher = request.getRequestDispatcher("query.jsp"); // re-assign handle request.setAttribute("handle", handle); SecureRandom random = new SecureRandom(); String temp = new BigInteger(130, random).toString(32); // the temporary KML/KMZ file to create in the server String tempKMLFile = temp + "." + queryResultFormat.getDefaultFileExtension(); ; try { Date date = new Date(); // get the absolute path of the temporary directory if (!request.getParameter("handle").toString().contains("timemap")) { tempDirectory = appName + "-temp"; basePath = context.getRealPath("/") + "/../ROOT/" + tempDirectory + "/"; // fix the temporary directory for this web application FileUtils.forceMkdir(new File(basePath)); @SuppressWarnings("unchecked") Iterator<File> it = FileUtils.iterateFiles(new File(basePath), null, false); while (it.hasNext()) { File tbd = new File((it.next()).getAbsolutePath()); if (FileUtils.isFileOlder(new File(tbd.getAbsolutePath()), date.getTime())) { FileUtils.forceDelete(new File(tbd.getAbsolutePath())); } } } else { //timemap case tempDirectory = "js/timemap"; basePath = context.getRealPath("/") + tempDirectory + "/"; // fix the temporary directory for this web application } // fix the temporary directory for this web application // create temporary KML/KMZ file File file = new File(basePath + tempKMLFile); // if file does not exist, then create it if (!file.exists()) { file.createNewFile(); } try { // query and write the result in the temporary KML/KMZ file FileOutputStream fos = new FileOutputStream(basePath + tempKMLFile); strabonWrapper.query(query, format, fos); fos.close(); if (request.getParameter("handle").toString().contains("timemap")) { request.setAttribute("pathToKML", tempDirectory + "/" + tempKMLFile); } else { request.setAttribute("pathToKML", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/" + tempDirectory + "/" + tempKMLFile); } } catch (MalformedQueryException e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); request.setAttribute(ERROR, e.getMessage()); } catch (Exception e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); request.setAttribute(ERROR, e.getMessage()); } dispatcher.forward(request, response); } catch (IOException e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); } } else { // "plain" is assumed as the default dispatcher = request.getRequestDispatcher("query.jsp"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { strabonWrapper.query(query, format, bos); if (format.equals(Common.getHTMLFormat())) { request.setAttribute(RESPONSE, bos.toString()); } else if (format.equals(Format.PIECHART.toString()) || format.equals(Format.AREACHART.toString()) || format.equals(Format.COLUMNCHART.toString())) { request.setAttribute("format", "CHART"); request.setAttribute(RESPONSE, strabonWrapper.getgChartString()); } else { request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString())); } } catch (MalformedQueryException e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); request.setAttribute(ERROR, e.getMessage()); } catch (Exception e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); request.setAttribute(ERROR, e.getMessage()); } finally { dispatcher.forward(request, response); } } } } }
From source file:fr.inria.soctrace.tools.ocelotl.core.caches.DichotomyCache.java
/** * Load the existing cache files from the current cache directory */// w ww . j a va 2 s.c o m private void readCachedData() { File workDir = new File(cacheDirectory); // Clear the current cache files cachedDichotomy.clear(); if (workDir.exists()) { Iterator<File> anIT = FileUtils.iterateFiles(workDir, null, true); while (anIT.hasNext()) { File traceCache = anIT.next(); if (!traceCache.getName().endsWith(OcelotlConstants.DichotomyCacheSuffix)) continue; // Try parsing the file and get the cache parameters CacheParameters param = parseTraceCache(traceCache); // If parsing was successful if (param.getTraceID() != -1) { // Register the cache file cachedDichotomy.put(param, traceCache); logger.debug("[DICHOTOMY CACHE] Found " + param.getTraceName() + " in " + traceCache.toString() + ", " + param.getMicroModelType() + ", " + param.getDataAggOperator() + ", " + param.getStartTimestamp() + ", " + param.getEndTimestamp()); } } computeCacheSize(); } else { System.err.println( "[DICHOTOMY CACHE] The provided cache directory (" + cacheDirectory + ")does not exist"); } }