fileContent = replaceWinEOL( fileContent ); tempFile.createFile(); OutputStream outputStream = tempFile.getContent().getOutputStream(); outputStream.write( fileContent.getBytes() );
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, "KettleVFS.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; } } }
/** * Creates a new content location in the current location. This method must never return null. This method will fail * if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentLocation createLocation( final String name ) throws ContentCreationException { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); if ( child.exists() ) { throw new ContentCreationException( "File already exists." ); } child.createFile(); try { return new FileObjectContentLocation( this, child ); } catch ( ContentIOException e ) { throw new ContentCreationException( "Failed to create the content-location", e ); } } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
child.createFile(); return new FileObjectContentItem( this, child ); } catch ( IOException e ) {
public static String createRamFile( String path, VariableSpace space ) { if ( space == null ) { space = new Variables(); space.initializeVariablesFrom( null ); } try { FileObject file = KettleVFS.getFileObject( "ram://" + path, space ); file.createFile(); return file.getName().getURI(); } catch ( FileSystemException | KettleFileException e ) { throw new RuntimeException( e ); } }
@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(); } }
@Test public void getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch() throws Exception { final String exact = "databaseExactMatch"; final String similar = exact.toLowerCase(); assertNotSame( similar, exact ); DatabaseMeta db = saveDatabase( exact ); // simulate legacy repository - store a DB with a name different only in case DatabaseMeta another = new DatabaseMeta(); another.setName( similar ); FileObject fileObject = repository.getFileObject( another ); assertFalse( fileObject.exists() ); // just create it - enough for this case fileObject.createFile(); assertTrue( fileObject.exists() ); ObjectId id = this.repository.getDatabaseID( exact ); assertEquals( db.getObjectId(), id ); }
fileObject.createFile(); logBasic( "File [" + realFilename + "] created!" );
@Override public void createFile() throws FileSystemException { decoratedFileObject.createFile(); }
@Override public void createFile() throws FileSystemException { container.createFile(); injectType(FileType.FILE); } }
@Override public void createFile() throws FileSystemException { container.createFile(); injectType(FileType.FILE); } }
@Override public void createFile() { try { this.fileObject.createFile(); } catch (FileSystemException e) { throw new VFSFileSystemException(e); } }
@Override public void createFile() throws FileSystemException { container.createFile(); injectType(FileType.FILE); } }
/** 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(); } }
/** 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(); } }
/** 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(); } }
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 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 InputStream createEmptyFile() throws FileSystemException, IOException { final FileObject root = manager.resolveFile("ram://file"); root.createFile(); return this.closeOnTearDown(root.getContent().getInputStream()); }
private InputStream createEmptyFile() throws FileSystemException, IOException { final FileObject root = manager.resolveFile("ram://file"); root.createFile(); return this.closeOnTearDown(root.getContent().getInputStream()); }