public static MasterReport loadMasterReport( String sourceFilename ) throws Exception { ResourceManager manager = new ResourceManager(); manager.registerDefaults(); FileObject fileObject = KettleVFS.getFileObject( sourceFilename ); URL url = new URL( fileObject.getName().getURI() ); Resource resource = manager.createDirectly( url, MasterReport.class ); MasterReport report = (MasterReport) resource.getResource(); return report; }
fileContent = replaceWinEOL( fileContent ); tempFile.createFile(); OutputStream outputStream = tempFile.getContent().getOutputStream(); outputStream.write( fileContent.getBytes() ); outputStream.close(); if ( !isWindows ) { String tempFilename = KettleVFS.getFilename( tempFile );
@Override public RepositoryObject getObjectInformation( ObjectId objectId, RepositoryObjectType objectType ) throws KettleException { try { String filename = calcDirectoryName( null ); if ( objectId.getId().startsWith( "/" ) ) { filename += objectId.getId().substring( 1 ); } else { filename += objectId.getId(); } FileObject fileObject = KettleVFS.getFileObject( filename ); if ( !fileObject.exists() ) { return null; } FileName fname = fileObject.getName(); String name = fname.getBaseName(); if ( !Utils.isEmpty( fname.getExtension() ) && name.length() > fname.getExtension().length() ) { name = name.substring( 0, name.length() - fname.getExtension().length() - 1 ); } String filePath = fileObject.getParent().getName().getPath(); final FileObject baseDirObject = KettleVFS.getFileObject( repositoryMeta.getBaseDirectory() ); final int baseDirObjectPathLength = baseDirObject.getName().getPath().length(); final String dirPath = baseDirObjectPathLength <= filePath.length() ? filePath.substring( baseDirObjectPathLength ) : "/"; RepositoryDirectoryInterface directory = loadRepositoryDirectoryTree().findDirectory( dirPath ); Date lastModified = new Date( fileObject.getContent().getLastModifiedTime() ); return new RepositoryObject( objectId, name, directory, "-", lastModified, objectType, "", false ); } catch ( Exception e ) { throw new KettleException( "Unable to get object information for object with id=" + objectId, e ); } }
private boolean checkContainsFile( String realSourceDirectoryOrFile, FileObject[] filelist, boolean isDirectory ) throws FileSystemException { boolean retval = false; for ( int i = 0; i < filelist.length; i++ ) { FileObject file = filelist[i]; if ( ( file.exists() && file.getType().equals( FileType.FILE ) ) ) { retval = true; } } return retval; }
public String nameResource( FileObject fileObject, VariableSpace space, boolean includeFileName ) throws FileSystemException { if ( includeFileName ) { return handleDataFile( fileObject.getName().getBaseName(), fileObject.getParent().getURL().toString(), "" ); } else { return handleDataFile( "", fileObject.getURL().toString(), "" ); } }
String shortSourceFilename = sourceFileObject.getName().getBaseName(); int lenstring = shortSourceFilename.length(); int lastindexOfDot = shortSourceFilename.lastIndexOf( '.' ); if ( !rootfolder.exists() ) { try { rootfolder.createFolder(); if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobUnZip.Log.RootFolderCreated", foldername ) ); String zipFilename = "zip:" + sourceFileObject.getName().getFriendlyURI(); FileObject zipFile = KettleVFS.getFileObject( zipFilename, this ); FileObject[] items = zipFile.findFiles( new AllFileSelector() { public boolean traverseDescendents( FileSelectInfo info ) { return true; if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobUnZip.Log.ProcessingZipEntry", item.getName().getURI(), sourceFileObject.toString() ) ); if ( item.getType().equals( FileType.FOLDER ) ) { if ( !newFileObject.exists() ) { newFileObject.createFolder(); Matcher matcher = pattern.matcher( item.getName().getURI() ); getIt = matcher.matches(); Matcher matcherexclude = patternexclude.matcher( item.getName().getURI() );
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()); }
private void resolveAndOpenCloseInputStream() throws IOException, FileSystemException { try (final FileObject zipFileObject = manager.resolveFile(zipFileUri)) { zipFileObject.getContent().getInputStream().close(); } }
@Test public void testGetInputStream() throws Exception { final FileObject fo = manager.resolveFile(TEST_DIR1); Assert.assertNotNull(fo); Assert.assertFalse(fo.exists()); // Create the test file final FileObject file = createTestFile(hdfs); Assert.assertTrue(fo.exists()); file.getContent().getInputStream().close(); }
FileSystemManager fsManager = VFS.getManager(); if (fsManager == null) { throw newError("Cannot get virtual file system manager"); return new URL(url).openStream(); } catch (IOException e) { throw newError( file.refresh(); && !file.getName().getURI().equals(url)) fsManager.getFilesCache().removeFile( file.getFileSystem(), file.getName()); file = fsManager.resolveFile(userDir, url); if (!file.isReadable()) { throw newError( "Virtual file is not readable: " + url); fileContent = file.getContent(); } finally { file.close(); return fileContent.getInputStream();
/** * Tests concurrent reads on a file. */ public void testReadSingleSequencial() throws Exception { final FileObject file = getReadFolder().resolveFile("file1.txt"); assertTrue(file.exists()); file.getContent().getInputStream().close(); file.getContent().getInputStream().close(); }
private HSSFWorkbook createWorkbook( FileObject file ) throws Exception { HSSFWorkbook wb = null; OutputStream os = null; try { os = file.getContent().getOutputStream(); wb = new HSSFWorkbook(); wb.createSheet( SHEET_NAME ); wb.write( os ); } finally { os.flush(); os.close(); } return wb; }
throwsErrorOnFileNotFound( file ); is = KettleVFS.getInputStream( file ); int fileSize = (int) file.getContent().getSize(); content = Const.createByteArray( fileSize ); is.read( content, 0, fileSize ); } catch ( KettleFileNotFoundException e ) { if ( failIfNoFile ) {
public void widgetSelected( SelectionEvent e ) { try { FileObject fileName = null; try { String curFile = wFilename.getText(); if ( curFile.trim().length() > 0 ) { fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile( jobMeta.environmentSubstitute( wFilename.getText() ) ); } else { fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile( Const.getUserHomeDirectory() ); } } catch ( FileSystemException ex ) { fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile( Const.getUserHomeDirectory() ); } VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog( fileName.getParent(), fileName ); FileObject selected = vfsFileChooser.open( shell, null, EXTENSIONS, FILETYPES, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE ); wFilename.setText( selected != null ? selected.getURL().toString() : Const.EMPTY_STRING ); } catch ( FileSystemException ex ) { ex.printStackTrace(); } } } );
final FileSystemManager fsManager = VFS.getManager(); FileObject base = (opts == null) ? fsManager.resolveFile(basePath) : fsManager.resolveFile(basePath, opts); if (base.getType() == FileType.FILE) base = base.getParent(); file = fsManager.resolveFile(base, fileName); if (!file.exists()) final FileName path = file.getName(); final URLStreamHandler handler = new VFSURLStreamHandler(path); return new URL(null, path.getURI(), handler);
InputStream imageStream = null; try ( FileObject imageFile = KettleVFS.getFileObject( data.realHeaderImage ) ) { if ( !imageFile.exists() ) { throw new KettleException( BaseMessages.getString( PKG, "ExcelInputLog.ImageFileNotExists", data.realHeaderImage ) ); data.headerImageHeight = m.getHeight() * 0.0625; byte[] imageData = new byte[(int) imageFile.getContent().getSize()]; imageStream = KettleVFS.getInputStream( imageFile ); imageStream.read( imageData );
private void writeFile(FileObject file, String content) throws IOException { if (!file.isWriteable()) { throw new IOException("Can't write into file"); } try (OutputStream outputStream = file.getContent().getOutputStream()) { if (content != null) { outputStream.write(content.getBytes(Charset.forName("UTF-8"))); //$NON-NLS-1$ } } }
@Override public InputStream getInputStream(final URL url) throws ConfigurationException { FileObject file; try { final FileSystemOptions opts = getOptions(url.getProtocol()); file = (opts == null) ? VFS.getManager().resolveFile(url.toString()) : VFS.getManager().resolveFile(url.toString(), opts); if (file.getType() != FileType.FILE) { throw new ConfigurationException("Cannot load a configuration from a directory"); } final FileContent content = file.getContent(); if (content == null) { final String msg = "Cannot access content of " + file.getName().getFriendlyURI(); throw new ConfigurationException(msg); } return content.getInputStream(); } catch (final FileSystemException fse) { final String msg = "Unable to access " + url.toString(); throw new ConfigurationException(msg, fse); } }
@Override public OutputStream getOutputStream(final URL url) throws ConfigurationException { try { final FileSystemOptions opts = getOptions(url.getProtocol()); final FileSystemManager fsManager = VFS.getManager(); final FileObject file = (opts == null) ? fsManager.resolveFile(url.toString()) : fsManager.resolveFile(url.toString(), opts); // throw an exception if the target URL is a directory if (file == null || file.getType() == FileType.FOLDER) { throw new ConfigurationException("Cannot save a configuration to a directory"); } final FileContent content = file.getContent(); if (content == null) { throw new ConfigurationException("Cannot access content of " + url); } return content.getOutputStream(); } catch (final FileSystemException fse) { throw new ConfigurationException("Unable to access " + url, fse); } }