List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:net.dv8tion.jda.core.utils.SimpleLog.java
/** * Sets up a File to log all messages that are not visible via sout and serr and meet a given log-level criteria. * All logs that would not be printed and are above given logLevel are printed to that File. * If you want to log Logs printed to sout and serr to file(s), use {@link #addFileLogs(java.io.File, java.io.File)} instead. * * @param logLevel/* w ww. j av a 2s . c o m*/ * The log-level criteria. Only logs equal or above this level are printed to the File * @param file * The File where the logs should be printed * @throws java.io.IOException * If the File can't be canonically resolved (access denied) */ public static void addFileLog(Level logLevel, File file) throws IOException { File canonicalFile = file.getCanonicalFile(); if (!fileLogs.containsKey(logLevel)) { fileLogs.put(logLevel, new HashSet<>()); } fileLogs.get(logLevel).add(canonicalFile); }
From source file:org.neo4j.io.fs.FileUtils.java
public static File getMostCanonicalFile(File file) { try {//from w w w.ja v a 2s.com return file.getCanonicalFile().getAbsoluteFile(); } catch (IOException e) { return file.getAbsoluteFile(); } }
From source file:net.dv8tion.jda.core.utils.SimpleLog.java
/** * Removes all File-logs created via {@link #addFileLog(net.dv8tion.jda.core.utils.SimpleLog.Level, java.io.File)} with given File. * To remove the sout and serr logs, call {@link #addFileLogs(java.io.File, java.io.File)} with null args. * * @param file/*from w w w . j a va2s.co m*/ * The file to remove from all FileLogs (except sout and serr logs) * @throws java.io.IOException * If the File can't be canonically resolved (access denied) */ public static void removeFileLog(File file) throws IOException { File canonicalFile = file.getCanonicalFile(); Iterator<Map.Entry<Level, Set<File>>> setIter = fileLogs.entrySet().iterator(); while (setIter.hasNext()) { Map.Entry<Level, Set<File>> set = setIter.next(); Iterator<File> fileIter = set.getValue().iterator(); while (fileIter.hasNext()) { File logFile = fileIter.next(); if (logFile.equals(canonicalFile)) { fileIter.remove(); break; } } if (set.getValue().isEmpty()) { setIter.remove(); } } }
From source file:info.schnatterer.songbirdDbTools.commands.playlist.ExportPlaylistsCommand.java
/** * Aggregates a list of member absolute paths from a {@link SimpleMediaList}. * //from w ww. j a va 2 s. c o m * @param simpleMediaList * the media list to read the member objects from * @return all member files as absolute string Urls */ private static List<String> getMemberPaths(final SimpleMediaList simpleMediaList) { List<String> memberFiles = new LinkedList<String>(); for (MemberMediaItem member : simpleMediaList.getMembers()) { MediaItem m = member.getMember(); try { File file = new File(new URI(m.getContentUrl())); /* * Make sure Songbird's slash-separated URI work (even on Windows). If this step is omitted, * relativize() is not going to work */ file = file.getCanonicalFile(); memberFiles.add(file.getAbsolutePath()); } catch (Exception e) { logger.warn(simpleMediaList.getList().getProperty(Property.PROP_MEDIA_LIST_NAME) + ": Unable to add path to playlist: " + m.getContentUrl() + ": \"" + e.getMessage() + "\". Omitting file...", e); // So we use the absolute path instead... } } return memberFiles; }
From source file:net.menthor.editor.v2.util.Util.java
public static File chooseFile(Component parent, String lastPath, String dialogTitle, String fileDescription, String fileExtension, String fileExtension2, boolean checkOverrideFile) throws IOException { JFileChooser fileChooser = createChooser(lastPath, checkOverrideFile); fileChooser.setDialogTitle(dialogTitle); FileNameExtensionFilter filter = new FileNameExtensionFilter(fileDescription, fileExtension, fileExtension2);/*ww w .j ava2s . c o m*/ fileChooser.addChoosableFileFilter(filter); if (SystemUtil.onWindows()) fileChooser.setFileFilter(filter); fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showDialog(parent, "Ok") == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (!(file.getName().endsWith("." + fileExtension)) && !(file.getName().endsWith("." + fileExtension2))) { file = new File(file.getCanonicalFile() + "." + fileExtension2); } else { file = new File(file.getCanonicalFile() + ""); } return file; } else { return null; } }
From source file:io.logspace.agent.hq.HqAgentController.java
private static File getFile(String path, String agentControllerId) { String resolvedPath = resolveProperties(path); File file = new File(resolvedPath); try {/*from ww w .jav a 2 s . co m*/ file = file.getCanonicalFile(); } catch (IOException e) { // ignore this } return new File(file.getAbsoluteFile(), createQueueFileName(agentControllerId)); }
From source file:Testing.TestMain.java
public static List<File> hyperAVAJAVAFileMp3Scan(File root, TreeItem<File> parent) { try {/*from w ww .j a va2 s. c om*/ TreeItem<File> treeRoot = new TreeItem<>(root); String[] extensions = new String[] { "mp3" }; root.getCanonicalPath(); List<File> returnedFiles = new LinkedList<File>(); List<File> files = (List<File>) FileUtils.listFiles(root, extensions, true); for (File file : files) { if (!file.toString().contains("$RECYCLE.BIN")) { System.out.println(file.toString()); returnedFiles.add(file.getCanonicalFile()); } } return returnedFiles; } catch (IOException ex) { Logger.getLogger(TestMain.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:org.apache.spark.network.util.JavaUtils.java
private static boolean isSymlink(File file) throws IOException { Preconditions.checkNotNull(file);/*from ww w . ja va2s . com*/ File fileInCanonicalDir = null; if (file.getParent() == null) { fileInCanonicalDir = file; } else { fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); } return !fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile()); }
From source file:org.eclipse.thym.core.internal.util.FileUtils.java
public static File[] untarFile(File source, File outputDir) throws IOException, TarException { TarFile tarFile = new TarFile(source); List<File> untarredFiles = new ArrayList<File>(); try {// www .j a v a 2s.c om for (Enumeration<TarEntry> e = tarFile.entries(); e.hasMoreElements();) { TarEntry entry = e.nextElement(); InputStream input = tarFile.getInputStream(entry); try { File outFile = new File(outputDir, entry.getName()); outFile = outFile.getCanonicalFile(); //bug 266844 untarredFiles.add(outFile); if (entry.getFileType() == TarEntry.DIRECTORY) { outFile.mkdirs(); } else { if (outFile.exists()) outFile.delete(); else outFile.getParentFile().mkdirs(); try { copyStream(input, false, new FileOutputStream(outFile), true); } catch (FileNotFoundException e1) { // TEMP: ignore this for now in case we're trying to replace // a running eclipse.exe } outFile.setLastModified(entry.getTime()); } } finally { input.close(); } } } finally { tarFile.close(); } return untarredFiles.toArray(new File[untarredFiles.size()]); }
From source file:name.npetrovski.jphar.DataEntry.java
/** * Create entry from file//www. ja v a 2 s .com * */ public static DataEntry createFromFile(File file, Compression.Type compression) throws IOException { EntryManifest em = new EntryManifest(); em.setCompression(new Compression(compression)); em.setTimestamp((int) file.lastModified() / 1000); em.getPath().setName(file.toPath().toString().replace("\\", "/")); DataEntry entry = new DataEntry(em); entry.setSource(file.getCanonicalFile()); if (file.isDirectory()) { em.getCompression().setType(Compression.Type.NONE); } else { byte[] data = Files.readAllBytes(file.toPath()); CRC32 crc = new CRC32(); crc.update(data); em.setCRC32((int) crc.getValue()); em.setUncompressedSize(data.length); } return entry; }