public void setOnChange(Consumer<T> changeConsumer) { this.changeConsumer = changeConsumer; notifyConsumer(); }
/** * fetches content of the given file * @param file * @return content string * @throws IOException */ public String getFileContent(File file) throws IOException { assertInDirectory(file); return FileUtils.readFileToString(file, "UTF-8"); }
private void notifyConsumer() { if (changeConsumer != null) { changeConsumer.accept(defineWatchedObject()); } }
@Override public void onDelete() { try { fileUtilities.remove(this.localFolder); LOGGER.info("Deleted " + this); } catch (IOException e) { LOGGER.error("Couldn't delete " + this, e); } }
public static String identifyLineDelimiter(File fileToAnalyse) throws IOException { final String fileContent = FileUtils.readFileToString(fileToAnalyse); return identifyLineDelimiter(fileContent); }
@Bean public FileSearcher fileSearcher() { return new FileSearcher(); }
@Bean public FileUtilities fileUtilities() { return new FileUtilities(); }
@Bean public FileSizeUtilities fileSizeUtilities() { return new FileSizeUtilities(); }
@Bean public FileAnalyser fileAnalyser() { return new FileAnalyser(); }
@Bean public FreeSpaceFetcher freeSpaceFetcher() { return new FreeSpaceFetcher(); }
@Bean public FileCopier fileCopier() { return new FileCopier(); }
public long getFreeSpace(String directory) { return getFreeSpace(new File(directory)); } }
public List<File> search(String directory, String name) { return search(new File(directory), name); }
public Set<PosixFilePermission> octToPosixFilePermission(int modeOct) { // TODO: optimize this method and make it cleaner int modeInt = Integer.parseInt(Integer.toString(modeOct, 8)); return intToPosixFilePermission(modeInt); } }
private boolean isInSubDirectory(File directory, File fileIside) { return fileIside != null && (fileIside.equals(directory) || isInSubDirectory(directory, fileIside.getParentFile())); }
public Set<PosixFilePermission> intToPosixFilePermission(int mode) { if (mode >= 1000 || mode < 0) { throw new IllegalArgumentException("Invalid mode " + mode); } final int owner = mode / 100; final int group = (mode - owner * 100) / 10; final int others = mode - owner * 100 - group * 10; if (owner > 7 || group > 7 || others > 7) { throw new IllegalArgumentException("Invalid mode " + mode); } return Sets.union( Sets.union(singleIntToFilePermission(owner, "OWNER"), singleIntToFilePermission(group, "GROUP")), singleIntToFilePermission(others, "OTHERS")); }
public String getDescription(File inputFile) { try { return getMatch(inputFile).getDescription(); } catch (MagicMatchNotFoundException e) { throw new IllegalStateException("Unable to detect mimetype of the file", e); } }
/** * creates a directory * @param directoryToCreate */ public void mkdir(File directoryToCreate) { assertInDirectory(directoryToCreate); directoryToCreate.mkdirs(); }
/** * writes content to file * @param file * @param content * @throws IOException */ public void writeToFile(File file, String content) throws IOException { assertInDirectory(file); FileUtils.writeStringToFile(file, content, "UTF-8"); }
/** * creates symbolic link * @param destination * @param target * @throws IOException */ public void createSymbolicLink(File destination, File target) throws IOException { assertInDirectory(destination); assertInDirectory(target); Files.createSymbolicLink(destination.toPath(), target.toPath()); }