Java Code Examples for org.apache.commons.vfs2.FileType#FILE

The following examples show how to use org.apache.commons.vfs2.FileType#FILE . 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: AbstractFileNameTest.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Test
public void testHashSignEncoded() {
    final AbstractFileName fileName = new AbstractFileName("file", "/foo/bar/file#name.txt", FileType.FILE) {
        @Override
        public FileName createName(final String absolutePath, final FileType fileType) {
            return null;
        }

        @Override
        protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) {
            if (addPassword) {
                buffer.append("pass");
            }
        }
    };

    Assert.assertEquals("pass/foo/bar/file%23name.txt", fileName.getURI());
    Assert.assertEquals("/foo/bar/file%23name.txt", fileName.getFriendlyURI());
}
 
Example 2
Source File: FSManager.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private FSManager() throws IOException {
  fsManager = VFS.getManager();

  final FileObject basePath =
      fsManager.resolveFile(RES_PREFIX + File.separatorChar + ODataServiceVersion.V40.name());
  final String absoluteBaseFolder = basePath.getURL().getPath();

  for (FileObject fo : find(basePath, null)) {
    if (fo.getType() == FileType.FILE
        && !fo.getName().getBaseName().contains("Metadata")
        && !fo.getName().getBaseName().contains("metadata")) {
      final String path = fo.getURL().getPath().replace(absoluteBaseFolder, "//" + ODataServiceVersion.V40.name());
      putInMemory(fo.getContent().getInputStream(), path);
    }
  }
}
 
Example 3
Source File: S3NFileObjectTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoRename() throws Exception {
  String someNewBucketName = "someNewBucketName";
  String someNewKey = "some/newKey";
  S3NFileName newFileName = new S3NFileName( SCHEME, someNewBucketName, "/" + someNewBucketName + "/" + someNewKey, FileType.FILE );
  S3NFileObject newFile = new S3NFileObject( newFileName, fileSystemSpy );
  ArgumentCaptor<CopyObjectRequest> copyObjectRequestArgumentCaptor = ArgumentCaptor.forClass( CopyObjectRequest.class );
  when( s3ServiceMock.doesBucketExistV2( someNewBucketName ) ).thenReturn( true );
  s3FileObjectFileSpy.moveTo( newFile );

  verify( s3ServiceMock ).copyObject( copyObjectRequestArgumentCaptor.capture() );
  assertEquals( someNewBucketName, copyObjectRequestArgumentCaptor.getValue().getDestinationBucketName() );
  assertEquals( someNewKey, copyObjectRequestArgumentCaptor.getValue().getDestinationKey() );
  assertEquals( BUCKET_NAME, copyObjectRequestArgumentCaptor.getValue().getSourceBucketName() );
  assertEquals( origKey, copyObjectRequestArgumentCaptor.getValue().getSourceKey() );
}
 
Example 4
Source File: LocalFile.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the file's type.
 */
@Override
protected FileType doGetType() throws Exception {
    // JDK BUG: 6192331
    // if (!file.exists())
    if (!file.exists() && file.length() < 1) {
        return FileType.IMAGINARY;
    }

    if (file.isDirectory()) {
        return FileType.FOLDER;
    }

    // In doubt, treat an existing file as file
    // if (file.isFile())
    // {
    return FileType.FILE;
    // }

    // throw new FileSystemException("vfs.provider.local/get-type.error", file);
}
 
Example 5
Source File: JobEntryAddResultFilenames.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() )
        || ( !info.getFile().getParent().equals( info.getBaseFolder() ) && includeSubfolders ) ) {
        if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null )
          || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard(
            short_filename, fileWildcard ) ) ) {
          returncode = true;
        }
      }
    }
  } catch ( Exception e ) {
    logError( "Error while finding files ... in ["
      + info.getFile().toString() + "]. Exception :" + e.getMessage() );
    returncode = false;
  }
  return returncode;
}
 
Example 6
Source File: Mail.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() )
        || ( ( !info.getFile().getParent().equals( info.getBaseFolder() ) && meta.isIncludeSubFolders() ) ) ) {
        if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null )
          || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard(
            short_filename, fileWildcard ) ) ) {
          returncode = true;
        }
      }
    }
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "Mail.Error.FindingFiles", info.getFile().toString(), e
      .getMessage() ) );
    returncode = false;
  }
  return returncode;
}
 
Example 7
Source File: ParseFileStrategy.java    From spoofax with Apache License 2.0 6 votes vote down vote up
@Override public IStrategoTerm invoke(Context context, IStrategoTerm current) {
    if(!TermUtils.isString(current)) return null;

    try {
        final String path = TermUtils.toJavaString(current);
        final FileObject resource = resourceService.resolve(path);
        if(resource.getType() != FileType.FILE) {
            return null;
        }
        final IdentifiedResource identifiedResource = languageIdentifierService.identifyToResource(resource);
        if(identifiedResource == null) {
            return null;
        }
        final String text = sourceTextService.text(resource);
        final ISpoofaxInputUnit input =
            unitService.inputUnit(resource, text, identifiedResource.language, identifiedResource.dialect);
        final ISpoofaxParseUnit result = syntaxService.parse(input);
        return result.ast();
    } catch(ParseException | IOException e) {
        throw new StrategoException("Parsing failed unexpectedly", e);
    }
}
 
Example 8
Source File: ContentTests.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts every file in a folder exists and has the expected content.
 */
private void assertSameContent(final FileInfo expected, final FileObject folder) throws Exception {
    for (final FileInfo fileInfo : expected.children.values()) {
        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);
        }
    }
}
 
Example 9
Source File: SmbFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the type of the file, returns null if the file does not exist.
 */
@Override
protected FileType doGetType() throws Exception {
    if (!file.exists()) {
        return FileType.IMAGINARY;
    } else if (file.isDirectory()) {
        return FileType.FOLDER;
    } else if (file.isFile()) {
        return FileType.FILE;
    }

    throw new FileSystemException("vfs.provider.smb/get-type.error", getName());
}
 
Example 10
Source File: Http5FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
protected FileType doGetType() throws Exception {
    lastHeadResponse = executeHttpUriRequest(new HttpHead(getInternalURI()));
    final int status = lastHeadResponse.getCode();

    if (status == HttpStatus.SC_OK
            || status == HttpStatus.SC_METHOD_NOT_ALLOWED /* method is not allowed, but resource exist */) {
        return FileType.FILE;
    } else if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_GONE) {
        return FileType.IMAGINARY;
    } else {
        throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status));
    }
}
 
Example 11
Source File: PubmedCentralCollectionReader.java    From bluima with Apache License 2.0 5 votes vote down vote up
private NextArticle getNextArticle() throws IOException {

        while (directoryIterator.hasNext()) {
            File f = directoryIterator.next();
            // LOG.debug("extracting " + f.getAbsolutePath());

            try {
                FileObject archive = fsManager.resolveFile("tgz:file://"
                        + f.getAbsolutePath());

                // List the children of the archive file
                FileObject[] children = archive.getChildren()[0].getChildren();
                for (int i = 0; i < children.length; i++) {
                    FileObject fo = children[i];
                    if (fo.isReadable() && fo.getType() == FileType.FILE
                            && fo.getName().getExtension().equals("nxml")) {
                        FileContent fc = fo.getContent();
                        Article article = archiveArticleParser.parse(fc
                                .getInputStream());

                        NextArticle nextArticle = new NextArticle();
                        nextArticle.article = article;
                        nextArticle.file = f.getAbsolutePath();

                        return nextArticle;
                    }
                }
            } catch (Exception e) {
                LOG.error("Error extracting " + f.getAbsolutePath() + ", " + e);
            }
        }
        return null;
    }
 
Example 12
Source File: ActionDeleteFiles.java    From hop with Apache License 2.0 5 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean doReturnCode = false;
  try {

    if ( !info.getFile().toString().equals( sourceFolder ) && !parentjob.isStopped() ) {
      // Pass over the Base folder itself
      String shortFilename = info.getFile().getName().getBaseName();

      if ( !info.getFile().getParent().equals( info.getBaseFolder() ) ) {
        // Not in the Base Folder..Only if include sub folders
        if ( includeSubfolders
          && ( info.getFile().getType() == FileType.FILE ) && getFileWildcard( shortFilename, fileWildcard ) ) {
          if ( log.isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "ActionDeleteFiles.DeletingFile", info
              .getFile().toString() ) );
          }
          doReturnCode = true;
        }
      } else {
        // In the Base Folder...
        if ( ( info.getFile().getType() == FileType.FILE ) && getFileWildcard( shortFilename, fileWildcard ) ) {
          if ( log.isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "ActionDeleteFiles.DeletingFile", info
              .getFile().toString() ) );
          }
          doReturnCode = true;
        }
      }
    }
  } catch ( Exception e ) {
    log.logError(
      BaseMessages.getString( PKG, "JobDeleteFiles.Error.Exception.DeleteProcessError" ), BaseMessages
        .getString( PKG, "JobDeleteFiles.Error.Exception.DeleteProcess", info.getFile().toString(), e
          .getMessage() ) );

    doReturnCode = false;
  }

  return doReturnCode;
}
 
Example 13
Source File: CompressedFileFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the file's type.
 */
@Override
protected FileType doGetType() throws FileSystemException {
    if (getName().getPath().endsWith("/")) {
        return FileType.FOLDER;
    }
    return FileType.FILE;
}
 
Example 14
Source File: RepositoryOpenDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected String getSelectedFile() throws FileSystemException, UnsupportedEncodingException {
  if ( StringUtils.isEmpty( fileNameTextField.getText() ) ) {
    return null;
  }

  if ( selectedView.getType() == FileType.FILE ) {
    selectedView = selectedView.getParent();
  }

  final FileObject targetFile =
      selectedView.resolveFile( fileNameTextField.getText().replaceAll( "\\%", "%25" ).replaceAll( "\\!", "%21" )
          .replaceAll( ":", "%3A" ) );
  return targetFile.getName().getPathDecoded();
}
 
Example 15
Source File: Http4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
protected FileType doGetType() throws Exception {
    lastHeadResponse = executeHttpUriRequest(new HttpHead(getInternalURI()));
    final int status = lastHeadResponse.getStatusLine().getStatusCode();

    if (status == HttpStatus.SC_OK
            || status == HttpStatus.SC_METHOD_NOT_ALLOWED /* method is not allowed, but resource exist */) {
        return FileType.FILE;
    } else if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_GONE) {
        return FileType.IMAGINARY;
    } else {
        throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status));
    }
}
 
Example 16
Source File: ActionCopyFiles.java    From hop with Apache License 2.0 4 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean resultat = false;
  String fil_name = null;

  try {
    if ( info.getFile().getType() == FileType.FILE ) {
      if ( info.getFile().getName().getBaseName().equals( filename )
        && ( info.getFile().getParent().toString().equals( foldername ) ) ) {
        // check if the file exists
        fil_name = destfolder + Const.FILE_SEPARATOR + filename;

        if ( HopVfs.getFileObject( fil_name).exists() ) {
          if ( isDetailed() ) {
            logDetailed( "      " + BaseMessages.getString( PKG, "JobCopyFiles.Log.FileExists", HopVfs.getFriendlyURI( fil_name ) ) );
          }

          if ( overwrite_files ) {
            if ( isDetailed() ) {
              logDetailed( "      "
                + BaseMessages.getString(
                PKG, "JobCopyFiles.Log.FileOverwrite", HopVfs.getFriendlyURI( info.getFile() ), HopVfs.getFriendlyURI( fil_name ) ) );
            }

            resultat = true;
          }
        } else {
          if ( isDetailed() ) {
            logDetailed( "      "
              + BaseMessages.getString(
              PKG, "JobCopyFiles.Log.FileCopied", HopVfs.getFriendlyURI( info.getFile() ), HopVfs.getFriendlyURI( fil_name ) ) );
          }

          resultat = true;
        }
      }

      if ( resultat && remove_source_files ) {
        // add this folder/file to remove files
        // This list will be fetched and all entries files
        // will be removed
        list_files_remove.add( info.getFile().toString() );
      }

      if ( resultat && add_result_filesname ) {
        // add this folder/file to result files name
        list_add_result.add( HopVfs.getFileObject( fil_name ).toString() );
      }
    }
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "JobCopyFiles.Error.Exception.CopyProcess", HopVfs.getFriendlyURI( info
      .getFile() ), HopVfs.getFriendlyURI( fil_name ), e.getMessage() ) );

    resultat = false;
  }

  return resultat;
}
 
Example 17
Source File: TestFileObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override protected FileType doGetType() throws Exception {
  return FileType.FILE;
}
 
Example 18
Source File: ActionCheckFilesLocked.java    From hop with Apache License 2.0 4 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  FileObject file_name = null;
  try {

    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself

      String short_filename = info.getFile().getName().getBaseName();

      if ( !info.getFile().getParent().equals( info.getBaseFolder() ) ) {

        // Not in the Base Folder..Only if include sub folders
        if ( includeSubfolders
          && ( info.getFile().getType() == FileType.FILE ) && GetFileWildcard( short_filename, fileWildcard ) ) {
          if ( isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "ActionCheckFilesLocked.CheckingFile", info
              .getFile().toString() ) );
          }

          returncode = true;

        }
      } else {
        // In the Base Folder...

        if ( ( info.getFile().getType() == FileType.FILE ) && GetFileWildcard( short_filename, fileWildcard ) ) {
          if ( isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "ActionCheckFilesLocked.CheckingFile", info
              .getFile().toString() ) );
          }

          returncode = true;

        }
      }
    }

  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "JobCheckFilesLocked.Error.Exception.ProcessError" ), BaseMessages
      .getString( PKG, "JobCheckFilesLocked.Error.Exception.Process", info.getFile().toString(), e
        .getMessage() ) );
    returncode = false;
  } finally {
    if ( file_name != null ) {
      try {
        file_name.close();

      } catch ( IOException ex ) { /* Ignore */
      }
    }
  }

  return returncode;
}
 
Example 19
Source File: RepositoryVfsFileObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isFile() throws FileSystemException {
  return getType() == FileType.FILE;
}
 
Example 20
Source File: RepositoryVfsFileObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void createFile() throws FileSystemException {
  type = FileType.FILE;
}