本文整理汇总了Java中org.springframework.core.io.Resource.isReadable方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.isReadable方法的具体用法?Java Resource.isReadable怎么用?Java Resource.isReadable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.io.Resource
的用法示例。
在下文中一共展示了Resource.isReadable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadAsResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if(resource.exists() || resource.isReadable()) {
return resource;
}
else {
throw new StorageFileNotFoundException("Could not read file: " + filename);
}
} catch (MalformedURLException e) {
throw new StorageFileNotFoundException("Could not read file: " + filename, e);
}
}
示例2: getResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
@Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
Resource resource = location.createRelative(resourcePath);
if (resource.exists() && resource.isReadable()) {
return resource;
}
if (getApiPath() != null && ("/" + resourcePath).startsWith(getApiPath())) {
return null;
}
if(getApiPublicPath() != null && ("/" + resourcePath).startsWith(getApiPublicPath())) {
return null;
}
LoggerFactory.getLogger(getClass()).info("Routing /" + resourcePath + " to /index.html");
resource = location.createRelative("/WEB-INF/app/" + resourcePath);
LoggerFactory.getLogger(getClass()).info("Routing to " + resource);
if (resource.exists() && resource.isReadable()) {
return resource;
}
return null;
}
示例3: loadAsResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
try {
Path file = this.rootLocation.resolve(filename);
Resource resource = new UrlResource(file.toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
throw new UploadFileNotFoundException(
"Could not read file: " + filename);
}
} catch (MalformedURLException e) {
throw new UploadFileNotFoundException("Could not read file: " + filename, e);
}
}
示例4: loadClassName
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
* 加载资源,根据resource获取className
*
* @param metadataReaderFactory spring中用来读取resource为class的工具
* @param resource 这里的资源就是一个Class
* @throws IOException
*/
private static String loadClassName(MetadataReaderFactory metadataReaderFactory, Resource resource)
throws IOException
{
try
{
if (resource.isReadable())
{
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (metadataReader != null)
{
return metadataReader.getClassMetadata().getClassName();
}
}
}
catch (Exception e)
{
LOG.error("根据resource获取类名称失败", e);
}
return null;
}
示例5: findMyTypes
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
protected List<Class<?>> findMyTypes(String basePackage) throws IOException, ClassNotFoundException {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
List<Class<?>> candidates = new ArrayList<>();
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage)
+ "/" + "**/*.class";
Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (isCandidate(metadataReader)) {
candidates.add(forName(metadataReader.getClassMetadata().getClassName()));
}
}
}
return candidates;
}
示例6: getClassSet
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
* 将符合条件的Bean以Class集合的形式返回
*
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public Set<Class<?>> getClassSet() throws IOException, ClassNotFoundException {
this.classSet.clear();
if (!this.packagesList.isEmpty()) {
for (String pkg : this.packagesList) {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesEntityTypeFilter(reader, readerFactory)) {
this.classSet.add(Class.forName(className));
}
}
}
}
}
return this.classSet;
}
示例7: scan
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
* 将符合条件的Bean以Class集合的形式返回
* @throws Exception 异常
* @return 类集合
*/
public Set<Class<?>> scan() throws Exception {
Set<Class<?>> classSet = new HashSet<Class<?>>();
if (!this.packagesList.isEmpty()) {
for (String pkg : this.packagesList) {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesEntityTypeFilter(reader, readerFactory)) {
classSet.add(Class.forName(className));
}
}
}
}
}
return classSet;
}
示例8: loadClassName
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
/**
* 加载资源,根据resource获取className
*
* @param metadataReaderFactory
* spring中用来读取resource为class的工具
* @param resource
* 这里的资源就是一个Class
* @throws IOException
*/
private static String loadClassName(MetadataReaderFactory metadataReaderFactory, Resource resource)
throws IOException {
try {
if (resource.isReadable()) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (metadataReader != null) {
return metadataReader.getClassMetadata().getClassName();
}
}
}
catch (Exception e) {
log.error("根据resource获取类名称失败", e);
}
return null;
}
示例9: loadAsResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
public Resource loadAsResource(String path) {
Path filePath = Paths.get(properties.getUploadFileRootPath(), path);
Resource resource = new FileSystemResource(filePath.toFile());
if (resource.exists() || resource.isReadable()) {
return resource;
}
else {
throw new StorageException("Could not read file: " + path);
}
}
示例10: 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
示例11: 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);
}
}
示例12: loadAsResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
public Resource loadAsResource(String filename) {
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if(resource.exists() || resource.isReadable()) {
return resource;
}
else {
throw new SIIStemTechnicalException("Could not read file: " + filename);
}
} catch (MalformedURLException e) {
throw new SIIStemTechnicalException("Could not read file: " + filename, e);
}
}
示例13: loadResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
public Resource loadResource(String uuid) throws Exception {
String filename = StringUtils.cleanPath(uuid);
Resource resource = new UrlResource(storageDir.resolve(filename).toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
}
else {
throw new TusStorageException(filename);
}
}
示例14: loadAsResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filepath) {
try {
Path file = load(filepath);
Resource resource = new UrlResource(file.toUri());
if(resource.exists() || resource.isReadable()) {
return resource;
}else {
throw new StorageFileNotFoundException("Couldn't read file: " + filepath);
}
} catch (MalformedURLException e) {
throw new StorageFileNotFoundException("Couldn't read file: " + filepath);
}
}
示例15: loadAsResource
import org.springframework.core.io.Resource; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
throw new StorageFileNotFoundException("Could not read chart: " + filename);
}
} catch (MalformedURLException e) {
throw new StorageFileNotFoundException("Could not read chart: " + filename, e);
}
}