当前位置: 首页>>代码示例>>Java>>正文


Java VFS类代码示例

本文整理汇总了Java中org.apache.commons.vfs2.VFS的典型用法代码示例。如果您正苦于以下问题:Java VFS类的具体用法?Java VFS怎么用?Java VFS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


VFS类属于org.apache.commons.vfs2包,在下文中一共展示了VFS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileExists

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
private boolean fileExists(String file)
{
	try
	{
		// this hack is no longer required, changed VFS to init without
		// providers.xm.
		// String current =
		// System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
		// System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
		// "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
		DefaultFileSystemManager fsManager = (DefaultFileSystemManager) VFS
				.getManager();
		// if (current != null)
		// System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
		// current);
		// else
		// System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
		FileObject f = VFSUtils.resolveFile(".", file);
		return f.exists();
	}
	catch (FileSystemException e)
	{
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:27,代码来源:YajswConfigurationImpl.java

示例2: buildJar

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
private void buildJar(String newJar) throws IOException
{
	ZipOutputStream out = new ZipOutputStream(new FileOutputStream(newJar ));
	FileSystemManager fsManager = VFS.getManager();
	for (String jar : _jar2class.keySet())
	{
		FileObject jarFile;
		if (jar.endsWith(".jar"))
			jarFile = fsManager.resolveFile( "jar:"+jar );
		else
			jarFile = fsManager.resolveFile( jar );
			
			for (String file : _jar2class.get(jar))
			{
				file = file.replaceAll("\\.", "/");
				file += ".class";
				FileObject f = fsManager.resolveFile(jarFile, file);
				if (f.exists())
					addFile(f, file, out);
				else
					System.out.println("file not found "+f);
			}	
			
	}
	out.close();
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:27,代码来源:JarBuilder.java

示例3: getFather

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
/**
 * Returns the FileObject that is the father of all logical children of this
 * FileObject. This may not be the current node itself, in case the node is
 * a container file, because then intermediate FileObject instances are
 * created by Apache VFS.
 * 
 * @return the father of this node's children in VFS
 */
private FileObject getFather() throws IOException {
    if (isDirectory()) {
        return fo;
    } else if (getSize() == 0) {
        return null;
    } else if (VFS.getManager().canCreateFileSystem(fo)) {
        FileObject father = fo;
        while (VFS.getManager().canCreateFileSystem(father)) {
            father = VFS.getManager().createFileSystem(father);
        }
        return father;
    } else {
        return null;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRNode.java

示例4: WatchFTPRunner

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
public WatchFTPRunner(FTPConfig config) {
    this.config = config;
    try { 
        fsManager = VFS.getManager();
       
        UserAuthenticator auth = new StaticUserAuthenticator("", config.getConnection().getUsername(), config.getConnection().getPassword()); 
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); 
        FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts,true);
        FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
       
        resolvedAbsPath = fsManager.resolveFile(config.getFolder() + config.getConnection().getPathtomonitor() , opts);
        
        log.info("Connection successfully established to " +  resolvedAbsPath.getPublicURIString());        
        log.debug("Exists: " + resolvedAbsPath.exists());
        log.debug("Type  : " + resolvedAbsPath.getType());       
    } catch (FileSystemException e) {
        log.error("File system exception for " + config.getFolder(), e);
        //throw here?
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:21,代码来源:WatchFTPRunner.java

示例5: main

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
public static void main(String[] args) {
	try {
		FileSystemManager fileSystemManager = VFS.getManager();
		
		FileObject fileObject;
		String path = "";
        fileObject = fileSystemManager.resolveFile("nfs://10.0.202.122//opt/glog/a.txt");
        if (fileObject == null) {
            throw new IOException("File cannot be resolved: " + path);
        }
        if (!fileObject.exists()) {
            throw new IOException("File does not exist: " + path);
        }
        System.out.println(fileObject.getName().getPath());
        BufferedReader stream = new BufferedReader(new InputStreamReader(fileObject.getContent().getInputStream(), "utf-8"));
       	String line = null;
       	while((line = stream.readLine()) != null) {
       		System.out.println(line);
       	}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:danniss,项目名称:common-vfs2-nfs,代码行数:26,代码来源:Main.java

示例6: copyToDir

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
@SneakyThrows
private static File copyToDir(FileObject jarredFile, File destination, boolean retryIfImaginary) {
    switch (jarredFile.getType()) {
        case FILE:
            return copyFileToDir(jarredFile, destination);
        case FOLDER:
            return copyDirToDir(jarredFile, destination);
        case IMAGINARY:
            if (retryIfImaginary) {
                log.debug("Imaginary file found, retrying extraction");
                VFS.getManager().getFilesCache().removeFile(jarredFile.getFileSystem(), jarredFile.getName());
                FileObject newJarredFile = VFS.getManager().resolveFile(jarredFile.getName().getURI());
                return copyToDir(newJarredFile, destination, false);
            } else {
                log.debug("Imaginary file found after retry, abandoning retry");
            }

        default:
            throw new IllegalStateException("File Type not supported: " + jarredFile.getType());
    }
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-jar-resources,代码行数:22,代码来源:JarUtils.java

示例7: VFSNotebookRepo

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
public VFSNotebookRepo(ZeppelinConfiguration conf) throws IOException {
  this.conf = conf;

  try {
    filesystemRoot = new URI(conf.getNotebookDir());
  } catch (URISyntaxException e1) {
    throw new IOException(e1);
  }

  if (filesystemRoot.getScheme() == null) { // it is local path
    try {
      this.filesystemRoot = new URI(new File(
          conf.getRelativeDir(filesystemRoot.getPath())).getAbsolutePath());
    } catch (URISyntaxException e) {
      throw new IOException(e);
    }
  } else {
    this.filesystemRoot = filesystemRoot;
  }
  fsManager = VFS.getManager();
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:22,代码来源:VFSNotebookRepo.java

示例8: SimpleJsonExtractor

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException {
  this.workUnitState = workUnitState;

  // Resolve the file to pull
  if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) {
    // Add authentication credential if authentication is needed
    UserAuthenticator auth =
        new StaticUserAuthenticator(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""),
            workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME), PasswordManager.getInstance(workUnitState)
                .readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD)));
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
    this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts);
  } else {
    this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY));
  }

  // Open the file for reading
  LOGGER.info("Opening file " + this.fileObject.getURL().toString());
  this.bufferedReader =
      this.closer.register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(),
          ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:24,代码来源:SimpleJsonExtractor.java

示例9: setNotebookDirectory

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
private void setNotebookDirectory(String notebookDirPath) throws IOException {
  try {
    if (conf.isWindowsPath(notebookDirPath)) {
      filesystemRoot = new File(notebookDirPath).toURI();
    } else {
      filesystemRoot = new URI(notebookDirPath);
    }
  } catch (URISyntaxException e1) {
    throw new IOException(e1);
  }

  if (filesystemRoot.getScheme() == null) { // it is local path
    File f = new File(conf.getRelativeDir(filesystemRoot.getPath()));
    this.filesystemRoot = f.toURI();
  }

  fsManager = VFS.getManager();
  FileObject file = fsManager.resolveFile(filesystemRoot.getPath());
  if (!file.exists()) {
    LOG.info("Notebook dir doesn't exist, create on is {}.", file.getName());
    file.createFolder();
  }
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:24,代码来源:VFSNotebookRepo.java

示例10: openFilesFromStartArgs

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
public static void openFilesFromStartArgs(final OtrosApplication otrosApplication, List<String> filesList, String path) {
  ArrayList<FileObject> fileObjects = new ArrayList<>();
  for (String file : filesList) {
    try {
      FileObject fo = VFS.getManager().resolveFile(new File(path), file);
      fileObjects.add(fo);
    } catch (FileSystemException e) {
      LOGGER.error("Cant resolve " + file + " in path " + path, e);
    }
  }
  final FileObject[] files = fileObjects.toArray(new FileObject[fileObjects.size()]);
  SwingUtilities.invokeLater(() -> {
    JFrame applicationJFrame = null;
    if (otrosApplication != null) {
      applicationJFrame = otrosApplication.getApplicationJFrame();
      OtrosSwingUtils.frameToFront(applicationJFrame);
    }
    if (files.length > 1) {
      new TailMultipleFilesIntoOneView(otrosApplication).openFileObjectsIntoOneView(files, applicationJFrame);
    } else if (files.length == 1) {
      //open log as one file
      LOGGER.debug("WIll open {}", files[0]);
      new TailLogWithAutoDetectActionListener(otrosApplication).openFileObjectInTailMode(files[0], Utils.getFileObjectShortName(files[0]));
    }
  });
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:27,代码来源:SingleInstanceRequestResponseDelegate.java

示例11: setUp

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws IOException {
  fsManager = VFS.getManager();
  System.out.println("Starting wiremock");
  wireMock = new WireMockServer(wireMockConfig().port(PORT));
  final byte[] gzipped = IOUtils.toByteArray(UtilsTest.class.getClassLoader().getResourceAsStream("hierarchy/hierarchy.log.gz"));
  final byte[] notGzipped = IOUtils.toByteArray(UtilsTest.class.getClassLoader().getResourceAsStream("hierarchy/hierarchy.log"));

  wireMock.stubFor(get(urlEqualTo("/log.txt"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "text/plain")
          .withBody(notGzipped)));

  wireMock.stubFor(get(urlEqualTo("/log.txt.gz"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "text/plain")
          .withBody(gzipped)));

  wireMock.start();

}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:24,代码来源:UtilsTest.java

示例12: shouldUpdateFileMonitoringLocation

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
@Test
public void shouldUpdateFileMonitoringLocation() throws FileSystemException {
    final String fileName = "res:config/motech-settings.properties";
    ConfigLocation configLocation = new ConfigLocation(fileName);
    FileObject newLocation = VFS.getManager().resolveFile(fileName);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);

    configFileMonitor.updateFileMonitor();

    InOrder inOrder = inOrder(coreConfigurationService, fileMonitor);
    inOrder.verify(fileMonitor).stop();
    inOrder.verify(fileMonitor).removeFile(any(FileObject.class));
    inOrder.verify(coreConfigurationService).getConfigLocation();
    inOrder.verify(fileMonitor).addFile(newLocation);
    inOrder.verify(fileMonitor).start();
}
 
开发者ID:motech,项目名称:motech,代码行数:17,代码来源:ConfigFileMonitorTest.java

示例13: UKBenchGroupDataset

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
/**
 * @param path
 * @param reader
 */
public UKBenchGroupDataset(String path, ObjectReader<IMAGE, FileObject> reader) {
	super(reader);
	this.ukbenchObjects = new HashMap<Integer, UKBenchListDataset<IMAGE>>();
	FileSystemManager manager;
	try {
		manager = VFS.getManager();
		this.base = manager.resolveFile(path);
	} catch (final FileSystemException e) {
		throw new RuntimeException(e);
	}

	for (int i = 0; i < UKBENCH_OBJECTS; i++) {
		this.ukbenchObjects.put(i, new UKBenchListDataset<IMAGE>(path, reader, i));
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:20,代码来源:UKBenchGroupDataset.java

示例14: getTrainingImages

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
/**
 * Load the training images using the given reader. To load the images as
 * {@link MBFImage}s, you would do the following: <code>
 * CIFAR100Dataset.getTrainingImages(CIFAR100Dataset.MBFIMAGE_READER);
 * </code>
 *
 * @param reader
 *            the reader
 * @param fineLabels
 *            if true, then the fine labels will be used; otherwise the
 *            coarse superclass labels will be used.
 * @return the training image dataset
 * @throws IOException
 */
public static <IMAGE> GroupedDataset<String, ListDataset<IMAGE>, IMAGE> getTrainingImages(BinaryReader<IMAGE> reader,
		boolean fineLabels)
		throws IOException
				{
	final MapBackedDataset<String, ListDataset<IMAGE>, IMAGE> dataset = new MapBackedDataset<String, ListDataset<IMAGE>, IMAGE>();

	final FileSystemManager fsManager = VFS.getManager();
	final FileObject base = fsManager.resolveFile(downloadAndGetPath());

	final List<String> classList = loadClasses(dataset, base, fineLabels);

	DataInputStream is = null;
	try {
		is = new DataInputStream(base.resolveFile(TRAINING_FILE).getContent().getInputStream());

		loadData(is, dataset, classList, reader, 50000, fineLabels);
	} finally {
		IOUtils.closeQuietly(is);
	}

	return dataset;
				}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:37,代码来源:CIFAR100Dataset.java

示例15: getTestImages

import org.apache.commons.vfs2.VFS; //导入依赖的package包/类
/**
 * Load the test images using the given reader. To load the images as
 * {@link MBFImage}s, you would do the following: <code>
 * CIFAR100Dataset.getTestImages(CIFAR100Dataset.MBFIMAGE_READER);
 * </code>
 *
 * @param reader
 *            the reader
 * @param fineLabels
 *            if true, then the fine labels will be used; otherwise the
 *            coarse superclass labels will be used.
 * @return the test image dataset
 * @throws IOException
 */
public static <IMAGE> GroupedDataset<String, ListDataset<IMAGE>, IMAGE> getTestImages(BinaryReader<IMAGE> reader,
		boolean fineLabels)
				throws IOException
				{
	final MapBackedDataset<String, ListDataset<IMAGE>, IMAGE> dataset = new MapBackedDataset<String, ListDataset<IMAGE>, IMAGE>();

	final FileSystemManager fsManager = VFS.getManager();
	final FileObject base = fsManager.resolveFile(downloadAndGetPath());

	final List<String> classList = loadClasses(dataset, base, fineLabels);

	DataInputStream is = null;
	try {
		is = new DataInputStream(base.resolveFile(TEST_FILE).getContent().getInputStream());
		loadData(is, dataset, classList, reader, 10000, fineLabels);
	} finally {
		IOUtils.closeQuietly(is);
	}

	return dataset;
				}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:36,代码来源:CIFAR100Dataset.java


注:本文中的org.apache.commons.vfs2.VFS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。