Java Code Examples for org.pentaho.di.core.vfs.KettleVFS#getTextFileContent()

The following examples show how to use org.pentaho.di.core.vfs.KettleVFS#getTextFileContent() . 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: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public boolean open(Node transNode, String fname, boolean importfile) {
  try {
    String xml = KettleVFS.getTextFileContent(fname, Const.XML_ENCODING);
    Domain domain = new SerializationService().deserializeDomain(xml);
    StarDomain starDomain = new StarDomain();
    starDomain.setDomain(domain);
    starDomain.setFilename(fname);
    createTabForDomain(starDomain);
    PropsUI.getInstance().addLastFile(LastUsedFile.FILE_TYPE_SCHEMA, fname, null, false, null);
    Spoon.getInstance().addMenuLast();
    return true;
  } catch(Exception e) {
    new ErrorDialog(Spoon.getInstance().getShell(), "Error", "There was an error opening model from file '"+fname+"'", e);
  }

  return false;
}
 
Example 2
Source File: JobEntryDosToUnix_ConversionIdempotency_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void doTest( String content, boolean toUnix, String expected ) throws Exception {
  try ( OutputStream os = new FileOutputStream( tmpFile ) ) {
    IOUtils.write( content.getBytes(), os );
  }

  entry.convert( KettleVFS.getFileObject( tmpFilePath ), toUnix );

  String converted = KettleVFS.getTextFileContent( tmpFilePath, "UTF-8" );
  assertEquals( expected, converted );
}
 
Example 3
Source File: SharedObjectsTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyBackupVfs() throws Exception {
  final String dirName = "ram:/SharedObjectsTest";

  FileObject baseDir = KettleVFS.getFileObject( dirName );
  try {
    baseDir.createFolder();
    final String fileName = dirName + "/shared.xml";
    SharedObjects sharedObjects = new SharedObjects( fileName );

    SharedObjectInterface shared1 = new TestSharedObject( "shared1", "<shared1>shared1</shared1>" );
    sharedObjects.storeObject( shared1 );
    sharedObjects.saveToFile();
    final String backupFileName = fileName + ".backup";
    FileObject backup = KettleVFS.getFileObject( backupFileName );
    Assert.assertFalse( backup.exists() );

    String contents = KettleVFS.getTextFileContent( fileName, "utf8" );
    Assert.assertTrue( contents.contains( shared1.getXML() ) );

    SharedObjectInterface shared2 = new TestSharedObject( "shared2", "<shared2>shared2</shared2>" );
    sharedObjects.storeObject( shared2 );
    sharedObjects.saveToFile();
    Assert.assertTrue( backup.exists() );
    String contentsBackup = KettleVFS.getTextFileContent( backupFileName, "utf8" );
    Assert.assertEquals( contents, contentsBackup );

  } finally {
    if ( baseDir.exists() ) {
      baseDir.deleteAll();
    }
  }

}
 
Example 4
Source File: BaseCluster.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static String loadFileContent( VariableSpace space, String filename ) throws Exception {
  String realFilename = space.environmentSubstitute( filename );
  return KettleVFS.getTextFileContent( realFilename, Charset.defaultCharset().name() );
}