本文整理匯總了Java中org.springframework.core.io.Resource.getFilename方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.getFilename方法的具體用法?Java Resource.getFilename怎麽用?Java Resource.getFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.core.io.Resource
的用法示例。
在下文中一共展示了Resource.getFilename方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadQuery
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Load a SQL query from a file on the classpath.
* @param resource The query file resource
* @return The query
*/
private String loadQuery(Resource resource) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append("\n");
}
return builder.toString();
} catch (IOException ex) {
String message = "Error reading query in " + resource.getFilename();
logger.error(message, ex);
throw new IllegalArgumentException(message, ex);
}
}
示例2: loadContent
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
private Map<String, String> loadContent() throws IOException
{
ClassPathStoreResourceResolver resourceResolver = new ClassPathStoreResourceResolver(applicationContext);
Resource[] contentResources = resourceResolver.getResources("classpath*:" + configPath + packageName + "/*.*");
Map<String, String> content = new HashMap<String, String>();
for (Resource contentResource : contentResources)
{
String fileName = contentResource.getFilename();
// ignore hidden directories / files
if (fileName.startsWith("."))
{
continue;
}
String key = packageName + "/" + fileName;
String value = convert(contentResource.getInputStream());
content.put(key, value);
}
return content;
}
示例3: transform
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) throws IOException {
resource = transformerChain.transform(request, resource);
final String fileName = resource.getFilename();
final String fileExt = FilenameUtils.getExtension(fileName);
switch (fileExt) {
case "js":
case "json":
case "css":
case "html":
log.trace("format {} supported for Text-Injection", fileExt);
return transformText(fileName, resource);
default:
log.trace("unsupported Resource-Type: {}", fileExt);
return resource;
}
}
示例4: getDefaultContentType
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@Override
protected MediaType getDefaultContentType(Resource resource) {
MediaType contentType = null;
if (resource instanceof WxMediaResource) {
contentType = ((WxMediaResource) resource).getContentType();
}
if (contentType == null && servletContext != null && resource.getFilename() != null) {
String mimeType = servletContext.getMimeType(resource.getFilename());
if (StringUtils.hasText(mimeType)) {
contentType = MediaType.parseMediaType(mimeType);
}
}
if (contentType != null) {
return contentType;
}
return super.getDefaultContentType(resource);
}
示例5: storeTempMediaToFile
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* 保存tempMedia到File
*
* @param mediaId
* @return File
*/
public File storeTempMediaToFile(String mediaId, Resource resource) throws IOException {
WxMediaResource wxMediaResource = (WxMediaResource) resource;
if (wxMediaResource.isUrlMedia()) {
return null;
}
String fileName = resource.getFilename();
if (fileName == null) {
fileName = mediaId;
}
File file = new File(StringUtils.applyRelativePath(defaultTempFilePath, fileName));
if (file.exists()) {
return file;
}
StoreEntity storeEntity = storeFile(file, mediaId, resource);
tempMediaFileDb.put(file.getAbsolutePath(), storeEntity);
tempMediaIdDb.put(mediaId, file.getAbsolutePath());
db.commit();
return file;
}
示例6: storeMediaToFile
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* 保存media到File
*
* @param mediaId
* @return File
*/
public File storeMediaToFile(String mediaId, Resource resource) throws IOException {
String fileName = resource.getFilename();
if (fileName == null) {
fileName = mediaId;
}
File file = new File(StringUtils.applyRelativePath(defaultFilePath, fileName));
if (file.exists()) {
return file;
}
StoreEntity storeEntity = storeFile(file, mediaId, resource);
mediaFileDb.put(file.getAbsolutePath(), storeEntity);
mediaIdDb.put(mediaId, file.getAbsolutePath());
db.commit();
return file;
}
示例7: init
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@PostConstruct
public void init() throws Exception {
File dir = new File(baseDir + "/1/avatar");
if (dir.exists()) {
return;
}
dir.mkdirs();
Resource[] resources = applicationContext
.getResources("classpath:/avatar/*");
if (resources == null) {
logger.info("cannot find default avatar for user.");
return;
}
for (Resource resource : resources) {
File file = new File(dir, resource.getFilename());
FileOutputStream fos = new FileOutputStream(file);
try {
FileCopyUtils.copy(resource.getInputStream(), fos);
fos.flush();
} finally {
fos.close();
}
}
}
示例8: init
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@PostConstruct
public void init() throws Exception {
File dir = new File(baseDir + "/cms/template/default");
if (dir.exists()) {
return;
}
dir.mkdirs();
Resource[] resources = applicationContext
.getResources("classpath:/cms/template/default/*");
if (resources == null) {
logger.info("cannot find default template for cms.");
return;
}
for (Resource resource : resources) {
File file = new File(dir, resource.getFilename());
FileOutputStream fos = new FileOutputStream(file);
try {
FileCopyUtils.copy(resource.getInputStream(), fos);
fos.flush();
} finally {
fos.close();
}
}
}
示例9: importBeans
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Import Spring bean definitions from either XML or Groovy sources into the
* current bean builder instance.
* @param resourcePattern the resource pattern
*/
public void importBeans(String resourcePattern) throws IOException {
Resource[] resources =
ResourcePatternUtils.getResourcePatternResolver(getResourceLoader()).getResources(resourcePattern);
for (Resource resource : resources) {
String filename = resource.getFilename();
if (filename.endsWith(".groovy")) {
loadBeanDefinitions(resource);
}
else if (filename.endsWith(".xml")) {
this.xmlBeanDefinitionReader.loadBeanDefinitions(resource);
}
}
}
示例10: getFilename
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Return the filename of the given multipart part. This value will be used for the
* {@code Content-Disposition} header.
* <p>The default implementation returns {@link Resource#getFilename()} if the part is a
* {@code Resource}, and {@code null} in other cases. Can be overridden in subclasses.
* @param part the part to determine the file name for
* @return the filename, or {@code null} if not known
*/
protected String getFilename(Object part) {
if (part instanceof Resource) {
Resource resource = (Resource) part;
return resource.getFilename();
}
else {
return null;
}
}
示例11: getMediaType
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
public static MediaType getMediaType(Resource resource) {
if(resource.getFilename() == null) {
return null;
}
String mediaType = fileTypeMap.getContentType(resource.getFilename());
return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
}
示例12: resolveUrlPath
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain) {
Resource resolvedResource = resolve(resourcePath, locations);
if (resolvedResource == null) {
return null;
}
try {
return resolvedResource.getURL().toString();
} catch (IOException e) {
return resolvedResource.getFilename();
}
}
示例13: openZipResource
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Open the given resource as a a ZipInputStream.
* @param resource resource
* @return ZipInputStream
*/
protected ZipInputStream openZipResource(Resource resource) {
try {
return new ZipInputStream(new BufferedInputStream(resource.getInputStream()));
} catch (IOException e) {
throw new IllegalMigrationStateException("Could not deploy zip resource for version tag " + resource.getFilename(), e);
}
}
示例14: getResourceFileCopy
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
protected File getResourceFileCopy(String resourcePath) throws IOException {
Resource resource = context.getResource(resourcePath);
final File tmp = new File(fileManager.getTempDir(), resource.getFilename());
FileUtils.copyFile(resource.getFile(), tmp);
FileUtils.forceDeleteOnExit(tmp);
return tmp;
}
示例15: resourcePath
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
public static String resourcePath(Resource resource) {
URI uri = null;
try {
uri = resource.getURI();
} catch (IOException e) {
return resource.getFilename();
}
String path = uri.getPath();
if (File.pathSeparator == "/") {
return path;
} else {
return path.substring(1);
}
}