List of usage examples for org.springframework.core.io UrlResource getFile
@Override public File getFile() throws IOException
From source file:org.psikeds.common.config.FileSystemResource.java
public FileSystemResource(final org.springframework.core.io.UrlResource ur) throws IOException { this(ur.getFile()); }
From source file:com.enonic.cms.core.plugin.container.OsgiContainer.java
private void copyFrameworkJar(final File targetFile) throws Exception { URL location = FrameworkProperties.class.getProtectionDomain().getCodeSource().getLocation(); final String locationFile = location.getFile(); LOG.info("Location of framework.jar : " + locationFile); if (locationFile.endsWith(".jar!/")) // for IBM Websphere 8.5 Liberty Profile {/*from w w w .j a v a2 s. c o m*/ String absolutePath = locationFile.substring(0, locationFile.length() - 2); location = new URL(absolutePath); } else if (ResourceUtils.URL_PROTOCOL_VFS.equals(location.getProtocol())) // JBOSS 7.1.1 VFS { final URI uri = ResourceUtils.toURI(location); final UrlResource urlResource = new UrlResource(uri); final File file = urlResource.getFile(); String absolutePath = file.getAbsolutePath(); if (!absolutePath.endsWith(urlResource.getFilename())) { // removing /contents folder from path and adding unpacked jar to path. absolutePath = absolutePath.substring(0, absolutePath.length() - VFS_CONTENTS_FOLDER.length()) + urlResource.getFilename(); } final StringBuilder stringBuilder = new StringBuilder("file:/"); if (!SystemUtils.IS_OS_WINDOWS) // windows already has one slash in path like /c:/Program Files/.... { stringBuilder.append('/'); } stringBuilder.append(absolutePath); location = new URL(stringBuilder.toString()); } LOG.info("Copying " + location.toString() + " to " + targetFile.toString()); Files.copy(Resources.newInputStreamSupplier(location), targetFile); }
From source file:de.langmi.spring.batch.examples.complex.file.renamefile.simple.SimpleRenameFileTaskletStep.java
/** */ @Override//from www. j a v a 2 s.c o m public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // get used output file String outputFilePath = (String) chunkContext.getStepContext().getJobParameters().get("output.file"); UrlResource oldFile = new UrlResource(outputFilePath); // get desired output file name String desiredOutputFilePath = (String) chunkContext.getStepContext().getJobExecutionContext() .get("desired.output.file"); UrlResource newFile = new UrlResource(desiredOutputFilePath); // rename oldFile.getFile().renameTo(newFile.getFile()); return RepeatStatus.FINISHED; }
From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java
@SuppressWarnings("deprecation") private void loadBeanDefinitionsFromUrl(String url, GenericApplicationContext context) { BeanDefinitionReader reader = null;//from w ww .ja v a 2 s .c o m if (url.endsWith(".xml")) { reader = new XmlBeanDefinitionReader(context); } else if (url.endsWith(".properties")) { reader = new PropertiesBeanDefinitionReader(context); } if (reader != null) { try { UrlResource urlResource = new UrlResource(url); InputStream is = urlResource.getInputStream(); Document document = builder.parse(is); Element routerElement = this.getRouterElement(document); this.stripOffProcessors(routerElement); this.addGAImportComponents(document, routerElement); DOMImplementationRegistry registry = null; try { registry = DOMImplementationRegistry.newInstance(); } catch (ClassCastException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } catch (ClassNotFoundException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } catch (InstantiationException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } catch (IllegalAccessException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } String originalConfigFileAbsolutePath = urlResource.getFile().getAbsolutePath(); String componentName = entry.getSourceComponent(); String configComponentIdentifier = "{" + originalConfigFileAbsolutePath + "}" + componentName; File outputFile = null; if (componentConfigFileMap.containsKey(configComponentIdentifier)) { outputFile = componentConfigFileMap.get(configComponentIdentifier); } else { outputFile = File.createTempFile(componentName, ".xml", replayWorkDir); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); FileOutputStream bas = new FileOutputStream(outputFile.getAbsolutePath()); output.setByteStream(bas); writer.write(document, output); bas.flush(); bas.close(); componentConfigFileMap.put(configComponentIdentifier, outputFile); } // FIXME Use of deprecated method UrlResource newUrlResource = new UrlResource(outputFile.toURL().toString()); ((XmlBeanDefinitionReader) reader).registerBeanDefinitions(document, newUrlResource); } catch (BeansException e) { log.error("error", e); throw new RuntimeException("BeansException : " + e.getMessage(), e); } catch (MalformedURLException e) { log.error("error", e); throw new RuntimeException("MalformedUrlException : " + e.getMessage(), e); } catch (IOException e) { log.error("error", e); throw new RuntimeException("IOExceptionException : " + e.getMessage(), e); } catch (SAXException e) { log.error("error", e); throw new RuntimeException("SAXException : " + e.getMessage(), e); } } else { throw new RuntimeException("No BeanDefinitionReader associated with " + url); } }
From source file:org.openadaptor.util.SystemTestUtil.java
/** * Runs adaptor using a given Spring config file. * /*from www . j a va 2 s . c om*/ * @param caller calling object * @param resourceLocation path to the config file. * @param configFile adaptor's Spring config file * @return an instance of adaptor that was executed * @throws Exception */ public static SpringAdaptor runAdaptor(Object caller, String resourceLocation, String configFile) throws Exception { SpringAdaptor adaptor = new SpringAdaptor(); UrlResource urlResource = new UrlResource( "file:" + ResourceUtil.getResourcePath(caller, resourceLocation, configFile)); String configPath = urlResource.getFile().getAbsolutePath(); adaptor.addConfigUrl(configPath); adaptorRun(adaptor); return adaptor; }