/** * Read a text file (like an XML document). WARNING DO NOT USE FOR DATA FILES. * * @param vfsFilename * the filename or URL to read from * @param charSetName * the character set of the string (UTF-8, ISO8859-1, etc) * @return The content of the file as a String * @throws IOException */ public static String getTextFileContent( String vfsFilename, String charSetName ) throws KettleFileException { return getTextFileContent( vfsFilename, null, charSetName ); }
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 ); } }
@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(); } } }