List of usage examples for java.io File toPath
public Path toPath()
From source file:ch.ivyteam.ivy.maven.IarDeployMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skipDeploy) { getLog().info("Skipping deployment of project."); return;/*from w ww . ja v a 2 s . c o m*/ } if (!deployIarFile.exists()) { getLog().warn("Skipping IAR deployment of '" + deployIarFile + "'. The file does not exist."); return; } File deployDir = getDeployDirectory(); if (!deployDir.exists()) { getLog().warn("Skipping IAR deployment to engine '" + deployEngineDirectory + "'. The directory '" + deployDir + "' does not exist."); return; } File uploadedIar = copyIarToEngine(deployDir); String iarPath = deployDir.toPath().relativize(uploadedIar.toPath()).toString(); IvyProjectDeployer deployer = new MarkerFileDeployer(deployDir, deployTimeoutInSeconds); deployer.deployIar(iarPath, getLog()); }
From source file:io.druid.query.groupby.epinephelinae.LimitedTemporaryStorage.java
/** * Create a new temporary file. All methods of the returned output stream may throw * {@link TemporaryStorageFullException} if the temporary storage area fills up. * * @return output stream to the file//from ww w. ja va2 s . c o m * * @throws TemporaryStorageFullException if the temporary storage area is full * @throws IOException if something goes wrong while creating the file */ public LimitedOutputStream createFile() throws IOException { if (bytesUsed.get() >= maxBytesUsed) { throw new TemporaryStorageFullException(maxBytesUsed); } synchronized (files) { if (closed) { throw new ISE("Closed"); } FileUtils.forceMkdir(storageDirectory); final File theFile = new File(storageDirectory, StringUtils.format("%08d.tmp", files.size())); final EnumSet<StandardOpenOption> openOptions = EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE); final FileChannel channel = FileChannel.open(theFile.toPath(), openOptions); files.add(theFile); return new LimitedOutputStream(theFile, Channels.newOutputStream(channel)); } }
From source file:com.linkedin.pinot.filesystem.LocalPinotFS.java
@Override public boolean move(URI srcUri, URI dstUri) throws IOException { File srcFile = new File(srcUri); File dstFile = new File(dstUri); if (dstFile.exists()) { FileUtils.deleteQuietly(dstFile); }//from w w w . j a v a 2s . c o m if (!srcFile.isDirectory()) { dstFile.getParentFile().mkdirs(); FileUtils.moveFile(srcFile, dstFile); } if (srcFile.isDirectory()) { Files.move(srcFile.toPath(), dstFile.toPath()); } return true; }
From source file:io.druid.segment.loading.LocalDataSegmentPusher.java
private DataSegment createDescriptorFile(DataSegment segment, File outDir) throws IOException { File descriptorFile = new File(outDir, "descriptor.json"); log.info("Creating descriptor file at[%s]", descriptorFile); // Avoid using Guava in DataSegmentPushers because they might be used with very diverse Guava versions in // runtime, and because Guava deletes methods over time, that causes incompatibilities. Files.write(descriptorFile.toPath(), jsonMapper.writeValueAsBytes(segment)); return segment; }
From source file:com.github.wasiqb.coteafs.appium.service.AppiumServer.java
/** * @author wasiq.bhamla//from ww w.java 2 s. c o m * @since Oct 27, 2017 3:00:49 PM */ private void setLogFile() { final String logFilePath = this.setting.getLogFilePath(); if (logFilePath != null) { final File logFile = new File(logFilePath); try { if (logFile.exists()) { Files.delete(logFile.toPath()); } } catch (final IOException e) { fail(AppiumServerLogFileError.class, "Error while deleting log file!", e); } this.builder = this.builder.withLogFile(logFile); } }
From source file:com.fujitsu.dc.engine.extension.support.ExtensionJarLoader.java
/** * ExtensionJarDirectory?? jar?URL??.//from www. jav a 2 s .com * ???? "jar"???? * @param extJarDir Extensionjar?? * @param searchDescend true: ?, false: ???? * @return jar? URL. */ private List<URL> getJarPaths(Path extJarDir, boolean searchDescend) throws DcEngineException { try { // ?? List<URL> uriList = new ArrayList<URL>(); // jar????? uriList.add(new URL("file", "", extJarDir.toFile().getAbsolutePath() + "/")); // jar? File[] jarFiles = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (!pathname.exists() || !pathname.canRead() || pathname.isDirectory()) { return false; } return FilenameUtils.isExtension(pathname.getName(), JAR_SUFFIX); } }); if (null != jarFiles) { for (File jarFile : jarFiles) { try { uriList.add(new URL("file", "", jarFile.getCanonicalPath())); log.info(String.format("Info: Adding extension jar file %s to classloader.", jarFile.toURI())); } catch (MalformedURLException e) { // ############################################################################3 // ????????? jar???????? jar???? // ? Extension????????? Extension????? UserScript?? // ???????????? // ?? Extension?????Script??? // ############################################################################3 log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } catch (IOException e) { log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } } } // ? File[] subDirs = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.exists() && pathname.isDirectory() && pathname.canRead(); } }); if (null != subDirs) { for (File subDir : subDirs) { // jar? uriList.addAll(getJarPaths(subDir.toPath(), searchDescend)); } } return uriList; } catch (RuntimeException e) { e.printStackTrace(); log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new DcEngineException("Error occured while loading Extension.", DcEngineException.STATUSCODE_SERVER_ERROR, e); } catch (Exception e) { log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new DcEngineException("Error occured while loading Extension.", DcEngineException.STATUSCODE_SERVER_ERROR, e); } }
From source file:com.liferay.blade.cli.ConvertThemeCommand.java
private boolean compassSupport(String themePath) throws Exception { File themeDir = new File(themePath); File customCss = new File(themeDir, "docroot/_diffs/css/custom.css"); if (!customCss.exists()) { customCss = new File(themeDir, "docroot/_diffs/css/_custom.scss"); }/*from www. j av a 2s. c o m*/ if (!customCss.exists()) { return false; } String css = new String(Files.readAllBytes(customCss.toPath())); Matcher matcher = _compassImport.matcher(css); return matcher.find(); }
From source file:io.personium.engine.extension.support.ExtensionJarLoader.java
/** * ExtensionJarDirectory?? jar?URL??.//from ww w . j av a2 s. c o m * ???? "jar"???? * @param extJarDir Extensionjar?? * @param searchDescend true: ?, false: ???? * @return jar? URL. */ private List<URL> getJarPaths(Path extJarDir, boolean searchDescend) throws PersoniumEngineException { try { // ?? List<URL> uriList = new ArrayList<URL>(); // jar????? uriList.add(new URL("file", "", extJarDir.toFile().getAbsolutePath() + "/")); // jar? File[] jarFiles = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (!pathname.exists() || !pathname.canRead() || pathname.isDirectory()) { return false; } return FilenameUtils.isExtension(pathname.getName(), JAR_SUFFIX); } }); if (null != jarFiles) { for (File jarFile : jarFiles) { try { uriList.add(new URL("file", "", jarFile.getCanonicalPath())); log.info(String.format("Info: Adding extension jar file %s to classloader.", jarFile.toURI())); } catch (MalformedURLException e) { // ############################################################################3 // ????????? jar???????? jar???? // ? Extension????????? Extension????? UserScript?? // ???????????? // ?? Extension?????Script??? // ############################################################################3 log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } catch (IOException e) { log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } } } // ? File[] subDirs = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.exists() && pathname.isDirectory() && pathname.canRead(); } }); if (null != subDirs) { for (File subDir : subDirs) { // jar? uriList.addAll(getJarPaths(subDir.toPath(), searchDescend)); } } return uriList; } catch (RuntimeException e) { e.printStackTrace(); log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new PersoniumEngineException("Error occured while loading Extension.", PersoniumEngineException.STATUSCODE_SERVER_ERROR, e); } catch (Exception e) { log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new PersoniumEngineException("Error occured while loading Extension.", PersoniumEngineException.STATUSCODE_SERVER_ERROR, e); } }
From source file:cross.datastructures.pipeline.ResultAwareCommandPipeline.java
/** * Calculates a byte-level digest of the given files. * * @param files the files to calculate the digest for. * @return the hexadecimal, zero-padded digest, or null if any exceptions * occurred//from w w w .j ava 2 s.c o m */ public String digest(Collection<File> files) { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); for (File file : files) { try (InputStream is = Files.newInputStream(file.toPath(), StandardOpenOption.READ)) { byte[] buffer = new byte[8192]; int read = 0; while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } } catch (IOException ioex) { Logger.getLogger(ResultAwareCommandPipeline.class.getName()).log(Level.SEVERE, null, ioex); return null; } } byte[] sha1 = digest.digest(); BigInteger bigInt = new BigInteger(1, sha1); return StringUtils.leftPad(bigInt.toString(16), 40, "0"); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(ResultAwareCommandPipeline.class.getName()).log(Level.SEVERE, null, ex); } return null; }