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


Java Resource.exists方法代码示例

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


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

示例1: validateJwtConfiguration

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
private Resource validateJwtConfiguration() {
  if (jwtFile.equals("")) {
    throw new FunctionalException(FunctionalException.Code.NO_JWT_FILE);
  }
  if (jwtSecret.equals("")) {
    throw new FunctionalException(FunctionalException.Code.NO_JWT_SECRET);
  }
  if (jwtAlias.equals("")) {
    throw new FunctionalException(FunctionalException.Code.NO_JWT_ALIAS);
  }
  Resource resource = getJwtResource();
  if (!resource.exists()) {
    throw new FunctionalException(FunctionalException.Code.JWT_FILE_NOT_FOUND);
  }
  return resource;
}
 
开发者ID:t0bst4r,项目名称:authorizer,代码行数:17,代码来源:JwtConfiguration.java

示例2: useOrmXmlForDefaultPersistenceUnit

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
 * Determine whether to register JPA's default "META-INF/orm.xml" with
 * Spring's default persistence unit, if any.
 * <p>Checks whether a "META-INF/orm.xml" file exists in the classpath and
 * uses it if it is not co-located with a "META-INF/persistence.xml" file.
 */
private boolean useOrmXmlForDefaultPersistenceUnit() {
	Resource ormXml = this.resourcePatternResolver.getResource(
			this.defaultPersistenceUnitRootLocation + DEFAULT_ORM_XML_RESOURCE);
	if (ormXml.exists()) {
		try {
			Resource persistenceXml = ormXml.createRelative(PERSISTENCE_XML_FILENAME);
			if (!persistenceXml.exists()) {
				return true;
			}
		}
		catch (IOException ex) {
			// Cannot resolve relative persistence.xml file - let's assume it's not there.
			return true;
		}
	}
	return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:DefaultPersistenceUnitManager.java

示例3: getSettings

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
 * Returns the settings used for creating this jar. This method tries to
 * locate and load the settings from the location indicated by
 * {@link #getSettingsLocation()}. If no file is found, the default
 * settings will be used.
 * <p/>
 * <p/> A non-null properties object will always be returned.
 *
 * @return settings for creating the on the fly jar
 * @throws Exception if loading the settings file fails
 */
protected Properties getSettings() throws Exception {
    Properties settings = new Properties(getDefaultSettings());
    // settings.setProperty(ROOT_DIR, getRootPath());
    Resource resource = new ClassPathResource(getSettingsLocation());

    if (resource.exists()) {
        InputStream stream = resource.getInputStream();
        try {
            if (stream != null) {
                settings.load(stream);
                logger.debug("Loaded jar settings from " + getSettingsLocation());
            }
        } finally {
            IOUtils.closeStream(stream);
        }
    } else {
        logger.info(getSettingsLocation() + " was not found; using defaults");
    }

    return settings;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:33,代码来源:AbstractConfigurableBundleCreatorTests.java

示例4: texture

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
@GetMapping
public ResponseEntity<Resource> texture(@PathVariable String textureId) {
	if (!REGEX_TEXTURE_ID.matcher(textureId).matches()) {
		return notFound().build();
	}
	Resource resource = texturesManager.textureResource(textureId);
	if (!resource.exists()) {
		return notFound().build();
	}
	return ok()
			.contentType(IMAGE_PNG)
			.cacheControl(
					maxAge(resourceProperties.getCache().getPeriod().getSeconds(), SECONDS)
							.cachePublic())
			.eTag(textureId)
			.body(resource);
}
 
开发者ID:yushijinhun,项目名称:akir,代码行数:18,代码来源:TexturesController.java

示例5: importStream

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
public InputStream importStream(String content)
{
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource(content);
    if (resource.exists() == false)
    {
        throw new ImporterException("Content URL " + content + " does not exist.");
    }
    
    try
    {
        return resource.getInputStream();
    }
    catch(IOException e)
    {
        throw new ImporterException("Failed to retrieve input stream for content URL " + content);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:ImporterComponent.java

示例6: loadAsResource

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
public Resource loadAsResource(String filename) {
    try {
        String filePath = filename.substring(0, 2) + "/" + filename.substring(2);
        Resource resource = new UrlResource(Paths.get(storageDirectory, filePath).toUri());
        if(resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new RuntimeException("Could not read file: " + filename);

        }
    } catch (Exception e) {
        throw new RuntimeException("Could not read file: " + filename, e);
    }
}
 
开发者ID:myliang,项目名称:fish-admin,代码行数:15,代码来源:StorageService.java

示例7: loadFromSystemProperty

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
private static SessionSettings loadFromSystemProperty(String systemProperty) throws ConfigError, IOException {
    // Try loading the settings from the system property
    if (systemProperty != null) {
        String configSystemProperty = System.getProperty(systemProperty);
        if (configSystemProperty != null) {
            Resource resource = loadResource(configSystemProperty);
            if (resource != null && resource.exists()) {
                logger.info("Loading settings from System property '" + systemProperty + "'");
                return new SessionSettings(resource.getInputStream());
            }
        }
    }
    return null;
}
 
开发者ID:esanchezros,项目名称:quickfixj-spring-boot-starter,代码行数:15,代码来源:SessionSettingsLocator.java

示例8: getResourceInputStream

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
 * Retrieve the remote source's input stream to parse data.
 * @param resource the resource
 * @param entityId the entity id
 * @return the input stream
 * @throws IOException if stream cannot be read
 */
protected InputStream getResourceInputStream(final Resource resource, final String entityId) throws IOException {
    logger.debug("Locating metadata resource from input stream.");
    if (!resource.exists() || !resource.isReadable()) {
        throw new FileNotFoundException("Resource does not exist or is unreadable");
    }
    return resource.getInputStream();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:AbstractMetadataResolverAdapter.java

示例9: findValidBlueprintConfigs

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
 * Checks if the given bundle contains existing configurations. The absolute paths are returned without performing
 * any checks.
 * 
 * @return
 */
private String[] findValidBlueprintConfigs(Bundle bundle, String[] locations) {
	List<String> configs = new ArrayList<String>(locations.length);
	ResourcePatternResolver loader = new OsgiBundleResourcePatternResolver(bundle);

	boolean debug = log.isDebugEnabled();
	for (String location : locations) {
		if (isAbsolute(location)) {
			configs.add(location);
		}
		// resolve the location to check if it's present
		else {
			try {
				String loc = location;
				if (loc.endsWith("/")) {
					loc = loc + "*.xml";
				}
				Resource[] resources = loader.getResources(loc);
				if (!ObjectUtils.isEmpty(resources)) {
					for (Resource resource : resources) {
						if (resource.exists()) {
							String value = resource.getURL().toString();
							if (debug)
								log.debug("Found location " + value);
							configs.add(value);
						}
					}
				}
			} catch (IOException ex) {
				if (debug)
					log.debug("Cannot resolve location " + location, ex);
			}
		}
	}
	return (String[]) configs.toArray(new String[configs.size()]);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:42,代码来源:BlueprintConfigurationScanner.java

示例10: contributeDefaults

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
private static void contributeDefaults(Map<String, Object> defaults, Resource resource) {
	if (resource.exists()) {
		YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
		yamlPropertiesFactoryBean.setResources(resource);
		yamlPropertiesFactoryBean.afterPropertiesSet();
		Properties p = yamlPropertiesFactoryBean.getObject();
		for (Object k : p.keySet()) {
			String key = k.toString();
			defaults.put(key, p.get(key));
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:13,代码来源:DefaultEnvironmentPostProcessor.java

示例11: addBanner

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
private void addBanner(ResourceLoader resourceLoader, String bannerResourceName,
        Function<Resource, Banner> function) {
    Resource bannerResource = resourceLoader.getResource(bannerResourceName);
    if (bannerResource.exists()) {
        banners.add(new BannerDecorator(function.apply(bannerResource)));
    }
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:8,代码来源:ShellBanner.java

示例12: validateSchema

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
 * Collate differences and validation problems with the schema with respect to an appropriate
 * reference schema.
 * 
 * @param outputFileNameTemplate String
 * @param out PrintWriter
 * @return the number of potential problems found.
 */
public synchronized int validateSchema(String outputFileNameTemplate, PrintWriter out)
{
    int totalProblems = 0;
    
    // Discover available reference files (e.g. for prefixes alf_, etc.)
    // and process each in turn.
    for (String schemaReferenceUrl : schemaReferenceUrls)
    {
        Resource referenceResource = getDialectResource(dialect.getClass(), schemaReferenceUrl);
        
        if (referenceResource == null || !referenceResource.exists())
        {
            String resourceUrl = resolveDialectUrl(dialect.getClass(), schemaReferenceUrl);
            LogUtil.debug(logger, DEBUG_SCHEMA_COMP_NO_REF_FILE, resourceUrl);
        }
        else
        {
            // Validate schema against each reference file
            int problems = validateSchema(referenceResource, outputFileNameTemplate, out);
            totalProblems += problems;
        }
    }
    
    // Return number of problems found across all reference files.
    return totalProblems;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:35,代码来源:SchemaBootstrap.java

示例13: loadFromClassPath

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
private static SessionSettings loadFromClassPath(String classpathLocation) throws ConfigError, IOException {
    // Try loading the settings file from the classpath
    if (classpathLocation != null) {
        Resource resource = loadResource(classpathLocation);
        if (resource != null && resource.exists()) {
            logger.info("Loading settings from default classpath location '" + classpathLocation + "'");
            return new SessionSettings(resource.getInputStream());
        }
    }
    return null;
}
 
开发者ID:esanchezros,项目名称:quickfixj-spring-boot-starter,代码行数:12,代码来源:SessionSettingsLocator.java

示例14: loadFromFileSystem

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
private static SessionSettings loadFromFileSystem(String fileSystemLocation) throws ConfigError, IOException {
    // Try loading the settings file from the same location in the filesystem
    if (fileSystemLocation != null) {
        Resource resource = loadResource(fileSystemLocation);
        if (resource != null && resource.exists()) {
            logger.info("Loading settings from default filesystem location '" + fileSystemLocation + "'");
            return new SessionSettings(resource.getInputStream());
        }
    }
    return null;
}
 
开发者ID:esanchezros,项目名称:quickfixj-spring-boot-starter,代码行数:12,代码来源:SessionSettingsLocator.java

示例15: parseJarFiles

import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
 * Parse the {@code jar-file} XML elements.
 */
protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException {
	List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL);
	for (Element element : jars) {
		String value = DomUtils.getTextValue(element).trim();
		if (StringUtils.hasText(value)) {
			Resource[] resources = this.resourcePatternResolver.getResources(value);
			boolean found = false;
			for (Resource resource : resources) {
				if (resource.exists()) {
					found = true;
					unitInfo.addJarFileUrl(resource.getURL());
				}
			}
			if (!found) {
				// relative to the persistence unit root, according to the JPA spec
				URL rootUrl = unitInfo.getPersistenceUnitRootUrl();
				if (rootUrl != null) {
					unitInfo.addJarFileUrl(new URL(rootUrl, value));
				}
				else {
					logger.warn("Cannot resolve jar-file entry [" + value + "] in persistence unit '" +
							unitInfo.getPersistenceUnitName() + "' without root URL");
				}
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:PersistenceUnitReader.java


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