/** File system. */ public FileSystem getLeaderFileSystem() throws FileStateInvalidException { return leader.getFileSystem(); }
public FileSystem getFileSystem() throws FileStateInvalidException { return fileObj.getFileSystem(); }
/** Returns <code>true</code> if the filesystem is default. * @return true if this is {@link Repository#getDefaultFileSystem} */ public final boolean isDefault() { FileSystem fs = null; try { fs = FileUtil.getConfigRoot().getFileSystem(); } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); } return this == fs; }
/** Check whether the given file has been changed. * @param file file to check * @return true if the file has been affected by the change */ public boolean hasChanged(FileObject file) { if (files == null) { // all files on source filesystem are said to change try { return file.getFileSystem() == getSource(); } catch (FileStateInvalidException ex) { // invalid files should not be changed return false; } } else { // specified set of files, so check it return files.contains(file); } } }
private static Number weightOf(FileObject f, FileSystem writable) { try { if (f.getFileSystem() == writable) { return Double.MAX_VALUE; } } catch (FileStateInvalidException x) {/* ignore */} Object weight = f.getAttribute(WEIGHT_ATTRIBUTE); if (weight instanceof Number) { return (Number) weight; } else if (weight == null) { return 0; } else { try { Logger.getLogger(MultiFileObject.class.getName()).log( Level.WARNING, "File {0} in {1} has nonnumeric weight {2} of type {3}", new Object[] {f.getPath(), f.getFileSystem(), weight, weight.getClass().getName()}); } catch (FileStateInvalidException x) {/* ignore */} return 0; } }
private static String encodeFsPart(FileObject fo) throws FileStateInvalidException { FileSystem fs = fo.getFileSystem(); assert fs != null : "File object " + fo + " returns null from getFileSystem()"; String n = fs.isDefault() ? SYSTEM_FILE_SYSTEM_NAME : fs.getSystemName(); if (n.isEmpty()) { n = String.format("%s.%h", fs.getClass().getName(), fs); } return encoder(n); }
/** * Gets a textual represtentation of this <code>FileObject</code>. * The precise format is not defined. In particular it is probably * <em>not</em> a resource path. * For that purpose use {@link #getPath} directly. * <p>Typically it is useful for debugging purposes. Example of correct usage: * <pre> * <font class="type">FileObject</font> <font class="variable-name">fo</font> = getSomeFileObject(); * ErrorManager.getDefault().log(<font class="string">"Got a change from "</font> + fo); * </pre> * @return some representation of this file object */ @Override public String toString() { String cname = getClass().getName(); String cnameShort = cname.substring(cname.lastIndexOf('.') + 1); try { return cnameShort + '@' + Integer.toHexString(System.identityHashCode(this)) + '[' + (isRoot() ? "root of " + getFileSystem() : getPath()) + ']'; // NOI18N } catch (FileStateInvalidException x) { return cnameShort + '@' + Integer.toHexString(System.identityHashCode(this)) + "[???]"; // NOI18N } }
/** Puts the dispatch event into the filesystem. */ private void dispatchEvent(FCLSupport.Op op, Enumeration<FileChangeListener> en, FileEvent fe) { try { FileSystem fs = getFileSystem(); fs.dispatchEvent(new ED(op, en, fe)); } catch (FileStateInvalidException ex) { // no filesystem, no notification } }
final void dispatchEvent(Enumeration<FileChangeListener> en, FileEvent fe) { try { getFileSystem().dispatchEvent(new ED(en, fe)); } catch (FileStateInvalidException ex) { // no filesystem, no notification } }
@SuppressWarnings("deprecation") // FileSystem.systemName historical part of serial form private void writeObject(ObjectOutputStream oos) throws IOException { fsname = f.getFileSystem().getSystemName(); path = f.getPath(); url = f.toURL(); assert url != null : "No URL for " + path; oos.defaultWriteObject(); }
public String getDisplayName() { String n = fo.getName(); try { n = fo.getFileSystem().getStatus().annotateName(n, Collections.singleton(fo)); } catch (FileStateInvalidException ex) { LOG.log(Level.WARNING, ex.getMessage(), ex); } return n; }
public void run() { LOG.fine("refreshAll - started"); //NOI18N refreshFor(File.listRoots()); try { getConfigRoot().getFileSystem().refresh(true); } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); } finally { LOG.fine("refreshAll - finished"); //NOI18N synchronized (REFRESH_RP) { refreshTask = null; } } } });
/** * Returns a FileObject representing an archive file containing the * FileObject given by the parameter. * <strong>Remember</strong> that any path within the archive is discarded * so you may need to check for non-root entries. * @param fo a file in a JAR filesystem * @return the file corresponding to the archive itself, * or null if <code>fo</code> is not an archive entry * @since 4.48 */ public static FileObject getArchiveFile(FileObject fo) { Parameters.notNull("fo", fo); //NOI18N try { FileSystem fs = fo.getFileSystem(); if (fs instanceof JarFileSystem) { File jarFile = ((JarFileSystem) fs).getJarFile(); return toFileObject(jarFile); } } catch (FileStateInvalidException e) { Exceptions.printStackTrace(e); } return null; }
/** Removes listener previously added by {@link #addRecursiveListener(org.openide.filesystems.FileChangeListener)} * * @param fcl the listener to remove * @since 7.28 */ public void removeRecursiveListener(FileChangeListener fcl) { if (!isFolder()) { removeFileChangeListener(fcl); return; } try { getFileSystem().removeFileChangeListener(new RecursiveListener(this, fcl, false)); } catch (FileStateInvalidException ex) { ExternalUtil.LOG.log(Level.FINE, "Cannot remove listener from " + this, ex); } }
public Permission getPermission() throws IOException { // Note this is normally called by URLClassPath with an unconnected // URLConnection, so the fo will probably be null anyway. if (fo != null) { File f = FileUtil.toFile(fo); if (f != null) { return new FilePermission(f.getAbsolutePath(), "read"); // NOI18N } try { FileSystem fs = fo.getFileSystem(); if (fs instanceof JarFileSystem) { return new FilePermission(((JarFileSystem) fs).getJarFile().getAbsolutePath(), "read"); // NOI18N } // [PENDING] could do XMLFileSystem too... } catch (FileStateInvalidException fsie) { // ignore } } // fallback return new FilePermission("<<ALL FILES>>", "read"); // NOI18N }
@Deprecated // have to override for compat public boolean isReadOnly() { MultiFileSystem fs = getMultiFileSystem(); if (fs.isReadOnly()) { return true; } if (leader.isReadOnly()) { // if we can make it writable then nothing try { FileSystem simple = fs.createWritableOn(getPath()); return simple == leader.getFileSystem(); } catch (IOException e) { return true; } } return false; }
private OverFiles(String path, List<FOItem> items, AbstractLookup lkp, AbstractLookup.Content cnt) { super(computeDelegates(path, items, lkp)); this.path = path; this.lkp = lkp; this.content = cnt; this.content.setPairs(order(items)); FileSystem fs = null; try { fs = FileUtil.getConfigRoot().getFileSystem(); } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); } this.weakL = FileUtil.weakFileChangeListener(this, fs); fs.addFileChangeListener(weakL); }
public @Override URL getURL(FileObject fo, int type) { if (type != URLMapper.INTERNAL) { return null; } try { FileSystem fs = fo.getFileSystem(); if (fs instanceof MemoryFileSystem) { String path = fo.getPath(); if (fo.isFolder() && !fo.isRoot()) { path += '/'; } return url((MemoryFileSystem) fs, path); } } catch (FileStateInvalidException x) { // ignore } return null; } // keep as separate method to avoid linking Handler until needed
public boolean canWrite() { MultiFileSystem fs = getMultiFileSystem(); if (fs.isReadOnly()) { return false; } if (!leader.canWrite()) { // if we can make it writable then nothing try { FileSystem simple = fs.createWritableOn(getPath()); return simple != leader.getFileSystem(); } catch (IOException e) { return false; } } return true; }
public ED(FCLSupport.Op op, Enumeration<FileChangeListener> en, FileEvent fe) { this.op = op; this.en = en; this.fe = fe; FileSystem fs = null; try { fs = this.fe.getFile().getFileSystem(); } catch (FileStateInvalidException ex) { ExternalUtil.exception(ex); } ListenerList<FileChangeListener> fsll = (fs != null) ? fs.getFCLSupport().listeners : null; ListenerList<FileChangeListener> repll = (fs != null && fs.getRepository() != null) ? fs.getRepository().getFCLSupport().listeners : null; fsList = ListenerList.allListeners(fsll); repList = ListenerList.allListeners(repll); }