当前位置: 首页>>代码示例>>Java>>正文


Java Resource.getFilename方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:dvsa,项目名称:mot-automated-testsuite,代码行数:22,代码来源:QueryFileLoader.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:20,代码来源:SiteSurfConfig.java

示例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;
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:19,代码来源:PropertyInjectionTransformer.java

示例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);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:18,代码来源:WxMediaResourceMessageConverter.java

示例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;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:26,代码来源:WxMediaStore.java

示例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;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:22,代码来源:WxMediaStore.java

示例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();
        }
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:32,代码来源:AvatarInitiator.java

示例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();
        }
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:32,代码来源:TemplateInitiator.java

示例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);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:GroovyBeanDefinitionReader.java

示例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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:FormHttpMessageConverter.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ResourceHttpMessageConverter.java

示例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();
  }
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:13,代码来源:AppConfig.java

示例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);
  }
}
 
开发者ID:satspeedy,项目名称:camunda-migrator,代码行数:13,代码来源:ZipResourceService.java

示例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;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:8,代码来源:AbstractJUnitTest.java

示例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);
    }
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:15,代码来源:WxMediaUtils.java


注:本文中的org.springframework.core.io.Resource.getFilename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。