@Override public String getPath() { return fileObj.getPath(); } }
@Override public String getPath() { return delegate.getPath(); }
public String getId() { String s = fo.getPath(); if (s.endsWith(".instance")) { // NOI18N s = s.substring(0, s.length() - ".instance".length()); } return s; }
/** * Gets a relative resource path between folder and fo. * @param folder root of filesystem or any other folder in folders hierarchy * @param fo arbitrary FileObject in folder's tree (including folder itself) * @return relative path between folder and fo. The returned path never * starts with a '/'. It never ends with a '/'. Specifically, if * folder==fo, returns "". Returns <code>null</code> if fo is not in * folder's tree. * @see #isParentOf * @since 4.16 */ public static String getRelativePath(FileObject folder, FileObject fo) { if (!isParentOf(folder, fo) && (folder != fo)) { return null; } String result = fo.getPath().substring(folder.getPath().length()); if (result.startsWith("/") && !result.startsWith("//")) { result = result.substring(1); } return result; }
/** For given file object finds the filesystem that the object is placed on. * The object must be created by this filesystem orherwise IllegalArgumentException * is thrown. * * @param fo file object * @return the filesystem (from the list we delegate to) the object has file on * @exception IllegalArgumentException if the file object is not represented in this filesystem */ protected final FileSystem findSystem(FileObject fo) throws IllegalArgumentException { try { if (fo instanceof MultiFileObject) { MultiFileObject mfo = (MultiFileObject) fo; return mfo.getLeaderFileSystem(); } } catch (FileStateInvalidException ex) { // can happen if there is no delegate, I do not know what to return // better, but we should not throw the exception return this; } throw new IllegalArgumentException(fo.getPath()); }
private static String encodeFoPart(FileObject fo) { String path = fo.getPath(); if (fo.isFolder()) { path += "/"; } if (!fo.isRoot()) { path = "/" + path; } try { return new URI(null, path, null).toString(); } catch (URISyntaxException x) { return "???"; } }
static MIMEResolver forDescriptor(FileObject fo, boolean warn) { if (warn && !isUserDefined(fo)) { ERR.log(Level.WARNING, "Ineffective registration of resolver {0} use @MIMEResolver.Registration! See bug #191777.", fo.getPath()); if (ERR.isLoggable(Level.FINE)) { try { ERR.fine(fo.asText()); } catch (IOException ex) { ERR.log(Level.FINE, null, ex); } } } return new Impl(fo); }
private static String getArchiveDisplayName(FileObject fo, FileObject archiveFile) { String displayName = null; File f = FileUtil.toFile(archiveFile); if (f != null) { String archivDisplayName = f.getAbsolutePath(); if (fo.isRoot()) { displayName = archivDisplayName; } else { String entryPath = fo.getPath(); displayName = NbBundle.getMessage( FileUtil.class, "LBL_file_in_filesystem", entryPath, archivDisplayName ); } } return displayName; }
/** Reads the full content of the file object and returns it as array of * bytes. * @return array of bytes * @exception IOException in case the content cannot be fully read * @since 7.21 */ public byte[] asBytes() throws IOException { long len = getSize(); if (len > Integer.MAX_VALUE) { throw new IOException("Too big file " + getPath()); // NOI18N } InputStream is = getInputStream(); try { byte[] arr = new byte[(int)len]; int pos = 0; while (pos < arr.length) { int read = is.read(arr, pos, arr.length - pos); if (read == -1) { break; } pos += read; } if (pos != arr.length) { throw new IOException("Just " + pos + " bytes read from " + getPath()); // NOI18N } return arr; } finally { is.close(); } }
/** * 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 } }
protected boolean instanceOf(Class<?> c) { Object r = ref.get(); if (r != null) { return c.isInstance(r); } else { String instanceOf = (String) fo.getAttribute("instanceOf"); if (instanceOf != null) { for (String xface : instanceOf.split(",")) { try { if (c.isAssignableFrom(Class.forName(xface, false, loader()))) { return true; } } catch (ClassNotFoundException x) { // Not necessarily a problem, e.g. from org-netbeans-lib-commons_net-antlibrary.instance LOG.log(Level.FINE, "could not load " + xface + " for " + fo.getPath(), x); } } return false; } else { return c.isAssignableFrom(getType()); } } }
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; } }
@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(); }
@Override public String findMIMEType(FileObject fo) { if (fo.hasExt("xml") && fo.getPath().startsWith(MIME_RESOLVERS_PATH)) { // NOI18N // do not try to check ourselves! return null; } init(); if (state == DescParser.ERROR) { return null; } FileElement[] smell2 = smell; //#163378, #157838 - copy to prevent concurrent modification and not synchronize to prevent deadlock // smell is filled in reverse order for (int i = smell2.length - 1; i >= 0; i--) { if (ERR.isLoggable(Level.FINE)) ERR.fine("findMIMEType - smell.resolve."); String s = smell2[i].resolve(fo); if (s != null) { if (s.equals(FileElement.EXIT_MIME_TYPE)) { // if file matches conditions and exit element is present, do not continue in loop and return null return null; } if (ERR.isLoggable(Level.FINE)) ERR.log(Level.FINE, "MIMEResolverImpl.findMIMEType({0})={1}", new Object[]{fo, s}); // NOI18N return s; } } return null; }
private void refresh(FileEvent ev) { if (!(ev.getFile().getPath() + "/").startsWith(path)) { return; } List<FOItem> items = new ArrayList<FOItem>(); Lookup[] delegates = computeDelegates(path, items, lkp); this.content.setPairs(order(items)); this.setLookups(delegates); }
/** Creates a file object that will mask the given file. * @param fs filesystem to work on * @param res resource name of the file * @exception IOException if it fails */ void maskFile(FileSystem fs, String res) throws IOException { FileObject where = findResourceOn(fs, fs.getRoot().getPath()); FileUtil.createData(where, res + MASK); }
for (FileObject f : fo.getChildren()) { if (f.isFolder()) { delegates.add(new OverFiles(f.getPath())); } else { if (f.hasExt("shadow")) {
private final String annotateName(FileObject fo) { String bundleName = (String) fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N if (bundleName != null) { try { bundleName = Utilities.translate(bundleName); ResourceBundle b = NbBundle.getBundle(bundleName); try { return b.getString(fo.getPath()); } catch (MissingResourceException ex) { // ignore--normal } } catch (MissingResourceException ex) { Exceptions.attachMessage(ex, warningMessage(bundleName, fo)); LOG.log(Level.INFO, null, ex); // ignore } } return (String) fo.getAttribute("displayName"); // NOI18N }
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
/** Converts the file to be writable. * The file has to be locked! * * @return file object (new leader) that is writable * @exception IOException if the object cannot be writable */ private FileObject writable(boolean copyContents) throws IOException { MultiFileSystem fs = getMultiFileSystem(); FileSystem single = fs.createWritableOn(getPath()); if (single != leader.getFileSystem()) { // if writing to a file that is not on writable fs => // copy it if (leader.isFolder()) { leader = FileUtil.createFolder(root(single), getPath()); } else { FileObject folder = FileUtil.createFolder(root(single), getParent().getPath()); if (copyContents) { leader = leader.copy(folder, leader.getName(), leader.getExt()); } else { leader = folder.createData(leader.getNameExt()); } } MfLock l = ((lock == null) ? null : lock.get()); if (l != null) { // update the lock l.addLock(leader); } } return leader; }