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

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

Introduction

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

Prototype

String getBaseName();

Source Link

Document

Returns the base name of this file.

Usage

From source file:com.github.junrar.vfs2.provider.rar.RARFileObject.java

/**
 * Attaches a child.// www.j a v  a  2  s .com
 * 
 * @param childName
 *            The name of the child.
 */
public void attachChild(FileName childName) {
    children.add(childName.getBaseName());
}

From source file:com.gs.obevo.db.impl.core.reader.RerunnableChangeParserTest.java

private FileObject file(String fileName, String fileContent) {
    FileName fileNameObj = mock(FileName.class);
    when(fileNameObj.getBaseName()).thenReturn(fileName);

    FileObject file = mock(FileObject.class);
    when(file.getName()).thenReturn(fileNameObj);
    when(file.getStringContent()).thenReturn(fileContent);

    return file;//from   w ww .j ava  2  s. c om
}

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

@Test
public void testCreateAndCommitOutputStream() throws Exception {
    String name = "file.txt";
    String filePath = "/some/path/";
    FileObject fileObject = Mockito.mock(FileObject.class);
    FileName fileName = Mockito.mock(FileName.class);
    Mockito.when(fileObject.getName()).thenReturn(fileName);
    Mockito.when(fileName.getBaseName()).thenReturn(name);
    FileObject parentFileObject = Mockito.mock(FileObject.class);
    FileObject tempFileObject = Mockito.mock(FileObject.class);
    Mockito.when(fileObject.getParent()).thenReturn(parentFileObject);
    Mockito.when(parentFileObject.resolveFile(Mockito.any())).thenReturn(tempFileObject);
    FileContent tempFileContent = Mockito.mock(FileContent.class);
    Mockito.when(tempFileObject.getContent()).thenReturn(tempFileContent);

    FTPRemoteFile file = new FTPRemoteFile(filePath + name, 0L, fileObject);

    try {/*from  w  ww .  ja  v  a  2 s. com*/
        file.commitOutputStream();
        Assert.fail("Expected IOException because called commitOutputStream before createOutputStream");
    } catch (IOException ioe) {
        Assert.assertEquals("Cannot commit " + filePath + name + " - it must be written first",
                ioe.getMessage());
    }

    file.createOutputStream();
    Mockito.verify(parentFileObject).resolveFile("_tmp_" + name);
    Mockito.verify(tempFileContent).getOutputStream();

    file.commitOutputStream();
    Mockito.verify(tempFileObject).moveTo(fileObject);
}

From source file:com.streamsets.pipeline.stage.origin.remote.TestFileFilter.java

private FileSelectInfo createFileSelectInfo(String fileName, boolean isFile) throws Exception {
    FileSelectInfo fileSelectInfo = Mockito.mock(FileSelectInfo.class);
    FileObject fileObject = Mockito.mock(FileObject.class);
    Mockito.when(fileSelectInfo.getFile()).thenReturn(fileObject);
    if (isFile) {
        Mockito.when(fileObject.getType()).thenReturn(FileType.FILE);
    } else {/*  w w  w . ja va2 s . c om*/
        Mockito.when(fileObject.getType()).thenReturn(FileType.FOLDER);
    }
    FileName fName = Mockito.mock(FileName.class);
    Mockito.when(fileObject.getName()).thenReturn(fName);
    Mockito.when(fName.getBaseName()).thenReturn(fileName);
    return fileSelectInfo;
}

From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java

private String getName(final FileName name) {
    String baseName = name.getBaseName();
    baseName = baseName.substring(0, baseName.length() - DOT_GROOVY.length());
    return baseName;
}

From source file:com.gs.obevo.db.impl.core.reader.DbDirectoryChangesetReaderTest.java

private FileSelectInfo getFileSelectInfo(String fileBaseName) {
    FileName fileNameObject = mock(FileName.class);
    when(fileNameObject.getBaseName()).thenReturn(fileBaseName);

    org.apache.commons.vfs2.FileObject file = mock(org.apache.commons.vfs2.FileObject.class);
    when(file.getName()).thenReturn(fileNameObject);

    FileSelectInfo info = mock(FileSelectInfo.class);
    when(info.getFile()).thenReturn(file);

    return info;/*from  w  ww. j a  va2 s.  co  m*/
}

From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java

private boolean isScriptFile(final FileObject file) {

    final FileName name = file.getName();

    if (name.getBaseName().endsWith(DOT_GROOVY)) {
        return true;
    }/*from  ww  w  .  j  ava  2  s .com*/

    return false;

}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java

/**
 * Called when the children of this file change.
 * //from  w  ww .  j av a  2 s  .  c  o m
 * @param child the child
 * @param newType the new type
 */
@Override
protected void onChildrenChanged(FileName child, FileType newType) {
    if (children != null && newType.equals(FileType.IMAGINARY)) {
        try {
            children.remove(UriParser.decode(child.getBaseName()));
        } catch (FileSystemException e) {
            throw new RuntimeException(e.getMessage());
        }
    } else {
        // if child was added we have to rescan the children
        // TODO - get rid of this
        children = null;
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java

private FileObject[] find2dFiles(final FileObject remoteWorking) throws IOException {
    final List<FileObject> resultList = new ArrayList<>();
    if (remoteWorking == null)
        return null;

    final FileObject[] children = remoteWorking.getChildren();
    for (final FileObject child : children) {
        final FileName childName = child.getName();
        final String baseName = childName.getBaseName();
        if (FilenameUtils.wildcardMatch(baseName, "*.2d") || FilenameUtils.wildcardMatch(baseName, "*.2d.zip")) //$NON-NLS-1$ //$NON-NLS-2$
        {/*from  ww w  .j  a v a  2 s . co  m*/
            resultList.add(child);
        }

    }
    return resultList.toArray(new FileObject[resultList.size()]);
}

From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java

private FileObject findTelemacResultFile(final FileObject resultDir) {
    if (resultDir == null)
        return null;

    FileObject[] children = null;
    try {/*w w w  .  j av a  2s.  c om*/
        children = resultDir.getChildren();
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
    for (final FileObject child : children) {
        final FileName childName = child.getName();
        final String baseName = childName.getBaseName();
        if (FilenameUtils.wildcardMatch(baseName, "*res*.slf*")) //$NON-NLS-1$ 
        {
            return child;
        }
    }

    final IPath path = ResultMeta1d2dHelper.getSavedPathFromResultData(m_calcUnitMeta,
            ResultMeta1d2dHelper.TELEMAC_RAW_DATA_META_NAME);
    if (path != null) {
        try {
            return resultDir.getParent().resolveFile(path.toOSString());
        } catch (final Exception e) {
            m_geoLog.formatLog(IStatus.INFO, CODE_RUNNING_FINE,
                    Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ResultManager.15"), //$NON-NLS-1$
                    resultDir.getName().getBaseName());
            return null;
        }
    }
    return null;
}