當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceUtils.isFileURL方法代碼示例

本文整理匯總了Java中org.springframework.util.ResourceUtils.isFileURL方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourceUtils.isFileURL方法的具體用法?Java ResourceUtils.isFileURL怎麽用?Java ResourceUtils.isFileURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.util.ResourceUtils的用法示例。


在下文中一共展示了ResourceUtils.isFileURL方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isReadable

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@Override
public boolean isReadable() {
	try {
		URL url = getURL();
		if (ResourceUtils.isFileURL(url)) {
			// Proceed with file system resolution...
			File file = getFile();
			return (file.canRead() && !file.isDirectory());
		}
		else {
			return true;
		}
	}
	catch (IOException ex) {
		return false;
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:AbstractFileResolvingResource.java

示例2: getFile

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
 * This implementation resolves "file:" URLs or alternatively delegates to
 * {@code ServletContext.getRealPath}, throwing a FileNotFoundException
 * if not found or not resolvable.
 * @see javax.servlet.ServletContext#getResource(String)
 * @see javax.servlet.ServletContext#getRealPath(String)
 */
@Override
public File getFile() throws IOException {
	URL url = this.servletContext.getResource(this.path);
	if (url != null && ResourceUtils.isFileURL(url)) {
		// Proceed with file system resolution...
		return super.getFile();
	}
	else {
		String realPath = WebUtils.getRealPath(this.servletContext, this.path);
		return new File(realPath);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:ServletContextResource.java

示例3: getFile

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
 * This implementation resolves "file:" URLs or alternatively delegates to
 * {@code PortletContext.getRealPath}, throwing a FileNotFoundException
 * if not found or not resolvable.
 * @see javax.portlet.PortletContext#getResource(String)
 * @see javax.portlet.PortletContext#getRealPath(String)
 */
@Override
public File getFile() throws IOException {
	URL url = getURL();
	if (ResourceUtils.isFileURL(url)) {
		// Proceed with file system resolution...
		return super.getFile();
	}
	else {
		String realPath = PortletUtils.getRealPath(this.portletContext, this.path);
		return new File(realPath);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:PortletContextResource.java

示例4: contentLength

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@Override
public long contentLength() throws IOException {
	URL url = getURL();
	if (ResourceUtils.isFileURL(url)) {
		// Proceed with file system resolution...
		return getFile().length();
	}
	else {
		// Try a URL connection content-length header...
		URLConnection con = url.openConnection();
		customizeConnection(con);
		return con.getContentLength();
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:AbstractFileResolvingResource.java

示例5: lastModified

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@Override
public long lastModified() throws IOException {
	URL url = getURL();
	if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
		// Proceed with file system resolution...
		return super.lastModified();
	}
	else {
		// Try a URL connection last-modified header...
		URLConnection con = url.openConnection();
		customizeConnection(con);
		return con.getLastModified();
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:AbstractFileResolvingResource.java

示例6: getConfig

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private Config getConfig(Resource configLocation) throws IOException {
	URL configUrl = configLocation.getURL();
	Config config = new XmlConfigBuilder(configUrl).build();
	if (ResourceUtils.isFileURL(configUrl)) {
		config.setConfigurationFile(configLocation.getFile());
	}
	else {
		config.setConfigurationUrl(configUrl);
	}
	return config;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:HazelcastInstanceFactory.java

示例7: getConfigurationSource

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private ConfigurationSource getConfigurationSource(URL url) throws IOException {
	InputStream stream = url.openStream();
	if (ResourceUtils.isFileURL(url)) {
		return new ConfigurationSource(stream, ResourceUtils.getFile(url));
	}
	return new ConfigurationSource(stream, url);
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:8,代碼來源:Log4J2LoggingSystem.java

示例8: exists

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@Override
public boolean exists() {
	try {
		URL url = getURL();
		if (ResourceUtils.isFileURL(url)) {
			// Proceed with file system resolution...
			return getFile().exists();
		}
		else {
			// Try a URL connection content-length header...
			URLConnection con = url.openConnection();
			customizeConnection(con);
			HttpURLConnection httpCon =
					(con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
			if (httpCon != null) {
				int code = httpCon.getResponseCode();
				if (code == HttpURLConnection.HTTP_OK) {
					return true;
				}
				else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
					return false;
				}
			}
			if (con.getContentLength() >= 0) {
				return true;
			}
			if (httpCon != null) {
				// no HTTP OK status, and no content-length header: give up
				httpCon.disconnect();
				return false;
			}
			else {
				// Fall back to stream existence: can we open the stream?
				InputStream is = getInputStream();
				is.close();
				return true;
			}
		}
	}
	catch (IOException ex) {
		return false;
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:44,代碼來源:AbstractFileResolvingResource.java

示例9: tryConfig

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private synchronized boolean tryConfig(final ServletConfig config, final String location) {
    final String path = StroomProperties.replaceProperties(location);

    logInfo("tryConfig() - " + location + " -> " + path);

    final Resource resource = StroomResourceLoaderUtil.getResource(resourceLoader, path);
    boolean existingFile = false;
    try {
        logInfo("tryConfig() - " + resource + " exists = " + resource.exists() + " url = " + resource.getURI());
        existingFile = resource.exists() && ResourceUtils.isFileURL(resource.getURL());

    } catch (final Exception ex) {
        logError("tryConfig() - " + ex.getMessage());
    }
    if (existingFile) {
        BasicConfigurator.resetConfiguration();
        Log4jWebConfigurer.initLogging(config.getServletContext(), resource);
        logInfo("tryConfig() - Started log4j using: " + path + " (" + resource.getFilename() + ")");

        logger = StroomLogger.getLogger(Log4JServlet.class);
        logger.info("tryConfig() - Started log4j using: " + path + " (" + resource.getFilename() + ")");

        boolean redirectSystemOut = true;
        final Enumeration<?> allApenders = Logger.getRootLogger().getAllAppenders();
        while (allApenders.hasMoreElements()) {
            final Appender appender = (Appender) allApenders.nextElement();
            if (appender.getClass().getName().contains("Console")) {
                redirectSystemOut = false;
            }
        }

        if (redirectSystemOut) {
            System.setErr(LoggerPrintStream.create(logger, true));
            System.setOut(LoggerPrintStream.create(logger, true));
        }

        return true;
    } else {
        logInfo("tryConfig() - Not found: " + path);
    }

    return false;
}
 
開發者ID:gchq,項目名稱:stroom-proxy,代碼行數:44,代碼來源:Log4JServlet.java


注:本文中的org.springframework.util.ResourceUtils.isFileURL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。