Java Code Examples for org.apache.commons.vfs2.FileObject#createFile()

The following examples show how to use org.apache.commons.vfs2.FileObject#createFile() . 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: ResourceAgent.java    From spoofax with Apache License 2.0 6 votes vote down vote up
@Override public int openRandomAccessFile(String fn, String mode) throws IOException {
    boolean appendMode = mode.indexOf('a') >= 0;
    boolean writeMode = appendMode || mode.indexOf('w') >= 0;
    boolean clearFile = false;

    final FileObject resource = resourceService.resolve(workingDir, fn);

    if(writeMode) {
        if(!resource.exists()) {
            resource.createFile();
        } else if(!appendMode) {
            clearFile = true;
        }
    }

    if(clearFile) {
        resource.delete();
        resource.createFile();
    }

    openFiles.put(fileCounter, new ResourceHandle(resource));

    return fileCounter++;
}
 
Example 2
Source File: FTPSConnectionTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnforceProtPOnPut() throws Exception {
  FileObject file = KettleVFS.createTempFile( "FTPSConnectionTest_testEnforceProtPOnPut", KettleVFS.Suffix.TMP);
  file.createFile();
  try {
    FTPSTestConnection connection = spy(
      new FTPSTestConnection(
        FTPSConnection.CONNECTION_TYPE_FTP_IMPLICIT_TLS_WITH_CRYPTED,
        "the.perfect.host", 2010, "warwickw", "julia", null ) );
    connection.replies.put( "PWD", new Reply( Arrays.asList( "257 \"/la\" is current directory" ) ) );
    connection.connect();
    connection.uploadFile( file.getPublicURIString(), "uploaded-file" );
    assertEquals( "buffer not set", "PBSZ 0\r\n", connection.commands.get( 0 ).toString() );
    assertEquals( "data privacy not set", "PROT P\r\n", connection.commands.get( 1 ).toString() );
  } finally {
    file.delete();
  }
}
 
Example 3
Source File: HopVfs.java    From hop with Apache License 2.0 5 votes vote down vote up
public static OutputStream getOutputStream( FileObject fileObject, boolean append ) throws IOException {
  FileObject parent = fileObject.getParent();
  if ( parent != null ) {
    if ( !parent.exists() ) {
      throw new IOException( BaseMessages.getString(
        PKG, "HopVFS.Exception.ParentDirectoryDoesNotExist", getFriendlyURI( parent ) ) );
    }
  }
  try {
    fileObject.createFile();
    FileContent content = fileObject.getContent();
    return content.getOutputStream( append );
  } catch ( FileSystemException e ) {
    // Perhaps if it's a local file, we can retry using the standard
    // File object. This is because on Windows there is a bug in VFS.
    //
    if ( fileObject instanceof LocalFile ) {
      try {
        String filename = getFilename( fileObject );
        return new FileOutputStream( new File( filename ), append );
      } catch ( Exception e2 ) {
        throw e; // throw the original exception: hide the retry.
      }
    } else {
      throw e;
    }
  }
}
 
Example 4
Source File: ProviderRandomSetLengthTests.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a file
 */
public void testRandomSetLength() throws Exception {
    FileObject file = null;
    try {
        file = this.createScratchFolder().resolveFile("random_write.txt");
        file.createFile();
        final String fileString = file.toString();
        final RandomAccessContent ra = file.getContent().getRandomAccessContent(RandomAccessMode.READWRITE);

        // Write long string
        ra.writeBytes(TEST_DATA);
        Assert.assertEquals(fileString, TEST_DATA.length(), ra.length());

        // Shrink to length 1
        ra.setLength(1);
        Assert.assertEquals(fileString, 1, ra.length());
        // now read 1
        ra.seek(0);
        Assert.assertEquals(fileString, TEST_DATA.charAt(0), ra.readByte());

        try {
            ra.readByte();
            Assert.fail("Expected " + Exception.class.getName());
        } catch (final IOException e) {
            // Expected
        }

        // Grow to length 2
        ra.setLength(2);
        Assert.assertEquals(fileString, 2, ra.length());
        // We have an undefined extra byte
        ra.seek(1);
        ra.readByte();

    } finally {
        if (file != null) {
            file.close();
        }
    }
}
 
Example 5
Source File: ActionShell.java    From hop with Apache License 2.0 5 votes vote down vote up
private FileObject createTemporaryShellFile( FileObject tempFile, String fileContent ) throws Exception {
  // Create a unique new temporary filename in the working directory, put the script in there
  // Set the permissions to execute and then run it...
  //
  if ( tempFile != null && fileContent != null ) {
    try {
      // flag indicates if current OS is Windows or not
      boolean isWindows = Const.isWindows();
      if ( !isWindows ) {
        fileContent = replaceWinEOL( fileContent );
      }
      tempFile.createFile();
      OutputStream outputStream = tempFile.getContent().getOutputStream();
      outputStream.write( fileContent.getBytes() );
      outputStream.close();
      if ( !isWindows ) {
        String tempFilename = HopVfs.getFilename( tempFile );
        // Now we have to make this file executable...
        // On Unix-like systems this is done using the command "/bin/chmod +x filename"
        //
        ProcessBuilder procBuilder = new ProcessBuilder( "chmod", "+x", tempFilename );
        Process proc = procBuilder.start();
        // Eat/log stderr/stdout all messages in a different thread...
        StreamLogger errorLogger = new StreamLogger( log, proc.getErrorStream(), toString() + " (stderr)" );
        StreamLogger outputLogger = new StreamLogger( log, proc.getInputStream(), toString() + " (stdout)" );
        new Thread( errorLogger ).start();
        new Thread( outputLogger ).start();
        proc.waitFor();
      }

    } catch ( Exception e ) {
      throw new Exception( "Unable to create temporary file to execute script", e );
    }
  }
  return tempFile;
}
 
Example 6
Source File: Shell.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Does a 'touch' command.
 */
private void touch(final String[] cmd) throws Exception {
    if (cmd.length < 2) {
        throw new Exception("USAGE: touch <path>");
    }
    final FileObject file = mgr.resolveFile(cwd, cmd[1]);
    if (!file.exists()) {
        file.createFile();
    }
    file.getContent().setLastModifiedTime(System.currentTimeMillis());
}
 
Example 7
Source File: SimpleVirtualFilesystem.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private VirtualFile getFileFromHash(FileObject tempFile, StreamingXXHash64 hash64, String directory) throws
        FileSystemException {
    FileObject hashNameFile = this.fsManager.resolveFile(directory + filePathFromHash(hash64));
    if (hashNameFile.exists()) {
        tempFile.delete();
    } else {
        hashNameFile.createFile();
        tempFile.moveTo(hashNameFile);
    }
    return new SimpleVirtualFile(hashNameFile);
}
 
Example 8
Source File: VFSZipper.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void unzip(InputStream is, FileObject outfileObj) throws IOException {
    Closer closer = Closer.create();
    try {
        ZipInputStream zis = new ZipInputStream(is);
        closer.register(zis);
        ZipEntry zipEntry = zis.getNextEntry();
        while (zipEntry != null) {
            FileObject entryFile = outfileObj.resolveFile(zipEntry.getName());

            if (zipEntry.isDirectory()) {
                logger.debug("Creating folder " + entryFile.getURL());
                entryFile.createFolder();
            } else {
                if (!entryFile.exists()) {
                    logger.debug("Creating file " + entryFile.getURL());
                    entryFile.createFile();
                } else {
                    logger.debug("Overwriting file " + entryFile.getURL());
                }
                Zipper.ZIP.unzipEntry(zis, entryFile.getContent().getOutputStream());
            }

            zipEntry = zis.getNextEntry();
        }
    } catch (IOException ioe) {
        logger.error("Error when unzipping", ioe);
        throw closer.rethrow(ioe);
    } finally {
        closer.close();
    }
}
 
Example 9
Source File: JobEntryShell.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private FileObject createTemporaryShellFile( FileObject tempFile, String fileContent ) throws Exception {
  // Create a unique new temporary filename in the working directory, put the script in there
  // Set the permissions to execute and then run it...
  //
  if ( tempFile != null && fileContent != null ) {
    try {
      // flag indicates if current OS is Windows or not
      boolean isWindows = Const.isWindows();
      if ( !isWindows ) {
        fileContent = replaceWinEOL( fileContent );
      }
      tempFile.createFile();
      OutputStream outputStream = tempFile.getContent().getOutputStream();
      outputStream.write( fileContent.getBytes() );
      outputStream.close();
      if ( !isWindows ) {
        String tempFilename = KettleVFS.getFilename( tempFile );
        // Now we have to make this file executable...
        // On Unix-like systems this is done using the command "/bin/chmod +x filename"
        //
        ProcessBuilder procBuilder = new ProcessBuilder( "chmod", "+x", tempFilename );
        Process proc = procBuilder.start();
        // Eat/log stderr/stdout all messages in a different thread...
        StreamLogger errorLogger = new StreamLogger( log, proc.getErrorStream(), toString() + " (stderr)" );
        StreamLogger outputLogger = new StreamLogger( log, proc.getInputStream(), toString() + " (stdout)" );
        new Thread( errorLogger ).start();
        new Thread( outputLogger ).start();
        proc.waitFor();
      }

    } catch ( Exception e ) {
      throw new Exception( "Unable to create temporary file to execute script", e );
    }
  }
  return tempFile;
}
 
Example 10
Source File: CustomRamProviderTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Tests VFS-625.
 * @throws FileSystemException
 */
@Test
public void testMoveFile() throws FileSystemException {
    final FileObject fileSource = manager.resolveFile("ram://virtual/source");
    fileSource.createFile();
    final FileObject fileDest = manager.resolveFile("ram://virtual/dest");
    Assert.assertTrue(fileSource.canRenameTo(fileDest));
    fileSource.moveTo(fileDest);
}
 
Example 11
Source File: DistributedCacheTestUtil.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
static FileObject createTestHadoopConfiguration( String rootFolderName ) throws Exception {
  FileObject location = KettleVFS.getFileObject( rootFolderName + "/hadoop-configurations/test-config" );

  FileObject lib = location.resolveFile( "lib" );
  FileObject libPmr = lib.resolveFile( "pmr" );
  FileObject pmrLibJar = libPmr.resolveFile( "configuration-specific.jar" );

  lib.createFolder();
  lib.resolveFile( "required.jar" ).createFile();

  libPmr.createFolder();
  pmrLibJar.createFile();

  return location;
}
 
Example 12
Source File: CustomRamProviderTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private InputStream createNonEmptyFile() throws FileSystemException, IOException {
    final FileObject root = manager.resolveFile("ram://file");
    root.createFile();

    final FileContent content = root.getContent();
    final OutputStream output = this.closeOnTearDown(content.getOutputStream());
    output.write(1);
    output.write(2);
    output.write(3);
    output.flush();
    output.close();

    return this.closeOnTearDown(content.getInputStream());
}
 
Example 13
Source File: AbstractFilesCacheTestsBase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/** Helper method, may be used in cache specific tests. */
protected int getFileHashCode() throws FileSystemException {
    final FileObject fo = getWriteFolder().resolveFile("file2");
    if (!fo.exists()) {
        fo.createFile();
    }

    return fo.hashCode();
}
 
Example 14
Source File: Webdav4VersioningTests.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 */
public void testVersioning() throws Exception {
    final FileObject scratchFolder = createScratchFolder();
    final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
    final Webdav4FileSystemConfigBuilder builder = (Webdav4FileSystemConfigBuilder) getManager()
            .getFileSystemConfigBuilder("webdav");
    builder.setVersioning(opts, true);
    final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
    final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
    assertSame(opts, newOpts);
    assertTrue(builder.isVersioning(newOpts));
    assertFalse(file.exists());
    file.createFile();
    assertTrue(file.exists());
    assertSame(FileType.FILE, file.getType());
    assertTrue(file.isFile());
    assertEquals(0, file.getContent().getSize());
    assertTrue(file.getContent().isEmpty());
    assertFalse(file.isExecutable());
    assertFalse(file.isHidden());
    assertTrue(file.isReadable());
    assertTrue(file.isWriteable());
    Map<?, ?> map = file.getContent().getAttributes();
    final String name = ((GenericURLFileName) file.getName()).getUserName();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));

    // Create the source file
    final String content = "Here is some sample content for the file.  Blah Blah Blah.";

    final OutputStream os = file.getContent().getOutputStream();
    try {
        os.write(content.getBytes("utf-8"));
    } finally {
        os.close();
    }
    assertSameContent(content, file);
    map = file.getContent().getAttributes();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    builder.setVersioning(opts, false);
}
 
Example 15
Source File: CustomRamProviderTest.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
private InputStream createEmptyFile() throws FileSystemException, IOException {
    final FileObject root = manager.resolveFile("ram://file");
    root.createFile();
    return this.closeOnTearDown(root.getContent().getInputStream());
}
 
Example 16
Source File: WebdavVersioningTests.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 */
public void testVersioningWithCreator() throws Exception {
    final FileObject scratchFolder = createScratchFolder();
    final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
    final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) getManager()
            .getFileSystemConfigBuilder("webdav");
    builder.setVersioning(opts, true);
    builder.setCreatorName(opts, "testUser");
    final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
    final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
    assertSame(opts, newOpts);
    assertTrue(builder.isVersioning(newOpts));
    assertFalse(file.exists());
    file.createFile();
    assertTrue(file.exists());
    assertSame(FileType.FILE, file.getType());
    assertTrue(file.isFile());
    assertEquals(0, file.getContent().getSize());
    assertTrue(file.getContent().isEmpty());
    assertFalse(file.isExecutable());
    assertFalse(file.isHidden());
    assertTrue(file.isReadable());
    assertTrue(file.isWriteable());
    Map<?, ?> map = file.getContent().getAttributes();
    final String name = ((URLFileName) file.getName()).getUserName();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    assertEquals("testUser", map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
        assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));

    // Create the source file
    final String content = "Here is some sample content for the file.  Blah Blah Blah.";

    final OutputStream os = file.getContent().getOutputStream();
    try {
        os.write(content.getBytes("utf-8"));
    } finally {
        os.close();
    }
    assertSameContent(content, file);
    map = file.getContent().getAttributes();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    assertEquals("testUser", map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
        assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    builder.setVersioning(opts, false);
    builder.setCreatorName(opts, null);
}
 
Example 17
Source File: WebdavVersioningTests.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 */
public void testVersioning() throws Exception {
    final FileObject scratchFolder = createScratchFolder();
    final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
    final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) getManager()
            .getFileSystemConfigBuilder("webdav");
    builder.setVersioning(opts, true);
    final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
    final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
    assertSame(opts, newOpts);
    assertTrue(builder.isVersioning(newOpts));
    assertFalse(file.exists());
    file.createFile();
    assertTrue(file.exists());
    assertSame(FileType.FILE, file.getType());
    assertTrue(file.isFile());
    assertEquals(0, file.getContent().getSize());
    assertTrue(file.getContent().isEmpty());
    assertFalse(file.isExecutable());
    assertFalse(file.isHidden());
    assertTrue(file.isReadable());
    assertTrue(file.isWriteable());
    Map<?, ?> map = file.getContent().getAttributes();
    final String name = ((URLFileName) file.getName()).getUserName();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));

    // Create the source file
    final String content = "Here is some sample content for the file.  Blah Blah Blah.";

    final OutputStream os = file.getContent().getOutputStream();
    try {
        os.write(content.getBytes("utf-8"));
    } finally {
        os.close();
    }
    assertSameContent(content, file);
    map = file.getContent().getAttributes();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    builder.setVersioning(opts, false);
}
 
Example 18
Source File: Webdav4VersioningTests.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 */
public void testVersioningWithCreator() throws Exception {
    final FileObject scratchFolder = createScratchFolder();
    final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
    final Webdav4FileSystemConfigBuilder builder = (Webdav4FileSystemConfigBuilder) getManager()
            .getFileSystemConfigBuilder("webdav");
    builder.setVersioning(opts, true);
    builder.setCreatorName(opts, "testUser");
    final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
    final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
    assertSame(opts, newOpts);
    assertTrue(builder.isVersioning(newOpts));
    assertFalse(file.exists());
    file.createFile();
    assertTrue(file.exists());
    assertSame(FileType.FILE, file.getType());
    assertTrue(file.isFile());
    assertEquals(0, file.getContent().getSize());
    assertTrue(file.getContent().isEmpty());
    assertFalse(file.isExecutable());
    assertFalse(file.isHidden());
    assertTrue(file.isReadable());
    assertTrue(file.isWriteable());
    Map<?, ?> map = file.getContent().getAttributes();
    final String name = ((GenericURLFileName) file.getName()).getUserName();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    assertEquals("testUser", map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
        assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));

    // Create the source file
    final String content = "Here is some sample content for the file.  Blah Blah Blah.";

    final OutputStream os = file.getContent().getOutputStream();
    try {
        os.write(content.getBytes("utf-8"));
    } finally {
        os.close();
    }
    assertSameContent(content, file);
    map = file.getContent().getAttributes();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    assertEquals("testUser", map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
        assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    builder.setVersioning(opts, false);
    builder.setCreatorName(opts, null);
}
 
Example 19
Source File: ProviderWriteTests.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Check listeners are notified of changes.
 */
public void testListener() throws Exception {
    final FileObject baseFile = createScratchFolder();

    final FileObject child = baseFile.resolveFile("newfile.txt");
    assertFalse(child.exists());

    final FileSystem fs = baseFile.getFileSystem();
    final TestListener listener = new TestListener(child);
    fs.addListener(child, listener);
    try {
        // Create as a folder
        listener.addCreateEvent();
        child.createFolder();
        listener.assertFinished();

        // Create the folder again. Should not get an event.
        child.createFolder();

        // Delete
        listener.addDeleteEvent();
        child.delete();
        listener.assertFinished();

        // Delete again. Should not get an event
        child.delete();

        // Create as a file
        listener.addCreateEvent();
        child.createFile();
        listener.assertFinished();

        // Create the file again. Should not get an event
        child.createFile();

        listener.addDeleteEvent();
        child.delete();

        // Create as a file, by writing to it.
        listener.addCreateEvent();
        child.getContent().getOutputStream().close();
        listener.assertFinished();

        // Recreate the file by writing to it
        child.getContent().getOutputStream().close();

        // Copy another file over the top
        final FileObject otherChild = baseFile.resolveFile("folder1");
        otherChild.createFolder();
        listener.addDeleteEvent();
        listener.addCreateEvent();
        child.copyFrom(otherChild, Selectors.SELECT_SELF);
        listener.assertFinished();

    } finally {
        fs.removeListener(child, listener);
    }
}
 
Example 20
Source File: JobEntryCreateFile.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) throws KettleException {
  Result result = previousResult;
  result.setResult( false );

  if ( filename != null ) {
    //Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
    if ( parentJobMeta.getNamedClusterEmbedManager() != null ) {
      parentJobMeta.getNamedClusterEmbedManager()
        .passEmbeddedMetastoreKey( this, parentJobMeta.getEmbeddedMetastoreProviderKey() );
    }

    String realFilename = getRealFilename();
    FileObject fileObject = null;
    try {
      fileObject = KettleVFS.getFileObject( realFilename, this );

      if ( fileObject.exists() ) {
        if ( isFailIfFileExists() ) {
          // File exists and fail flag is on.
          result.setResult( false );
          logError( "File [" + realFilename + "] exists, failing." );
        } else {
          // File already exists, no reason to try to create it
          result.setResult( true );
          logBasic( "File [" + realFilename + "] already exists, not recreating." );
        }
        // add filename to result filenames if needed
        if ( isAddFilenameToResult() ) {
          addFilenameToResult( realFilename, result, parentJob );
        }
      } else {
        // No file yet, create an empty file.
        fileObject.createFile();
        logBasic( "File [" + realFilename + "] created!" );
        // add filename to result filenames if needed
        if ( isAddFilenameToResult() ) {
          addFilenameToResult( realFilename, result, parentJob );
        }
        result.setResult( true );
      }
    } catch ( IOException e ) {
      logError( "Could not create file [" + realFilename + "], exception: " + e.getMessage() );
      result.setResult( false );
      result.setNrErrors( 1 );
    } finally {
      if ( fileObject != null ) {
        try {
          fileObject.close();
          fileObject = null;
        } catch ( IOException ex ) {
          // Ignore
        }
      }
    }
  } else {
    logError( "No filename is defined." );
  }

  return result;
}