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


Java Resource.isReadable方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:Yuiffy,項目名稱:file-download-upload-zip-demo,代碼行數:17,代碼來源:FileSystemStorageService.java

示例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;
}
 
開發者ID:howma03,項目名稱:sporticus,代碼行數:23,代碼來源:ConfigurationWeb.java

示例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);
    }
}
 
開發者ID:itdl,項目名稱:AIweb,代碼行數:17,代碼來源:UploadKaServiceImpl.java

示例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;
}
 
開發者ID:netease-lede,項目名稱:rocketmq-easyclient,代碼行數:28,代碼來源:ScanPackage.java

示例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;
}
 
開發者ID:namics,項目名稱:spring-batch-support,代碼行數:19,代碼來源:AutomaticJobRegistrarConfigurationSupport.java

示例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;
}
 
開發者ID:jweixin,項目名稱:jwx,代碼行數:29,代碼來源:ClasspathPackageScanner.java

示例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;
}
 
開發者ID:yaoakeji,項目名稱:hibatis,代碼行數:27,代碼來源:ClassScanner.java

示例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;
}
 
開發者ID:devpage,項目名稱:sharding-quickstart,代碼行數:25,代碼來源:PackageUtil.java

示例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);
    }
}
 
開發者ID:spring-sprout,項目名稱:osoon,代碼行數:11,代碼來源:UserFileService.java

示例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);
    }
}
 
開發者ID:myliang,項目名稱:fish-admin,代碼行數:15,代碼來源:StorageService.java

示例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);
    }
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:16,代碼來源:FileSystemStorageService.java

示例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);

    }
}
 
開發者ID:thomasooo,項目名稱:spring-boot-tus,代碼行數:13,代碼來源:StorageServiceImpl.java

示例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);
    }
}
 
開發者ID:chaokunyang,項目名稱:amanda,代碼行數:15,代碼來源:FileSystemStorageService.java

示例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);
    }
}
 
開發者ID:robinhowlett,項目名稱:handycapper,代碼行數:16,代碼來源:FileSystemStorageService.java


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