本文整理汇总了Java中org.apache.commons.vfs2.FileSystemManager类的典型用法代码示例。如果您正苦于以下问题:Java FileSystemManager类的具体用法?Java FileSystemManager怎么用?Java FileSystemManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileSystemManager类属于org.apache.commons.vfs2包,在下文中一共展示了FileSystemManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJar
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的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();
}
示例2: main
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的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();
}
}
示例3: getFileSystemManager
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
/**
* Returns the global filesystem manager
*
* @return the global filesystem manager
*/
public static FileSystemManager getFileSystemManager() {
aLock.readLock().lock();
try {
if (fileSystemManager == null) {
try {
StandardFileSystemManager fm = new StandardFileSystemManager();
fm.setCacheStrategy(CacheStrategy.MANUAL);
fm.init();
LOGGER.info("Supported schemes: {} ", Joiner.on(", ").join(fm.getSchemes()));
fileSystemManager = fm;
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
return fileSystemManager;
} finally {
aLock.readLock().unlock();
}
}
示例4: UKBenchGroupDataset
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的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));
}
}
示例5: getTrainingImages
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的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;
}
示例6: getTestImages
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的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;
}
示例7: Record
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
protected Record(FileObject image) throws FileSystemException, IOException {
final FileSystemManager fsManager = VFS.getManager();
final FileObject imagesBase = fsManager.resolveFile(downloadAndGetImagePath());
final FileObject annotationsBase = fsManager.resolveFile(downloadAndGetAnnotationPath());
// get the id
id = imagesBase.getName().getRelativeName(image.getName());
// the class
objectClass = image.getParent().getName().getBaseName();
// find the annotation file
final String annotationFileName = id.replace("image_", "annotation_").replace(".jpg", ".mat");
final FileObject annotationFile = annotationsBase.resolveFile(annotationFileName);
parseAnnotations(annotationFile);
}
示例8: getTrainingImages
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
/**
* Load the training images using the given reader. To load the images as
* {@link MBFImage}s, you would do the following: <code>
* CIFAR10Dataset.getTrainingImages(CIFAR10Dataset.MBFIMAGE_READER);
* </code>
*
* @param reader
* the reader
* @return the training image dataset
* @throws IOException
*/
public static <IMAGE> GroupedDataset<String, ListDataset<IMAGE>, IMAGE> getTrainingImages(BinaryReader<IMAGE> reader)
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);
for (final String t : TRAINING_FILES) {
DataInputStream is = null;
try {
is = new DataInputStream(base.resolveFile(t).getContent().getInputStream());
loadData(is, dataset, classList, reader);
} finally {
IOUtils.closeQuietly(is);
}
}
return dataset;
}
示例9: getTestImages
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
/**
* Load the test images using the given reader. To load the images as
* {@link MBFImage}s, you would do the following: <code>
* CIFAR10Dataset.getTestImages(CIFAR10Dataset.MBFIMAGE_READER);
* </code>
*
* @param reader
* the reader
* @return the test image dataset
* @throws IOException
*/
public static <IMAGE> GroupedDataset<String, ListDataset<IMAGE>, IMAGE> getTestImages(BinaryReader<IMAGE> reader)
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);
DataInputStream is = null;
try {
is = new DataInputStream(base.resolveFile(TEST_FILE).getContent().getInputStream());
loadData(is, dataset, classList, reader);
} finally {
IOUtils.closeQuietly(is);
}
return dataset;
}
示例10: testVfs
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
@Test
public void testVfs() throws Exception {
((DefaultFileSystemManager)VFS.getManager()).addProvider("mtm", new MetadataToMondrianVfs());
FileSystemManager fsManager = VFS.getManager();
FileObject fobj = fsManager.resolveFile("mtm:src/test/resources/example_olap.xmi");
StringBuilder buf = new StringBuilder(1000);
InputStream in = fobj.getContent().getInputStream();
int n;
while ((n = in.read()) != -1) {
buf.append((char) n);
}
in.close();
String results = buf.toString();
assertTrue(results.indexOf("<Cube name=\"customer2 Table\">") >= 0);
}
示例11: addFileObjects
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
/**
* Appends the specified FileObjects to the list of FileObjects to search
* for classes and resources.
*
* @param manager The FileSystemManager.
* @param files the FileObjects to append to the search path.
* @throws FileSystemException if an error occurs.
*/
private void addFileObjects(final FileSystemManager manager,
final FileObject[] files) throws FileSystemException
{
for (int i = 0; i < files.length; i++)
{
FileObject file = files[i];
if (!file.exists())
{
// Does not exist - skip
continue;
}
// TODO - use federation instead
if (manager.canCreateFileSystem(file))
{
// Use contents of the file
file = manager.createFileSystem(file);
}
resources.add(file);
}
}
示例12: testFiles
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
private static void testFiles(FileSystemManager mgr) throws FileSystemException
{
for (int i = 0; i < 10; i++)
{
// warmup jvm
mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:[email protected]/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
}
long start = System.currentTimeMillis();
for (int i = 0; i < NUOF_RESOLVES; i++)
{
mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:[email protected]/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
}
long end = System.currentTimeMillis();
System.err.println("time to resolve " + NUOF_RESOLVES + " files: "
+ (end - start) + "ms");
}
示例13: testNames
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
private static void testNames(FileSystemManager mgr, FileName rootName) throws FileSystemException
{
for (int i = 0; i < 10; i++)
{
// warmup jvm
mgr.resolveName(rootName,
"/many/path/elements/with%25esc/any%25where/to/file.txt");
}
long start = System.currentTimeMillis();
for (int i = 0; i < NUOF_RESOLVES; i++)
{
mgr.resolveName(rootName,
"/many/path/elements/with%25esc/any%25where/to/file.txt");
}
long end = System.currentTimeMillis();
System.err.println("time to resolve " + NUOF_RESOLVES + " names: "
+ (end - start) + "ms");
}
示例14: getBaseTestFolder
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
/**
* Returns the base folder for tests.
*/
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager)
throws Exception
{
if (!inited)
{
// Import the test tree
FileObject fo = manager.resolveFile("ram:/");
RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
fs.importTree(new File(AbstractVfsTestCase.getTestDirectory()));
fo.close();
inited=true;
}
final String uri = "ram:/";
return manager.resolveFile(uri);
}
示例15: testDefaultInstance
import org.apache.commons.vfs2.FileSystemManager; //导入依赖的package包/类
/**
* Sanity test.
*/
public void testDefaultInstance() throws Exception
{
// Locate the default manager
final FileSystemManager manager = VFS.getManager();
// Lookup a test jar file
final File jarFile = getTestResource("test.jar");
FileObject file = manager.toFileObject(jarFile);
assertNotNull(file);
assertTrue(file.exists());
assertSame(FileType.FILE, file.getType());
// Expand it
file = manager.createFileSystem(file);
assertNotNull(file);
assertTrue(file.exists());
assertSame(FileType.FOLDER, file.getType());
}