List of usage examples for org.springframework.core.io ClassPathResource getFile
@Override public File getFile() throws IOException
From source file:de.ingrid.admin.Config.java
/** * Try to get the override configuration first from the classpath and * otherwise expect it inside the conf directory. The first option is mainly * for development, but should also apply for production since the * conf-directory also is in the Classpath. With this function the * development environment does not need any manual setup anymore, as long * as the test-resources is in the classpath. * // w w w . j a va 2s. c o m * @return the resource to the override configuration */ private Resource getOverrideConfigResource() { ClassPathResource override = new ClassPathResource("config.override.properties"); try { override.getFile(); return override; } catch (FileNotFoundException e) { // do nothing here! get file from conf directory (see return value) } catch (IOException e) { log.error("Error when getting config.override.properties", e); } return new FileSystemResource("conf/config.override.properties"); }
From source file:com.thoughtworks.go.config.CachedGoConfigIntegrationTest.java
private void checkInPartial(String partial, File externalConfigRepo) throws IOException { ClassPathResource resource = new ClassPathResource(partial); if (resource.getFile().isDirectory()) { FileUtils.copyDirectory(resource.getFile(), externalConfigRepo); } else {/* ww w . j a va2 s . c o m*/ FileUtils.copyFileToDirectory(resource.getFile(), externalConfigRepo); } gitAddDotAndCommit(externalConfigRepo); }
From source file:com.ephesoft.dcma.da.common.ExecuteUpdatePatch.java
private void updateProperty(String propertyFilePath, String propertyName, String updatedValue, String updateComment) {/*from ww w . ja va 2 s .c o m*/ LOG.info("Updating property:" + propertyName + " to value:" + updatedValue); try { ClassPathResource classPathResource = new ClassPathResource(propertyFilePath); File propertyFile = classPathResource.getFile(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put(propertyName, updatedValue); FileUtils.updateProperty(propertyFile, propertyMap, updateComment); } catch (IOException e) { LOG.error("An Exception occurred updating the property:" + propertyName + e.getMessage(), e); } }
From source file:com.thoughtworks.go.config.CachedGoConfigIntegrationTest.java
private Modification setupExternalConfigRepo(File configRepo, String configRepoTestResource) throws IOException { ClassPathResource resource = new ClassPathResource(configRepoTestResource); FileUtils.copyDirectory(resource.getFile(), configRepo); CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("init") .withArg(configRepo.getAbsolutePath()).runOrBomb(null); CommandLine.createCommandLine("git").withEncoding("utf-8").withArgs("config", "commit.gpgSign", "false") .withWorkingDir(configRepo.getAbsoluteFile()).runOrBomb(null); gitAddDotAndCommit(configRepo);/*from w w w. j a v a 2 s.c om*/ ConsoleResult consoleResult = CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("log") .withArg("-1").withArg("--pretty=format:%h").withWorkingDir(configRepo).runOrBomb(null); Modification modification = new Modification(); modification.setRevision(consoleResult.outputAsString()); return modification; }
From source file:com.ephesoft.dcma.da.common.ExecuteUpdatePatch.java
private String fetchPropertyFromPropertiesFile(String propertyName, String propertyFileName) { ClassPathResource classPathResource = new ClassPathResource(propertyFileName); FileInputStream fileInputStream = null; File propertyFile = null;//from ww w.j a v a2s . c om String property = null; try { propertyFile = classPathResource.getFile(); Properties properties = new Properties(); fileInputStream = new FileInputStream(propertyFile); properties.load(fileInputStream); property = properties.getProperty(propertyName); } catch (IOException e) { LOG.error("An Exception occurred while executing the patch." + e.getMessage(), e); } return property; }
From source file:org.nd4j.linalg.api.test.NDArrayTests.java
@Test public void testIrisStatsDouble() throws IOException { Nd4j.dtype = DataBuffer.DOUBLE; ClassPathResource res = new ClassPathResource("/iris.txt"); File file = res.getFile(); INDArray data = Nd4j.readTxt(file.getAbsolutePath(), "\t"); INDArray mean = Nd4j.create(// w w w.j a v a2s .com new double[] { 5.843333333333335, 3.0540000000000007, 3.7586666666666693, 1.1986666666666672 }); INDArray std = Nd4j.create( new double[] { 0.8280661279778629, 0.4335943113621737, 1.7644204199522617, 0.7631607417008414 }); INDArray testSum = Nd4j.create( new double[] { 876.4999990463257, 458.1000003814697, 563.7999982833862, 179.7999987155199 }); INDArray sum = data.sum(0); INDArray test = data.mean(0); INDArray testStd = data.std(0); assertEquals(sum, testSum); assertEquals(mean, test); assertEquals(std, testStd); }
From source file:org.nd4j.linalg.api.test.NDArrayTests.java
@Test public void testIrisStats() throws IOException { Nd4j.dtype = DataBuffer.FLOAT; ClassPathResource res = new ClassPathResource("/iris.txt"); File file = res.getFile(); INDArray data = Nd4j.readTxt(file.getAbsolutePath(), "\t"); INDArray sum = data.sum(0);/* w w w . j a v a2 s. co m*/ INDArray mean = Nd4j.create( new double[] { 5.843333333333335, 3.0540000000000007, 3.7586666666666693, 1.1986666666666672 }); INDArray std = Nd4j.create( new double[] { 0.8280661279778629, 0.4335943113621737, 1.7644204199522617, 0.7631607417008414 }); INDArray testSum = Nd4j.create( new double[] { 876.4999990463257, 458.1000003814697, 563.7999982833862, 179.7999987155199 }); assertEquals(testSum, sum); INDArray testMean = data.mean(0); assertEquals(mean, testMean); INDArray testStd = data.std(0); assertEquals(std, testStd); }
From source file:com.ephesoft.dcma.da.common.ExecuteUpdatePatch.java
/** * This method updates the Batch classes. *///w ww . j a v a2s.c o m public void updateBatchClasses() { batchClassNameVsBatchClassMap = readBatchClassSerializeFile(); if (batchClassNameVsBatchClassMap == null || batchClassNameVsBatchClassMap.isEmpty()) { LOG.info("No data recovered from serialized file. Returning.."); return; } Map<String, BatchClass> newBatchClassNameVsBatchClassMap = new HashMap<String, BatchClass>(); newBatchClassNameVsBatchClassMap.putAll(batchClassNameVsBatchClassMap); for (String batchClassName : newBatchClassNameVsBatchClassMap.keySet()) { List<BatchClass> batchClasses = batchClassService.getAllBatchClassesExcludeDeleted(); for (BatchClass batchClass : batchClasses) { if (batchClassName.equalsIgnoreCase(batchClass.getName())) { batchClassNameVsBatchClassMap.remove(batchClassName); break; } } } if (batchClassNameVsBatchClassMap.size() > 0) { updatePluginConfigsForBatchClass(); updateModuleConfigsForBatchClass(); for (String batchClassName : batchClassNameVsBatchClassMap.keySet()) { BatchClass newBatchClassToBeAdded = batchClassNameVsBatchClassMap.get(batchClassName); ClassPathResource classPathResource = new ClassPathResource( DataAccessConstant.DCMA_BATCH_PROPERTIES); StringBuffer uncFolderLocation = new StringBuffer(); FileInputStream fileInputStream = null; File propertyFile = null; try { propertyFile = classPathResource.getFile(); Properties properties = new Properties(); fileInputStream = new FileInputStream(propertyFile); properties.load(fileInputStream); uncFolderLocation.append(properties.getProperty(DataAccessConstant.BASE_FOLDER_LOCATION)); } catch (IOException e) { LOG.error("Unable to retriving property file :" + e.getMessage(), e); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ioe) { if (propertyFile != null) { LOG.error(DataAccessConstant.PROBLEM_CLOSING_STREAM_FOR_FILE + propertyFile.getName()); } } } if (newBatchClassToBeAdded != null) { createUNCFolder(uncFolderLocation, newBatchClassToBeAdded); newBatchClassToBeAdded.setVersion(INITIAL_VERSION); newBatchClassToBeAdded.setLastModifiedBy(null); // Assign super admin roles to newly added batch class. assignSuperAdminRoleToBatchClass(newBatchClassToBeAdded, getAllSuperAdminRoles()); batchClassService.createBatchClassWithoutWatch(newBatchClassToBeAdded); } LOG.info(DataAccessConstant.UPDATING_BATCH_CLASSES); } } }
From source file:org.alfresco.filesys.repo.CIFSContentComparatorTest.java
public void testProjectFiles() throws Exception { CIFSContentComparator contentComparator = new CIFSContentComparator(); contentComparator.init();//ww w. j a va 2s . c o m ClassPathResource file0Resource = new ClassPathResource("filesys/ContentComparatorTest0.mpp"); assertNotNull("unable to find test resource filesys/ContentComparatorTest0.mpp", file0Resource); ClassPathResource file1Resource = new ClassPathResource("filesys/ContentComparatorTest1.mpp"); assertNotNull("unable to find test resource filesys/ContentComparatorTest1.mpp", file1Resource); ClassPathResource file2Resource = new ClassPathResource("filesys/ContentComparatorTest2.mpp"); assertNotNull("unable to find test resource filesys/ContentComparatorTest2.mpp", file1Resource); File textFile = TempFileProvider.createTempFile("testCIFSContentComparator", "txt"); FileOutputStream os1 = new FileOutputStream(textFile); os1.write("The quick brown fox".getBytes("UTF-8")); os1.close(); /** * Compare same project file with itself */ { File file1 = file1Resource.getFile(); ContentReader reader = new FileContentReader(file1); reader.setMimetype("application/vnd.ms-project"); reader.setEncoding("UTF-8"); boolean result = contentComparator.isContentEqual(reader, file1); assertTrue("compare same project file, should be equal", result); } /** * Compare project file with plain text file */ { File file1 = file1Resource.getFile(); ContentReader reader = new FileContentReader(file1); reader.setMimetype("application/vnd.ms-project"); reader.setEncoding("UTF-8"); boolean result = contentComparator.isContentEqual(reader, textFile); assertTrue("compare project file with text file, should not be equal", !result); } /** * Compare different project files */ { File file1 = file1Resource.getFile(); File file2 = file2Resource.getFile(); ContentReader reader = new FileContentReader(file1); reader.setMimetype("application/vnd.ms-project"); reader.setEncoding("UTF-8"); boolean result = contentComparator.isContentEqual(reader, file2); assertTrue("compare different project file, should not be equal", !result); } }