List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:cn.org.once.cstack.cli.utils.ApplicationUtils.java
public String deployFromAWar(File path, boolean openBrowser) throws MalformedURLException, URISyntaxException { checkConnectedAndApplicationSelected(); String body = ""; Guard.guardTrue(path != null, "Please specify a file path"); try {//from w w w. java 2 s.c om File file = path; FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.available(); fileInputStream.close(); FileSystemResource resource = new FileSystemResource(file); Map<String, Object> params = new HashMap<>(); params.put("file", resource); params.putAll(authenticationUtils.getMap()); body = (String) restUtils.sendPostForUpload(authenticationUtils.finalHost + urlLoader.actionApplication + currentApplication.getName() + "/deploy", params).get("body"); } catch (IOException e) { throw new CloudUnitCliException("The file could not be opened", e); } if (StringUtils.isNotEmpty(body) && openBrowser) { DesktopAPI.browse(URI.create(currentApplication.getLocation())); } return MessageFormat.format("Application deployed. Access on {0}", currentApplication.getLocation()); }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java
@Test public void testEmptyBaseDirRelativeDir() throws Exception { String aTargetFilename = "target/Z6-input.zip"; ZipFilesTasklet aTasklet = new ZipFilesTasklet(); aTasklet.setSourceBaseDirectory(new FileSystemResource("")); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:src/test/resources/testFiles/input.csv"); aTasklet.setSourceFactory(aSourceFactory); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setExpression(aTargetFilename); aTasklet.setDestinationFactory(aDestinationFactory); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(null, null)); assertTrue(new File(aTargetFilename).exists()); ZipFile aZipFile = new ZipFile(new File(aTargetFilename)); Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries(); assertTrue(aEntries.hasMoreElements()); assertEquals("src/test/resources/testFiles/input.csv", aEntries.nextElement().getName()); assertFalse(aEntries.hasMoreElements()); aZipFile.close();//from w w w . ja v a 2 s .com }
From source file:com.goodhuddle.huddle.service.impl.ThemeServiceImpl.java
@Override public Resource getThemeSettingAttachment(String path) { return new FileSystemResource(fileStore.getFile(getSettingAttachmentPath(path))); }
From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java
@Override protected Resource createResource(String path) { return new FileSystemResource(path); }
From source file:com.sitewhere.server.SiteWhereServer.java
/** * Load the springified server configuration. * /*from ww w . j a va 2 s . c om*/ * @return */ protected ApplicationContext loadServerApplicationContext(File configFile) throws SiteWhereException { GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new FileSystemResource(configFile)); context.refresh(); return context; }
From source file:com.wooki.test.unit.ConversionsTest.java
@Test(enabled = true) public void testAptConversion() { String result = " ------\n Title\n ------\n Author\n ------\n Date\n\n Paragraph 1, line 1.\n Paragraph 1, line 2.\n\n Paragraph 2, line 1.\n Paragraph 2, line 2.\n\nSection title\n\n* Sub-section title\n\n** Sub-sub-section title\n\n*** Sub-sub-sub-section title\n\n**** Sub-sub-sub-sub-section title\n\n * List item 1.\n\n * List item 2.\n\n Paragraph contained in list item 2.\n\n * Sub-list item 1.\n\n * Sub-list item 2.\n\n * List item 3.\n Force end of list:\n\n []\n\n+------------------------------------------+\nVerbatim text not contained in list item 3\n+------------------------------------------+\n\n [[1]] Numbered item 1.\n\n [[A]] Numbered item A.\n\n [[B]] Numbered item B.\n\n [[2]] Numbered item 2.\n\n List numbering schemes: [[1]], [[a]], [[A]], [[i]], [[I]].\n\n [Defined term 1] of definition list.\n\n [Defined term 2] of definition list.\n\n+-------------------------------+\nVerbatim text\n in a box\n+-------------------------------+\n\n --- instead of +-- suppresses the box around verbatim text.\n\n[Figure name] Figure caption\n\n*----------*--------------+----------------:\n| Centered | Left-aligned | Right-aligned |\n| cell 1,1 | cell 1,2 | cell 1,3 |\n*----------*--------------+----------------:\n| cell 2,1 | cell 2,2 | cell 2,3 |\n*----------*--------------+----------------:\nTable caption\n\n No grid, no caption:\n\n*-----*------*\n cell | cell\n*-----*------*\n cell | cell\n*-----*------*\n\n Horizontal line:\n\n=======================================================================\n\n^L\n New page.\n\n <Italic> font. <<Bold>> font. <<<Monospaced>>> font.\n\n {Anchor}. Link to {{anchor}}. Link to {{http://www.pixware.fr}}.\n Link to {{{anchor}showing alternate text}}.\n Link to {{{http://www.pixware.fr}Pixware home page}}.\n\n Force line\\\n break.\n\n Non\\ breaking\\ space.\n\n Escaped special characters: \\~, \\=, \\-, \\+, \\*, \\[, \\], \\<, \\>, \\{, \\}, \\\\.\n\n Copyright symbol: \\251, \\xA9, \\u00a9.\n\n~~Commented out."; File aptFile = null;/*from w ww . ja v a 2 s .com*/ String from = "apt"; File out = null; try { out = File.createTempFile("fromAptToXHTML", ".html"); InputStream apt = new ByteArrayInputStream(result.getBytes()); try { aptFile = File.createTempFile("wooki", ".apt"); FileOutputStream fos = new FileOutputStream(aptFile); logger.debug("APT File is " + aptFile.getAbsolutePath()); byte[] content = null; int available = 0; while ((available = apt.available()) > 0) { content = new byte[available]; apt.read(content); fos.write(content); } fos.flush(); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String to = "xhtml"; Converter converter = new DefaultConverter(); InputFileWrapper input = InputFileWrapper.valueOf(aptFile.getAbsolutePath(), from, "ISO-8859-1", converter.getInputFormats()); OutputFileWrapper output = OutputFileWrapper.valueOf(out.getAbsolutePath(), to, "UTF-8", converter.getOutputFormats()); converter.convert(input, output); } catch (UnsupportedFormatException e) { e.printStackTrace(); } catch (ConverterException e) { e.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } InputStream newHTML = fromAptToDocbook.performTransformation(new FileSystemResource(out)); SAXParserFactory factory = SAXParserFactory.newInstance(); // cration d'un parseur SAX SAXParser parser; try { parser = factory.newSAXParser(); parser.parse(new InputSource(newHTML), htmlParser); } catch (ParserConfigurationException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); } catch (SAXException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); } Book book = htmlParser.getBook(); logger.debug("The book title is " + book.getTitle()); }
From source file:com.consol.citrus.admin.service.ProjectService.java
/** * Removes the citrus admin connector dependency from the target project Maven POM. *//* w ww. j a v a2 s. c o m*/ public void removeConnector() { if (project.isMavenProject()) { try { String pomXml = FileUtils.readToString(new FileSystemResource(project.getMavenPomFile())); pomXml = pomXml.replaceAll( "\\s*<dependency>[\\s\\n\\r]*<groupId>com\\.consol\\.citrus</groupId>[\\s\\n\\r]*<artifactId>citrus-admin-connector</artifactId>[\\s\\n\\r]*<version>.*</version>[\\s\\n\\r]*</dependency>", ""); pomXml = pomXml.replaceAll( "\\s*<dependency>[\\s\\n\\r]*<groupId>com\\.consol\\.citrus</groupId>[\\s\\n\\r]*<artifactId>citrus-admin-connector</artifactId>[\\s\\n\\r]*</dependency>", ""); FileUtils.writeToFile(pomXml, new FileSystemResource(project.getMavenPomFile()).getFile()); project.getSettings().setUseConnector(false); project.getSettings().setConnectorActive(false); saveProject(project); List<String> listenerBeans = springBeanService.getBeanNames(getProjectContextConfigFile(), getActiveProject(), WebSocketPushMessageListener.class.getName()); for (String listenerBean : listenerBeans) { springBeanService.removeBeanDefinition(getProjectContextConfigFile(), getActiveProject(), listenerBean); } } catch (IOException e) { throw new ApplicationRuntimeException( "Failed to add admin connector dependency to Maven pom.xml file", e); } } }
From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java
protected static Resource getDefaultWaveMakerHome() { Resource userHome = null;//www . j ava 2 s .co m if (SystemUtils.IS_OS_WINDOWS) { String userProfileEnvVar = System.getenv("USERPROFILE"); if (StringUtils.hasText(userProfileEnvVar)) { userProfileEnvVar = userProfileEnvVar.endsWith("/") ? userProfileEnvVar : userProfileEnvVar + "/"; userHome = new FileSystemResource(System.getenv("USERPROFILE")); } } if (userHome == null) { String userHomeProp = System.getProperty("user.home"); userHomeProp = userHomeProp.endsWith("/") ? userHomeProp : userHomeProp + "/"; userHome = new FileSystemResource(userHomeProp); } String osVersionStr = System.getProperty("os.version"); if (osVersionStr.contains(".")) { String sub = osVersionStr.substring(osVersionStr.indexOf(".") + 1); if (sub.contains(".")) { osVersionStr = osVersionStr.substring(0, osVersionStr.indexOf('.', osVersionStr.indexOf('.') + 1)); } } try { if (SystemUtils.IS_OS_WINDOWS) { userHome = new FileSystemResource( javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory()); } else if (SystemUtils.IS_OS_MAC) { userHome = userHome.createRelative("Documents/"); } if (!userHome.exists()) { throw new WMRuntimeException(MessageResource.PROJECT_USERHOMEDNE, userHome); } Resource wmHome = userHome.createRelative(WAVEMAKER_HOME); if (!wmHome.exists()) { wmHome.getFile().mkdir(); } return wmHome; } catch (IOException ex) { throw new WMRuntimeException(ex); } }
From source file:com.consol.citrus.admin.service.TestCaseService.java
/** * Get total number of tests in project. * @param project// ww w . j a v a 2 s . c om * @return */ public long getTestCount(Project project) { long testCount = 0L; try { List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(), StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern())); for (File sourceFile : sourceFiles) { String sourceCode = FileUtils.readToString(new FileSystemResource(sourceFile)); testCount += StringUtils.countOccurrencesOf(sourceCode, "@CitrusTest"); testCount += StringUtils.countOccurrencesOf(sourceCode, "@CitrusXmlTest"); } } catch (IOException e) { log.warn("Failed to read Java source files - list of test cases for this project is incomplete", e); } return testCount; }