public OutputStream getOutputStream() throws ContentIOException, IOException { return getBackend().getContent().getOutputStream(); }
private void prepareToWrite() throws KettleException { try { os = writeTo.getContent().getOutputStream(); out = new OutputStreamWriter( os, Const.XML_ENCODING ); } catch ( UnsupportedEncodingException e ) { throw new KettleException( e ); } catch ( FileSystemException e ) { throw new KettleException( e ); } }
OutputStream outputStream = tempFile.getContent().getOutputStream(); outputStream.write( fileContent.getBytes() ); outputStream.close();
private static String createVirtualFile( String filename, String... rows ) throws Exception { String virtualFile = TestUtils.createRamFile( filename ); StringBuilder content = new StringBuilder(); if ( rows != null ) { for ( String row : rows ) { content.append( row ); } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write( content.toString().getBytes() ); try ( OutputStream os = KettleVFS.getFileObject( virtualFile ).getContent().getOutputStream() ) { IOUtils.copy( new ByteArrayInputStream( bos.toByteArray() ), os ); } return virtualFile; }
@Before public void setup() throws Exception { when( fileObject.getContent() ).thenReturn( fileContent ); when( fileContent.getOutputStream( anyBoolean() ) ).thenReturn( outputStream ); }
private static String createVirtualFile( String filename, String... rows ) throws Exception { String virtualFile = TestUtils.createRamFile( filename ); StringBuilder content = new StringBuilder(); if ( rows != null ) { for ( String row : rows ) { content.append( row ); } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write( content.toString().getBytes() ); OutputStream os = KettleVFS.getFileObject( virtualFile ).getContent().getOutputStream(); try { IOUtils.copy( new ByteArrayInputStream( bos.toByteArray() ), os ); } finally { os.close(); } return virtualFile; }
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; } } }
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; }
ReportProcessor reportProcessor = null; try { fout = new BufferedOutputStream( targetFile.getContent().getOutputStream() ); reportProcessor = createReportProcessor( fout ); reportProcessor.processReport();
private FileObject createTemplateFile( String content ) throws IOException { FileObject f2 = createTemplateFile(); if ( content == null ) { f2.delete(); } else { OutputStreamWriter fw = null; try { fw = new OutputStreamWriter( f2.getContent().getOutputStream() ); fw.write( content ); } finally { if ( fw != null ) { fw.close(); } } } return f2; }
/** * this method is used to download a file from a remote host * * @param file remote file to download * @param localFilename target filename * @throws KettleException */ public void downloadFile( FTPFile file, String localFilename ) throws KettleException { try { FileObject localFile = KettleVFS.getFileObject( localFilename, nameSpace ); writeToFile( connection.downloadStream( file ), localFile.getContent().getOutputStream(), localFilename ); } catch ( Exception e ) { throw new KettleException( e ); } }
@Test public void testPDI12424ParametersFromMetaAreCopiedToTrans() throws KettleException, URISyntaxException, IOException { String testParam = "testParam"; String testParamValue = "testParamValue"; TransMeta mockTransMeta = mock( TransMeta.class ); when( mockTransMeta.listVariables() ).thenReturn( new String[] {} ); when( mockTransMeta.listParameters() ).thenReturn( new String[] { testParam } ); when( mockTransMeta.getParameterValue( testParam ) ).thenReturn( testParamValue ); FileObject ktr = KettleVFS.createTempFile( "parameters", ".ktr", "ram://" ); try ( OutputStream outputStream = ktr.getContent().getOutputStream( true ) ) { InputStream inputStream = new ByteArrayInputStream( "<transformation></transformation>".getBytes() ); IOUtils.copy( inputStream, outputStream ); } Trans trans = new Trans( mockTransMeta, null, null, null, ktr.getURL().toURI().toString() ); assertEquals( testParamValue, trans.getParameterValue( testParam ) ); }
@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); } }
/** * Creates an output stream to write the file content to. */ @Override protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { return file.getContent().getOutputStream(bAppend); }
@Override protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { final OutputStream os = getContainer().getContent().getOutputStream(false); return new GZIPOutputStream(os); }
@Override public OutputStream append() throws ResourceException { try { final FileContent content = _fileObject.getContent(); return content.getOutputStream(true); } catch (final Exception e) { throw new ResourceException(this, e); } }
@Override protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { final OutputStream os = getContainer().getContent().getOutputStream(false); return new BZip2CompressorOutputStream(os); }
@Test public void testGetOutputStream() throws Exception { decorated.getOutputStream(); verify( fileContent ).getOutputStream(); }
@Test public void testGetOutputStream1() throws Exception { decorated.getOutputStream( false ); verify( fileContent ).getOutputStream( false ); }
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()); }