当前位置: 首页>>代码示例>>Java>>正文


Java VirtualFile.exists方法代码示例

本文整理汇总了Java中play.vfs.VirtualFile.exists方法的典型用法代码示例。如果您正苦于以下问题:Java VirtualFile.exists方法的具体用法?Java VirtualFile.exists怎么用?Java VirtualFile.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.vfs.VirtualFile的用法示例。


在下文中一共展示了VirtualFile.exists方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllTemplate

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 * List all found templates
 * @return A list of executable templates
 */
public static List<Template> getAllTemplate() {
    List<Template> res = new ArrayList<Template>();
    for (VirtualFile virtualFile : Play.templatesPath) {
        scan(res, virtualFile);
    }
    for (VirtualFile root : Play.roots) {
        VirtualFile vf = root.child("conf/routes");
        if (vf != null && vf.exists()) {
            Template template = load(vf);
            if (template != null) {
                template.compile();
            }
        }
    }
    return res;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:21,代码来源:TemplateLoader.java

示例2: redirectToStatic

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 * Send a 302 redirect response.
 * @param file The Location to redirect
 */
protected static void redirectToStatic(String file) {
    try {
        VirtualFile vf = Play.getVirtualFile(file);
        if (vf == null || !vf.exists()) {
            throw new NoRouteFoundException(file);
        }
        throw new RedirectToStatic(Router.reverse(Play.getVirtualFile(file)));
    } catch (NoRouteFoundException e) {
        StackTraceElement element = PlayException.getInterestingStrackTraceElement(e);
        if (element != null) {
            throw new NoRouteFoundException(file, Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber());
        } else {
            throw e;
        }
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:21,代码来源:Controller.java

示例3: getResourceAsStream

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 * You know ...
 */
@Override
public InputStream getResourceAsStream(String name) {
    for (VirtualFile vf : Play.javaPath) {
        VirtualFile res = vf.child(name);
        if (res != null && res.exists()) {
            return res.inputstream();
        }
    }
    return super.getResourceAsStream(name);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:14,代码来源:ApplicationClassloader.java

示例4: getResource

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 * You know ...
 */
@Override
public URL getResource(String name) {
    for (VirtualFile vf : Play.javaPath) {
        VirtualFile res = vf.child(name);
        if (res != null && res.exists()) {
            try {
                return res.getRealFile().toURI().toURL();
            } catch (MalformedURLException ex) {
                throw new UnexpectedException(ex);
            }
        }
    }
    return super.getResource(name);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:18,代码来源:ApplicationClassloader.java

示例5: getResources

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 * You know ...
 */
@Override
public Enumeration<URL> getResources(String name) throws IOException {
    List<URL> urls = new ArrayList<URL>();
    for (VirtualFile vf : Play.javaPath) {
        VirtualFile res = vf.child(name);
        if (res != null && res.exists()) {
            try {
                urls.add(res.getRealFile().toURI().toURL());
            } catch (MalformedURLException ex) {
                throw new UnexpectedException(ex);
            }
        }
    }
    Enumeration<URL> parent = super.getResources(name);
    while (parent.hasMoreElements()) {
        URL next = parent.nextElement();
        if (!urls.contains(next)) {
            urls.add(next);
        }
    }
    final Iterator<URL> it = urls.iterator();
    return new Enumeration<URL>() {

        public boolean hasMoreElements() {
            return it.hasNext();
        }

        public URL nextElement() {
            return it.next();
        }
    };
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:36,代码来源:ApplicationClassloader.java

示例6: getJava

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 * Retrieve the corresponding source file for a given class name.
 * It handles innerClass too !
 * @param name The fully qualified class name 
 * @return The virtualFile if found
 */
public static VirtualFile getJava(String name) {
    String fileName = name;
    if (fileName.contains("$")) {
        fileName = fileName.substring(0, fileName.indexOf("$"));
    }
    fileName = fileName.replace(".", "/") + ".java";
    for (VirtualFile path : Play.javaPath) {
        VirtualFile javaFile = path.child(fileName);
        if (javaFile.exists()) {
            return javaFile;
        }
    }
    return null;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:21,代码来源:ApplicationClasses.java

示例7: serveStatic

import play.vfs.VirtualFile; //导入方法依赖的package包/类
public void serveStatic(HttpServletResponse servletResponse, HttpServletRequest servletRequest, RenderStatic renderStatic) throws IOException {

        VirtualFile file = Play.getVirtualFile(renderStatic.file);
        if (file == null || file.isDirectory() || !file.exists()) {
            serve404(servletRequest, servletResponse, new NotFound("The file " + renderStatic.file + " does not exist"));
        } else {
            servletResponse.setContentType(MimeTypes.getContentType(file.getName()));
            boolean raw = Play.pluginCollection.serveStatic(file, Request.current(), Response.current());
            if (raw) {
                copyResponse(Request.current(), Response.current(), servletRequest, servletResponse);
            } else {
                if (Play.mode == Play.Mode.DEV) {
                    servletResponse.setHeader("Cache-Control", "no-cache");
                    servletResponse.setHeader("Content-Length", String.valueOf(file.length()));
                    if (!servletRequest.getMethod().equals("HEAD")) {
                        copyStream(servletResponse, file.inputstream());
                    } else {
                        copyStream(servletResponse, new ByteArrayInputStream(new byte[0]));
                    }
                } else {
                    long last = file.lastModified();
                    String etag = "\"" + last + "-" + file.hashCode() + "\"";
                    if (!isModified(etag, last, servletRequest)) {
                        servletResponse.setHeader("Etag", etag);
                        servletResponse.setStatus(304);
                    } else {
                        servletResponse.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last)));
                        servletResponse.setHeader("Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600"));
                        servletResponse.setHeader("Etag", etag);
                        copyStream(servletResponse, file.inputstream());
                    }
                }
            }
        }
    }
 
开发者ID:eBay,项目名称:restcommander,代码行数:36,代码来源:ServletWrapper.java

示例8: serveFileOrGetDirectory

import play.vfs.VirtualFile; //导入方法依赖的package包/类
private VirtualFile serveFileOrGetDirectory() throws IOException, ParseException {
  VirtualFile file = WebPage.toVirtualFile(URLDecoder.decode(request.path, "UTF-8"));
  if (file.exists() && isAllowed(file)) {
    Http.Response.current().cacheFor("30d");
    renderBinary(file.getRealFile());
  }
  else if (!file.isDirectory()) showNotFoundError();
  return file;
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:10,代码来源:Web.java

示例9: toVirtualFile

import play.vfs.VirtualFile; //导入方法依赖的package包/类
public static VirtualFile toVirtualFile(String path) {
  VirtualFile file = ROOT.dir.child(path);
  if (!file.exists()) file = resolveLinkedPages(file);
  if (!canonicalPath(file.getRealFile()).startsWith(ROOT.dir.getRealFile().getPath()))
    throw new SecurityException("Access denied");
  return file;
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:8,代码来源:WebPage.java

示例10: loadMetadata

import play.vfs.VirtualFile; //导入方法依赖的package包/类
private static Properties loadMetadata(VirtualFile dir) {
  VirtualFile metaFile = dir.child("metadata.properties");
  if (metaFile.exists()) {
    try (Reader reader = new InputStreamReader(metaFile.inputstream(), "UTF-8")) {
      Properties metadata = new Properties();
      metadata.load(reader);
      return metadata;
    }
    catch (IOException e) {
      logger.error("Cannot load " + metaFile, e);
    }
  }
  return new Properties();
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:15,代码来源:WebPage.java

示例11: serveStatic

import play.vfs.VirtualFile; //导入方法依赖的package包/类
public void serveStatic(GrizzlyRequest grizzlyRequest, GrizzlyResponse grizzlyResponse, RenderStatic renderStatic) {
    VirtualFile file = Play.getVirtualFile(renderStatic.file);
    if (file == null || file.isDirectory() || !file.exists()) {
        serve404(grizzlyRequest, grizzlyResponse, new NotFound("The file " + renderStatic.file + " does not exist"));
    } else {
        grizzlyResponse.setContentType(MimeTypes.getContentType(file.getName()));
        boolean raw = false;
        for (PlayPlugin plugin : Play.plugins) {
            if (plugin.serveStatic(file, Request.current(), Response.current())) {
                raw = true;
                break;
            }
        }
        try {
            if (raw) {
                copyResponse(Request.current(), Response.current(), grizzlyRequest, grizzlyResponse);
            } else {
                if (Play.mode == Play.Mode.DEV) {
                    grizzlyResponse.setHeader("Cache-Control", "no-cache");
                    grizzlyResponse.setHeader("Content-Length", String.valueOf(file.length()));
                    if (!grizzlyRequest.getMethod().equals("HEAD")) {
                        copyStream(grizzlyResponse, file.inputstream());
                    } else {
                        copyStream(grizzlyResponse, new ByteArrayInputStream(new byte[0]));
                    }
                } else {
                    long last = file.lastModified();
                    String etag = "\"" + last + "-" + file.hashCode() + "\"";
                    if (!isModified(etag, last, grizzlyRequest)) {
                        grizzlyResponse.setHeader("Etag", etag);
                        grizzlyResponse.setStatus(304);
                    } else {
                        grizzlyResponse.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last)));
                        grizzlyResponse.setHeader("Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600"));
                        grizzlyResponse.setHeader("Etag", etag);
                        copyStream(grizzlyResponse, file.inputstream());
                    }
                }

            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:46,代码来源:PlayGrizzlyAdapter.java

示例12: reverseWithCheck

import play.vfs.VirtualFile; //导入方法依赖的package包/类
public static String reverseWithCheck(String name, VirtualFile file, boolean absolute) {
    if (file == null || !file.exists()) {
        throw new NoRouteFoundException(name + " (file not found)");
    }
    return reverse(file, absolute);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:7,代码来源:Router.java

示例13: serialize

import play.vfs.VirtualFile; //导入方法依赖的package包/类
/**
 *
 * TODO: reuse beanutils or MapUtils?
 *
 * @param entityProperties
 * @param prefix
 * @return an hash with the resolved entity name and the corresponding value
 */
static Map<String, String[]> serialize(Map<?, ?> entityProperties, String prefix) {

    if (entityProperties == null) {
        return MapUtils.EMPTY_MAP;
    }

    final Map<String, String[]> serialized = new HashMap<String, String[]>();

    for (Object key : entityProperties.keySet()) {

        Object value = entityProperties.get(key);
        if (value == null) {
            continue;
        }
        if (value instanceof Map<?, ?>) {
            serialized.putAll(serialize((Map<?, ?>) value, prefix + "." + key));
        } else if (value instanceof Date) {
            serialized.put(prefix + "." + key.toString(), new String[]{new SimpleDateFormat(DateBinder.ISO8601).format(((Date) value))});
        } else if (Collection.class.isAssignableFrom(value.getClass())) {
            Collection<?> l = (Collection<?>) value;
            String[] r = new String[l.size()];
            int i = 0;
            for (Object el : l) {
                r[i++] = el.toString();
            }
            serialized.put(prefix + "." + key.toString(), r);
        } else if (value instanceof String && value.toString().matches("<<<\\s*\\{[^}]+}\\s*")) {
            Matcher m = Pattern.compile("<<<\\s*\\{([^}]+)}\\s*").matcher(value.toString());
            m.find();
            String file = m.group(1);
            VirtualFile f = Play.getVirtualFile(file);
            if (f != null && f.exists()) {
                serialized.put(prefix + "." + key.toString(), new String[]{f.contentAsString()});
            }
        } else {
            serialized.put(prefix + "." + key.toString(), new String[]{value.toString()});
        }
    }

    return serialized;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:50,代码来源:Fixtures.java

示例14: verifyURL

import play.vfs.VirtualFile; //导入方法依赖的package包/类
private void verifyURL(WebPage page, String url) throws FileNotFoundException {
  VirtualFile file = page.dir.child(url);
  if (!file.exists()) throw new FileNotFoundException(url);
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:5,代码来源:WebAdmin.java


注:本文中的play.vfs.VirtualFile.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。