org.apache.commons.vfs2.provider.AbstractFileName Java Examples

The following examples show how to use org.apache.commons.vfs2.provider.AbstractFileName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectionFileSystem.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a url for {@link ConnectionFileName}
 *
 * @param abstractFileName  File name
 * @param connectionDetails Connection details for the file name
 * @return created url otherwise null
 */
public static String getUrl( AbstractFileName abstractFileName, ConnectionDetails connectionDetails ) {
  VFSConnectionDetails vfsConnectionDetails = (VFSConnectionDetails) connectionDetails;
  String url = null;

  if ( vfsConnectionDetails != null ) {
    String domain = vfsConnectionDetails.getDomain();
    if ( !domain.equals( "" ) ) {
      domain = "/" + domain;
    }
    url = vfsConnectionDetails.getType() + ":/" + domain + abstractFileName.getPath();
    if ( url.matches( DOMAIN_ROOT ) ) {
      url += vfsConnectionDetails.getName();
    }
  }

  return url;
}
 
Example #2
Source File: JarFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
protected JarFileObject(final AbstractFileName name, final ZipEntry entry, final JarFileSystem fs,
         final boolean zipExists) throws FileSystemException {
     super(name, entry, fs, zipExists);
     if (entry != null) {
// For Java 9 and up: Force the certificates to be read and cached now. This avoids an
// IllegalStateException in java.util.jar.JarFile.isMultiRelease() when it tries
// to read the certificates and the file is closed.
     	((JarEntry) entry).getCertificates();
     }
     this.fs = fs;

     try {
         getAttributes(); // early get the attributes as the zip file might be closed
     } catch (final IOException e) {
         throw new FileSystemException(e);
     }
 }
 
Example #3
Source File: TarFileSystem.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
protected TarFileSystem(final AbstractFileName rootName, final FileObject parentLayer,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    super(rootName, parentLayer, fileSystemOptions);

    // Make a local copy of the file
    file = parentLayer.getFileSystem().replicateFile(parentLayer, Selectors.SELECT_SELF);

    // Open the Tar file
    if (!file.exists()) {
        // Don't need to do anything
        tarFile = null;
        return;
    }

    // tarFile = createTarFile(this.file);
}
 
Example #4
Source File: VirtualFileSystem.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: GoogleDriveFileObject.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected GoogleDriveFileObject( final AbstractFileName fileName, final GoogleDriveFileSystem fileSystem )
    throws FileSystemException {
  super( fileName, fileSystem );
  try {
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    DATA_STORE_FACTORY = new CustomDataStoreFactory( DATA_STORE_DIR );
    driveService = getDriveService();
    resolveFileMetadata();
  } catch ( Exception e ) {
    throw new FileSystemException( e );
  }
}
 
Example #6
Source File: GoogleDriveFileSystem.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private synchronized FileObject processFile( FileName name, boolean useCache ) throws FileSystemException {
  if ( !super.getRootName().getRootURI().equals( name.getRootURI() ) ) {
    throw new FileSystemException( "vfs.provider/mismatched-fs-for-name.error",
        new Object[] { name, super.getRootName(), name.getRootURI() } );
  } else {
    FileObject file;
    if ( useCache ) {
      file = super.getFileFromCache( name );
    } else {
      file = null;
    }

    if ( file == null ) {
      try {
        file = this.createFile( (AbstractFileName) name );
      } catch ( Exception var5 ) {
        return null;
      }

      file = super.decorateFileObject( file );
      if ( useCache ) {
        super.putFileToCache( file );
      }
    }

    if ( super.getFileSystemManager().getCacheStrategy().equals( CacheStrategy.ON_RESOLVE ) ) {
      file.refresh();
    }

    return file;
  }
}
 
Example #7
Source File: VirtualFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a virtual file system, with the supplied file as its root.
 *
 * @param rootFile The root of the file system.
 * @return A FileObject in the FileSystem.
 * @throws FileSystemException if an error occurs.
 */
public FileObject createFileSystem(final FileObject rootFile) throws FileSystemException {
    final AbstractFileName rootName = (AbstractFileName) getContext().getFileSystemManager()
            .resolveName(rootFile.getName(), FileName.ROOT_PATH);
    final VirtualFileSystem fs = new VirtualFileSystem(rootName, rootFile.getFileSystem().getFileSystemOptions());
    addComponent(fs);
    fs.addJunction(FileName.ROOT_PATH, rootFile);
    return fs.getRoot();
}
 
Example #8
Source File: ConnectionFileSystem.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public FileObject resolveFile( FileName name ) throws FileSystemException {
  try {
    return this.createFile( (AbstractFileName) name );
  } catch ( Exception e ) {
    throw new FileSystemException( "vfs.provider/resolve-file.error", name, e );
  }
}
 
Example #9
Source File: TarFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a layered file system. This method is called if the file system is not cached.
 *
 * @param scheme The URI scheme.
 * @param file The file to create the file system on top of.
 * @return The file system.
 */
@Override
protected FileSystem doCreateFileSystem(final String scheme, final FileObject file,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH,
            FileType.FOLDER);
    return new TarFileSystem(rootName, file, fileSystemOptions);
}
 
Example #10
Source File: WebSolutionFileObject.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public WebSolutionFileObject( final AbstractFileName name,
                              final AbstractFileSystem fileSystem,
                              final SolutionFileModel fs )
{
  super( name, fileSystem );
  this.fs = fs;
}
 
Example #11
Source File: TarFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected TarFileObject(final AbstractFileName name, final TarArchiveEntry entry, final TarFileSystem fs,
        final boolean tarExists) throws FileSystemException {
    super(name, fs);
    setTarEntry(entry);
    if (!tarExists) {
        type = FileType.IMAGINARY;
    }
}
 
Example #12
Source File: ZipFileSystem.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
public ZipFileSystem(final AbstractFileName rootName, final FileObject parentLayer,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    super(rootName, parentLayer, fileSystemOptions);

    // Make a local copy of the file
    file = parentLayer.getFileSystem().replicateFile(parentLayer, Selectors.SELECT_SELF);
    this.charset = ZipFileSystemConfigBuilder.getInstance().getCharset(fileSystemOptions);

    // Open the Zip file
    if (!file.exists()) {
        // Don't need to do anything
        zipFile = null;
        return;
    }
}
 
Example #13
Source File: ZipFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected ZipFileObject(final AbstractFileName name, final ZipEntry entry, final ZipFileSystem fs,
        final boolean zipExists) throws FileSystemException {
    super(name, fs);
    setZipEntry(entry);
    if (!zipExists) {
        type = FileType.IMAGINARY;
    }
}
 
Example #14
Source File: HttpFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected HttpFileObject(final AbstractFileName name, final FS fileSystem,
        final HttpFileSystemConfigBuilder builder) {
    super(name, fileSystem);
    final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions();
    urlCharset = builder.getUrlCharset(fileSystemOptions);
    userAgent = builder.getUserAgent(fileSystemOptions);
    followRedirect = builder.getFollowRedirect(fileSystemOptions);
}
 
Example #15
Source File: CompressedFileFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected CompressedFileFileObject(final AbstractFileName name, final FileObject container, final FS fs) {
    super(name, fs);
    this.container = container;

    // todo, add getBaseName(String) to FileName
    String basename = container.getName().getBaseName();
    final int pos = basename.lastIndexOf('.');
    if (pos > 0) {
        basename = basename.substring(0, pos);
    }
    children = new String[] { basename };
}
 
Example #16
Source File: FtpFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected FtpFileObject(final AbstractFileName name, final FtpFileSystem fileSystem, final FileName rootName)
        throws FileSystemException {
    super(name, fileSystem);
    final String relPath = UriParser.decode(rootName.getRelativeName(name));
    if (".".equals(relPath)) {
        // do not use the "." as path against the ftp-server
        // e.g. the uu.net ftp-server do a recursive listing then
        // this.relPath = UriParser.decode(rootName.getPath());
        // this.relPath = ".";
        this.relPath = null;
    } else {
        this.relPath = relPath;
    }
}
 
Example #17
Source File: GoogleDriveFileObject.java    From hop with Apache License 2.0 5 votes vote down vote up
protected GoogleDriveFileObject( final AbstractFileName fileName, final GoogleDriveFileSystem fileSystem )
    throws FileSystemException {
  super( fileName, fileSystem );
  try {
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    DATA_STORE_FACTORY = new CustomDataStoreFactory( DATA_STORE_DIR );
    driveService = getDriveService();
    resolveFileMetadata();
  } catch ( Exception e ) {
    throw new FileSystemException( e );
  }
}
 
Example #18
Source File: Http4FileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
@Override
protected FileObject createFile(final AbstractFileName name) throws Exception {
    return new Http4FileObject<>(name, this);
}
 
Example #19
Source File: TestFileWithDomainObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public TestFileWithDomainObject( AbstractFileName name,
                                 TestFileWithDomainSystem fs ) {
  super( name, fs );
}
 
Example #20
Source File: ConnectionFileNameParser.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static AbstractFileName parseUri( String uri, FileNameParser fileNameParser ) throws FileSystemException {
  StringBuilder name = new StringBuilder();

  String scheme = UriParser.extractScheme( uri, name );
  UriParser.canonicalizePath( name, 0, name.length(), fileNameParser );

  UriParser.fixSeparators( name );

  FileType fileType = UriParser.normalisePath( name );

  // Extract the named connection name
  final String connection = UriParser.extractFirstElement( name );

  String path = name.toString();

  return new ConnectionFileName( scheme, connection, path, fileType );
}
 
Example #21
Source File: HttpFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected HttpFileObject(final AbstractFileName name, final FS fileSystem) {
    this(name, fileSystem, HttpFileSystemConfigBuilder.getInstance());
}
 
Example #22
Source File: UrlFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected UrlFileObject(final UrlFileSystem fs, final AbstractFileName fileName) {
    super(fileName, fs);
}
 
Example #23
Source File: GzipFileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
@Override
protected FileObject createFile(final AbstractFileName name) throws FileSystemException {
    return new GzipFileObject(name, getParentLayer(), this);
}
 
Example #24
Source File: GzipFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected GzipFileObject(final AbstractFileName name, final FileObject container, final GzipFileSystem fs) {
    super(name, container, fs);
}
 
Example #25
Source File: SftpFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected SftpFileObject(final AbstractFileName name, final SftpFileSystem fileSystem) throws FileSystemException {
    super(name, fileSystem);
    relPath = UriParser.decode(fileSystem.getRootName().getRelativeName(name));
}
 
Example #26
Source File: SftpFileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a file object. This method is called only if the requested file is not cached.
 */
@Override
protected FileObject createFile(final AbstractFileName name) throws FileSystemException {
    return new SftpFileObject(name, this);
}
 
Example #27
Source File: FtpFileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a file object.
 */
@Override
protected FileObject createFile(final AbstractFileName name) throws FileSystemException {
    return new FtpFileObject(name, this, getRootName());
}
 
Example #28
Source File: Bzip2FileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
@Override
protected FileObject createFile(final AbstractFileName name) throws FileSystemException {
    return new Bzip2FileObject(name, getParentLayer(), this);
}
 
Example #29
Source File: ConnectionFileObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ConnectionFileObject( AbstractFileName name, ConnectionFileSystem fs, AbstractFileObject resolvedFileObject,
                             String domain ) {
  super( name, fs );
  this.resolvedFileObject = resolvedFileObject;
  this.domain = domain;
}
 
Example #30
Source File: TestFileObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public TestFileObject( AbstractFileName name,
                       TestFileSystem fs ) {
  super( name, fs );
}