de.matrixweb.vfs.VFS类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中de.matrixweb.vfs.VFS类的一些代码示例,展示了VFS类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。VFS类的具体详情如下:
包路径:de.matrixweb.vfs.VFS
类名称:VFS

VFS介绍

[英]This implements a file system abstraction which is able to mount native Files as read-only parts into the VFS. The native files are never overwritten. To create a native filesystem from the virtual use #exportFS(File), to import a native filesystem use #importFS(File).
[中]这实现了一个文件系统抽象,它能够将本机文件作为只读部分装载到VFS中。本机文件永远不会被覆盖。要从虚拟使用#exportFS(文件)创建本机文件系统,要导入本机文件系统,请使用#importFS(文件)。

代码示例

代码示例来源:origin: de.matrixweb.smaller/resource

/**
 * @param vfs
 * @param ext
 * @return Returns a list of {@link VFile} which match the given extension
 * @throws IOException
 */
public static List<VFile> getFilesByExtension(final VFS vfs, final String ext)
  throws IOException {
 return getFilesByExtension(vfs.find("/"), ext);
}

代码示例来源:origin: de.matrixweb.smaller/resource

final String sourceType, final String resultType,
 final ProcessorCallback callback) throws IOException {
final VFile snapshot = vfs.stack();
try {
 final VFile source = vfs.find(input.getPath());
 final VFile target = vfs.find(FilenameUtils.removeExtension(input
   .getPath()) + "." + resultType);
 VFSUtils.pipe(source, target, new Pipe() {
 vfs.rollback(snapshot);
 throw e;

代码示例来源:origin: de.matrixweb.vfs/vfs

/**
 * @see de.matrixweb.vfs.VFile#getURL()
 */
@Override
public URL getURL() {
 return getRoot().getVfs().createUrl(this);
}

代码示例来源:origin: de.matrixweb.vfs/vfs

private void internalImportFS(final File source, final File file) throws IOException {
 if (file.isDirectory()) {
  for (final File dir : file.listFiles()) {
   internalImportFS(source, dir);
  }
 } else {
  final VFile targetFile = find(file.getAbsolutePath().replace('\\', '/')
    .substring(source.getAbsolutePath().replace('\\', '/').length()));
  VFSUtils.write(targetFile, IOHelper.readToString(file));
 }
}

代码示例来源:origin: de.matrixweb.smaller/pipeline

private void writeResults(final VFS vfs, final File outputDir,
  final Manifest manifest) throws IOException {
 if (!GlobalOptions.isOutOnly(manifest)) {
  vfs.exportFS(outputDir);
 }
 for (final ProcessDescription processDescription : manifest
   .getProcessDescriptions()) {
  if (processDescription.getOutputFile() != null) {
   FileUtils
     .writeStringToFile(
       new File(outputDir, processDescription.getOutputFile()),
       VFSUtils.readToString(vfs.find(processDescription
         .getOutputFile())));
  }
 }
}

代码示例来源:origin: de.matrixweb.smaller/resource

/**
 * @see de.matrixweb.smaller.resource.ResourceResolver#resolve(java.lang.String)
 */
@Override
public Resource resolve(final String path) {
 try {
  return new VFSResource(this, this.vfs.find(path.startsWith("/") ? path
    : '/' + path));
 } catch (final IOException e) {
  throw new SmallerException("Failed to resolve '" + path + "'", e);
 }
}

代码示例来源:origin: de.matrixweb.smaller/resource

final String resultType, final ProcessorCallback callback)
 throws IOException {
final VFile snapshot = vfs.stack();
try {
  final VFile target = vfs.find(FilenameUtils.removeExtension(file
    .getPath()) + "." + resultType);
   : null;
} catch (final IOException e) {
 vfs.rollback(snapshot);
 throw e;

代码示例来源:origin: de.matrixweb.vfs/vfs

/**
 * @see de.matrixweb.vfs.scanner.ResourceLister#list(java.lang.String)
 */
@Override
public Set<String> list(String path) {
 if (path.endsWith("/") && path.length() > 1) {
  path = path.substring(0, path.length() - 1);
 }
 final Set<String> list = new HashSet<String>();
 try {
  for (final VFile file : new ArrayList<VFile>(this.vfs.find(path).getChildren())) {
   // FIX #2: Should not happen, but this is at least a guard
   if (file != null) {
    list.add(file.getPath());
   }
  }
 } catch (final IOException e) {
  // Ignore this
 }
 return list;
}

代码示例来源:origin: de.matrixweb.smaller/merge

private Resource executeComplexMerge(final VFS vfs, final Resource resource,
  final Map<String, Object> options) throws IOException {
 final Object typeOption = options.get("type");
 if (!(resource instanceof ResourceGroup) || typeOption != null
   && resource.getType() != Type.valueOf(typeOption.toString())) {
  return resource;
 }
 final ResourceGroup group = (ResourceGroup) resource;
 final Resource input = group.getResources().get(0);
 final VFile snapshot = vfs.stack();
 try {
  final VFile target = vfs.find(input.getPath());
  final Writer writer = VFSUtils.createWriter(target);
  try {
   writer.write(group.getMerger().merge(group.getResources()));
  } finally {
   IOUtils.closeQuietly(writer);
  }
  return input.getResolver().resolve(target.getPath());
 } catch (final IOException e) {
  vfs.rollback(snapshot);
  throw e;
 }
}

代码示例来源:origin: de.matrixweb.vfs/vfs

/**
 * @see java.net.URLConnection#getInputStream()
 */
@Override
public InputStream getInputStream() throws IOException {
 final String host = getURL().getHost();
 final VFS vfs = getInstance().active.get(host);
 if (vfs == null) {
  throw new IOException("Host '" + host
    + "' is not known in the registry.");
 }
 return vfs.find(getURL().getFile()).getInputStream();
}

代码示例来源:origin: de.matrixweb.smaller/merge

/**
 * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS,
 *      de.matrixweb.smaller.resource.Resource, java.util.Map)
 */
@Override
public Resource execute(final VFS vfs, final Resource resource,
  final Map<String, Object> options) throws IOException {
 // Version 1.0.0 handling
 if (getVersion(options).isAtLeast(Version._1_0_0)) {
  try {
   if (!(resource instanceof ResourceGroup) && resource != null
     && FilenameUtils.isExtension(resource.getPath(), "json")) {
    return executeSimpleMerge(vfs, resource, options);
   }
   return executeComplexMerge(vfs, resource, options);
  } catch (final IOException e) {
   throw new SmallerException("Failed to merge files", e);
  }
 }
 final VFile snapshot = vfs.stack();
 try {
  final VFile file = vfs.find(resource.getPath());
  VFSUtils.write(file, resource.getContents());
  return resource.getResolver().resolve(file.getPath());
 } catch (final IOException e) {
  vfs.rollback(snapshot);
  throw e;
 }
}

代码示例来源:origin: de.matrixweb.smaller/pipeline

@Deprecated
private Result prepareResult(final VFS vfs, final ResourceResolver resolver,
  final Task task) throws IOException {
 final Resources resources = new Resources();
 for (final String out : task.getOut()) {
  LOGGER.info("Preparing output file: {}", out);
  final String ext = FilenameUtils.getExtension(out);
  final VFile file = findLastModified(vfs.find("/"), ext);
  if (file != null) {
   final VFile target = vfs.find('/' + out);
   LOGGER.info("Copy '{}' -> '{}'", file, target);
   VFSUtils.copy(file, target);
   resources.addResource(resolver.resolve(target.getPath()));
  }
 }
 return new Result(resources);
}

代码示例来源:origin: de.matrixweb.vfs/vfs

public VFile find(final String path) throws IOException {
 if (path.startsWith("/")) {
  return getRoot().getVfs().find(path);

代码示例来源:origin: de.matrixweb.smaller/jshint

final String content = VFSUtils.readToString(vfs.find(result)).trim();
if (content.length() > 0) {
 throw new JsHintException(content);

代码示例来源:origin: de.matrixweb.smaller/resource

final VFile file = vfs.find("/__temp__json__input");
final List<Resource> resources = getJsonSourceFiles(resolver.resolve(in));

代码示例来源:origin: de.matrixweb.smaller/uglifyjs

private Resource executeWithNode(final VFS vfs, final Resource resource,
  final Map<String, Object> options) throws IOException {
 if (this.node == null) {
  try {
   this.node = new NodeJsExecutor();
   this.node.setModule(getClass(), "uglifyjs-" + this.version);
  } catch (final IOException e) {
   this.node = null;
   throw new SmallerException("Failed to setup node for uglify", e);
  }
 }
 final VFile infile = vfs.find(resource.getPath());
 if (!infile.exists()) {
  throw new SmallerException("Uglify input '" + infile
    + "' does not exists");
 }
 final String resultPath = this.node.run(vfs, resource.getPath(), options);
 final VFile outfile = vfs.find('/' + resultPath);
 if (!outfile.exists()) {
  throw new SmallerException("Uglify result '" + outfile
    + "' does not exists");
 }
 return resource.getResolver().resolve(outfile.getPath());
}

代码示例来源:origin: de.matrixweb.smaller/sweetjs

/**
 * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS,
 *      de.matrixweb.smaller.resource.Resource, java.util.Map)
 */
@Override
public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException {
 if (this.node == null) {
  try {
   this.node = new NodeJsExecutor();
   this.node.setModule(getClass(), "sweetjs-" + this.version, null);
  } catch (final IOException e) {
   this.node = null;
   throw new SmallerException("Failed to setup node for sweetjs", e);
  }
 }
 String outfile = this.node.run(vfs, resource != null ? resource.getPath() : null, options);
 if (outfile != null) {
  final VFile file = vfs.find('/' + outfile);
  if (!file.exists()) {
   throw new SmallerException("SweetjsProcessor result does not exists");
  }
 }
 return resource == null || outfile == null ? resource : resource.getResolver().resolve('/' + outfile);
}

代码示例来源:origin: de.matrixweb.smaller/svgo

/**
 * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS,
 *      de.matrixweb.smaller.resource.Resource, java.util.Map)
 */
@Override
public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException {
 if (this.node == null) {
  try {
   this.node = new NodeJsExecutor();
   this.node.setModule(getClass(), "svgo-" + this.version, null);
  } catch (final IOException e) {
   this.node = null;
   throw new SmallerException("Failed to setup node for svgo", e);
  }
 }
 String outfile = this.node.run(vfs, resource != null ? resource.getPath() : null, options);
 if (outfile != null) {
  final VFile file = vfs.find('/' + outfile);
  if (!file.exists()) {
   throw new SmallerException("SvgoProcessor result does not exists");
  }
 }
 return resource == null || outfile == null ? resource : resource.getResolver().resolve('/' + outfile);
}

代码示例来源:origin: de.matrixweb.smaller/browserify

/**
 * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS,
 *      de.matrixweb.smaller.resource.Resource, java.util.Map)
 */
@Override
public Resource execute(final VFS vfs, final Resource resource,
  final Map<String, Object> options) throws IOException {
 if (this.node == null) {
  try {
   this.node = new NodeJsExecutor();
   this.node.setModule(getClass(), "browserify-" + this.version,
     "browserify.js");
  } catch (final IOException e) {
   this.node = null;
   throw new SmallerException("Failed to setup node for browserify", e);
  }
 }
 final String outfile = this.node.run(vfs,
   resource != null ? resource.getPath() : null, options);
 if (outfile != null) {
  final VFile file = vfs.find('/' + outfile);
  if (!file.exists()) {
   throw new SmallerException("BrowserifyProcessor result does not exists");
  }
 }
 return resource == null || outfile == null ? resource : resource
   .getResolver().resolve('/' + outfile);
}

代码示例来源:origin: de.matrixweb.smaller/pipeline

VFSUtils.write(vfs.find(processDescription.getOutputFile()), resolver
  .resolve(input).getContents());

相关文章