Example usage for org.springframework.core.io FileSystemResource FileSystemResource

List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource

Introduction

In this page you can find the example usage for org.springframework.core.io FileSystemResource FileSystemResource.

Prototype

public FileSystemResource(Path filePath) 

Source Link

Document

Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File .

Usage

From source file:com.google.api.ads.adwords.jaxws.extensions.processors.onmemory.ReportProcessorOnMemoryTest.java

@Before
public void setUp() throws InterruptedException, IOException, OAuthException {
    Resource resource = new FileSystemResource("src/test/resources/aw-report-sample.properties");
    DynamicPropertyPlaceholderConfigurer.setDynamicResource(resource);
    properties = PropertiesLoaderUtils.loadProperties(resource);

    reportProcessorOnMemory = new ReportProcessorOnMemory(10, 2);

    MockitoAnnotations.initMocks(this);

    doAnswer(new Answer<Void>() {
        @Override// w  ww.java  2  s .  c om
        public Void answer(InvocationOnMock invocation) throws Throwable {
            return null;
        }
    }).when(reportProcessorOnMemory);

}

From source file:org.jasig.i18n.translate.AutoTranslateMojo.java

public void execute() throws MojoExecutionException {

    Map<String, String> mainMap = null;

    try {//  w ww  .j av a  2s  .c om
        // parse the main messages file and create a set of its defined 
        // message keys
        Resource resource = new FileSystemResource(messagesDirectory + mainMessagesFile);
        mainMap = messageFileService.getMessageMapFromFile(resource);
    } catch (IOException ex) {
        System.out.println("Main messages file could not be located");
    }

    // update each language file, setting the values for any missing keys
    // to an auto-translated version of the default language message
    for (String key : languageKeys) {

        try {

            // parse the target language messages file and collect a set of
            // defined keys
            Resource languageFile = new FileSystemResource(
                    messagesDirectory + "Messages_" + key + ".properties");
            Map<String, String> targetMap = messageFileService.getMessageMapFromFile(languageFile);

            Map<String, String> updatedMap = translationService.getAutoUpdatedTranslationMap(mainMap, targetMap,
                    key);

            messageFileService.updateMessageFile(languageFile, updatedMap);

        } catch (Exception ex) {
            System.out.println("Messages file for language '" + key + "' (" + key + ") cannot be located");
            return;
        }
    }

}

From source file:org.opennms.tools.NotificationsGenerator.java

/**
 * Generate notifications./*  w  w  w . j  a  v  a2s .  c  o  m*/
 *
 * @param onmsHome the OpenNMS home directory
 * @param notificationsTemplate the notifications template
 * @throws Exception the exception
 */
public void generateNotifications(File onmsHome, File notificationsTemplate) throws Exception {
    File thresholdsFile = new File(onmsHome, "etc/thresholds.xml");
    if (!thresholdsFile.exists()) {
        throw new FileNotFoundException(thresholdsFile.getAbsolutePath());
    }
    if (!notificationsTemplate.exists()) {
        throw new FileNotFoundException(notificationsTemplate.getAbsolutePath());
    }

    ThresholdingConfig thresholdsConfig = CastorUtils.unmarshal(ThresholdingConfig.class,
            new FileSystemResource(thresholdsFile), true);

    Notifications notifications = CastorUtils.unmarshal(Notifications.class,
            new FileSystemResource(notificationsTemplate), true);
    notifications.getHeader().setCreated(EventConstants.formatToString(new Date()));

    notifications.getNotificationCollection()
            .addAll(eventProcessor.getNotifications(thresholdsConfig.getGroupCollection()));

    File notificationsFile = new File(onmsHome, "etc/notifications.xml");
    System.out.println("Generating " + notificationsFile);
    Marshaller m = new Marshaller(new FileWriter(notificationsFile));
    m.setSuppressNamespaces(false);
    m.marshal(notifications);
}

From source file:fr.acxio.tools.agia.io.ResourceCopyFactory.java

@Override
public Resource getResource(Map<? extends Object, ? extends Object> sParameters)
        throws ResourceCreationException {
    Resource aResult = null;/*from w ww.j a va 2s  .  c o  m*/
    try {
        Resource aSourceResource = (Resource) sParameters.get(ResourceFactoryConstants.PARAM_SOURCE);
        String aFilename = aSourceResource.getFilename();
        String aFileNameWOExtension = aFilename.substring(0, aFilename.lastIndexOf('.'));
        String aExtension = extension;
        if (aExtension == null) {
            aExtension = aFilename.substring(aFilename.lastIndexOf('.'));
        }
        File aParentPath = (parentFolder != null) ? parentFolder.getFile() : null;
        if (aParentPath == null) {
            aParentPath = aSourceResource.getFile().getParentFile();
        }
        StringBuilder aNewFilename = new StringBuilder();
        if (prefix != null) {
            aNewFilename.append(prefix);
        }
        aNewFilename.append(aFileNameWOExtension);
        if (suffix != null) {
            aNewFilename.append(suffix);
        }
        aNewFilename.append(aExtension);
        File aNewFile = new File(aParentPath, aNewFilename.toString());
        aResult = new FileSystemResource(aNewFile);
    } catch (Exception e) {
        throw new ResourceCreationException(e);
    }
    return aResult;
}

From source file:fr.acxio.tools.agia.tasks.FileCopyTaskletTest.java

@Test
public void testExecuteDestDirDoesNotExist() throws Exception {
    FileCopyTasklet aTasklet = new FileCopyTasklet();
    aTasklet.setOrigin(new FileSystemResource("src/test/resources/testFiles/input.csv"));
    aTasklet.setDestination(new FileSystemResource("target/CP-testfiles/input-copy.csv"));
    StepContribution aStepContribution = mock(StepContribution.class);
    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
    verify(aStepContribution, times(1)).incrementReadCount();
    verify(aStepContribution, times(1)).incrementWriteCount(1);
}

From source file:org.cbioportal.annotation.TestAnnotationPipeline.java

@Test
public void pipelineTest() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParametersBuilder()
            .addString("filename", classLoader.getResource("data/testmaf.txt").getPath())
            .addString("outputFilename", "target/test-outputs/output.txt").addString("replace", "false")
            .addString("isoformOverride", "uniprot").toJobParameters());
    AssertFile.assertFileEquals(/*from  w w  w  .  j av a 2s  . c o  m*/
            new FileSystemResource(classLoader.getResource("data/expectedmaf.txt").getPath()),
            new FileSystemResource("target/test-outputs/output.txt"));
}

From source file:com.github.cherimojava.orchidae.Starter.java

private ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context)
        throws IOException {
    ServletContextHandler servletContext = new ServletContextHandler();
    servletContext.addEventListener(new ContextLoaderListener(context));
    ServletHolder holder = new ServletHolder("default", new DispatcherServlet(context));
    holder.getRegistration()/*from   w ww  . j a v  a  2 s . c om*/
            .setMultipartConfig(new MultipartConfigElement("./tmp", 20000000, 20000000, 200000));
    servletContext.addServlet(holder, "/*");
    servletContext.addEventListener(new ServletListener(context));
    servletContext.setResourceBase(new FileSystemResource(new File("./")).toString());
    servletContext.setSessionHandler(new SessionHandler());
    return servletContext;
}

From source file:com.siberhus.tdfl.DflSimpleTest.java

@Test
public void testLoadXlsFileToBeanAutomatically() throws DataFileLoaderException {

    employeeDfl.setDataFileProcessor(employeeBeanWrapDfp);
    employeeDfl.setResource(new FileSystemResource(XLS_FILE_IN_NAME));
    //      employeeDfl.setDestination(new FileSystemResource(XLS_FILE_OUT_NAME));
    employeeDfl.load();//  w w  w . ja va2  s . co m

    //      File processedFile = new File(XLS_FILE_OUT_NAME);
    //      Assert.assertTrue(processedFile.exists());
    //      FileUtils.deleteQuietly(processedFile);   
}

From source file:com.fredhopper.core.connector.index.DefaultIndexerTest.java

/**
 *
 */// ww  w .  j  a  v a 2 s. c  o m
@Before
public void setUp() throws Exception {

    mockPublishingService = mock(DefaultPublishingService.class);
    when(Boolean.valueOf(mockPublishingService.publishZip(any(), any()))).thenReturn(Boolean.TRUE);

    newFolder = tmpFolder.newFolder();
    final FileSystemResource dataDirResource = new FileSystemResource(newFolder);

    final CollectorFactory collectorFactory = mock(CollectorFactory.class);
    mockCategoryCollector = mock(CategoryDataCollector.class);
    when(collectorFactory.getCategoryCollector(DEFAULT_INSTANCE_CONFIG)).thenReturn(mockCategoryCollector);
    mockProductCollector = mock(ProductDataCollector.class);
    when(collectorFactory.getProductCollector(DEFAULT_INSTANCE_CONFIG)).thenReturn(mockProductCollector);
    mockMetaAttributeCollector = mock(MetaAttributeCollector.class);
    when(collectorFactory.getMetaAttributeCollector(DEFAULT_INSTANCE_CONFIG))
            .thenReturn(mockMetaAttributeCollector);

    generator = mock(Generator.class);
    newFile = tmpFolder.newFile();
    when(generator.generate(eq(mockMetaAttributeCollector), eq(mockCategoryCollector), eq(mockProductCollector),
            any())).thenReturn(newFile);

    defaultFhIndexer = new DefaultIndexer();
    defaultFhIndexer.setDataDirectoryResource(dataDirResource);
    defaultFhIndexer.setPublishingService(mockPublishingService);
    defaultFhIndexer.setCollectorFactory(collectorFactory);
    defaultFhIndexer.setGenerator(generator);
    defaultFhIndexer.setInstanceConfigService(instanceConfigService);

}

From source file:org.codehaus.grails.struts.action.ServletContextWrapper.java

public InputStream getResourceAsStream(String name) {
    if (!application.isWarDeployed() && name.equals("/WEB-INF/web.xml")) {
        BuildSettings settings = BuildSettingsHolder.getSettings();
        try {//w  ww. ja  v a  2 s. c o m
            Resource resource = new FileSystemResource(
                    settings.getResourcesDir().getAbsolutePath() + "/web.xml");
            if (resource.exists()) {
                return resource.getInputStream();
            } else {
                return null;
            }
        } catch (IOException e) {
            adaptee.log(e.getMessage(), e);
            return null;
        }

    } else {
        return adaptee.getResourceAsStream(name);
    }
}