List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:com.epam.catgenome.manager.GffManagerTest.java
private boolean testCollapsed(String path) throws IOException, FeatureIndexException, InterruptedException, NoSuchAlgorithmException, GeneReadingException { Resource resource = context.getResource(path); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(request); Assert.assertNotNull(geneFile);//from w w w. j a va 2s . c o m Assert.assertNotNull(geneFile.getId()); Track<Gene> track = new Track<>(); track.setId(geneFile.getId()); track.setStartIndex(1); track.setEndIndex(TEST_END_INDEX); track.setChromosome(testChromosome); track.setScaleFactor(FULL_QUERY_SCALE_FACTOR); Track<Gene> featureList = gffManager.loadGenes(track, false); Assert.assertTrue(featureList.getBlocks().stream().anyMatch(g -> g.getItems().size() > 1)); track = new Track<>(); track.setId(geneFile.getId()); track.setStartIndex(1); track.setEndIndex(TEST_END_INDEX); track.setChromosome(testChromosome); track.setScaleFactor(FULL_QUERY_SCALE_FACTOR); double time1 = Utils.getSystemTimeMilliseconds(); Track<Gene> featureListCollapsed = gffManager.loadGenes(track, true); double time2 = Utils.getSystemTimeMilliseconds(); logger.info("genes loading : {} ms", time2 - time1); Assert.assertNotNull(featureListCollapsed); Assert.assertFalse(featureListCollapsed.getBlocks().isEmpty()); Assert.assertTrue(featureListCollapsed.getBlocks().stream().filter(GeneUtils::isGene) .allMatch(g -> g.getItems().size() == 1)); Assert.assertFalse(featureListCollapsed.getBlocks().stream().filter(GeneUtils::isGene) .allMatch(g -> g.getItems().get(0).getItems().isEmpty())); return true; }
From source file:grails.core.DefaultGrailsApplication.java
/** * Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names * *//*w ww . ja va2 s .co m*/ public DefaultGrailsApplication(Resource[] resources) { this(); for (Resource resource : resources) { Class<?> aClass; try { aClass = classLoader .loadClass(GrailsResourceUtils.getClassName(resource.getFile().getAbsolutePath())); } catch (ClassNotFoundException e) { throw new GrailsConfigurationException( "Class not found loading Grails application: " + e.getMessage(), e); } catch (IOException e) { throw new GrailsConfigurationException( "Class not found loading Grails application: " + e.getMessage(), e); } loadedClasses.add(aClass); } }
From source file:com.epam.catgenome.manager.GffManagerTest.java
@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testLoadExonsInTrack() throws IOException, FeatureIndexException, InterruptedException, NoSuchAlgorithmException { Resource resource = context.getResource(GENES_SORTED_GTF_PATH); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(request); Assert.assertNotNull(geneFile);/* w w w . j a v a2 s. c om*/ Assert.assertNotNull(geneFile.getId()); List<Block> exons = gffManager.loadExonsInViewPort(geneFile.getId(), testChromosome.getId(), TEST_CENTER_POSITION, TEST_VIEW_PORT_SIZE, TEST_INTRON_LENGTH); List<Block> exons2 = gffManager.loadExonsInTrack(geneFile.getId(), testChromosome.getId(), exons.get(0).getStartIndex(), exons.get(exons.size() - 1).getEndIndex(), TEST_INTRON_LENGTH); Assert.assertFalse(exons2.isEmpty()); Assert.assertEquals(exons.size(), exons2.size()); for (int i = 0; i < exons2.size(); i++) { Assert.assertEquals(exons.get(i).getStartIndex(), exons2.get(i).getStartIndex()); Assert.assertEquals(exons.get(i).getEndIndex(), exons2.get(i).getEndIndex()); } testOverlapping(exons2); }
From source file:com.helpinput.spring.SourceScaner.java
private void initBeanInfosAndFileReaders() { for (Map<String, BeanInfo> beanInfosInPath : scanedBeanInfos.values()) { for (BeanInfo beanInfo : beanInfosInPath.values()) { beanInfo.scaned = false;/*from www .j av a2s .c o m*/ beanInfo.needParse = true; beanInfo.isNew = false; } } if (!Utils.hasLength(this.dirs)) return; String rootPath = new File(Thread.currentThread().getContextClassLoader().getResource("").toString()) .getParentFile().getParent().substring(5); rootPath = rootPath.replace('\\', '/'); for (String path : dirs) { path = path.replace('\\', '/'); if (path.startsWith("/")) path = rootPath + path; path = "file:" + path; Map<String, BeanInfo> beanInfosInPath = scanedBeanInfos.get(path); if (beanInfosInPath == null) { beanInfosInPath = new ConcurrentHashMap<>(); scanedBeanInfos.put(path, beanInfosInPath); } Resource[] resources; try { resources = resourcePatternResolver.getResources(path); } catch (Exception e) { //?????? if (hasLength(beanInfosInPath)) { for (BeanInfo beanInfo : beanInfosInPath.values()) { parserBeanInfoError(beanInfo); } } logger.info("read \"" + path + "\" error?", e); continue; } for (Resource resource : resources) { String fileName = null; BeanInfo beanInfo = null; String relativePath = null; try { File resourceFile = resource.getFile(); fileName = resourceFile.toURI().getPath(); relativePath = PathUtil.getRelativePath(rootPath, fileName); long newModified = resourceFile.lastModified(); beanInfo = beanInfosInPath.get(relativePath); if (beanInfo != null) { beanInfo.needParse = (newModified != beanInfo.lastModified); beanInfo.isUpdate = true; } else { beanInfo = new BeanInfo(fileName, relativePath, newModified); beanInfosInPath.put(relativePath, beanInfo); beanInfo.needParse = true; } beanInfo.scaned = true; beanInfo.lastModified = newModified; if (beanInfo.needParse) { BufferedReader reader = null; try { reader = FileUtils.getFileBufferedReader(fileName); CompilationUnit cu = JavaParser.parse(reader, true); beanInfo.cu = cu; beanInfo.packageName = ParserUtils.getPackageName(cu); ClassOrInterfaceDeclaration real = ParserUtils.getClassName(cu); if (real != null) { beanInfo.isInterface = real.isInterface(); beanInfo.scanName = real.getName(); beanInfo.needParse = beanInfo.needParse && (!beanInfo.isInterface); } beanInfo.importName = beanInfo.packageName + "." + beanInfo.scanName; beanInfo.referencWrapPt = Pattern.compile("^.*\\W+" + beanInfo.scanName + "\\W+.*$"); } finally { closeWithWarning(reader); } } } catch (IOException | ParseException e) { e.printStackTrace(); if (beanInfo != null) { parserBeanInfoError(beanInfo); continue; } } } } }
From source file:de.ingrid.admin.Config.java
public void initialize() throws IOException { Resource confOverride = getOverrideConfigResource(); File configFile = confOverride.getFile(); // create override file if it does not exist if (!configFile.exists()) { // if override file does not exist then try to look for previous // communication and plug description to get the configuration try {//from ww w . ja v a 2s . com log.warn("No config.override.properties found in conf-directory. Trying to recover " + "configuration from previously generated files."); configFile.getParentFile().mkdir(); configFile.createNewFile(); // read communicaton and write properties this.ibusses = readFromCommunicationXml(); if (this.ibusses != null) writeCommunicationToProperties(); // read plug description and write properties PlugdescriptionCommandObject pd = new PlugdescriptionCommandObject( new File("conf/plugdescription.xml")); writePlugdescriptionToProperties(pd); } catch (IOException e1) { log.error("Error creating override configuration", e1); e1.printStackTrace(); } } // set system property for use in JSP file! if (indexing) { System.setProperty(IKeys.INDEXING, "true"); } // plug description String plugDescription = System.getProperty(IKeys.PLUG_DESCRIPTION); if (plugDescription == null) { System.setProperty(IKeys.PLUG_DESCRIPTION, plugdescriptionLocation); } // ignore the following properties from the plug description, which do not need to be written // to the configuration file IGNORE_LIST.add("QUERY_EXTENSION_CONTAINER"); IGNORE_LIST.add("connection"); // writeCommunication(this.communicationLocation, this.ibusses); }
From source file:com.epam.catgenome.manager.ProjectManagerTest.java
@Test @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) public void testAllFileTypesLoading() throws IOException, InterruptedException, FeatureIndexException, NoSuchAlgorithmException, VcfReadingException { Project project = new Project(); project.setName(TEST_PROJECT_NAME);/*from w ww . j av a2s. co m*/ project.setItems(Collections .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); projectManager.saveProject(project); Project loadedProject = projectManager.loadProject(project.getId()); Assert.assertNotNull(loadedProject); Assert.assertEquals(1, loadedProject.getItems().size()); // Add Vcf addVcfFileToProject(project.getId(), TEST_VCF_FILE_NAME1, TEST_VCF_FILE_PATH); // Add genes Resource resource = context.getResource("classpath:templates/genes_sorted.gtf"); FeatureIndexedFileRegistrationRequest geneRequest = new FeatureIndexedFileRegistrationRequest(); geneRequest.setReferenceId(referenceId); geneRequest.setName("genes"); geneRequest.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(geneRequest); projectManager.addProjectItem(project.getId(), geneFile.getBioDataItemId()); // Add BED file resource = context.getResource("classpath:templates/genes_sorted.bed"); IndexedFileRegistrationRequest request = new IndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setName("bed"); request.setPath(resource.getFile().getAbsolutePath()); BedFile bedFile = bedManager.registerBed(request); projectManager.addProjectItem(project.getId(), bedFile.getBioDataItemId()); // Add SEG file resource = context.getResource("classpath:templates/test_seg.seg"); request = new IndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setName("seg"); request.setPath(resource.getFile().getAbsolutePath()); SegFile segFile = segManager.registerSegFile(request); projectManager.addProjectItem(project.getId(), segFile.getBioDataItemId()); // Add MAF file resource = context.getResource("classpath:templates/maf/" + "TCGA.ACC.mutect.abbe72a5-cb39-48e4-8df5-5fd2349f2bb2.somatic.sorted.maf.gz"); request = new IndexedFileRegistrationRequest(); request.setPath(resource.getFile().getAbsolutePath()); request.setReferenceId(referenceId); MafFile mafFile = mafManager.registerMafFile(request); Assert.assertNotNull(mafFile); projectManager.addProjectItem(project.getId(), mafFile.getBioDataItemId()); loadedProject = projectManager.loadProject(project.getId()); // Test VCF item ProjectItem vcfItem = loadedProject.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF).findFirst().get(); Assert.assertNotNull(vcfItem); Assert.assertNotNull(vcfItem.getBioDataItem()); VcfFile loadedVcf = (VcfFile) vcfItem.getBioDataItem(); Assert.assertNotNull(loadedVcf.getId()); Assert.assertNotNull(loadedVcf.getIndex()); Assert.assertFalse(loadedVcf.getIndex().getPath().isEmpty()); Assert.assertFalse(loadedVcf.getPath().isEmpty()); Assert.assertFalse(loadedVcf.getSamples().isEmpty()); // Test BED item ProjectItem bedItem = loadedProject.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.BED).findFirst().get(); Assert.assertNotNull(bedItem); Assert.assertNotNull(bedItem.getBioDataItem()); BedFile loadedBed = (BedFile) bedItem.getBioDataItem(); Assert.assertNotNull(loadedBed.getId()); Assert.assertNotNull(loadedBed.getIndex()); Assert.assertFalse(loadedBed.getIndex().getPath().isEmpty()); Assert.assertFalse(loadedBed.getPath().isEmpty()); // Test SEG Files ProjectItem segItem = loadedProject.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.SEG).findFirst().get(); Assert.assertNotNull(segItem); Assert.assertNotNull(segItem.getBioDataItem()); SegFile loadedSeg = (SegFile) segItem.getBioDataItem(); Assert.assertNotNull(loadedSeg.getId()); Assert.assertNotNull(loadedSeg.getIndex()); Assert.assertFalse(loadedSeg.getPath().isEmpty()); Assert.assertFalse(loadedSeg.getSamples().isEmpty()); // Test MAF Files ProjectItem mafItem = loadedProject.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.MAF).findFirst().get(); Assert.assertNotNull(mafItem); Assert.assertNotNull(mafItem.getBioDataItem()); SegFile loadedMaf = (SegFile) segItem.getBioDataItem(); Assert.assertNotNull(loadedMaf.getId()); Assert.assertNotNull(loadedMaf.getIndex()); Assert.assertFalse(loadedMaf.getPath().isEmpty()); Assert.assertFalse(loadedMaf.getSamples().isEmpty()); // Test load my projects List<Project> myProjects = projectManager.loadTopLevelProjectsForCurrentUser(); Assert.assertFalse(myProjects.isEmpty()); }
From source file:com.epam.catgenome.manager.GffManagerTest.java
@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testLoadExonsInViewPort() throws InterruptedException, NoSuchAlgorithmException, FeatureIndexException, IOException { Resource resource = context.getResource(GENES_SORTED_GTF_PATH); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(request); Assert.assertNotNull(geneFile);/* w ww .j a v a 2 s.c o m*/ Assert.assertNotNull(geneFile.getId()); double time1 = Utils.getSystemTimeMilliseconds(); List<Block> exons = gffManager.loadExonsInViewPort(geneFile.getId(), testChromosome.getId(), TEST_CENTER_POSITION, TEST_VIEW_PORT_SIZE, TEST_INTRON_LENGTH); double time2 = Utils.getSystemTimeMilliseconds(); Assert.assertFalse(exons.isEmpty()); logger.info("Loading exons took {} ms", time2 - time1); List<Block> exonsBelow = exons.stream().filter(e -> e.getEndIndex() < TEST_CENTER_POSITION) .collect(Collectors.toList()); List<Block> exonsAbove = exons.stream().filter(e -> e.getStartIndex() > TEST_CENTER_POSITION) .collect(Collectors.toList()); Assert.assertFalse(exonsBelow.isEmpty()); Assert.assertFalse(exonsAbove.isEmpty()); testOverlapping(exons); final Map<String, Pair<Integer, Integer>> metaMap = fileManager.loadIndexMetadata(geneFile); Pair<Integer, Integer> bounds = metaMap.get(testChromosome.getName()); if (bounds == null) { bounds = metaMap.get(Utils.changeChromosomeName(testChromosome.getName())); } testFillRange(exonsBelow, TEST_VIEW_PORT_SIZE / 2, TEST_CENTER_POSITION, false, bounds.getLeft()); testFillRange(exonsAbove, TEST_VIEW_PORT_SIZE / 2, TEST_CENTER_POSITION, true, bounds.getRight()); }
From source file:de.ingrid.admin.Config.java
public void writeCommunicationToProperties() { Resource override = getOverrideConfigResource(); try (InputStream is = new FileInputStream(override.getFile().getAbsolutePath())) { Properties props = new Properties() { private static final long serialVersionUID = 6956076060462348684L; @Override// ww w . j a v a2 s.c o m public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; props.load(is); // --------------------------- props.setProperty("communication.clientName", communicationProxyUrl); String communications = ""; for (int i = 0; i < ibusses.size(); i++) { CommunicationCommandObject ibus = ibusses.get(i); communications += ibus.getBusProxyServiceUrl() + "," + ibus.getIp() + "," + ibus.getPort(); if (i != (ibusses.size() - 1)) communications += "##"; } props.setProperty("communications.ibus", communications); // --------------------------- try (OutputStream os = new FileOutputStream(override.getFile().getAbsolutePath())) { props.store(os, "Override configuration written by the application"); } } catch (Exception e) { log.error("Error writing properties: ", e); } }
From source file:grails.core.DefaultGrailsApplication.java
/** * Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names * *//* ww w . ja va2s .c om*/ public DefaultGrailsApplication(org.grails.io.support.Resource[] resources) { this(); for (org.grails.io.support.Resource resource : resources) { Class<?> aClass; try { aClass = classLoader .loadClass(GrailsResourceUtils.getClassName(resource.getFile().getAbsolutePath())); } catch (ClassNotFoundException e) { throw new GrailsConfigurationException( "Class not found loading Grails application: " + e.getMessage(), e); } catch (IOException e) { throw new GrailsConfigurationException( "Class not found loading Grails application: " + e.getMessage(), e); } loadedClasses.add(aClass); } }
From source file:it.infn.mw.iam.config.saml.SamlConfig.java
private List<MetadataProvider> metadataProviders() throws MetadataProviderException, IOException, ResourceException { List<MetadataProvider> providers = new ArrayList<>(); for (IamSamlIdpMetadataProperties p : samlProperties.getIdpMetadata()) { String trimmedMedataUrl = p.getMetadataUrl().trim(); if (trimmedMedataUrl.startsWith("classpath:")) { LOG.info("Adding classpath based metadata provider for URL: {}", trimmedMedataUrl); ClasspathResource cpMetadataResources = new ClasspathResource( trimmedMedataUrl.replaceFirst("classpath:", "")); ResourceBackedMetadataProvider metadataProvider = new ResourceBackedMetadataProvider( metadataFetchTimer, cpMetadataResources); metadataProvider.setParserPool(basicParserPool); providers.add(metadataDelegate(metadataProvider, p)); } else if (trimmedMedataUrl.startsWith("file:")) { LOG.info("Adding File based metadata provider for URL: {}", trimmedMedataUrl); Resource metadataResource = resourceLoader.getResource(trimmedMedataUrl); FilesystemMetadataProvider metadataProvider = new FilesystemMetadataProvider( metadataResource.getFile()); metadataProvider.setParserPool(basicParserPool); providers.add(metadataDelegate(metadataProvider, p)); } else if (trimmedMedataUrl.startsWith("http")) { LOG.info("Adding HTTP metadata provider for URL: {}", trimmedMedataUrl); File metadataBackupFile = Files.createTempFile("metadata", "xml").toFile(); metadataBackupFile.deleteOnExit(); FileBackedHTTPMetadataProvider metadataProvider = new FileBackedHTTPMetadataProvider( metadataFetchTimer, httpClient(), trimmedMedataUrl, metadataBackupFile.getAbsolutePath()); metadataProvider.setParserPool(basicParserPool); providers.add(metadataDelegate(metadataProvider, p)); } else {//from ww w .j a v a 2 s . co m LOG.error("Skipping invalid saml.idp-metatadata value: {}", trimmedMedataUrl); } } if (providers.isEmpty()) { String message = "Empty SAML metadata providers after initialization"; LOG.error(message); throw new IllegalStateException(message); } return providers; }