本文整理汇总了Java中org.apache.commons.vfs2.NameScope类的典型用法代码示例。如果您正苦于以下问题:Java NameScope类的具体用法?Java NameScope怎么用?Java NameScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameScope类属于org.apache.commons.vfs2包,在下文中一共展示了NameScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
@Override
public synchronized void save(Note note) throws IOException {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
String json = gson.toJson(note);
FileObject rootDir = getRootDir();
FileObject noteDir = rootDir.resolveFile(note.id(), NameScope.CHILD);
if (!noteDir.exists()) {
noteDir.createFolder();
}
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile(".note.json", NameScope.CHILD);
// false means not appending. creates file if not exists
OutputStream out = noteJson.getContent().getOutputStream(false);
out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING)));
out.close();
noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD));
}
示例2: remove
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
@Override
public void remove(String noteId) throws IOException {
FileObject rootDir = fsManager.resolveFile(getPath("/"));
FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD);
if (!noteDir.exists()) {
// nothing to do
return;
}
if (!isDirectory(noteDir)) {
// it is not look like zeppelin note savings
throw new IOException("Can not remove " + noteDir.getName().toString());
}
noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN);
}
示例3: save
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
@Override
public synchronized void save(Note note, AuthenticationInfo subject) throws IOException {
LOG.info("Saving note:" + note.getId());
String json = note.toJson();
FileObject rootDir = getRootDir();
FileObject noteDir = rootDir.resolveFile(note.getId(), NameScope.CHILD);
if (!noteDir.exists()) {
noteDir.createFolder();
}
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile(".note.json", NameScope.CHILD);
// false means not appending. creates file if not exists
OutputStream out = noteJson.getContent().getOutputStream(false);
out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING)));
out.close();
noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD));
}
示例4: remove
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
FileObject rootDir = fsManager.resolveFile(getPath("/"));
FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD);
if (!noteDir.exists()) {
// nothing to do
return;
}
if (!isDirectory(noteDir)) {
// it is not look like zeppelin note savings
throw new IOException("Can not remove " + noteDir.getName().toString());
}
noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN);
}
示例5: loadResource
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Searches through the search path of for the first class or resource
* with specified name.
* @param name The resource to load.
* @return The Resource.
* @throws FileSystemException if an error occurs.
*/
private Resource loadResource(final String name) throws FileSystemException
{
final Iterator<FileObject> it = resources.iterator();
while (it.hasNext())
{
final FileObject baseFile = it.next();
final FileObject file =
baseFile.resolveFile(name, NameScope.DESCENDENT_OR_SELF);
if (file.exists())
{
return new Resource(name, baseFile, file);
}
}
return null;
}
示例6: createFile
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Creates a file object. This method is called only if the requested
* file is not cached.
*/
@Override
protected FileObject createFile(final AbstractFileName name) throws Exception
{
// Find the file that the name points to
final FileName junctionPoint = getJunctionForFile(name);
final FileObject file;
if (junctionPoint != null)
{
// Resolve the real file
final FileObject junctionFile = junctions.get(junctionPoint);
final String relName = junctionPoint.getRelativeName(name);
file = junctionFile.resolveFile(relName, NameScope.DESCENDENT_OR_SELF);
}
else
{
file = null;
}
// Return a wrapper around the file
return new DelegateFileObject(name, this, file);
}
示例7: assertSameContent
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Asserts every file in a folder exists and has the expected content.
*/
private void assertSameContent(final FileInfo expected,
final FileObject folder) throws Exception
{
for (Iterator<FileInfo> iterator = expected.children.values().iterator(); iterator.hasNext();)
{
final FileInfo fileInfo = iterator.next();
final FileObject child = folder.resolveFile(fileInfo.baseName, NameScope.CHILD);
assertTrue(child.getName().toString(), child.exists());
if (fileInfo.type == FileType.FILE)
{
assertSameContent(fileInfo.content, child);
}
else
{
assertSameContent(fileInfo, child);
}
}
}
示例8: testChildName
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Tests child file names.
*/
public void testChildName() throws Exception
{
final FileName baseName = getReadFolder().getName();
final String basePath = baseName.getPath();
final FileName name = getManager().resolveName(baseName, "some-child", NameScope.CHILD);
// Test path is absolute
assertTrue("is absolute", basePath.startsWith("/"));
// Test base name
assertEquals("base name", "some-child", name.getBaseName());
// Test absolute path
assertEquals("absolute path", basePath + "/some-child", name.getPath());
// Test parent path
assertEquals("parent absolute path", basePath, name.getParent().getPath());
// Try using a compound name to find a child
assertBadName(name, "a/b", NameScope.CHILD);
// Check other invalid names
checkDescendentNames(name, NameScope.CHILD);
}
示例9: assertSameName
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Checks that a relative name resolves to the expected absolute path.
* Tests both forward and back slashes.
*/
private void assertSameName(final String expectedPath,
final FileName baseName,
final String relName,
final NameScope scope)
throws Exception
{
// Try the supplied name
FileName name = getManager().resolveName(baseName, relName, scope);
assertEquals(expectedPath, name.getPath());
String temp;
// Replace the separators
temp = relName.replace('\\', '/');
name = getManager().resolveName(baseName, temp, scope);
assertEquals(expectedPath, name.getPath());
// And again
temp = relName.replace('/', '\\');
name = getManager().resolveName(baseName, temp, scope);
assertEquals(expectedPath, name.getPath());
}
示例10: testDescendentName
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Tests descendent name resolution.
*/
public void testDescendentName()
throws Exception
{
final FileName baseName = getReadFolder().getName();
// Test direct child
String path = baseName.getPath() + "/some-child";
assertSameName(path, baseName, "some-child", NameScope.DESCENDENT);
// Test compound name
path = path + "/grand-child";
assertSameName(path, baseName, "some-child/grand-child", NameScope.DESCENDENT);
// Test relative names
assertSameName(path, baseName, "./some-child/grand-child", NameScope.DESCENDENT);
assertSameName(path, baseName, "./nada/../some-child/grand-child", NameScope.DESCENDENT);
assertSameName(path, baseName, "some-child/./grand-child", NameScope.DESCENDENT);
// Test badly formed descendent names
checkDescendentNames(baseName, NameScope.DESCENDENT);
}
示例11: checkAbsoluteNames
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
/**
* Tests resolution of absolute names.
*/
private void checkAbsoluteNames(final FileName name) throws Exception
{
// Root
assertSameName("/", name, "/");
assertSameName("/", name, "//");
assertSameName("/", name, "/.");
assertSameName("/", name, "/some file/..");
// Some absolute names
assertSameName("/a", name, "/a");
assertSameName("/a", name, "/./a");
assertSameName("/a", name, "/a/.");
assertSameName("/a/b", name, "/a/b");
// Some bad names
assertBadName(name, "/..", NameScope.FILE_SYSTEM);
assertBadName(name, "/a/../..", NameScope.FILE_SYSTEM);
}
示例12: resolveFile
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
@Override
public FileObject resolveFile(String name, NameScope scope) {
try {
return FileObject.TO_DA_FILE_OBJECT.valueOf(this.fileObject.resolveFile(name, scope));
} catch (FileSystemException e) {
throw new VFSFileSystemException(e);
}
}
示例13: getNote
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
private Note getNote(FileObject noteDir) throws IOException {
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD);
if (!noteJson.exists()) {
throw new IOException(noteJson.getName().toString() + " not found");
}
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
FileContent content = noteJson.getContent();
InputStream ins = content.getInputStream();
String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
ins.close();
Note note = gson.fromJson(json, Note.class);
// note.setReplLoader(replLoader);
// note.jobListenerFactory = jobListenerFactory;
for (Paragraph p : note.getParagraphs()) {
if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
p.setStatus(Status.ABORT);
}
}
return note;
}
示例14: get
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
@Override
public Note get(String noteId) throws IOException {
FileObject rootDir = fsManager.resolveFile(getPath("/"));
FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD);
return getNote(noteDir);
}
示例15: getNote
import org.apache.commons.vfs2.NameScope; //导入依赖的package包/类
private Note getNote(FileObject noteDir) throws IOException {
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD);
if (!noteJson.exists()) {
throw new IOException(noteJson.getName().toString() + " not found");
}
FileContent content = noteJson.getContent();
InputStream ins = content.getInputStream();
String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
ins.close();
Note note = Note.fromJson(json);
for (Paragraph p : note.getParagraphs()) {
if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
p.setStatus(Status.ABORT);
}
List<ApplicationState> appStates = p.getAllApplicationStates();
if (appStates != null) {
for (ApplicationState app : appStates) {
if (app.getStatus() != ApplicationState.Status.ERROR) {
app.setStatus(ApplicationState.Status.UNLOADED);
}
}
}
}
return note;
}