List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:br.com.thiaguten.archive.ZipArchive.java
protected ArchiveOutputStream createArchiveOutputStream(Path path) throws IOException { // for some internal optimizations should use // the constructor that accepts a File argument return new ZipArchiveOutputStream(path.toFile()); }
From source file:io.pravega.segmentstore.storage.impl.extendeds3.S3FileSystemImpl.java
@Override public S3ObjectMetadata getObjectMetadata(String bucketName, String key) { S3ObjectMetadata metadata = new S3ObjectMetadata(); AclSize data = aclMap.get(key);//from w w w.j a v a 2 s .co m if (data == null) { throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", ""); } metadata.setContentLength(data.getSize()); Path path = Paths.get(this.baseDir, bucketName, key); metadata.setLastModified(new Date(path.toFile().lastModified())); return metadata; }
From source file:com.mesosphere.dcos.cassandra.common.config.HeapConfig.java
public void writeHeapSettings(final Path path) throws IOException { FileWriter writer = null;/*from www .j a va2 s .c o m*/ try { writer = new FileWriter(path.toFile(), false); List<String> settings = getHeapSettings(); for (String setting : settings) { writer.write(setting + '\n'); } writer.flush(); } finally { if (writer != null) { try { writer.close(); } catch (IOException ex) { } } } }
From source file:io.mangoo.build.Watcher.java
@SuppressWarnings("all") private void handleEvents(WatchKey watchKey, Path path) { for (WatchEvent<?> watchEvent : watchKey.pollEvents()) { WatchEvent.Kind<?> watchEventKind = watchEvent.kind(); if (OVERFLOW.equals(watchEventKind)) { continue; }/*from www .j av a 2s . com*/ WatchEvent<Path> ev = (WatchEvent<Path>) watchEvent; Path name = ev.context(); Path child = path.resolve(name); if (ENTRY_MODIFY.equals(watchEventKind) && !child.toFile().isDirectory()) { handleNewOrModifiedFile(child); } if (ENTRY_CREATE.equals(watchEventKind)) { if (!child.toFile().isDirectory()) { handleNewOrModifiedFile(child); } try { if (Files.isDirectory(child, NOFOLLOW_LINKS)) { registerAll(child); } } catch (IOException e) { LOG.error("Something fishy happened. Unable to register new dir for watching", e); } } } }
From source file:com.joyent.manta.client.crypto.EncryptingEntityTest.java
private void canCountBytesFromStreamWithUnknownLength(SupportedCipherDetails cipherDetails) throws Exception { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader.getResource("com/joyent/manta/client/crypto/EncryptingEntityTest.class"); Path path = Paths.get(resource.toURI()); long size = path.toFile().length(); MantaInputStreamEntity entity = new MantaInputStreamEntity(resource.openStream()); Assert.assertEquals(entity.getContentLength(), -1L, "Content length should be set to unknown value"); byte[] keyBytes = SecretKeyUtils.generate(cipherDetails).getEncoded(); verifyEncryptionWorksRoundTrip(keyBytes, cipherDetails, entity, (actualBytes) -> { Assert.assertEquals(actualBytes.length, size, "Incorrect number of bytes counted"); return true; });// w w w . java2 s. com }
From source file:eu.itesla_project.iidm.ddb.eurostag_imp_exp.tools.DdbUpdateEurostagDataTool.java
@Override public void run(CommandLine line) throws Exception { String dataDir = line.getOptionValue(DATA_DIR); String ddFile = line.getOptionValue(DD_FILE); String jbossHost = line.getOptionValue(HOST); String jbossPort = line.getOptionValue(PORT); String jbossUser = line.getOptionValue(USER); String jbossPassword = line.getOptionValue(PASSWORD); String eurostagVersion = line.getOptionValue(EUROSTAG_VERSION); Path ddFilePath = Paths.get(ddFile); Path ddData = Paths.get(dataDir); Path ddPath = ddData.resolve("gene"); Path genPath = ddData.resolve("reguls"); Path dicoPath = ddData.resolve("dico.txt"); if ((ddFilePath.toFile().isFile()) == false) { throw new RuntimeException(DD_FILE + ": " + ddFile + " is not a file!"); }//ww w .j a v a 2s .c o m DdbDtaImpExp ddbImpExp = new DdbDtaImpExp(new DdbConfig(jbossHost, jbossPort, jbossUser, jbossPassword)); ddbImpExp.setUpdateFlag(true); ddbImpExp.loadEurostagData(ddFilePath, dicoPath, eurostagVersion, genPath); }
From source file:com.github.harti2006.neo4j.StartNeo4jServerMojo.java
private void startNeo4jServer() throws MojoExecutionException { final Log log = getLog(); try {//from www . j a v a 2 s . c om final Path serverLocation = getServerLocation(); final String[] neo4jCommand = new String[] { serverLocation.resolve(Paths.get("bin", "neo4j")).toString(), "start" }; final File workingDir = serverLocation.toFile(); final Process neo4jStartProcess = Runtime.getRuntime().exec(neo4jCommand, null, workingDir); try (BufferedReader br = new BufferedReader( new InputStreamReader(neo4jStartProcess.getInputStream()))) { String line; while ((line = br.readLine()) != null) { log.info("NEO4J SERVER > " + line); } } if (neo4jStartProcess.waitFor(5, SECONDS) && neo4jStartProcess.exitValue() == 0) { log.info("Started Neo4j server"); } else { throw new MojoExecutionException("Neo4j server did not start up properly"); } } catch (IOException | InterruptedException e) { throw new MojoExecutionException("Could not start neo4j server", e); } }
From source file:com.edsoft.teknosaproject.bean.TreeNodeBean.java
public void saveFile() { Path path = Paths.get("E:", "TREE", "hiyerari.txt"); //Path path = Paths.get("E:", "Hiyerari", "hiyerari.txt"); OutputStream stream;//from w w w . ja va 2s . com ObjectOutput object; try { stream = new FileOutputStream(path.toFile()); object = new ObjectOutputStream(stream); object.writeObject(root); object.flush(); object.close(); stream.close(); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "TAMMA", "Baarl")); } catch (IOException ex) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "HATA", "Kayt srasnda hata oldu")); } }
From source file:com.compomics.pladipus.controller.setup.InstallActiveMQ.java
private void downloadActiveMQ() throws IOException, ZipException { //File downloadFile = PladipusFileDownloadingService.downloadFile(link, activeMQFolder); if (!activeMQFolder.exists() & !activeMQFolder.mkdirs()) { throw new IOException("could not make install folder"); }/*w ww .ja v a 2 s. c om*/ URL website = new URL(link); Path downloadFile = Files.createTempFile("activemqdownload", null); try (ReadableByteChannel rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream(downloadFile.toFile())) { //todo replace with loop and replace Long.MAX_VALUE with buffer size? if (fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE) != 0) { try (FileInputStream fis = new FileInputStream(downloadFile.toFile())) { if (DigestUtils.md5Hex(fis).equals("4b844f588672e6616bd6f006253d6148")) { ZipFile zipFile = new ZipFile(downloadFile.toFile()); zipFile.extractAll(activeMQFolder.getPath()); } else { throw new IOException("md5 digest did not match, aborting"); } } } } }
From source file:com.facebook.buck.util.unarchive.Untar.java
/** Sets the modification time and the execution bit on a file */ private void setAttributes(ProjectFilesystem filesystem, Path path, TarArchiveEntry entry) throws IOException { Path filePath = filesystem.getRootPath().resolve(path); File file = filePath.toFile(); file.setLastModified(entry.getModTime().getTime()); Set<PosixFilePermission> posixPermissions = MorePosixFilePermissions.fromMode(entry.getMode()); if (posixPermissions.contains(PosixFilePermission.OWNER_EXECUTE)) { // setting posix file permissions on a symlink does not work, so use File API instead if (entry.isSymbolicLink()) { file.setExecutable(true, true); } else {/*from w w w .j a va 2s.c om*/ MostFiles.makeExecutable(filePath); } } }