public InputStream getInputStream() throws IOException { return content.getInputStream(); }
/** * Obtain an {@link InputStream} for this source. * * @throws IOException if an IO error occurs * @throws SourceException if a source exception occurs * @return {@link InputStream} * @see org.apache.excalibur.source.Source#getInputStream() */ public InputStream getInputStream() throws IOException, SourceException { return m_fileContent.getInputStream(); }
public InputStream getInputStream() throws IOException { return content.getInputStream(); }
/** * Creates an input stream to read the file content from. */ protected InputStream doGetInputStream() throws Exception { return file.getContent().getInputStream(); }
public InputStream openStream() throws IOException { return getContent().getInputStream(); } }
protected String readURL(URL url) throws FileNotFoundException, IOException { if (url.toExternalForm().startsWith("vfs")) { FileObject from = VFS.getManager().resolveFile(url.toExternalForm()); return IOUtils.toString(from.getContent().getInputStream()); } else { return FileUtils.readFileToString(FileUtils.toFile(url)); } } }
protected InputStream doGetInputStream() throws Exception { InputStream is = getContainer().getContent().getInputStream(); return new GZIPInputStream(is); }
protected String readURL(URL url) throws FileNotFoundException, IOException { if (url.toExternalForm().startsWith("vfs")) { FileObject from = VFS.getManager().resolveFile(url.toExternalForm()); return IOUtils.toString(from.getContent().getInputStream()); } else { return FileUtils.readFileToString(FileUtils.toFile(url)); } } }
/** * Writes the content of a file to an OutputStream. */ public static void writeContent(final FileObject file, final OutputStream outstr) throws IOException { final InputStream instr = file.getContent().getInputStream(); try { final byte[] buffer = new byte[1024]; while (true) { final int nread = instr.read(buffer); if (nread < 0) { break; } outstr.write(buffer, 0, nread); } } finally { instr.close(); } }
/** * Writes the content of the file to Ant log. */ private void logContent(final FileObject file, final String prefix) throws Exception { final InputStream instr = file.getContent().getInputStream(); try { final BufferedReader reader = new BufferedReader(new InputStreamReader(instr)); while (true) { final String line = reader.readLine(); if (line == null) { break; } log(prefix + line); } } finally { instr.close(); } } }
/** * Returns the content of a file, as a byte array. * * @param file The file to get the content of. */ public static byte[] getContent(final FileObject file) throws IOException { final FileContent content = file.getContent(); final int size = (int) content.getSize(); final byte[] buf = new byte[size]; final InputStream in = content.getInputStream(); try { int read = 0; for (int pos = 0; pos < size && read >= 0; pos += read) { read = in.read(buf, pos, size - pos); } } finally { in.close(); } return buf; }
/** * Read a VFS path and return the input stream content. * * @param vfsPath the VFS path. * @return the input stream content. * @throws FileManipulatorException in case of read failure. */ public InputStream read( String vfsPath ) throws FileManipulatorException { FileObject file = null; try { file = this.resolveFile( vfsPath ); if ( !file.exists() || !file.getType().equals( FileType.FILE ) ) { LOGGER.error( "{} doesn't exist or is not a file" ); throw new IllegalArgumentException( vfsPath + " doesn't exist or is not a file" ); } return file.getContent().getInputStream(); } catch ( Exception e ) { LOGGER.error( "Can't read {}", vfsPath, e ); throw new FileManipulatorException( "Can't read " + vfsPath, e ); } }
protected InputStream doGetInputStream() throws Exception { // check file InputStream is = getContainer().getContent().getInputStream(); return wrapInputStream(getName().getURI(), is); }
public <T> T get(final Class<T> type) { assert type != null; log.trace("Getting: {}", file); BufferedInputStream input = null; try { Marshaller<T> marshaller = xstore.getMarshaller(type); FileObject parent = file.getParent(); if (parent != null && !parent.exists()) { parent.createFolder(); } input = new BufferedInputStream(file.getContent().getInputStream()); T value = marshaller.unmarshal(input); log.trace("Value: {}", value); return value; } catch (FileSystemException e) { throw new XStoreException(e); } finally { Closer.close(input); } }
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo(); // // TODO: Support multi-path cat, and the special '-' token (which is the default if no paths are given) // FileObject file = resolveFile(context, path); ensureFileExists(file); ensureFileHasContent(file); FileContent content = file.getContent(); FileContentInfo info = content.getContentInfo(); log.debug("Content type: {}", info.getContentType()); log.debug("Content encoding: {}", info.getContentEncoding()); // // TODO: Only cat files which we think are text, or warn if its not, allow flag to force // log.debug("Displaying file: {}", file.getName()); BufferedReader reader = new BufferedReader(new InputStreamReader(content.getInputStream())); try { cat(reader, io); } finally { Closer.close(reader); } FileObjects.close(file); return CommandAction.Result.SUCCESS; }
private void grep(final CommandContext context, final MatchActionProcessor processor, final FileObject file) throws Exception { assert context != null; assert processor != null; assert file != null; ensureFileExists(file); ensureFileHasContent(file); ensureFileIsReadable(file); BufferedInputStream input = new BufferedInputStream(file.getContent().getInputStream()); try { processor.processMatches(input, context.getIo().outputStream); } finally { Closer.close(input); } }
protected void sort(final CommandContext context, final FileObject file) throws Exception { assert context != null; assert file != null; new FileObjectAssert(file).exists().isReadable(); ensureFileHasContent(file); BufferedInputStream input = new BufferedInputStream(file.getContent().getInputStream()); try { sort(input, context.getIo().out); } finally { Closer.close(input); } }
private void grep(final CommandContext context, final MatchActionProcessor processor, final FileObject file) throws Exception { assert context != null; assert processor != null; assert file != null; new FileObjectAssert(file).exists().isReadable(); ensureFileHasContent(file); BufferedInputStream input = new BufferedInputStream(file.getContent().getInputStream()); try { processor.processMatches(input, context.getIo().streams.out); } finally { Closer.close(input); } }
/** * Transfer a VFS Resource from the repository to the local file system. * * @param srcVfsURI * a <code>String</code> identifying the VFS resource to be fetched * @param destination * a <code>File</code> identifying the destination file * @throws <code>IOException</code> on failure * @see "Supported File Systems in the jakarta-commons-vfs documentation" */ public void get(String srcVfsURI, File destination) throws IOException { VfsResource src = new VfsResource(srcVfsURI, getVFSManager()); fireTransferInitiated(src, TransferEvent.REQUEST_GET); try { FileContent content = src.getContent(); if (content == null) { throw new IllegalArgumentException("invalid vfs uri " + srcVfsURI + ": no content found"); } FileUtil.copy(content.getInputStream(), destination, progress); } catch (IOException ex) { fireTransferError(ex); throw ex; } catch (RuntimeException ex) { fireTransferError(ex); throw ex; } }
/** * Gets the {@link InputStream} for a given file. {@inheritDoc} * @param file File name. * @return {@link InputStream} for <code>file</code>. */ @Override public InputStream getInputStream(String file) { InputStream result; try { result = getFileSystemManager().resolveFile(file).getContent().getInputStream(); } catch (FileSystemException e) { throw new CargoException("Failed to find file [" + file + "]", e); } return result; }