List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:fi.jumi.launcher.daemon.DirBasedStewardTest.java
@Test public void copies_the_embedded_daemon_JAR_to_the_settings_dir() throws IOException { Path daemonJar = steward.getDaemonJar(jumiHome); assertThat(daemonJar.getFileName().toString(), is(expectedName)); assertThat(FileUtils.readFileToByteArray(daemonJar.toFile()), is(expectedContent)); }
From source file:eu.openanalytics.shinyproxy.controllers.IssueController.java
public void sendSupportMail(IssueForm form, Proxy proxy) { String supportAddress = getSupportAddress(); if (supportAddress == null) throw new RuntimeException("Cannot send mail: no support address configured"); if (mailSender == null) throw new RuntimeException("Cannot send mail: no smtp settings configured"); try {/*from ww w . ja va 2s . c o m*/ MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); // Headers helper.setFrom(environment.getProperty("proxy.support.mail-from-address", "issues@shinyproxy.io")); helper.addTo(supportAddress); helper.setSubject("ShinyProxy Error Report"); // Body StringBuilder body = new StringBuilder(); String lineSep = System.getProperty("line.separator"); body.append(String.format("This is an error report generated by ShinyProxy%s", lineSep)); body.append(String.format("User: %s%s", form.userName, lineSep)); if (form.appName != null) body.append(String.format("App: %s%s", form.appName, lineSep)); if (form.currentLocation != null) body.append(String.format("Location: %s%s", form.currentLocation, lineSep)); if (form.customMessage != null) body.append(String.format("Message: %s%s", form.customMessage, lineSep)); helper.setText(body.toString()); // Attachments (only if container-logging is enabled) if (logService.isLoggingEnabled() && proxy != null) { Path[] filePaths = logService.getLogFiles(proxy); for (Path p : filePaths) { if (Files.exists(p)) helper.addAttachment(p.toFile().getName(), p.toFile()); } } mailSender.send(message); } catch (Exception e) { throw new RuntimeException("Failed to send email", e); } }
From source file:com.gs.obevo.db.impl.platforms.oracle.OracleReveng.java
@Override protected File printInstructions(PrintStream out, AquaRevengArgs args) { DbEnvironment env = getDbEnvironment(args); JdbcDataSourceFactory jdbcFactory = new OracleJdbcDataSourceFactory(); DataSource ds = jdbcFactory.createDataSource(env, new Credential(args.getUsername(), args.getPassword()), 1);/* w ww. ja va 2 s . com*/ JdbcHelper jdbc = new JdbcHelper(null, false); Path interim = new File(args.getOutputPath(), "interim").toPath(); interim.toFile().mkdirs(); try (Connection conn = ds.getConnection(); BufferedWriter fileWriter = Files.newBufferedWriter(interim.resolve("output.sql"), Charset.defaultCharset())) { // https://docs.oracle.com/database/121/ARPLS/d_metada.htm#BGBJBFGE // Note - can't remap schema name, object name, tablespace name within JDBC calls; we will leave that to the existing code in AbstractDdlReveng jdbc.update(conn, "{ CALL DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false) }"); MutableList<Map<String, Object>> maps = jdbc.queryForList(conn, "SELECT CASE WHEN OBJECT_TYPE = 'TABLE' THEN 1 WHEN OBJECT_TYPE = 'INDEX' THEN 2 ELSE 3 END SORT_ORDER,\n" + " OBJECT_TYPE,\n" + " dbms_metadata.get_ddl(REPLACE(object_type,' ','_'), object_name, owner) || ';' AS object_ddl\n" + "FROM DBA_OBJECTS WHERE OWNER = '" + args.getDbSchema() + "' AND OBJECT_TYPE NOT IN ('PACKAGE BODY', 'LOB','MATERIALIZED VIEW', 'TABLE PARTITION')\n" + "ORDER BY 1"); for (Map<String, Object> map : maps) { Clob clobObject = (Clob) map.get("OBJECT_DDL"); InputStream in = clobObject.getAsciiStream(); StringWriter w = new StringWriter(); try { IOUtils.copy(in, w); } catch (IOException e) { throw new RuntimeException(e); } String clobAsString = w.toString(); clobAsString = clobAsString.replaceAll(";.*$", ""); LOG.debug("Content for {}: ", map.get("OBJECT_TYPE"), clobAsString); fileWriter.write(clobAsString); fileWriter.newLine(); fileWriter.write("~"); fileWriter.newLine(); } } catch (SQLException | IOException e) { throw new RuntimeException(e); } return interim.toFile(); }
From source file:im.bci.gamesitekit.GameSiteKitMain.java
private void copyMedias() throws IOException { Path mediaOutputDir = outputDir.resolve("media"); FileUtils.copyDirectory(templateDir.resolve("media").toFile(), mediaOutputDir.toFile()); FileUtils.copyDirectory(inputDir.resolve("media").toFile(), mediaOutputDir.toFile()); }
From source file:io.fabric8.vertx.maven.plugin.ConfigConversionUtilTest.java
@Test public void convertArrayYamlToJson() throws Exception { Path yamlFile = Paths.get(this.getClass().getResource("/testconfig2.yaml").toURI()); Path jsonFilePath = Files.createTempFile("testconfig2", ".json"); assertNotNull(yamlFile);//from ww w . jav a 2 s. c o m assertTrue(yamlFile.toFile().isFile()); assertTrue(yamlFile.toFile().exists()); ConfigConverterUtil.convertYamlToJson(yamlFile, jsonFilePath); assertNotNull(jsonFilePath); String jsonDoc = new String(Files.readAllBytes(jsonFilePath)); assertNotNull(jsonDoc); JSONObject jsonMap = new JSONObject(jsonDoc); assertNotNull(jsonMap); assertNotNull(jsonMap.get("names")); JSONArray names = jsonMap.getJSONArray("names"); assertTrue(names.length() == 4); assertEquals(names.get(0), "kamesh"); }
From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandler.java
@Override public void created(Path path) { File createdFile = path.toFile(); LOG.info("Created called with " + createdFile); boolean succeeded = false; try {//w ww . j a v a2 s . c o m if (createdFile.getName().endsWith(".tar")) { LOG.info("Processing file at " + path); CustomProcessorInfo customProcessorInfo = this.getCustomProcessorInfo(createdFile); if (customProcessorInfo == null) { LOG.warn("No information found for CustomProcessorRuntime in " + createdFile); return; } InputStream jarFile = this.getJarFile(customProcessorInfo, createdFile); if (jarFile == null) { LOG.warn("No jar file found for CustomProcessorRuntime in " + createdFile); return; } File tempJarFile = FileUtil.writeInputStreamToTempFile(jarFile, ".jar"); ProxyUtil<CustomProcessorRuntime> customProcessorProxyUtil = new ProxyUtil<>( CustomProcessorRuntime.class); CustomProcessorRuntime customProcessorRuntime = customProcessorProxyUtil.loadClassFromJar( tempJarFile.getAbsolutePath(), customProcessorInfo.getCustomProcessorImpl()); jarFile.reset(); this.catalogService.addCustomProcessorInfoAsBundle(customProcessorInfo, jarFile); succeeded = true; } else { LOG.info("Failing unsupported file that was received: " + path); } } catch (IOException e) { LOG.warn("Exception occured while processing tar file: " + createdFile, e); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { LOG.warn("Could not load a class from jar file implementing CustomProcessorRuntime interface from " + createdFile, e); } catch (ComponentConfigException e) { LOG.warn("UI specification for custom processor incorrect for custom processor file: " + createdFile, e); } finally { try { if (succeeded) { LOG.info("CustomProcessorRuntime uploaded successfully from " + createdFile + " Moving file to " + uploadSuccessPath); moveFileToSuccessDirectory(createdFile); } else { LOG.warn("CustomProcessorRuntime failed to upload from " + createdFile + " Moving file to " + uploadFailPath); moveFileToFailDirectory(createdFile); } } catch (IOException e1) { LOG.warn("Error moving " + createdFile.getAbsolutePath() + " to " + (succeeded ? uploadSuccessPath : uploadFailPath), e1); } } }
From source file:com.textocat.textokit.commons.consumer.AnnotationPerLineWriter.java
@Override public void process(CAS cas) throws AnalysisEngineProcessException { String docUriStr = DocumentUtils.getDocumentUri(cas); if (docUriStr == null) { throw new IllegalStateException("Can't extract document URI"); }//from w ww. j a v a2 s . c o m Path docUriPath = IoUtils.extractPathFromURI(docUriStr); if (docUriPath.isAbsolute()) { docUriPath = Paths.get("/").relativize(docUriPath); } Path outputPath = outputDir.resolve(docUriPath); outputPath = IoUtils.addExtension(outputPath, outputFileSuffix); try (PrintWriter out = IoUtils.openPrintWriter(outputPath.toFile())) { for (AnnotationFS anno : CasUtil.select(cas, targetType)) { String text = anno.getCoveredText(); text = StringUtils.replaceChars(text, "\r\n", " "); out.println(text); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:com.arpnetworking.test.junitbenchmarks.JsonBenchmarkConsumerTest.java
@Test public void testCreatesParentDirs() throws IOException { final Path path = Paths.get("target/tmp/test/another/directory/testConsumerMultiClose.json"); path.toFile().deleteOnExit(); FileUtils.deleteDirectory(Paths.get("target/tmp/test/another").toFile()); final JsonBenchmarkConsumer consumer = new JsonBenchmarkConsumer(path); final Result result = DataCreator.createResult(); consumer.accept(result);// w w w .j a v a 2 s .co m consumer.close(); }
From source file:com.github.blindpirate.gogradle.crossplatform.DefaultGoBinaryManager.java
private void addXPermissionToAllDescendant(Path path) { listFiles(path.toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream().map(File::toPath) .forEach(IOUtils::chmodAddX); }
From source file:eu.over9000.skadi.io.PersistenceHandler.java
private StateContainer readFromFile() throws IOException, JAXBException { final Path stateFile = this.getStateFilePath(); StateContainer state;//from www . ja v a2 s . c o m synchronized (this.fileLock) { state = (StateContainer) this.unmarshaller.unmarshal(stateFile.toFile()); } LOGGER.debug("load state from file"); return state; }