本文整理匯總了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);
}
}