public InputStream getInputStream() throws IOException { return content.getInputStream(); }
/** * Obtain an {@link OutputStream} to the source * * @return an {@link OutputStream} * @see org.apache.excalibur.source.ModifiableSource#getOutputStream() */ public OutputStream getOutputStream() throws IOException { return m_fileContent.getOutputStream(); }
public long getLastModified() { try { return content.getLastModifiedTime(); } catch (FileSystemException fse) { } return -1; }
/** * 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; }
FileContentInfo contentInfo = content.getContentInfo(); io.info("Content type: {}", contentInfo.getContentType()); io.info("Content encoding: {}", contentInfo.getContentEncoding()); Map<String,Object> attrs = content.getAttributes(); if (attrs != null && !attrs.isEmpty()) { io.info("Attributes:"); Certificate[] certs = content.getCertificates(); if (certs != null && certs.length != 0) { io.info("Certificate:"); io.info("Size: {} bytes", content.getSize()); io.info("Last modified: {}", DateFormat.getInstance().format(new Date(content.getLastModifiedTime())));
public static UnixFsObject.RegularFile fromFileObject( RelativePath toFile, FileObject fromFile, FileAttributes attributes ) throws FileSystemException { FileContent content = fromFile.getContent(); LocalDateTime time = new LocalDateTime( content.getLastModifiedTime() ); return regularFile( toFile, time, content.getSize(), fromNull( attributes ) ); }
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; }
public int getContentLength() { try { return (int) content.getSize(); } catch (FileSystemException fse) { } return -1; }
/** * Handles an out-of-date file. */ protected void handleOutOfDateFile(final FileObject srcFile, final FileObject destFile) throws FileSystemException { log("Copying " + srcFile + " to " + destFile); destFile.copyFrom(srcFile, Selectors.SELECT_SELF); if (preserveLastModified && srcFile.getFileSystem().hasCapability(Capability.GET_LAST_MODIFIED) && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE)) { final long lastModTime = srcFile.getContent().getLastModifiedTime(); destFile.getContent().setLastModifiedTime(lastModTime); } }
/** * Sets the last-modified time of this file. */ protected void doSetLastModifiedTime(final long modtime) throws Exception { file.getContent().setLastModifiedTime(modtime); }
public String getContentEncoding() { try { return content.getContentInfo().getContentEncoding(); } catch (FileSystemException e) { throw new RuntimeException(e.getMessage()); } }
/** * Returns the certificates of this file. */ protected Certificate[] doGetCertificates() throws Exception { return file.getContent().getCertificates(); }
/** * Returns the attributes of this file. */ protected Map doGetAttributes() throws Exception { return file.getContent().getAttributes(); }
FileContentInfo contentInfo = content.getContentInfo(); io.info("Content type: {}", contentInfo.getContentType()); io.info("Content encoding: {}", contentInfo.getContentEncoding()); Map<String,Object> attrs = content.getAttributes(); if (attrs != null && !attrs.isEmpty()) { io.info("Attributes:"); Certificate[] certs = content.getCertificates(); if (certs != null && certs.length != 0) { io.info("Certificate:"); io.info("Size: {} bytes", content.getSize()); io.info("Last modified: {}", DateFormat.getInstance().format(new Date(content.getLastModifiedTime())));
private void init() { if (!init) { try { resourceImpl = fsManager.resolveFile(vfsURI); content = resourceImpl.getContent(); exists = resourceImpl.exists(); lastModified = content.getLastModifiedTime(); contentLength = content.getSize(); } catch (FileSystemException e) { Message.debug(e); Message.verbose(e.getLocalizedMessage()); exists = false; lastModified = 0; contentLength = 0; } init = true; } }
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); new FileObjectAssert(file).exists(); ensureFileHasContent(file); org.apache.commons.vfs.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 Result.SUCCESS; }
public int getContentLength() { try { return (int) content.getSize(); } catch (FileSystemException fse) { } return -1; }
getFileSystem().hasCapability(Capability.GET_LAST_MODIFIED)) destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime());
public Object call() throws Exception { FileObject toFile = root.resolveFile( to.path.string ); toFile.getParent().createFolder(); toFile.copyFrom( from, Selectors.SELECT_SELF ); toFile.getContent().setLastModifiedTime( to.lastModified.toDateTime().toDate().getTime() ); return Unit.unit(); } };
public String getContentType() { try { return content.getContentInfo().getContentType(); } catch (FileSystemException e) { throw new RuntimeException(e.getMessage()); } }