本文整理了Java中org.openide.filesystems.FileUtil.createMemoryFileSystem()
方法的一些代码示例,展示了FileUtil.createMemoryFileSystem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.createMemoryFileSystem()
方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:createMemoryFileSystem
[英]Factory method that creates an empty implementation of a filesystem that completely resides in a memory.
To specify the MIME type of a data file without using a MIME resolver, set the mimeType file attribute.
Since 7.42, a URLMapper is available for files (and folders) in memory filesystems. These URLs are valid only so long as the filesystem has not been garbage-collected, so hold the filesystem (or a file in it) strongly for as long as you expect the URLs to be in play.
[中]工厂方法,该方法创建完全驻留在内存中的文件系统的空实现。
要在不使用MIME解析器的情况下指定数据文件的MIME类型,请设置mimeType文件属性。
自7.42以来,URLMapper可用于内存文件系统中的文件(和文件夹)。这些URL只有在文件系统未被垃圾收集的情况下才有效,因此,只要您希望URL发挥作用,就一直保持文件系统(或其中的一个文件)。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
try {
InputStream is = fo.openInputStream();
org.openide.filesystems.FileObject tmp = FileUtil.createMemoryFileSystem().getRoot().createData("resolver.xml");
OutputStream os = tmp.getOutputStream();
for (;;) {
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/**
* @param rep may be null
*/
private static synchronized void setRepository (Repository rep) {
repository = rep;
if (repository == null) {
// if not provided use default one
repository = new Repository (FileUtil.createMemoryFileSystem ());
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/**
* @param rep may be null
*/
private static synchronized void setRepository (Repository rep) {
repository = rep;
if (repository == null) {
// if not provided use default one
repository = new Repository (FileUtil.createMemoryFileSystem ());
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-junit-ant
public @Override FileObject getProjectDirectory() {
return FileUtil.createMemoryFileSystem().getRoot();
}
public @Override Lookup getLookup() {
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2
private static FileObject createFileObject() {
try {
return FileUtil.createMemoryFileSystem().getRoot().createData("disasm", "s"); // NOI18N
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
}
return null;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-wizards
/** Don't call me from EDT! */
private FileSystem getSFS() {
assert !EventQueue.isDispatchThread() : "Called from ETD!"; // NOI18N
if (sfs == null) {
try {
// XXX takes very long time. Consider to call it when e.g. module is loaded
sfs = data.getProject().getLookup().lookup(NbModuleProvider.class).getEffectiveSystemFilesystem();
} catch (IOException ex) {
Logger.getLogger(GUIRegistrationPanel.class.getName()).log(Level.INFO, null, ex);
sfs = FileUtil.createMemoryFileSystem();
}
}
return sfs;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-navigation
/**
* Creates file in memory.
*
* @param name - file name
* @return file
*/
public static FileObject createMemoryFile(String name) {
FileObject fo = null;
try {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
fo = FileUtil.createData(root, name);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return fo;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project
private String getMimeType(String filename) {
try {
return FileUtil.createMemoryFileSystem().getRoot().createData(filename).getMIMEType();
} catch (IOException ex) {
// ignored, should not happen
LOGGER.log(Level.WARNING, null, ex);
}
return "content/unknown"; // NOI18N
}
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-spi
@Before
public void setUpFileSystem()
throws Exception
{
// logger.info("********************** setup()");
fileSystem = FileUtil.createMemoryFileSystem();
}
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-persistence
@Before
public void setupFixture()
throws Exception
{
itemPersistenceSupport = new MetadataItemPersistenceSupport(MockItem1.class, "MockItem Persistence", StorageType.EXTERNAL, "MockItem");
fileSystem = FileUtil.createMemoryFileSystem();
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
FileObject doCreateFromTemplate(FileObject template, JavaFileObject sourceFile) throws IOException {
FileObject scratchFolder = FileUtil.createMemoryFileSystem().getRoot();
String name = FileObjects.getName(sourceFile, false);
if (template == null) {
return FileUtil.createData(scratchFolder, name);
}
FileObjectFromTemplateCreator creator = Lookup.getDefault().lookup(FileObjectFromTemplateCreator.class);
if (creator == null) {
return FileUtil.createData(scratchFolder, name);
}
File pack = BaseUtilities.toFile(sourceFile.toUri()).getParentFile();
while (FileUtil.toFileObject(pack) == null) {
pack = pack.getParentFile();
}
FileObject targetFolder = FileUtil.toFileObject(pack);
scratchFolder.setAttribute(FileObjectFromTemplateCreator.ATTR_ORIG_FILE, targetFolder);
return creator.create(template, scratchFolder, name);
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
/**
*
* @param url of root to be indexed
* @return result of indexing
* @throws IOException
* @throws IllegalArgumentException
* @deprecated Only used by unit tests, the start method is used by impl dep by tests of several modules, safer to keep it.
*/
@Deprecated
public final Changes analyse(@NonNull final URL url) throws IOException, IllegalArgumentException {
return analyse(
SPIAccessor.getInstance().createContext(
FileUtil.createMemoryFileSystem().getRoot(),
url,
JavaIndex.NAME,
JavaIndex.VERSION,
null,
false,
false,
false,
SuspendSupport.NOP,
null,
null));
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
@Override
public void run(CompilationController cc) throws Exception {
final WorkingCopy copy = new WorkingCopy(cc.impl, overlay);
copy.setJavaSource(JavaSource.this);
if (sources.isEmpty()) {
//runUserActionTask for source-less JavaSources does not require toPhase
//so automatically initializing also for runModificationTask:
copy.toPhase(Phase.PARSED);
}
task.run(copy);
final JavacTaskImpl jt = copy.impl.getJavacTask();
Log.instance(jt.getContext()).nerrors = 0;
final List<ModificationResult.Difference> diffs = copy.getChanges(result.tag2Span);
if (diffs != null && diffs.size() > 0) {
final FileObject file = copy.getFileObject();
result.diffs.put(file != null ? file : FileUtil.createMemoryFileSystem().getRoot().createData("temp", "java"), diffs);
}
}
};
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-viewer
@Before
public void setUp()
throws IOException
{
viewer = new MetadataViewerTopComponent(); // always create a new one for test isolation
frame = new JFrame("test");
frame.getContentPane().add(viewer);
frame.pack();
dataObject1 = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("dataobject1"));
dataObject2 = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("dataobject2"));
assertNotNull(dataObject1);
assertNotNull(dataObject2);
// Must reset panelProviders: they are the same instance across al tests, since they are
// only initialized once by the global Lookup.
for (final MetadataPanelProvider panelProvider : Lookup.getDefault().lookupAll(MetadataPanelProvider.class))
{
panelProvider.setDataObject(null);
assertNull(panelProvider.getDataObject());
}
}
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-tiff-provider
@Test
public void testFindMetadataItemFromGoodFile()
throws Exception
{
final DataObject dataObject = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("goodfile"));
final MetadataItemHolder<TIFF> holder = tiffProvider.findOrCreateItems(dataObject, EXTERNAL).iterator().next();
assertNotNull(holder);
assertTrue(holder.isAvailable());
}
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-tiff-provider
@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());
}
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-tiff-provider
@Test
public void testLastestModificationTimeIsUpdated()
throws Exception
{
final DataObject dataObject = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("goodfile"));
final MetadataItemHolder<TIFF> holder = tiffProvider.findOrCreateItems(dataObject, EXTERNAL).iterator().next();
assertNotNull(holder);
final Date timestamp1 = holder.getLatestModificationTime();
assertTrue(holder.isAvailable());
Thread.sleep(1000);
final Date now = new Date();
holder.get().setArtist("new artist");
final Date timestamp2 = holder.getLatestModificationTime();
assertTrue(timestamp2.getTime() - now.getTime() < 50);
assertNotSame(timestamp1, timestamp2);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-project
} catch (IOException e) {
Util.err.notify(ErrorManager.INFORMATIONAL, e);
return fs = FileUtil.createMemoryFileSystem();
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-project
} catch (IOException e) {
Util.err.notify(ErrorManager.INFORMATIONAL, e);
return fs = FileUtil.createMemoryFileSystem();
代码示例来源:origin: it.tidalwave.metadata/it-tidalwave-metadata-viewer
@Before
public void setupFixture()
throws IOException, NoSuchMetadataTypeException
{
panelProvider = new MetadataPanelProviderMock();
FileUtil.setMIMEType("test", "image/test");
final FileSystem fileSystem = FileUtil.createMemoryFileSystem();
final FileObject root = fileSystem.getRoot();
dataObjectWithNoMetadata = DataObject.find(root.createData("nometadata.test"));
assertTrue(dataObjectWithNoMetadata instanceof DataObjectMock);
assertNull(dataObjectWithNoMetadata.getLookup().lookup(Metadata.class));
dataObjectWithItem = DataObject.find(root.createData("item.test"));
assertTrue(dataObjectWithItem instanceof DataObjectMock);
Metadata metadata = dataObjectWithItem.getLookup().lookup(Metadata.class);
assertNotNull(metadata);
MetadataItemHolder<MetadataItemMock> holder = metadata.findOrCreateItem(MetadataItemMock.class, INTERNAL);
assertNotNull(holder);
assertTrue(holder.isAvailable());
dataObjectWithNoItem = DataObject.find(root.createData("noitem.test"));
assertTrue(dataObjectWithNoItem instanceof DataObjectMock);
metadata = dataObjectWithNoItem.getLookup().lookup(Metadata.class);
assertNotNull(metadata);
holder = metadata.findOrCreateItem(MetadataItemMock.class, INTERNAL);
assertNotNull(holder);
assertFalse(holder.isAvailable());
}
内容来源于网络,如有侵权,请联系作者删除!