本文整理汇总了Java中org.springframework.util.StringUtils.applyRelativePath方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.applyRelativePath方法的具体用法?Java StringUtils.applyRelativePath怎么用?Java StringUtils.applyRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.applyRelativePath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: storeResource
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 保存Resource到持久化,这个实现中是文件
*
* @param mediaEntity
* @return File
*/
@Override
public Resource storeResource(MediaEntity mediaEntity) throws IOException {
if (!(mediaEntity.getResource() instanceof WxMediaResource)) {
return null;
}
WxMediaResource wxMediaResource = (WxMediaResource) mediaEntity.getResource();
if (wxMediaResource.isUrlMedia()) {
return null;
}
String fileName = wxMediaResource.getFilename();
if (fileName == null) {
fileName = mediaEntity.getMediaId();
}
File file = new File(StringUtils.applyRelativePath(Type.TEMP.equals(mediaEntity.getStoreType()) ? defaultTempFilePath : defaultFilePath, fileName));
if (file.exists()) {
return new FileSystemResource(file);
}
file.createNewFile();
file.setLastModified(System.currentTimeMillis());
FileCopyUtils.copy(mediaEntity.getResource().getInputStream(), new FileOutputStream(file));
mediaEntity.setResourcePath(file.getAbsolutePath());
store(mediaEntity);
return new FileSystemResource(file);
}
示例2: storeTempMediaToFile
import org.springframework.util.StringUtils; //导入方法依赖的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;
}
示例3: storeMediaToFile
import org.springframework.util.StringUtils; //导入方法依赖的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;
}
示例4: getFile
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public synchronized File getFile(String path) throws IOException {
if (this.file == null) {
// 拿到临时文件路径
String pathToUse = StringUtils.applyRelativePath(path, this.filename);
this.file = new File(pathToUse);
if (!this.file.exists()) {
this.file.getParentFile().mkdirs();
this.file.createNewFile();
}
FileCopyUtils.copy(this.getBody(), file);
}
return this.file;
}
示例5: createRelative
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public Resource createRelative(String mediaId) throws IOException {
if (isFileResource) {
String pathToUse = StringUtils.applyRelativePath(StringUtils.cleanPath(file.getPath()), mediaId);
return new WxMediaResource(new File(pathToUse));
}
return WxContextUtils.getBean(WxApiService.class).getTempMedia(mediaId);
}
示例6: createRelative
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* This implementation creates a ServletContextResource, applying the given path
* relative to the path of the underlying file of this resource descriptor.
* @see org.springframework.util.StringUtils#applyRelativePath(String, String)
*/
@Override
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new ServletContextResource(this.servletContext, pathToUse);
}
示例7: createRelative
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Returns a resource relative to this resource. This implementation creates
* an <code>OsgiBundleResource</code>, applying the given path relative to
* the path of the underlying resource of this descriptor.
*
* @param relativePath the relative path (relative to this resource)
* @return the resource handle for the relative resource
* @throws IOException if the relative resource cannot be determined
* @see org.springframework.util.StringUtils#applyRelativePath(String,
* String)
*/
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new OsgiBundleResource(this.bundle, pathToUse);
}