當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。