Refine search
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; // ... Path p = FileSystems.getDefault().getPath("", "myFile"); byte [] fileData = Files.readAllBytes(p);
@Signature(@Arg("pattern")) public Memory matches(Environment env, Memory... args) { FileSystem aDefault = FileSystems.getDefault(); PathMatcher pathMatcher = aDefault.getPathMatcher(args[0].toString()); return pathMatcher.matches(aDefault.getPath(file.getPath())) ? Memory.TRUE : Memory.FALSE; }
/** * Creates a FileSystemXAResourceRegistry. * * @param relativePath the path recovery dir is relative to */ FileSystemXAResourceRegistry (LocalTransactionProvider provider, Path relativePath) { this.provider = provider; if (relativePath == null) this.xaRecoveryPath = FileSystems.getDefault().getPath(RECOVERY_DIR); else this.xaRecoveryPath = relativePath.resolve(RECOVERY_DIR); }
default File createDataDir(String dataDirLoc) throws IOException { Path dataDirPath = FileSystems.getDefault().getPath(dataDirLoc); Files.createDirectories(dataDirPath); return dataDirPath.toFile(); }
public static String getCurrentWorkingDirectoryPath() { return FileSystems.getDefault().getPath("").toAbsolutePath().toString(); }
public String deleteBackup(String aFilename) { log.debug("Delete backup repository: " + aFilename); try { Files.delete(FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename)); } catch (IOException e) { log.error("Could not delete file: " + aFilename + " message: " + e.getMessage(), e); } return aFilename; }
public void watch(File file) throws IOException { String dirString; if (file.isFile()) { dirString = file.getParentFile().getAbsolutePath(); } else { throw new IOException(file.getName() + " is not a file"); } if (dirString == null) { dirString = "/"; } Path dir = FileSystems.getDefault().getPath(dirString); logger.info("watch " + dir); WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); synchronized (watchKeys) { watchKeys.put(key, new File(dirString)); watchFiles.add(file); } }
public static <T> PersistentAtomicReference<T> create(final String filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return create(FileSystems.getDefault().getPath(filename), javaType, initialValue); }
/** * @param url URL or path to check and convert to URL. * @return URL. * @throws SQLException If URL is invalid. */ private static String checkAndConvertUrl(String url) throws SQLException { try { return new URL(url).toString(); } catch (MalformedURLException e) { try { return FileSystems.getDefault().getPath(url).toUri().toURL().toString(); } catch (MalformedURLException e1) { throw new SQLException("Invalid keystore UR: " + url, SqlStateCode.CLIENT_CONNECTION_FAILED, e); } } } }
public String backup(String aFilename) { if(aFilename == null || aFilename.equalsIgnoreCase("")) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); aFilename = defaultName + dateFormat.format(Calendar.getInstance().getTime()) + fileExtension; } else aFilename = aFilename + fileExtension; try { Files.copy(repositoryPath, FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename), StandardCopyOption.COPY_ATTRIBUTES); } catch (IOException e) { log.error("Could not backup to file: " + aFilename + " message: " + e.getMessage(), e); } log.debug("Backup repository: " + aFilename); return aFilename; }
public String restoreBackup(String aFilename) { log.debug("Restore backup repository: " + aFilename); try { Path target = null; if(Files.exists(repositoryPath)) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); target = FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), defaultName + dateFormat.format(Calendar.getInstance().getTime()) + fileExtension); Files.move(repositoryPath, target); } Files.copy(FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename), repositoryPath, StandardCopyOption.COPY_ATTRIBUTES); } catch (IOException e) { log.error("Error restoring the file: " + aFilename + " message: " + e.getMessage(), e); return null; } return aFilename; }
@Override public String validate(String value) { final Path path = FileSystems.getDefault().getPath(value); if (path == null && value != null) { return String.format("Path '%s' provided could not be located.", value); } final boolean isDir = Files.isDirectory(path); final boolean isWritable = Files.isWritable(path); if (!isDir) { return String.format("Path '%s' provided is not a directory.", value); } if (!isWritable) { return String.format("Path '%s' provided is not writable.", value); } return null; }
static void writeXML(Object obj, String fileName) { try { Path p = FileSystems.getDefault().getPath(resolveFileName(fileName)); try (BufferedWriter bw = Files.newBufferedWriter(p, StandardCharsets.UTF_8)) { XMLSerializer.write(obj, bw); } } catch (RuntimeException re) { throw re; } catch (Exception exp) { throw new RuntimeException(exp); } }
@Override public void init(JavacTask javacTask, String... args) { Iterator<String> itr = Arrays.asList(args).iterator(); String path = null; while (itr.hasNext()) { if (itr.next().equals("--out")) { path = itr.next(); break; } } checkArgument(path != null, "No --out specified"); javacTask.addTaskListener( new RefasterRuleCompilerAnalyzer( ((BasicJavacTask) javacTask).getContext(), FileSystems.getDefault().getPath(path))); } }
public static String getFileOwner(String path) throws IOException { return Files.getOwner(FileSystems.getDefault().getPath(path)).getName(); }
private static BTraceConfig getConfig() throws IOException { FileSystem fs = FileSystems.getDefault(); Path agentPath = null; Path bootPath = null; ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader)cl).getURLs(); for (URL url: urls) { final String path = url.getPath(); if (path.contains("btrace-agent")) { agentPath = fs.getPath(path); } else if (path.contains("btrace-boot")) { bootPath = fs.getPath(path); } } if (agentPath == null) { throw new IllegalArgumentException("btrace-agent.jar not found"); } if (bootPath == null) { throw new IllegalArgumentException("btrace-boot.jar not found"); } Path tmpDir = Files.createTempDirectory("btrace-bench-"); Path targetPath = Files.copy(agentPath, tmpDir.resolve("btrace-agent.jar"), StandardCopyOption.REPLACE_EXISTING); Files.copy(bootPath, tmpDir.resolve("btrace-boot.jar"), StandardCopyOption.REPLACE_EXISTING); URL traceLoc = BTraceBench.class.getResource("/scripts/TraceScript.class"); String trace = traceLoc.getPath(); return new BTraceConfig(tmpDir, targetPath.toString(), trace); } }
private BufferedReader getReaderFor(String filePath) throws HiveException { try { Path fullFilePath = FileSystems.getDefault().getPath(filePath); Path fileName = fullFilePath.getFileName(); if (Files.exists(fileName)) { return Files.newBufferedReader(fileName, Charset.defaultCharset()); } else if (Files.exists(fullFilePath)) { return Files.newBufferedReader(fullFilePath, Charset.defaultCharset()); } else { throw new HiveException("Could not find \"" + fileName + "\" or \"" + fullFilePath + "\" in IN_FILE() UDF."); } } catch(IOException exception) { throw new HiveException(exception); } }
public static <T> PersistentAtomicReference<T> create(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return new PersistentAtomicReference<>(filename, javaType, initialValue); }
public static void main(String[] args) throws Exception { String path = args[0]; BTraceProbeFactory bpf = new BTraceProbeFactory(SharedSettings.GLOBAL); BTraceProbe bp = bpf.createProbe(new FileInputStream(path)); FileSystem fs = FileSystems.getDefault(); Path p = fs.getPath(args[1]); Files.write(p.resolve(bp.getClassName().replace(".", "_") + "_full.class"), bp.getFullBytecode()); Files.write(p.resolve(bp.getClassName().replace(".", "_") + "_dh.class"), bp.getDataHolderBytecode()); } }
private BufferedReader getReaderFor(String filePath) throws HiveException { try { Path fullFilePath = FileSystems.getDefault().getPath(filePath); Path fileName = fullFilePath.getFileName(); if (Files.exists(fileName)) { return Files.newBufferedReader(fileName, Charset.defaultCharset()); } else if (Files.exists(fullFilePath)) { return Files.newBufferedReader(fullFilePath, Charset.defaultCharset()); } else { throw new HiveException("Could not find \"" + fileName + "\" or \"" + fullFilePath + "\" in IN_FILE() UDF."); } } catch(IOException exception) { throw new HiveException(exception); } }