/** Extract jar file into folder represented by file object. If the JAR contains * files with name filesystem.attributes, it is assumed that these files * has been created by DefaultAttributes implementation and the content * of these files is treated as attributes and added to extracted files. * <p><code>META-INF/</code> directories are skipped over. * * @param fo file object of destination folder * @param is input stream of jar file * @exception IOException if the extraction fails * @deprecated Use of XML filesystem layers generally obsoletes this method. * For tests, use {@link org.openide.util.test.TestFileUtils#unpackZipFile}. */ @Deprecated public static void extractJar(final FileObject fo, final InputStream is) throws IOException { FileSystem fs = fo.getFileSystem(); fs.runAtomicAction( new FileSystem.AtomicAction() { public void run() throws IOException { extractJarImpl(fo, is); } } ); }
/** * Refreshes all necessary filesystems. Not all instances of <code>FileObject</code> are refreshed * but just those that represent passed <code>files</code> and their children recursively. * @param files * @since 7.6 */ public static void refreshFor(File... files) { FileSystem fs = getDiskFileSystemFor(files); if (fs != null) { try { fs.getRoot().setAttribute("request_for_refreshing_files_be_aware_this_is_not_public_api", files); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
createFolder(fo, name); } else { FileObject fd = createData(fo, name); FileLock lock = fd.lock(); OutputStream os = fd.getOutputStream(lock); copy(jis, os); } finally { os.close(); String prefix = fo.isRoot() ? dirName : (fo.getPath() + '/' + dirName); String orig = (String) files.next(); String fn = prefix + orig; FileObject obj = fo.getFileSystem().findResource(fn);
boolean canHaveRootAttributeOnReadOnlyFS(String name) { Set<String> tmp = rootAttributes; if (tmp == null) { tmp = new HashSet<String>(); for (FileSystem fs : getDelegates()) { if (fs == null) { continue; } if (!fs.isReadOnly()) { continue; } Enumeration<String> en = fs.getRoot().getAttributes(); while (en.hasMoreElements()) { tmp.add(en.nextElement()); } rootAttributes = tmp; } } if (tmp == Collections.<String>emptySet()) { return true; } return tmp.contains(name); } }
/** fireFileChange defines if should be fired fileChanged event after close of stream*/ synchronized OutputStream getOutputStream(FileLock lock, boolean fireFileChanged) throws IOException { FileSystem fs = getAbstractFileSystem(); if (fs.isReadOnly()) { throw new FSException(NbBundle.getMessage(AbstractFileObject.class, "EXC_FSisRO", fs.getDisplayName())); } if (isReadOnly()) { throw new FSException(NbBundle.getMessage(AbstractFileObject.class, "EXC_FisRO", name, fs.getDisplayName())); } testLock(lock); return StreamPool.createOutputStream(this, fireFileChanged); }
private FileObject[] findFileObjectsInRepository(File f) { if (!f.equals(FileUtil.normalizeFile(f))) { throw new IllegalArgumentException( "Parameter file was not " + // NOI18N "normalized. Was " + f + " instead of " + FileUtil.normalizeFile(f) FileSystem fs = en.nextElement(); String rootName = null; FileObject fsRoot = fs.getRoot(); File root = findFileInRepository(fsRoot); Object rootPath = fsRoot.getAttribute("FileSystem.rootPath"); //NOI18N FileObject fo = fs.findResource(res); File file2Fo = (fo != null) ? findFileInRepository(fo) : null;
@Override public void taskFinished(Task task) { FileObject modeDir = userDir.get().getFileObject("config/Windows2Local/Modes"); OutputStream os; if (modeDir != null) { throw new IOException("Cannot find layer in " + project); // NOI18N for (FileObject m : modeDir.getChildren()) { if (m.isData() && "wsmode".equals(m.getExt())) { final String name = "Windows2/Modes/" + m.getNameExt(); // NOI18N FileObject mode = FileUtil.createData(layer.getRoot(), name); // NOI18N os = mode.getOutputStream(); os.write(DesignSupport.readMode(m).getBytes("UTF-8")); // NOI18N DialogDisplayer.getDefault().notifyLater(nd); } catch (IOException ex) { Exceptions.printStackTrace(ex);
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); }
FileObject fo = FileUtil.getConfigFile (BROWSER_FOLDER); if (fo != null) { DataFolder folder = DataFolder.findFolder (fo); DataObject [] dobjs = folder.getChildren (); for (int i = 0; i<dobjs.length; i++) { if (Boolean.TRUE.equals(dobjs[i].getPrimaryFile().getAttribute(EA_HIDDEN)) || dobjs[i].getCookie(InstanceCookie.class) == null) { FileObject fo2 = dobjs[i].getPrimaryFile(); String n = fo2.getName(); try { n = fo2.getFileSystem().getStatus().annotateName(n, dobjs[i].files()); } catch (FileStateInvalidException e) {
} else if (CndPathUtilities.isPathAbsolute(bdir)) { try { FileObject res = relativeDirFO.getFileSystem().findResource(bdir); if (res != null && res.isValid()) { res.refresh(); if (res == null || !res.isValid()) { res = FileUtil.createFolder(relativeDirFO.getFileSystem().getRoot(), bdir); Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex);
public static FileProxy createAbsolute(Project project, String path) { FileObject projectFO = project.getProjectDirectory(); File projectFile = FileUtil.toFile(projectFO); if (projectFile == null) { try { return new FileProxyFileObject(projectFO.getFileSystem().getRoot(), path); } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); // I don't know how this is possible; but to avoid NPE let's return FileProxyFile return new FileProxyFile(new File(path)); } } else { return new FileProxyFile(new File(path)); } }
private Set<DataObject> createTemplate(TemplateWizard wiz, DataFolder df, String targetName, FileObject cssFolder, JSFVersion jsfVersion) throws IOException { CreateTemplateAction createTemplateAction = new CreateTemplateAction( templatePanel.getComponent(), Templates.getTargetName(wiz), Templates.getTargetFolder(wiz), cssFolder, jsfVersion); df.getPrimaryFile().getFileSystem().runAtomicAction(createTemplateAction); FileObject target = df.getPrimaryFile().getFileObject(targetName, XHTML_EXT); DataObject dob = DataObject.find(target); JSFPaletteUtilities.reformat(dob); return Collections.singleton(dob); }
private void performOperation(final ModelOperation<POMModel> operation) { try { pom.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { @Override public void run() throws IOException { Utilities.performPOMModelOperations(pom, Collections.singletonList(operation)); } }); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
@Override public FileObject resolveFileObject(String filename) throws IllegalArgumentException { if (filename == null) { throw new NullPointerException("null filename passed to resolveFile"); // NOI18N } FileObject f; if (RELATIVE_SLASH_SEPARATED_PATH.matcher(filename).matches()) { return dir.getFileObject(filename); } else { try { return dir.getFileSystem().findResource(filename) ; } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); return null; } } }
File f = FileUtil.toFile(fo); FileObject archiveFile = FileUtil.getArchiveFile(fo); displayName = getArchiveDisplayName(fo, archiveFile); if (fo.isRoot()) { displayName = fo.getFileSystem().getDisplayName(); } else { displayName = NbBundle.getMessage( FileUtil.class, "LBL_file_in_filesystem", fo.getPath(), fo.getFileSystem().getDisplayName() );
private void bEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bEditActionPerformed String mimeType = (String) lFiles.getSelectedValue (); if (mimeType == null) return; FileObject fileObject = Repository.getDefault ().getDefaultFileSystem ().findResource ("Editors/" + mimeType + "/language.nbs"); try { DataObject dataObject = DataObject.find (fileObject); OpenCookie openCookie = dataObject.getCookie (OpenCookie.class); openCookie.open (); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace (ex); } }//GEN-LAST:event_bEditActionPerformed
@Test public void testFindMetadataItemFromBadJPG() throws Exception { final DataObject dataObject = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("badfile")); final MetadataItemHolder<TIFF> holder = tiffProvider.findOrCreateItems(dataObject, EXTERNAL).iterator().next(); assertNotNull(holder); assertFalse(holder.isAvailable()); }
"System/org-openide-actions-PropertiesAction", // NOI18N })); FileObject folder = FileUtil.createFolder(layer.getRoot(), "Loaders/" + mime + "/Actions"); // NOI18N List<DataObject> kids = new ArrayList<DataObject>(); Iterator it = actions.iterator(); FileObject kid; if (name != null) { kid = folder.createData(name.replaceAll("[^/]*/", "") + ".shadow"); // NOI18N kid.setAttribute("originalFile", "Actions/" + name + ".instance"); // NOI18N } else { kid = folder.createData("sep-" + (++i) + ".instance"); // NOI18N kid.setAttribute("instanceClass", "javax.swing.JSeparator"); // NOI18N kids.add(DataObject.find(kid)); DataFolder.findFolder(folder).setOrder(kids.toArray(new DataObject[kids.size()]));
private static FileObject createFileObject() { try { return FileUtil.createMemoryFileSystem().getRoot().createData("disasm", "s"); // NOI18N } catch (IOException ioe) { Exceptions.printStackTrace(ioe); } return null; } }
/** Get the displayed icon for this node. * A filesystem may {@link org.openide.filesystems.FileSystem#getStatus specially alter} this. * Subclassers overriding this method should consider the recommendations * in {@link DataObject#createNodeDelegate}. * @param type the icon type from {@link java.beans.BeanInfo} * @return the desired icon */ public java.awt.Image getOpenedIcon (int type) { java.awt.Image img = super.getOpenedIcon(type); try { img = obj.getPrimaryFile ().getFileSystem ().getStatus ().annotateIcon (img, type, new LazyFilesSet()); } catch (FileStateInvalidException e) { // no fs, do nothing } return img; }