List of usage examples for org.apache.commons.vfs FileUtil getContent
public static byte[] getContent(final FileObject file) throws IOException
From source file:org.pentaho.di.job.entries.sftp.SFTPClient.java
/** * Init Helper Class with connection settings * * @param serverIP//from w ww .j a va 2s . c o m * IP address of remote server * @param serverPort * port of remote server * @param userName * username of remote server * @param privateKeyFilename * filename of private key * @param passPhrase * passphrase * @throws KettleJobException */ public SFTPClient(InetAddress serverIP, int serverPort, String userName, String privateKeyFilename, String passPhrase) throws KettleJobException { if (serverIP == null || serverPort < 0 || userName == null || userName.equals("")) { throw new KettleJobException( "For a SFTP connection server name and username must be set and server port must be greater than zero."); } this.serverIP = serverIP; this.serverPort = serverPort; this.userName = userName; JSch jsch = new JSch(); try { if (!Const.isEmpty(privateKeyFilename)) { // We need to use private key authentication this.prvkey = privateKeyFilename; byte[] passphrasebytes = new byte[0]; if (!Const.isEmpty(passPhrase)) { // Set passphrase this.passphrase = passPhrase; passphrasebytes = GetPrivateKeyPassPhrase().getBytes(); } jsch.addIdentity(getUserName(), FileUtil.getContent(KettleVFS.getFileObject(prvkey)), // byte[] privateKey null, // byte[] publicKey passphrasebytes); // byte[] passPhrase } s = jsch.getSession(userName, serverIP.getHostAddress(), serverPort); } catch (IOException e) { throw new KettleJobException(e); } catch (KettleFileException e) { throw new KettleJobException(e); } catch (JSchException e) { throw new KettleJobException(e); } }
From source file:org.sonatype.gshell.commands.bsf.ScriptCommand.java
private Object exec(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo();// w ww. j av a2 s. c o m FileObject cwd = fileSystemAccess.getCurrentDirectory(context.getVariables()); FileObject file = fileSystemAccess.resolveFile(cwd, path); if (!file.exists()) { io.error("File not found: {}", file.getName()); // TODO: i18n return Result.FAILURE; } else if (!file.getType().hasContent()) { io.error("File has not content: {}", file.getName()); // TODO: i18n return Result.FAILURE; } else if (!file.isReadable()) { io.error("File is not readable: {}", file.getName()); // TODO: i18n return Result.FAILURE; } if (language == null) { language = detectLanguage(file); } BSFEngine engine = createEngine(context); byte[] bytes = FileUtil.getContent(file); String script = new String(bytes); log.info("Evaluating file ({}): {}", language, path); // TODO: i18n try { return engine.eval(file.getName().getBaseName(), 1, 1, script); } finally { engine.terminate(); file.close(); } }
From source file:pt.webdetails.cpf.repository.vfs.VfsRepositoryFile.java
@Override public byte[] getData() { try {/* w w w. ja v a2s .co m*/ return FileUtil.getContent(file); } catch (Exception e) { throw new RuntimeException("Error reading file: " + file, e); } }