List of usage examples for org.apache.commons.vfs2 FileUtil writeContent
public static void writeContent(final FileObject file, final OutputStream output) throws IOException
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does a 'cat' command./* w w w. ja v a 2 s .co m*/ * * @param cmd * @throws SimpleShellException */ public void cat(String[] cmd) throws SimpleShellException { if (cmd.length < 2) { throw new SimpleShellException("USAGE: cat <path>"); } // Locate the file FileObject file; try { file = mgr.resolveFile(cwd, cmd[1]); } catch (FileSystemException ex) { String errMsg = String.format("Error resolving file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { if (file.exists() == false) { // Can't cat a file that doesn't exist System.out.println(String.format("File '%s' does not exist", cmd[1])); return; } } catch (FileSystemException ex) { String errMsg = String.format("Error exists() on file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { if (file.getType() != FileType.FILE) { // Only cat files System.out.println(String.format("File '%s' is not an actual file.", cmd[1])); return; } } catch (FileSystemException ex) { String errMsg = String.format("Error getType() on file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { // Dump the contents to System.out FileUtil.writeContent(file, System.out); } catch (IOException ex) { String errMsg = String.format("Error WriteContent() on file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } System.out.println(); }
From source file:org.apache.commons.vfs2.example.Shell.java
/** * Does a 'cat' command./*from w w w. j a va 2 s . c om*/ */ private void cat(final String[] cmd) throws Exception { if (cmd.length < 2) { throw new Exception("USAGE: cat <path>"); } // Locate the file final FileObject file = mgr.resolveFile(cwd, cmd[1]); // Dump the contents to System.out FileUtil.writeContent(file, System.out); System.out.println(); }
From source file:tain.kr.test.vfs.v01.Shell.java
/** * Does a 'cat' command./*from w w w . jav a 2 s . c o m*/ */ private void cat(final String[] cmd) throws Exception { if (cmd.length < 2) { throw new Exception("USAGE: cat <path>"); } // Locate the file final FileObject file = mgr.resolveFile(cwd, cmd[1]); // Dump the contents to System.out FileUtil.writeContent(file, System.out); System.out.println(); }