List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:org.bonitasoft.web.designer.controller.WidgetDirectiveLoaderControllerTest.java
@Test public void should_load_files_on_disk_according_to_asked_path() throws Exception { Path expectedFile = widgetRepositoryPath.resolve("pbLabel/pbLabel.js"); mockMvc.perform(get("/runtime/widgets/pbLabel/pbLabel.js")) .andExpect(status().isOk()).andExpect(content().bytes(readAllBytes(expectedFile))) .andExpect(header().string("Content-Length", String.valueOf(expectedFile.toFile().length()))) .andExpect(header().string("Content-Disposition", "inline; filename=\"pbLabel.js\"")) .andExpect(content().encoding("UTF-8")); }
From source file:eu.itesla_project.online.tools.AmplExportOnlineWorkflowStatesTool.java
private void exportState(OnlineDb onlinedb, String workflowId, Integer stateId, Path folder) { System.out.println("Exporting network data of workflow " + workflowId + ", state " + stateId); Network network = onlinedb.getState(workflowId, stateId); if (network == null) { System.out.println(// w ww.java 2s .com "Cannot export network data: no stored state " + stateId + " for workflow " + workflowId); return; } Path stateFolder = Paths.get(folder.toString(), "wf_" + workflowId + "_state_" + stateId); System.out.println("Exporting network data of workflow " + workflowId + ", state " + stateId + " to folder " + stateFolder); if (stateFolder.toFile().exists()) { System.out.println("Cannot export network data of workflow " + workflowId + ", state " + stateId + ": folder " + stateFolder + " already exists"); return; } if (!stateFolder.toFile().mkdirs()) { System.out.println("Cannot export network data of workflow " + workflowId + ", state " + stateId + ": unable to create " + stateFolder + " folder"); return; } DataSource dataSource = new FileDataSource(stateFolder, "wf_" + workflowId + "_state_" + stateId); Exporters.export("AMPL", network, new Properties(), dataSource); }
From source file:com.yqboots.fss.web.controller.FileItemController.java
@PreAuthorize(FileItemPermissions.WRITE) @RequestMapping(value = WebKeys.MAPPING_ROOT, method = RequestMethod.POST) public String update(@Valid @ModelAttribute(WebKeys.MODEL) final FileUploadForm form, @PageableDefault final Pageable pageable, final BindingResult bindingResult, final ModelMap model) throws IOException { new FileUploadFormValidator().validate(form, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute(WebKeys.PAGE, fileItemManager.findByPath(StringUtils.EMPTY, pageable)); return VIEW_HOME; }//w w w.j a v a 2 s . c o m final MultipartFile file = form.getFile(); final String path = form.getPath(); final boolean overrideExisting = form.isOverrideExisting(); final Path destination = Paths .get(fileItemManager.getFullPath(path) + File.separator + file.getOriginalFilename()); if (Files.exists(destination) && overrideExisting) { file.transferTo(destination.toFile()); } else { Files.createDirectories(destination.getParent()); Files.createFile(destination); file.transferTo(destination.toFile()); } model.clear(); return REDIRECT_VIEW_PATH; }
From source file:at.makubi.maven.plugin.avrohugger.AvrohuggerGeneratorTest.java
public void testAvrohuggerGenerator() throws IOException { Path inputDirectory = Paths.get(getBasedir()).resolve("src/test/resources/unit/avrohugger-maven-plugin"); Path schemaDirectory = inputDirectory.resolve("schema"); File expectedRecord = inputDirectory.resolve("expected/Record.scala").toFile(); File actualRecords = outputDirectory.resolve("at/makubi/maven/plugin/model/Record.scala").toFile(); avrohuggerGenerator.generateScalaFiles(schemaDirectory.toFile(), outputDirectory.toString(), new SystemStreamLog(), false); assertTrue("Generated Scala file does not match expected one", FileUtils.contentEquals(expectedRecord, actualRecords)); }
From source file:org.wso2.appserver.integration.tests.webapp.virtualhost.WSAS2058AppbasePathRepeatedVirtualHostTestCase.java
@BeforeClass(alwaysRun = true, enabled = false) public void setEnvironment() throws Exception { super.init(userMode); serverConfigurationManager = new ServerConfigurationManager( new AutomationContext("AS", TestUserMode.SUPER_TENANT_ADMIN)); webAppURL = getWebAppURL(WebAppTypes.WEBAPPS); //Restart the Server only once if (isRestarted == 0) { File sourceFile = Paths.get(TestConfigurationProvider.getResourceLocation(), "artifacts", "AS", "tomcat", "catalina-server-repeated-appbase-name.xml").toFile(); Path targetFilePath = Paths.get(FrameworkPathUtil.getCarbonServerConfLocation(), "tomcat", "catalina-server.xml"); serverConfigurationManager.applyConfigurationWithoutRestart(sourceFile, targetFilePath.toFile(), true); //Get first path and replace it in the server without restarting virtualHostAppBase = Paths.get(FrameworkPathUtil.getCarbonHome()).getParent().getFileName().toString(); Charset charset = StandardCharsets.UTF_8; String content = new String(Files.readAllBytes(targetFilePath), charset); content = content.replaceAll("virtual_appbase_name", virtualHostAppBase); Files.write(targetFilePath, content.getBytes(charset)); serverConfigurationManager.restartGracefully(); sessionCookie = loginLogoutClient.login(); }/*from w w w. j av a2 s .co m*/ ++isRestarted; }
From source file:com.netflix.nicobar.core.persistence.PathArchiveRepository.java
@Override public void deleteArchive(ModuleId moduleId) throws IOException { Path moduleDir = rootDir.resolve(moduleId.toString()); if (Files.exists(moduleDir)) { FileUtils.deleteDirectory(moduleDir.toFile()); }//from w ww . jav a2 s . c o m }
From source file:io.fabric8.vertx.maven.plugin.utils.PackageHelper.java
/** * @param dir/*from w w w .j av a2 s.com*/ * @return */ private synchronized File createFatJar(Path dir) { File jarFile = null; try { jarFile = new File(dir.toFile(), outputFileName); boolean useTmpFile = false; File theCreatedFile = jarFile; if (jarFile.isFile()) { useTmpFile = true; theCreatedFile = new File(dir.toFile(), outputFileName + "__"); } if (!jarFile.getParentFile().exists() && !jarFile.getParentFile().mkdirs()) { log.error("Failed to create parent directories for :" + jarFile.getAbsolutePath()); } ZipExporter zipExporter = this.archive.as(ZipExporter.class); try (FileOutputStream jarOut = new FileOutputStream(theCreatedFile)) { zipExporter.exportTo(jarOut); } if (useTmpFile) { jarFile.delete(); theCreatedFile.renameTo(jarFile); } } catch (Exception e) { log.error("Error building fat jar ", e); } return jarFile; }
From source file:com.movilizer.mds.webservice.services.MafManagementService.java
protected MafCliMetaFile readMetaFile(File sourceFile) throws FileNotFoundException { String metaFileName = sourceFile.getName().replace(GROOVY_EXTENSION, META_FILE_EXTENSION); Path metaFilePath = sourceFile.toPath().resolveSibling(metaFileName); if (logger.isDebugEnabled()) { logger.debug(String.format(Messages.LOADING_MAF_METADATA, metaFilePath.toString())); }/*www . j av a2 s .co m*/ return gson.fromJson(new FileReader(metaFilePath.toFile()), MafCliMetaFile.class); }
From source file:com.yahoo.maven.visitor.VisitorGenerator.java
public void generate() throws IOException { for (Visitor visitor : getVisitors()) { String name = visitor.getVisitedName(); int packageTail = name.lastIndexOf("."); String aPackage = packageTail == -1 ? null : name.substring(0, packageTail); String disjunctName = packageTail == -1 ? name : name.substring(packageTail + 1, name.length()); String className = capitalizer.capitalize(disjunctName); String dir = aPackage == null ? "" : StringUtils.replace(aPackage, ".", FileSystems.getDefault().getSeparator()); List<TypeParameterContext> typeParameterContexts = new ArrayList<>(); Set<String> typeParameterNames = new LinkedHashSet<>(); if (visitor.getTypeParameters() != null) { typeParameterContexts.addAll(Arrays.asList(visitor.getTypeParameters())); for (TypeParameter typeParameter : visitor.getTypeParameters()) { typeParameterNames.add(typeParameter.getName()); }//ww w. j ava2 s.c o m } List<DisjunctContext> disjuncts = new ArrayList<>(); for (Disjunction disjunction : visitor.getDisjunctions()) { List<ParameterContext> parameterContexts = new ArrayList<>(); if (disjunction.parameters != null) { for (Parameter parameter : disjunction.parameters) { parameterContexts.add(new ParameterContext() { @Override public String getType() { return parameter.type; } @Override public String getName() { return parameter.name; } @Override public String getHashExpression() { switch (getType()) { case "boolean": return "(" + getName() + " ? 1 : 0)"; case "char": case "byte": case "short": return "(int) " + getName(); case "int": return getName(); case "long": return "(int) (" + getName() + " ^ (" + getName() + " >>> 32))"; case "float": return "(" + getName() + " != +0.0f ? Float.floatToIntBits(" + getName() + ") : 0)"; case "double": return "(int) (Double.doubleToLongBits(" + getName() + ") ^ (Double.doubleToLongBits(" + getName() + ") >>> 32))"; default: return "(" + getName() + " != null ? " + getName() + ".hashCode() : 0)"; } } }); } } disjuncts.add(new DisjunctContext() { @Override public String getMethodName() { return disjunction.name; } @Override public List<ParameterContext> getParameters() { return parameterContexts.isEmpty() ? null : parameterContexts; } @Override public boolean hasAsMethod() { return parameterContexts.size() == 1 && !primitives.contains(parameterContexts.get(0).getType()); } }); } class AbstractBaseContext implements BaseContext { @Override public String getPackage() { return aPackage; } @Override public String getVisitedClassName() { return className; } @Override public List<TypeParameterContext> getTypeParameters() { return typeParameterContexts.isEmpty() ? null : typeParameterContexts; } @Override public List<DisjunctContext> getDisjuncts() { return disjuncts.isEmpty() ? null : disjuncts; } } Path outputFolder = getOutputDirectory().resolve(dir); File outputFolderAsFile = outputFolder.toFile(); if (!outputFolderAsFile.mkdirs() && !outputFolderAsFile.exists()) { throw new IOException("Unable to make directory: " + outputFolderAsFile.getAbsolutePath()); } try (Writer visitedWriter = Files.newBufferedWriter(outputFolder.resolve(className + ".java"))) { class ThisVisitedContext extends AbstractBaseContext implements VisitedContext { } visitedTemplate.merge(visitedWriter, new ThisVisitedContext()); } try (Writer visitorWriter = Files.newBufferedWriter(outputFolder.resolve(className + "Visitor.java"))) { class ThisVisitorContext extends AbstractBaseContext implements VisitorContext { } visitorTemplate.merge(visitorWriter, new ThisVisitorContext()); } try (Writer visitorWriter = Files .newBufferedWriter(outputFolder.resolve("Defaulting" + className + "Visitor.java"))) { class ThisDefaultingVisitorContext extends AbstractBaseContext implements DefaultingVisitorContext { } defaultingVisitorTemplate.merge(visitorWriter, new ThisDefaultingVisitorContext()); } try (Writer visitorWriter = Files .newBufferedWriter(outputFolder.resolve("Identity" + className + "Visitor.java"))) { class ThisIdentityVisitorContext extends AbstractBaseContext implements IdentityVisitorContext { } identityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext()); } try (Writer visitorWriter = Files .newBufferedWriter(outputFolder.resolve("DefaultingIdentity" + className + "Visitor.java"))) { class ThisIdentityVisitorContext extends AbstractBaseContext implements IdentityVisitorContext, DefaultingVisitorContext { } defaultingIdentityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext()); } } }
From source file:com.spotify.helios.testing.TemporaryJobBuilder.java
public TemporaryJobBuilder imageFromInfoFile(final Path path) { return imageFromInfoFile(path.toFile()); }