List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:au.edu.uq.cmm.paul.servlet.WebUIController.java
private ArrayList<BuildInfo> loadBuildInfo(ServletContext servletContext) { final ArrayList<BuildInfo> res = new ArrayList<>(); res.add(BuildInfo.readBuildInfo("au.edu.uq.cmm", "aclslib")); res.add(BuildInfo.readBuildInfo("au.edu.uq.cmm", "eccles")); try {// www .ja va2 s. co m Path start = FileSystems.getDefault().getPath(servletContext.getRealPath("/META-INF/maven")); Files.walkFileTree(start, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().equals("pom.properties")) { try (InputStream is = new FileInputStream(file.toFile())) { res.add(BuildInfo.readBuildInfo(is)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException ex) { LOG.error("Problem loading build info"); } return res; }
From source file:org.sonar.java.AbstractJavaClasspath.java
private static Set<File> getMatchingDirs(String pattern, Path dir) throws IOException { if (!StringUtils.isEmpty(pattern)) { // find all dirs and subdirs that match the pattern PathMatcher matcher = FileSystems.getDefault().getPathMatcher(getGlob(dir, pattern)); return new DirFinder().find(dir, matcher); } else {/*from ww w . j av a 2 s. c o m*/ // no pattern, so we just return dir return Collections.singleton(dir.toFile()); } }
From source file:uk.ac.ebi.metabolights.webservice.utils.FileUtil.java
/** * Delete a single file/*from w w w . java2 s . c o m*/ * * @param fileName to be deleted * @return success/fail status * @author jrmacias * @date 20151012 */ public static boolean deleteFile(String fileName) { boolean result = false; try { // try to delete the file result = Files.deleteIfExists(FileSystems.getDefault().getPath(fileName)); logger.info("File {} have {} been deleted.", fileName, result ? "successfully" : "not"); } catch (IOException ex) { logger.error("Error deleting file: {}", ex.getMessage()); } return result; }
From source file:com.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java
private void _setupFileRenameMatcher() throws Exception { FileSystem fileSystem = FileSystems.getDefault(); pathMatcher = fileSystem.getPathMatcher("glob:**/" + candidateFilesPatternForRename); }
From source file:httpUtils.HttpUtils.java
/** * Get the file as an HttpServletResponse * @param request//from w w w .j a va 2s .c o m * @param response * @param file * @return */ public static HttpServletResponse getAssetAsStream(HttpServletRequest request, HttpServletResponse response, File file) { InputStream dataStream = null; try { dataStream = new FileInputStream(file); } catch (FileNotFoundException e) { log.warn("file not found", e); } long fileLength = file.length(); String fileName = file.getName(); long fileLastModified = file.lastModified(); String contentType = null; Path path = FileSystems.getDefault().getPath("", file.getPath()); try { contentType = Files.probeContentType(path); } catch (IOException e) { log.warn("content type determination failed", e); } //TODO make this better if (fileName.endsWith("js") && contentType == null) { contentType = "application/javascript"; } else if (fileName.endsWith("css") && contentType == null) { contentType = "text/css"; } return getFileAsStream(request, response, dataStream, fileLength, fileName, fileLastModified, contentType); }
From source file:org.apache.solr.core.StandardDirectoryFactory.java
public void renameWithOverwrite(Directory dir, String fileName, String toName) throws IOException { Directory baseDir = getBaseDir(dir); if (baseDir instanceof FSDirectory) { Path path = ((FSDirectory) baseDir).getDirectory().toAbsolutePath(); try {//from w w w .java 2s. c om Files.move(path.resolve(fileName), path.resolve(toName), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); } catch (AtomicMoveNotSupportedException e) { Files.move(FileSystems.getDefault().getPath(path.toString(), fileName), FileSystems.getDefault().getPath(path.toString(), toName), StandardCopyOption.REPLACE_EXISTING); } } else { super.renameWithOverwrite(dir, fileName, toName); } }
From source file:org.xenmaster.setup.debian.Bootstrapper.java
protected boolean downloadNetbootFiles() { if (System.currentTimeMillis() - lastChecked < 50 * 60 * 1000) { return false; }/*from ww w .jav a 2s. c om*/ File localVersionFile = new File(Settings.getInstance().getString("StorePath") + "/netboot/version"); int localVersion = -1; try (FileInputStream fis = new FileInputStream(localVersionFile)) { localVersion = Integer.parseInt(IOUtils.toString(fis)); } catch (IOException | NumberFormatException ex) { Logger.getLogger(getClass()).error("Failed to retrieve local version file", ex); } int remoteVersion = -1; try { remoteVersion = Integer.parseInt(IOUtils.toString(XenMasterSite.getFileAsStream("/netboot/version"))); } catch (IOException | NumberFormatException ex) { Logger.getLogger(getClass()).error("Failed to retrieve remote version file", ex); } lastChecked = System.currentTimeMillis(); if (localVersion < remoteVersion) { Logger.getLogger(getClass()) .info("New version " + remoteVersion + " found. Please hold while downloading netboot data"); try { TarArchiveInputStream tais = new TarArchiveInputStream( new GZIPInputStream(XenMasterSite.getFileAsStream("/netboot/netboot.tar.gz"))); TarArchiveEntry tae = null; FileOutputStream fos = null; while ((tae = tais.getNextTarEntry()) != null) { if (tais.canReadEntryData(tae)) { String target = Settings.getInstance().getString("StorePath") + "/" + tae.getName(); if (tae.isSymbolicLink()) { Path targetFile = FileSystems.getDefault().getPath(tae.getLinkName()); Path linkName = FileSystems.getDefault().getPath(target); // Link might already have been written as null file if (targetFile.toFile().exists()) { targetFile.toFile().delete(); } Files.createSymbolicLink(linkName, targetFile); Logger.getLogger(getClass()).info( "Created sym link " + linkName.toString() + " -> " + targetFile.toString()); } else if (tae.isDirectory()) { new File(target).mkdir(); Logger.getLogger(getClass()).info("Created dir " + target); } else if (tae.isFile()) { fos = new FileOutputStream(target); byte[] b = new byte[1024]; int curPos = 0; while (tais.available() > 0) { tais.read(b, curPos, 1024); fos.write(b, curPos, 1024); } fos.flush(); fos.close(); Logger.getLogger(getClass()).info("Wrote file " + target); } } } tais.close(); // Write local version IOUtils.write("" + remoteVersion, new FileOutputStream(localVersionFile)); } catch (IOException ex) { Logger.getLogger(getClass()).error("Failed to download netboot files", ex); } } else { return false; } return true; }
From source file:com.twosigma.beaker.groovy.utils.GroovyEvaluator.java
public void setShellOptions(String cp, String in, String od) throws IOException { if (od == null || od.isEmpty()) { od = FileSystems.getDefault().getPath(System.getenv("beaker_tmp_dir"), "dynclasses", sessionId) .toString();//w w w . j a v a2s . c om } else { od = od.replace("$BEAKERDIR", System.getenv("beaker_tmp_dir")); } // check if we are not changing anything if (currentClassPath.equals(cp) && currentImports.equals(in) && outDirInput.equals(od)) return; currentClassPath = cp; currentImports = in; Map<String, String> env = System.getenv(); outDirInput = od; outDir = envVariablesFilter(od, env); if (cp.isEmpty()) classPath = new ArrayList<String>(); else { List<String> cpList = new ArrayList<String>(); for (String p : Arrays.asList(cp.split("[\\s" + File.pathSeparatorChar + "]+"))) { p = envVariablesFilter(p, env); cpList.add(p); } classPath = cpList; } if (!in.isEmpty()) { String[] importLines = in.split("\\n+"); for (String line : importLines) { if (!line.trim().isEmpty()) { imports.add(line); } } } try { (new File(outDir)).mkdirs(); } catch (Exception e) { } resetEnvironment(); }
From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java
public List<SyncFile> findByParentFilePathName(String parentFilePathName) throws SQLException { QueryBuilder<SyncFile, Long> queryBuilder = queryBuilder(); Where<SyncFile, Long> where = queryBuilder.where(); FileSystem fileSystem = FileSystems.getDefault(); parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\"); where.like("filePathName", new SelectArg(parentFilePathName + "%")); return where.query(); }
From source file:cpd3314.project.CPD3314ProjectTest.java
@Test public void testFormatYAML() throws Exception { System.out.println("main"); String[] args = { "-format=YAML" }; CPD3314Project.main(args);// w w w .j a va 2s . c om File expected = FileSystems.getDefault().getPath("testFiles", "formatYAML.yaml").toFile(); File result = new File("CPD3314.yaml"); assertTrue("Output File Doesn't Exist", result.exists()); assertYAMLFilesEqual(expected, result); }