List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:org.openflexo.toolbox.FileUtils.java
public static boolean createNewFile(File newFile) throws IOException { boolean ret = false; if (!newFile.exists()) { if (!newFile.getParentFile().exists()) { ret = newFile.getParentFile().mkdirs(); if (!ret) { newFile = newFile.getCanonicalFile(); ret = newFile.getParentFile().mkdirs(); }// w w w.j av a2s. c om if (!ret) { System.err.println("WARNING: cannot create directory: " + newFile.getParent() + " createNewFile(File)[" + FileUtils.class.getName() + "]"); } } try { ret = newFile.createNewFile(); } catch (IOException e) { newFile = newFile.getCanonicalFile(); ret = newFile.createNewFile(); if (!ret) { System.err.println("WARNING: cannot create file: " + newFile.getAbsolutePath() + " createNewFile(File)[" + FileUtils.class.getName() + "]"); } } } return ret; }
From source file:org.nuxeo.ecm.webengine.model.impl.DirectoryStack.java
/** * Gets the file given its name in this virtual directory. * <p>/* w ww . j a v a2s .c om*/ * The canonical file is returned if any file is found * * @param name the file name to lookup * @return the file in the canonical form * * @throws IOException */ public File getFile(String name) throws IOException { for (File entry : dirs) { File file = new File(entry, name); if (file.exists()) { return file.getCanonicalFile(); } } return null; }
From source file:org.lilyproject.runtime.source.ModuleSourceManager.java
private String getKey(File location) { try {//from w ww . ja v a 2 s .co m return location.getCanonicalFile().getAbsolutePath(); } catch (IOException e) { throw new LilyRTException("Error making key for module source location " + location, e); } }
From source file:org.jetbrains.teamcity.widgets.WidgetContentController.java
@Override protected boolean isLegalPath(@NotNull File maybeChild, @NotNull File possibleParent) throws IOException { final File parent = possibleParent.getCanonicalFile(); File child = maybeChild.getCanonicalFile(); while (child != null) { if (child.equals(parent)) { return true; }// www .ja v a 2 s . co m child = child.getParentFile(); } return false; }
From source file:com.samczsun.helios.tasks.AddFilesTask.java
private void handle(File file) throws IOException { if (file.getCanonicalFile().isDirectory()) { handleDirectory(file);/*from w ww . java 2 s . com*/ } else { handleFile(file); } }
From source file:org.nuxeo.ecm.webengine.loader.store.FileResourceStore.java
public FileResourceStore(File root) throws IOException { this.root = root.getCanonicalFile(); }
From source file:com.iqiyi.demo.fileoperator.ui.activity.FileExplorerActivity.java
@Subscribe public void onClickFile(FileExplorerEvents.OnClickFile event) { File f = event.mFile; try {/* www. j a v a2 s . c om*/ f = f.getAbsoluteFile(); f = f.getCanonicalFile(); if (TextUtils.isEmpty(f.toString())) f = new File("/"); } catch (IOException e) { e.printStackTrace(); } if (f.isDirectory()) { String path = f.toString(); Toast.makeText(this, "Enter path : \n" + f.toString(), Toast.LENGTH_LONG).show(); doOpenDirectory(path, true); } else if (f.exists()) { Toast.makeText(this, "Path : \n" + f.getPath() + "\n" + f.getName(), Toast.LENGTH_LONG).show(); } }
From source file:org.echocat.nodoodle.transport.HandlerUnpackerTest.java
@Test public void testUnpack() throws Exception { final HandlerPacker packer = new HandlerPacker(new NodoodleInformationFactory()); final HandlerUnpacker unpacker = new HandlerUnpacker(null); final File file = new File(System.getProperty("java.io.tmpdir"), "nodoodle/test.zip"); file.getCanonicalFile().getParentFile().mkdirs(); final FileOutputStream fos = new FileOutputStream(file); final ServletImpl servlet1 = new ServletImpl(); // noinspection AccessingNonPublicFieldOfAnotherObject servlet1._test = "abc"; servlet1.handle(null, null);//from ww w . java2 s .c om try { packer.pack(servlet1, fos); } finally { IOUtils.closeQuietly(fos); } final FileInputStream fis = new FileInputStream(file); try { final HandlerUnpacker.Result result = unpacker.unpack("", fis); final Handler<?> servlet = result.getHandler(); assertThat(servlet, IsNull.<Object>notNullValue()); servlet.handle(null, null); } finally { IOUtils.closeQuietly(fis); } }
From source file:com.cloudera.recordbreaker.schemadict.SchemaDictionary.java
/** * Load the schema dictionary from the given directory. *//* w w w. java 2 s.c o m*/ public SchemaDictionary(File dir) throws IOException { this.dir = dir.getCanonicalFile(); if (!dir.exists()) { if (!dir.mkdirs()) { throw new IOException("Could not create: " + dir); } } File dictFiles[] = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(SchemaDictionaryEntry.SUMMARY_ENDING); } }); for (int i = 0; i < dictFiles.length; i++) { String name = dictFiles[i].getName(); String fileRoot = name.substring(0, name.length() - SchemaDictionaryEntry.SUMMARY_ENDING.length()); SchemaDictionaryEntry sde = new SchemaDictionaryEntry(); sde.loadDictionaryEntry(dir, fileRoot); dictElts.add(sde); } }
From source file:cn.jarlen.mediaplayer.sample.activities.FileExplorerActivity.java
@Subscribe public void onClickFile(FileExplorerEvents.OnClickFile event) { File f = event.mFile; try {/* w w w . jav a2 s . c o m*/ f = f.getAbsoluteFile(); f = f.getCanonicalFile(); if (TextUtils.isEmpty(f.toString())) f = new File("/"); } catch (IOException e) { e.printStackTrace(); } if (f.isDirectory()) { String path = f.toString(); mSettings.setLastDirectory(path); doOpenDirectory(path, true); } else if (f.exists()) { VideoActivity.intentTo(this, f.getPath(), f.getName()); } }