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

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

Introduction

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

Prototype

String getURI();

Source Link

Document

Returns the absolute URI of this file.

Usage

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

@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    GenericFileName genericFileName = (GenericFileName) name.getRoot();
    String hostName = genericFileName.getHostName();
    int port = genericFileName.getPort();
    // TODO: load from metastore
    NamedCluster namedCluster = namedClusterService.getClusterTemplate();
    namedCluster.setHdfsHost(hostName);/*from   w  w  w .  j a v a2 s.com*/
    if (port > 0) {
        namedCluster.setHdfsPort(String.valueOf(port));
    } else {
        namedCluster.setHdfsPort("");
    }
    namedCluster.setMapr(MAPRFS.equals(name.getScheme()));
    try {
        return new HDFSFileSystem(name, fileSystemOptions, hadoopFileSystemLocator
                .getHadoopFilesystem(namedCluster, URI.create(name.getURI() == null ? "" : name.getURI())));
    } catch (ClusterInitializationException e) {
        throw new FileSystemException(e);
    }
}

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

@Test
public void testDoCreateFileSystemNoPort() throws FileSystemException, ClusterInitializationException {
    String testHostname = "testHostname";
    FileName fileName = mock(FileName.class);
    GenericFileName genericFileName = mock(GenericFileName.class);
    when(fileName.getURI()).thenReturn("");
    when(fileName.getRoot()).thenReturn(genericFileName);
    when(genericFileName.getHostName()).thenReturn(testHostname);
    when(genericFileName.getPort()).thenReturn(-1);
    assertTrue(hdfsFileProvider.doCreateFileSystem(fileName, null) instanceof HDFSFileSystem);
    verify(hadoopFileSystemLocator).getHadoopFilesystem(namedCluster, URI.create(""));
    verify(namedCluster).setHdfsHost(testHostname);
    verify(namedCluster).setHdfsPort("");
}

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

@Test
public void testDoCreateFileSystemPort() throws FileSystemException, ClusterInitializationException {
    String testHostname = "testHostname";
    FileName fileName = mock(FileName.class);
    GenericFileName genericFileName = mock(GenericFileName.class);
    when(fileName.getURI()).thenReturn("");
    when(fileName.getRoot()).thenReturn(genericFileName);
    when(genericFileName.getHostName()).thenReturn(testHostname);
    when(genericFileName.getPort()).thenReturn(111);
    assertTrue(hdfsFileProvider.doCreateFileSystem(fileName, null) instanceof HDFSFileSystem);
    verify(hadoopFileSystemLocator).getHadoopFilesystem(namedCluster, URI.create(""));
    verify(namedCluster).setHdfsHost(testHostname);
    verify(namedCluster).setHdfsPort("111");
}

From source file:org.pentaho.di.core.util.CurrentDirectoryResolver.java

public VariableSpace resolveCurrentDirectory(VariableSpace parentVariables,
        RepositoryDirectoryInterface directory, String filename) {
    Variables tmpSpace = new Variables();
    tmpSpace.setParentVariableSpace(parentVariables);
    tmpSpace.initializeVariablesFrom(parentVariables);

    if (directory != null) {
        tmpSpace.setVariable(Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, directory.toString());
        tmpSpace.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, directory.toString());
        tmpSpace.setVariable(Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, directory.toString());
    } else if (filename != null) {
        try {/*  w ww  .  java  2 s  .  c o m*/
            FileObject fileObject = KettleVFS.getFileObject(filename, tmpSpace);

            if (!fileObject.exists()) {
                // don't set variables if the file doesn't exist
                return tmpSpace;
            }

            FileName fileName = fileObject.getName();

            // The filename of the transformation
            tmpSpace.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName());

            // The directory of the transformation
            FileName fileDir = fileName.getParent();
            tmpSpace.setVariable(Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI());
            tmpSpace.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI());
            tmpSpace.setVariable(Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, fileDir.getURI());
        } catch (Exception e) {
        }
    }
    return tmpSpace;
}

From source file:org.pentaho.di.trans.steps.propertyinput.PropertyInputMetaTest.java

@Test
public void testOpenNextFile() throws Exception {

    PropertyInputMeta propertyInputMeta = Mockito.mock(PropertyInputMeta.class);
    PropertyInputData propertyInputData = new PropertyInputData();
    FileInputList fileInputList = new FileInputList();
    FileObject fileObject = Mockito.mock(FileObject.class);
    FileName fileName = Mockito.mock(FileName.class);
    Mockito.when(fileName.getRootURI()).thenReturn("testFolder");
    Mockito.when(fileName.getURI()).thenReturn("testFileName.ini");

    String header = "test ini data with umlauts";
    String key = "key";
    String testValue = "value-with-";
    String testData = "[" + header + "]\r\n" + key + "=" + testValue;
    String charsetEncode = "Windows-1252";

    InputStream inputStream = new ByteArrayInputStream(testData.getBytes(Charset.forName(charsetEncode)));
    FileContent fileContent = Mockito.mock(FileContent.class);
    Mockito.when(fileObject.getContent()).thenReturn(fileContent);
    Mockito.when(fileContent.getInputStream()).thenReturn(inputStream);
    Mockito.when(fileObject.getName()).thenReturn(fileName);
    fileInputList.addFile(fileObject);/*  ww w .  java  2  s. co m*/

    propertyInputData.files = fileInputList;
    propertyInputData.propfiles = false;
    propertyInputData.realEncoding = charsetEncode;

    PropertyInput propertyInput = Mockito.mock(PropertyInput.class);

    Field logField = BaseStep.class.getDeclaredField("log");
    logField.setAccessible(true);
    logField.set(propertyInput, Mockito.mock(LogChannelInterface.class));

    Mockito.doCallRealMethod().when(propertyInput).dispose(propertyInputMeta, propertyInputData);

    propertyInput.dispose(propertyInputMeta, propertyInputData);

    Method method = PropertyInput.class.getDeclaredMethod("openNextFile");
    method.setAccessible(true);
    method.invoke(propertyInput);

    Assert.assertEquals(testValue, propertyInputData.wini.get(header).get(key));
}

From source file:org.pentaho.platform.repository.solution.filebased.FileObjectTestHelper.java

public static FileObject mockFile(final String contents, final boolean exists) throws FileSystemException {
    FileObject fileObject = mock(FileObject.class);
    when(fileObject.exists()).thenReturn(exists);
    FileContent fileContent = mock(FileContent.class);
    when(fileObject.getContent()).thenReturn(fileContent);
    when(fileContent.getInputStream()).thenReturn(IOUtils.toInputStream(contents));
    final FileObject parent = mock(FileObject.class);
    when(fileObject.getParent()).thenReturn(parent);
    final FileName fileName = mock(FileName.class);
    when(parent.getName()).thenReturn(fileName);
    when(fileName.getURI()).thenReturn("mondrian:/catalog");
    return fileObject;
}

From source file:pl.otros.logview.api.io.UtilsTest.java

@Test
private void testGetObjectShortName(String scheme, String url, String baseName, String output) {
    // given/*from   ww w  .ja va2s . c  o m*/
    FileObject fileObjectMock = mock(FileObject.class);
    FileName fileNameMock = mock(FileName.class);

    when(fileObjectMock.getName()).thenReturn(fileNameMock);
    when(fileNameMock.getScheme()).thenReturn(scheme);
    when(fileNameMock.getURI()).thenReturn(url);
    when(fileNameMock.getBaseName()).thenReturn(baseName);

    // when
    String fileObjectShortName = Utils.getFileObjectShortName(fileObjectMock);

    // then
    AssertJUnit.assertEquals(output, fileObjectShortName);
}

From source file:pl.otros.logview.io.UtilsTest.java

@Test(enabled = false)
private void testGetObjectShortName(String scheme, String url, String baseName, String output) {
    // given//from   w  ww  . ja v a2s .  c o m
    FileObject fileObjectMock = mock(FileObject.class);
    FileName fileNameMock = mock(FileName.class);

    when(fileObjectMock.getName()).thenReturn(fileNameMock);
    when(fileNameMock.getScheme()).thenReturn(scheme);
    when(fileNameMock.getURI()).thenReturn(url);
    when(fileNameMock.getBaseName()).thenReturn(baseName);

    // when
    String fileObjectShortName = Utils.getFileObjectShortName(fileObjectMock);

    // then
    AssertJUnit.assertEquals(output, fileObjectShortName);
}

From source file:pt.webdetails.cpk.utils.ZipUtil.java

private FileName getTopFileName(List<FileObject> files) {
    FileName topFileName = null;
    try {//from  w w  w  . j  a va  2s  .c  om
        if (!files.isEmpty()) {
            topFileName = files.get(0).getParent().getName();
        }
        for (FileObject file : files) {
            logger.debug(file.getParent().getName().getPath());
            FileName myFileName = file.getParent().getName();
            if (topFileName.getURI().length() > myFileName.getURI().length()) {
                topFileName = myFileName;
            }
        }
    } catch (Exception exception) {
        logger.error(exception);
    }
    return topFileName;
}