org.apache.commons.vfs2.VFS.getManager()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.apache.commons.vfs2.VFS.getManager()方法的一些代码示例,展示了VFS.getManager()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。VFS.getManager()方法的具体详情如下:
包路径:org.apache.commons.vfs2.VFS
类名称:VFS
方法名:getManager

VFS.getManager介绍

[英]Returns the default FileSystemManager instance.

Warning, if you close this instance you may affect all current and future users of this manager singleton.
[中]返回默认的FileSystemManager实例。
警告,如果关闭此实例,可能会影响此manager singleton的所有当前和未来用户。

代码示例

代码示例来源:origin: apache/incubator-gobblin

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)));
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Initialize step info. Method is final against redefine in descendants.
 */
@Before
public final void beforeCommon() throws Exception {
 KettleEnvironment.init();
 PluginRegistry.addPluginType( CompressionPluginType.getInstance() );
 PluginRegistry.init( false );
 stepMeta = new StepMeta();
 stepMeta.setName( "test" );
 trans = new Trans();
 trans.setLog( log );
 trans.setRunning( true );
 transMeta = new TransMeta() {
  @Override
  public StepMeta findStep( String name ) {
   return stepMeta;
  }
 };
 fs = VFS.getManager();
 inPrefix = '/' + this.getClass().getPackage().getName().replace( '.', '/' ) + "/files/";
}

代码示例来源:origin: pentaho/pentaho-kettle

@Before
public void setup() throws FileSystemException {
 fs = VFS.getManager();
 filesPath = '/' + this.getClass().getPackage().getName().replace( '.', '/' ) + "/files/";
 transName = "LoadFileInput";
 transMeta = new TransMeta();
 transMeta.setName( transName );
 trans = new Trans( transMeta );
 stepMetaInterface = spy( new LoadFileInputMeta() );
 stepInputFiles = new FileInputList();
 Mockito.doReturn( stepInputFiles ).when( stepMetaInterface ).getFiles( any( VariableSpace.class ) );
 String stepId = PluginRegistry.getInstance().getPluginId( StepPluginType.class, stepMetaInterface );
 stepMeta = new StepMeta( stepId, "Load File Input", stepMetaInterface );
 transMeta.addStep( stepMeta );
 stepDataInterface = new LoadFileInputData();
 stepCopyNr = 0;
 stepLoadFileInput = new LoadFileInput( stepMeta, stepDataInterface, stepCopyNr, transMeta, trans );
 assertSame( stepMetaInterface, stepMeta.getStepMetaInterface() );
 runtimeSMI = stepMetaInterface;
 runtimeSDI = runtimeSMI.getStepData();
 inputField = new LoadFileInputField();
 ((LoadFileInputMeta) runtimeSMI).setInputFields( new LoadFileInputField[] { inputField } );
 stepLoadFileInput.init( runtimeSMI, runtimeSDI );
}

代码示例来源:origin: org.apache.commons/commons-configuration2

try
  builder = VFS.getManager().getFileSystemConfigBuilder(scheme);

代码示例来源:origin: org.apache.commons/commons-configuration2

@Override
public InputStream getInputStream(final URL url) throws ConfigurationException
{
  FileObject file;
  try
  {
    final FileSystemOptions opts = getOptions(url.getProtocol());
    file = (opts == null) ? VFS.getManager().resolveFile(url.toString())
        : VFS.getManager().resolveFile(url.toString(), opts);
    if (file.getType() != FileType.FILE)
    {
      throw new ConfigurationException("Cannot load a configuration from a directory");
    }
    final FileContent content = file.getContent();
    if (content == null)
    {
      final String msg = "Cannot access content of " + file.getName().getFriendlyURI();
      throw new ConfigurationException(msg);
    }
    return content.getInputStream();
  }
  catch (final FileSystemException fse)
  {
    final String msg = "Unable to access " + url.toString();
    throw new ConfigurationException(msg, fse);
  }
}

代码示例来源:origin: jbake-org/jbake

/**
   * Starts watching the file system for changes to trigger a bake.
   *
   * @param config JBakeConfiguration settings
   */
  public void start(JBakeConfiguration config) {
    try {
      FileSystemManager fsMan = VFS.getManager();
      FileObject listenPath = fsMan.resolveFile(config.getContentFolder().toURI());
      FileObject templateListenPath = fsMan.resolveFile(config.getTemplateFolder().toURI());
      FileObject assetPath = fsMan.resolveFile(config.getAssetFolder().toURI());

      logger.info("Watching for (content, template, asset) changes in [{}]", config.getSourceFolder().getPath());
      DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(config));
      monitor.setRecursive(true);
      monitor.addFile(listenPath);
      monitor.addFile(templateListenPath);
      monitor.addFile(assetPath);
      monitor.start();
    } catch (FileSystemException e) {
      logger.error("Problems watching filesystem changes", e);
    }
  }
}

代码示例来源:origin: org.apache.commons/commons-configuration2

@Override
public OutputStream getOutputStream(final URL url) throws ConfigurationException
{
  try
  {
    final FileSystemOptions opts = getOptions(url.getProtocol());
    final FileSystemManager fsManager = VFS.getManager();
    final FileObject file = (opts == null) ? fsManager.resolveFile(url.toString())
        : fsManager.resolveFile(url.toString(), opts);
    // throw an exception if the target URL is a directory
    if (file == null || file.getType() == FileType.FOLDER)
    {
      throw new ConfigurationException("Cannot save a configuration to a directory");
    }
    final FileContent content = file.getContent();
    if (content == null)
    {
      throw new ConfigurationException("Cannot access content of " + url);
    }
    return content.getOutputStream();
  }
  catch (final FileSystemException fse)
  {
    throw new ConfigurationException("Unable to access " + url, fse);
  }
}

代码示例来源:origin: org.apache.commons/commons-configuration2

@Override
public String getFileName(final String path)
{
  if (UriParser.extractScheme(path) == null)
  {
    return super.getFileName(path);
  }
  try
  {
    final FileSystemManager fsManager = VFS.getManager();
    final FileName name = fsManager.resolveURI(path);
    return name.getBaseName();
  }
  catch (final FileSystemException fse)
  {
    fse.printStackTrace();
    return null;
  }
}

代码示例来源:origin: org.apache.commons/commons-configuration2

/**
 * Returns the file that is monitored by this strategy. Note that the return
 * value can be <b>null </b> under some circumstances.
 *
 * @return the monitored file
 */
protected FileObject getFileObject()
{
  if (!getFileHandler().isLocationDefined())
  {
    return null;
  }
  try
  {
    final FileSystemManager fsManager = VFS.getManager();
    final String uri = resolveFileURI();
    if (uri == null)
    {
      throw new ConfigurationRuntimeException("Unable to determine file to monitor");
    }
    return fsManager.resolveFile(uri);
  }
  catch (final FileSystemException fse)
  {
    final String msg = "Unable to monitor " + getFileHandler().getURL().toString();
    log.error(msg);
    throw new ConfigurationRuntimeException(msg, fse);
  }
}

代码示例来源:origin: pentaho/mondrian

FileSystemManager fsManager = VFS.getManager();
if (fsManager == null) {
  throw newError("Cannot get virtual file system manager");

代码示例来源:origin: org.apache.commons/commons-configuration2

@Override
public String getBasePath(final String path)
{
  if (UriParser.extractScheme(path) == null)
  {
    return super.getBasePath(path);
  }
  try
  {
    final FileSystemManager fsManager = VFS.getManager();
    final FileName name = fsManager.resolveURI(path);
    return name.getParent().getURI();
  }
  catch (final FileSystemException fse)
  {
    fse.printStackTrace();
    return null;
  }
}

代码示例来源:origin: org.apache.commons/commons-configuration2

@Override
public URL getURL(final String basePath, final String file) throws MalformedURLException
{
  if ((basePath != null && UriParser.extractScheme(basePath) == null)
    || (basePath == null && UriParser.extractScheme(file) == null))
  {
    return super.getURL(basePath, file);
  }
  try
  {
    final FileSystemManager fsManager = VFS.getManager();
    FileName path;
    if (basePath != null && UriParser.extractScheme(file) == null)
    {
      final FileName base = fsManager.resolveURI(basePath);
      path = fsManager.resolveName(base, file);
    }
    else
    {
      path = fsManager.resolveURI(file);
    }
    final URLStreamHandler handler = new VFSURLStreamHandler(path);
    return new URL(null, path.getURI(), handler);
  }
  catch (final FileSystemException fse)
  {
    throw new ConfigurationRuntimeException("Could not parse basePath: " + basePath
      + " and fileName: " + file, fse);
  }
}

代码示例来源:origin: org.apache.commons/commons-configuration2

final FileSystemManager fsManager = VFS.getManager();
if (url != null)

代码示例来源:origin: otros-systems/otroslogviewer

private FileObject getFileObjectForLocalFile(File file) {
 try {
  return VFS.getManager().toFileObject(file);
 } catch (FileSystemException e) {
  throw new RuntimeException("Cannot open file: " + file, e);
 }
}

代码示例来源:origin: org.apache.commons/commons-configuration2

final FileSystemManager fsManager = VFS.getManager();

代码示例来源:origin: org.apache.commons/commons-vfs2

@Before
public void setup() throws IOException {
  final File zipFile = new File("src/test/resources/test-data/test.zip");
  newZipFile = File.createTempFile(getClass().getSimpleName(), ".zip");
  newZipFile.deleteOnExit();
  FileUtils.copyFile(zipFile, newZipFile);
  zipFileUri = "zip:file:" + newZipFile.getAbsolutePath() + "!/read-tests/file1.txt";
  manager = VFS.getManager();
}

代码示例来源:origin: org.apache.commons/commons-vfs2

/**
 * Even if the file name is absolute, the base file must be given. This is an inconsistency in the API, but it is
 * documented as such.
 *
 * @see "VFS-519"
 */
@Test(expected = NullPointerException.class)
public void testResolveFileAbsoluteThrows() throws FileSystemException {
  final String absolute = new File("/").getAbsoluteFile().toURI().toString();
  VFS.getManager().resolveFile((File) null, absolute);
}

代码示例来源:origin: org.apache.commons/commons-vfs2

@Test
@Ignore
public void testFileNameWithSpaces() throws URISyntaxException, IOException {
  final File file = new File("target", "a name.txt");
  final String fileURL = file.toURI().toURL().toExternalForm();
  assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath()));
  assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath()));
  final FileSystemManager manager = VFS.getManager();
  final FileObject fo = manager.resolveFile(fileURL);
  assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath()));
}

代码示例来源:origin: org.apache.commons/commons-vfs2

private void testResloveFolderSlash(final String uri, final boolean followRedirect) throws FileSystemException {
  VFS.getManager().getFilesCache().close();
  final FileSystemOptions opts = new FileSystemOptions();
  HttpFileSystemConfigBuilder.getInstance().setFollowRedirect(opts, followRedirect);
  final FileObject file = VFS.getManager().resolveFile(uri, opts);
  try {
    checkReadTestsFolder(file);
  } catch (final FileNotFolderException e) {
    // Expected: VFS HTTP does not support listing children yet.
  }
}

代码示例来源:origin: org.apache.commons/commons-vfs2

@Test
public void testAttributes() throws Exception {
  final FileObject file = JarProviderTestCase.getTestJar(VFS.getManager(), "test.jar");
  final Map<String, Object> attributes = file.getContent().getAttributes();
  Assert.assertEquals("1.0", attributes.get("Manifest-Version"));
  // Debugging:
  // this.printAttributes(attributes);
}

相关文章