List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:com.careerly.common.support.ReloadablePropertySourcesPlaceholderConfigurer.java
@Override public void run() { try {//from w w w .j a va 2s . c o m boolean changed = false; for (Resource resource : lastModifiedResources.keySet()) { long lastModified = lastModifiedResources.get(resource); long modified = resource.lastModified(); if (modified > lastModified) { String modifiedTime = new DateTime(modified).toString("yyyy-MM-dd HH:mm:ss"); logger.info("properties changed, file: {}, modified: {}", resource.getFile().getPath(), modifiedTime); changed = true; lastModifiedResources.put(resource, modified); } } // ????? if (changed) { reload(); } } catch (IOException e) { logger.error("properties reload failure", e); } }
From source file:org.kemri.wellcome.controller.Dhis2ServerController.java
@RequestMapping(value = Views.DB_CONFIGURE, method = RequestMethod.POST) public @ResponseBody Map<String, ? extends Object> configServer(HttpServletRequest request, @RequestBody DatabaseProperties dbProperties) throws Exception { Set<ConstraintViolation<DatabaseProperties>> failures = validator.validate(dbProperties); if (!failures.isEmpty()) { return Collections.singletonMap("u", validationDBMessages(failures).toString()); } else {/*w w w. ja v a 2 s .co m*/ try { Properties properties = new Properties(); properties.setProperty("jdbc.url", "jdbc:mysql://" + dbProperties.getDatabaseUrl() + ":3306/" + dbProperties.getDatabaseName()); properties.setProperty("jdbc.username", dbProperties.getUsername()); properties.setProperty("jdbc.password", dbProperties.getPassword()); properties.setProperty("hibernate.hbm2ddl.auto", "update"); properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect"); properties.setProperty("hibernate.query.substitutions", "true 'T', false 'F'"); properties.setProperty("hibernate.show_sql", "false"); properties.setProperty("hibernate.c3p0.minPoolSize", "50"); properties.setProperty("hibernate.c3p0.maxPoolSize", "1000"); properties.setProperty("hibernate.c3p0.timeout", "300"); properties.setProperty("hibernate.c3p0.max_statement", "700"); properties.setProperty("hibernate.c3p0.testConnectionOnCheckout", "false"); properties.setProperty("jdbc.driverClassName", "com.mysql.jdbc.Driver"); //save properties to project root folder ServletContext servletContext = request.getSession().getServletContext(); Resource resource = new ServletContextResource(servletContext, databaseProperties); properties.store(new FileOutputStream(resource.getFile()), null); } catch (IOException e) { log.error("\n " + e.getMessage() + "\n"); return Collections.singletonMap("u", e.getMessage()); } return Collections.singletonMap("u", "Saved"); } }
From source file:it.publisys.ims.discovery.job.EntityTasks.java
private EntityDescriptorType[] loadAndCacheEntities(EntitiesDescriptorDocument entitiesDescriptorDocument) { Resource resourceCache = new ClassPathResource(METADATA_DIR + "/" + PROTECTEDAPP_GUARD_CACHED_XML); EntityDescriptorType[] entityDescriptors = entitiesDescriptorDocument.getEntitiesDescriptor() .getEntityDescriptorArray(); // Cache the metadata locally try {//from w ww . j ava 2 s. c o m Utils.writeSAML2MetadataToDisk(entitiesDescriptorDocument, resourceCache.getFile().getAbsolutePath()); } catch (Exception ex) { log.error(String.format("Errore durante la scrittura del file di cache '%s' su disco", PROTECTEDAPP_GUARD_CACHED_XML), ex); } return entityDescriptors; }
From source file:com.netflix.genie.web.tasks.job.JobMonitoringCoordinator.java
/** * Constructor./*from w w w .ja v a 2 s .com*/ * * @param hostName The name of the host this Genie process is running on * @param jobSearchService The search service to use to find jobs * @param publisher The application event publisher to use to publish synchronous events * @param eventMulticaster The event eventMulticaster to use to publish asynchronous events * @param scheduler The task scheduler to use to register scheduling of job checkers * @param executor The executor to use to launch processes * @param registry The metrics registry * @param jobsDir The directory where job output is stored * @param jobsProperties The properties pertaining to jobs * @param jobSubmitterService implementation of the job submitter service * @throws IOException on error with the filesystem */ @Autowired public JobMonitoringCoordinator(final String hostName, final JobSearchService jobSearchService, final ApplicationEventPublisher publisher, final ApplicationEventMulticaster eventMulticaster, final TaskScheduler scheduler, final Executor executor, final Registry registry, final Resource jobsDir, final JobsProperties jobsProperties, final JobSubmitterService jobSubmitterService) throws IOException { super(jobSubmitterService, scheduler, publisher, registry); this.hostName = hostName; this.jobSearchService = jobSearchService; this.eventMulticaster = eventMulticaster; this.executor = executor; this.jobsDir = jobsDir.getFile(); this.jobsProperties = jobsProperties; // Automatically track the number of jobs running on this node this.unableToReAttach = registry.counter("genie.jobs.unableToReAttach.rate"); }
From source file:podd.util.WebappInitializationUtil.java
private User createRepoAdminUser(Resource resource) { try {/*from w w w. j a va2 s .c o m*/ File propertyFile = resource.getFile(); final FileReader fileReader = new FileReader(propertyFile); Properties properties = new Properties(); properties.load(fileReader); // try to load the user and if it doesn't exist create a new one String username = properties.get(USERNAME_KEY).toString(); User admin = userDao.loadByUserName(username); if (null == admin) { admin = entityFactory.createUser(null); } // add properties to the user for (Object key : properties.keySet()) { final String value = properties.get(key).toString(); String methodName = getSetterMethodName((String) key); final Method method = User.class.getDeclaredMethod(methodName, String.class); method.invoke(admin, value); } admin.setStatus(ACTIVE); admin.setRepositoryRole(rrDao.getRepositoryRole(REPOSITORY_ADMINISTRATOR.getName())); LOGGER.info("Creating repository administrator user: " + admin.getUserName()); userDao.saveOrUpdate(admin); return admin; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:podd.util.WebappInitialisationUtil.java
private User createRepoAdminUser(Resource resource) { try {//from w w w . j av a 2s . c o m File propertyFile = resource.getFile(); final FileReader fileReader = new FileReader(propertyFile); Properties properties = new Properties(); properties.load(fileReader); // try to load the user and if it doesn't exist create a new one String username = properties.get(USERNAME_KEY).toString(); User admin = userDao.loadByUserName(username); if (null == admin) { admin = entityFactory.createUser(null); } // add properties to the user for (Object key : properties.keySet()) { final String value = properties.get(key).toString(); String methodName = getSetterMethodName((String) key); final Method method = User.class.getDeclaredMethod(methodName, String.class); method.invoke(admin, value); } admin.setStatus(ACTIVE); admin.setRepositoryRole(rrDao.getRepositoryRole(RepositoryRole.REPOSITORY_ADMINISTRATOR.getName())); logger.info("Creating repository administrator user: " + admin.getUserName()); userDao.saveOrUpdate(admin); return admin; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java
@Override public Resource copyRecursive(Resource root, Resource target, String includedPattern, String excludedPattern) { try {// ww w . j av a2 s.c o m IOUtils.copy(root.getFile(), target.getFile(), includedPattern, excludedPattern); } catch (IOException ex) { throw new WMRuntimeException(ex); } return target; }
From source file:org.jruby.rack.mock.MockServletContext.java
public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try {//from ww w . ja va 2s .co m return resource.getFile().getAbsolutePath(); } catch (IOException ex) { logger.log("WARN: Couldn't determine real path of resource " + resource, ex); return null; } }
From source file:com.wavemaker.tools.javaservice.JavaServiceDefinition.java
/** * Normal constructor. Attempts to use reflection (and a custom, very isolated classloader) to read information * about the class.//w ww . j a v a 2 s . c o m * * @throws IOException */ public JavaServiceDefinition(String serviceClassName, String serviceId, Resource serviceCompiledDir, Resource serviceLibDir, List<String> excludeTypeNames) throws ClassNotFoundException, LinkageError, IOException { this(serviceClassName, serviceId, serviceCompiledDir == null ? null : Arrays.asList(new File[] { serviceCompiledDir.getFile() }), serviceLibDir == null ? null : Arrays.asList(new File[] { serviceLibDir.getFile() }), excludeTypeNames); }
From source file:com.google.code.maven.plugin.http.client.transformer.JiraRssLinkedIssuesEnricher.java
@Override protected Resource doTransform(Resource input) throws Exception { Assert.notNull(input, "source can not be null"); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(input.getFile()), charset)); if (target.getFile().getParentFile() != null && !target.getFile().getParentFile().exists()) { Assert.isTrue(target.getFile().getParentFile().mkdirs(), "failed to make directory tree for [" + target.getFile().getParentFile() + "]"); }//w w w. j ava2s .co m String line; StringBuilder item = new StringBuilder(); BufferedWriter writer = new BufferedWriter(new FileWriter(target.getFile())); // read rss and find jira links while ((line = reader.readLine()) != null) { if (line.contains(CHANNEL_END_TAG)) { break; } if (line.contains(ITEM_END_TAG)) { item.append(line.substring(0, line.indexOf(ITEM_END_TAG))); linkedIssues.addAll(inspectItem(item.toString())); } if (line.contains(ITEM_START_TAG)) { item = new StringBuilder(); item.append(line.substring(line.indexOf(ITEM_START_TAG))); } else { item.append(line).append("\n"); } writer.write(line); writer.newLine(); writer.flush(); } enrich(writer, linkedIssues, depth - 1); while (remaining.get() > 0) { Thread.sleep(100); } // write end of rss do { writer.write(line); } while ((line = reader.readLine()) != null); reader.close(); writer.close(); if (deleteSource) { Assert.isTrue(input.getFile().delete(), "failed to delete source"); } return target; }