Example usage for org.apache.commons.vfs2 FileName getPath

List of usage examples for org.apache.commons.vfs2 FileName getPath

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileName getPath.

Prototype

String getPath();

Source Link

Document

Returns the absolute path of this file, within its file system.

Usage

From source file:com.streamsets.pipeline.lib.remote.TestFTPRemoteConnector.java

private FileObject createFileObject(String path) {
    FileObject fileObject = Mockito.mock(FileObject.class);
    FileName fn = Mockito.mock(FileName.class);
    Mockito.when(fn.getPath()).thenReturn(path);
    Mockito.when(fileObject.getName()).thenReturn(fn);
    return fileObject;
}

From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java

/**
 * By default FileObject.getChildren() will use doListChildrenResolved() if available
 * //from  w w  w  . ja  va2 s.  c om
 * @throws Exception 
 */
@Test
public void A005_listChildren() throws Exception {
    String currAccountStr = testProperties.getProperty("azure.account.name");
    String currKey = testProperties.getProperty("azure.account.key");
    String currContainerStr = testProperties.getProperty("azure.test0001.container.name");
    String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net

    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider());
    currMan.init();

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currFileNameStr = "uploadFile02";
    String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr,
            currFileNameStr);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    FileObject[] currObjs = currFile.getChildren();
    for (FileObject obj : currObjs) {
        FileName currName = obj.getName();
        Boolean res = obj.exists();
        FileType ft = obj.getType();

        log.info(String.format("\nNAME.PATH : '%s'\nEXISTS : %b\nTYPE : %s\n\n", currName.getPath(), res, ft));
    }
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java

/**
 * By default FileObject.getChildren() will use doListChildrenResolved() if available
 * /* w  ww .j a v a2  s.c o  m*/
 * @throws Exception 
 */
@Test
public void A007_listChildren() throws Exception {
    String currAccountStr = testProperties.getProperty("s3.access.id");
    String currKey = testProperties.getProperty("s3.access.secret");
    String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name");
    String currHost = testProperties.getProperty("s3.host");
    String currRegion = testProperties.getProperty("s3.region");

    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    SS3FileProvider currSS3 = new SS3FileProvider();

    // Optional set endpoint
    //currSS3.setEndpoint(currHost);

    // Optional set region
    //currSS3.setRegion(currRegion);

    currMan.addProvider(SS3Constants.S3SCHEME, currSS3);
    currMan.init();

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currFileNameStr = "uploadFile02";
    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr,
            currFileNameStr);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    FileObject[] currObjs = currFile.getChildren();
    for (FileObject obj : currObjs) {
        FileName currName = obj.getName();
        Boolean res = obj.exists();
        FileType ft = obj.getType();

        log.info(String.format("\nNAME.PATH : '%s'\nEXISTS : %b\nTYPE : %s\n\n", currName.getPath(), res, ft));
    }
}

From source file:org.aludratest.service.file.impl.FileServiceConfiguration.java

/**
 * @param file the file/*  ww w  .j a  va 2s  .c  o m*/
 * @return the full path
 */
public final String pathFromRoot(FileObject file) {
    FileName rootFolderName = rootFolder.getName();
    FileName fileName = file.getName();
    try {
        return rootFolderName.getRelativeName(fileName);
    } catch (FileSystemException e) {
        throw new AutomationException(
                "Error resolving relative path " + rootFolderName.getPath() + " -> " + fileName.getPath(), e);
    }
}

From source file:org.apache.accumulo.start.classloader.vfs.providers.HdfsFileSystem.java

@Override
public FileObject resolveFile(final FileName name) throws FileSystemException {

    synchronized (this) {
        if (null == this.fs) {
            final String hdfsUri = name.getRootURI();
            final Configuration conf = new Configuration(true);
            conf.set(org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY, hdfsUri);
            this.fs = null;
            try {
                fs = org.apache.hadoop.fs.FileSystem.get(conf);
            } catch (final IOException e) {
                log.error("Error connecting to filesystem " + hdfsUri, e);
                throw new FileSystemException("Error connecting to filesystem " + hdfsUri, e);
            }/*from   ww w . ja v a  2s. c om*/
        }
    }

    boolean useCache = (null != getContext().getFileSystemManager().getFilesCache());
    FileObject file;
    if (useCache) {
        file = this.getFileFromCache(name);
    } else {
        file = null;
    }
    if (null == file) {
        String path = null;
        try {
            path = URLDecoder.decode(name.getPath(), UTF_8.name());
        } catch (final UnsupportedEncodingException e) {
            path = name.getPath();
        }
        final Path filePath = new Path(path);
        file = new HdfsFileObject((AbstractFileName) name, this, fs, filePath);
        if (useCache) {
            this.putFileToCache(file);
        }

    }

    /**
     * resync the file information if requested
     */
    if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
        file.refresh();
    }

    return file;
}

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

protected File getRealRoot() {
    if (realRoot == null) {
        try {/*ww  w . ja va2 s.  c  om*/
            FileName name = getFile("/").getName();
            realRoot = new File(((LocalFileName) name).getRootFile(), name.getPath());
        } catch (FileSystemException e) {
            logger.error(e.getMessage(), e);
            throw new IllegalArgumentException(e);
        }
    }

    return realRoot;
}

From source file:org.obiba.opal.web.FilesResourceTest.java

@Test
public void testCreateFolder_FolderCreatedSuccessfully() throws FileSystemException, URISyntaxException {
    expect(fileObjectMock.getType()).andReturn(FileType.FOLDER).atLeastOnce();
    expect(fileObjectMock.exists()).andReturn(true).atLeastOnce();

    FileObject childFolderMock = createMock(FileObject.class);

    FileName fileNameMock = createMock(FileName.class);
    expect(fileNameMock.getBaseName()).andReturn("folder").atLeastOnce();
    expect(fileNameMock.getPath()).andReturn("folder1/folder").atLeastOnce();

    expect(childFolderMock.getName()).andReturn(fileNameMock).atLeastOnce();
    expect(childFolderMock.exists()).andReturn(false).atLeastOnce();

    FileContent mockContent = createMock(FileContent.class);
    expect(childFolderMock.getContent()).andReturn(mockContent).atLeastOnce();
    expect(mockContent.getLastModifiedTime()).andReturn((long) 1).atLeastOnce();

    childFolderMock.createFolder();/*from w w w  .j  a  va2s .co  m*/
    FileObject parentFolderMock = createMock(FileObject.class);
    expect(childFolderMock.getParent()).andReturn(parentFolderMock).atLeastOnce();
    expect(childFolderMock.isReadable()).andReturn(true).atLeastOnce();
    expect(childFolderMock.isWriteable()).andReturn(true).atLeastOnce();
    expect(parentFolderMock.isWriteable()).andReturn(true).atLeastOnce();
    expect(fileObjectMock.resolveFile("folder")).andReturn(childFolderMock).atLeastOnce();
    expect(uriInfoMock.getBaseUriBuilder()).andReturn(UriBuilder.fromPath("/"));

    replay(fileObjectMock, uriInfoMock, parentFolderMock, childFolderMock, fileNameMock, mockContent);

    Response response = getFileResource().createFolder("folder1", "folder", uriInfoMock);
    assertThat(response.getStatus()).isEqualTo(Status.CREATED.getStatusCode());
    verify(fileObjectMock, uriInfoMock, parentFolderMock, childFolderMock, fileNameMock, mockContent);
}

From source file:org.pentaho.big.data.impl.vfs.hdfs.HDFSFileObjectTest.java

@Test
public void testDoRename() throws Exception {
    FileObject fileObject = mock(FileObject.class);
    FileName fileName = mock(FileName.class);
    when(fileObject.getName()).thenReturn(fileName);
    String path2 = "fake-path-2";
    when(fileName.getPath()).thenReturn(path2);
    HadoopFileSystemPath newPath = mock(HadoopFileSystemPath.class);
    when(hadoopFileSystem.getPath(path2)).thenReturn(newPath);
    hdfsFileObject.doRename(fileObject);
    verify(hadoopFileSystem).rename(hadoopFileSystemPath, newPath);
}

From source file:org.pentaho.metaverse.analyzer.kettle.extensionpoints.job.entry.JobEntryExternalResourceListenerTest.java

@Test
public void testBeforeAfterExecution() throws Exception {
    IJobEntryExternalResourceConsumer consumer = mock(IJobEntryExternalResourceConsumer.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    Job job = mock(Job.class);
    when(job.getJobMeta()).thenReturn(mockJobMeta);
    JobEntryInterface jobEntryInterface = mock(JobEntryInterface.class);
    when(jobEntryInterface.getParentJob()).thenReturn(job);
    when(jobEntryInterface.getResourceDependencies(mockJobMeta))
            .thenReturn(Collections.singletonList(new ResourceReference(null,
                    Collections.singletonList(new ResourceEntry("myFile", ResourceEntry.ResourceType.FILE)))));
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);

    IExecutionProfile executionProfile = mock(IExecutionProfile.class);
    IExecutionData executionData = mock(IExecutionData.class);
    when(executionProfile.getExecutionData()).thenReturn(executionData);
    JobLineageHolderMap.getInstance().getLineageHolder(job).setExecutionProfile(executionProfile);

    JobEntryExternalResourceListener listener = new JobEntryExternalResourceListener(consumer);

    FileObject mockFile = mock(FileObject.class);
    FileName mockFilename = mock(FileName.class);
    when(mockFilename.getPath()).thenReturn("/path/to/file");
    when(mockFile.getName()).thenReturn(mockFilename);
    ResultFile resultFile = mock(ResultFile.class);
    when(resultFile.getFile()).thenReturn(mockFile);
    List<ResultFile> resultFiles = Collections.singletonList(resultFile);
    Result result = mock(Result.class);
    when(result.getResultFilesList()).thenReturn(resultFiles);

    // Call beforeExecution for coverage
    listener.beforeExecution(null, null, null);

    listener.afterExecution(job, jobEntryCopy, jobEntryInterface, result);
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionDirectFileModel.java

@Override
public byte[] getData(final FileName fullName) throws FileSystemException {
    /*/*from  www . j a v  a  2 s  . c  o  m*/
    /api/repo/files/{0}/download?withManifest=false
    public Response doGetFileOrDirAsDownloadMethod(
      @PathParam("pathId") String pathId,
      @QueryParam("withManifest") String strWithManifest )
    */
    logger.debug("getData: " + fullName);

    try {
        final String fileId = pathToId(fullName.getPath());
        Response response = null;
        if (this.doGetFileOrDirAsDownloadMethod == null) {
            response = this.fileRes.doGetFileOrDirAsDownload("", fileId, "false");
        } else {
            // apply [5.0-SNAPSHOT] backport
            try {
                response = (Response) this.doGetFileOrDirAsDownloadMethod.invoke(this.fileRes, fileId, "false");
            } catch (InvocationTargetException e) {
                throw new FileSystemException(FAILED_TO_ACCESS_REPOSITORY);
            } catch (IllegalAccessException e) {
                throw new FileSystemException(FAILED_TO_ACCESS_REPOSITORY);
            }
        }
        throwExceptionOnBadResponse(response);
        StreamingOutput output = (StreamingOutput) response.getEntity();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        output.write(stream);
        return stream.toByteArray();
    } catch (FileNotFoundException e) {
        throw new FileSystemException(FILE_NOT_FOUND, fullName);
    } catch (IOException e) {
        throw new FileSystemException(FAILED_TO_WRITE_FILE, fullName);
    }
}