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


Java StringUtils.cleanPath方法代码示例

本文整理汇总了Java中org.springframework.util.StringUtils.cleanPath方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.cleanPath方法的具体用法?Java StringUtils.cleanPath怎么用?Java StringUtils.cleanPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.StringUtils的用法示例。


在下文中一共展示了StringUtils.cleanPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: store

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public void store(MultipartFile file) {
    String filename = StringUtils.cleanPath(file.getOriginalFilename());
    try {
        if (file.isEmpty()) {
            throw new UploadException("Failed to store empty file " + filename);
        }
        if (filename.contains("..")) {
            // This is a security check
            throw new UploadException(
                    "Cannot store file with relative path outside current directory "
                            + filename);
        }
        Files.copy(file.getInputStream(), this.rootLocation.resolve(filename),
                StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new UploadException("Failed to store file " + filename, e);
    }
}
 
开发者ID:itdl,项目名称:AIweb,代码行数:20,代码来源:UploadKaServiceImpl.java

示例2: store

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public UserSessionFile store(MultipartFile file, String sessionId) {
    String filename = StringUtils.cleanPath(file.getOriginalFilename());
    try {
        if (file.isEmpty()) {
            throw new StorageException(
                "Failed to store empty file " + filename);
        }

        Path sessionPath = buildSessionPath(sessionId);
        Files.createDirectories(sessionPath);
        Files.copy(file.getInputStream(), buildPathToFile(sessionPath,
            filename),
            StandardCopyOption.REPLACE_EXISTING);
        return new UserSessionFile(filename, sessionId);
    } catch (IOException e) {
        throw new StorageException("Failed to store file " + filename, e);
    }
}
 
开发者ID:nilshoffmann,项目名称:jmzTab-m,代码行数:20,代码来源:FileSystemStorageService.java

示例3: processStream

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public int processStream(String uuid, InputStream inputStream) throws Exception {
    String filename = StringUtils.cleanPath(uuid);
    File file = new File(storageDir.resolve(filename).toString());

    if (!file.isFile()){
        new FileOutputStream(file).close();
        if(!file.isFile()){
            log.error("Cannot create new file");
            throw new TusPermissionDeniedException("Cannot create new file");
        }
    }

    InputStream storageFile;
    try{
        storageFile = new FileInputStream(file);
    }catch(IOException e){
        log.error("Cannot read old file");
        throw new TusPermissionDeniedException("Cannot read old file");
    }

    storageFile = new SequenceInputStream(storageFile, inputStream);
    Files.copy(storageFile, storageDir.resolve(filename), StandardCopyOption.REPLACE_EXISTING);
    file = new File(storageDir.resolve(filename).toString());

    return (int) file.length();
}
 
开发者ID:thomasooo,项目名称:spring-boot-tus,代码行数:27,代码来源:StorageServiceImpl.java

示例4: toStringShouldReturnFilePath

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Test
public void toStringShouldReturnFilePath() throws Exception {
	File file = this.temporaryFolder.newFolder();
	Directory directory = new Directory(file);
	String expected = StringUtils.cleanPath(file.getPath());
	assertThat(directory.toString()).isEqualTo(expected);
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:8,代码来源:DirectoryTests.java

示例5: determineRelativeName

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
 * Small utility method used for determining the file name by striping the
 * root path from the file full path.
 * 
 * @param rootPath
 * @param resource
 * @return
 */
private String determineRelativeName(String rootPath, Resource resource) {
	try {
		String path = StringUtils.cleanPath(resource.getURL().getPath());
		return path.substring(path.indexOf(rootPath) + rootPath.length());
	}
	catch (IOException ex) {
		throw (RuntimeException) new IllegalArgumentException("illegal resource " + resource.toString()).initCause(ex);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:18,代码来源:JarCreator.java

示例6: OsgiBundleResource

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
 * 
 * Constructs a new <code>OsgiBundleResource</code> instance.
 * 
 * @param bundle OSGi bundle used by this resource
 * @param path resource path inside the bundle.
 */
public OsgiBundleResource(Bundle bundle, String path) {
	Assert.notNull(bundle, "Bundle must not be null");
	this.bundle = bundle;

	// check path
	Assert.notNull(path, "Path must not be null");

	this.path = StringUtils.cleanPath(path);

	this.searchType = OsgiResourceUtils.getSearchType(this.path);

	switch (this.searchType) {
		case OsgiResourceUtils.PREFIX_TYPE_NOT_SPECIFIED:
			pathWithoutPrefix = path;
			break;
		case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_SPACE:
			pathWithoutPrefix = path.substring(BUNDLE_URL_PREFIX.length());
			break;
		case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_JAR:
			pathWithoutPrefix = path.substring(BUNDLE_JAR_URL_PREFIX.length());
			break;
		case OsgiResourceUtils.PREFIX_TYPE_CLASS_SPACE:
			pathWithoutPrefix = path.substring(ResourceLoader.CLASSPATH_URL_PREFIX.length());
			break;
		// prefix unknown so the path will be resolved outside the context
		default:
			pathWithoutPrefix = null;
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:37,代码来源:OsgiBundleResource.java

示例7: normalize

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
 * Normalize the path removing sequences like "path/..".
 * @see StringUtils#cleanPath(String)
 */
@Override
public UriComponents normalize() {
	String normalizedPath = StringUtils.cleanPath(getPath());
	return new HierarchicalUriComponents(getScheme(), this.userInfo, this.host,
			this.port, new FullPathComponent(normalizedPath), this.queryParams,
			getFragment(), this.encoded, false);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:HierarchicalUriComponents.java

示例8: loadResource

import org.springframework.util.StringUtils; //导入方法依赖的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

示例9: generate

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private void generate(Directory root, File pomFile) {
	String name = StringUtils.getFilename(pomFile.getName());
	String extension = StringUtils.getFilenameExtension(pomFile.getName());
	String prefix = name.substring(0, name.length() - extension.length() - 1);
	File[] files = pomFile.getParentFile().listFiles((f) -> include(f, prefix));
	MultiValueMap<File, MavenCoordinates> coordinates = new LinkedMultiValueMap<>();
	for (File file : files) {
		String rootPath = StringUtils.cleanPath(root.getFile().getPath());
		String relativePath = StringUtils.cleanPath(file.getPath())
				.substring(rootPath.length() + 1);
		coordinates.add(file.getParentFile(),
				MavenCoordinates.fromPath(relativePath));
	}
	coordinates.forEach(this::writeMetadata);
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:16,代码来源:MavenMetadataGenerator.java

示例10: getFilter

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private BiPredicate<Path, BasicFileAttributes> getFilter(Directory root,
		List<String> include, List<String> exclude) {
	PathFilter filter = new PathFilter(include, exclude);
	String rootPath = StringUtils.cleanPath(root.getFile().getPath());
	return (path, fileAttributes) -> {
		if (!path.toFile().isFile()) {
			return false;
		}
		String relativePath = StringUtils.cleanPath(path.toString())
				.substring(rootPath.length() + 1);
		return filter.isMatch(relativePath);
	};
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:14,代码来源:DirectoryScanner.java

示例11: runShouldCallHandler

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Test
public void runShouldCallHandler() throws Exception {
	InRequest request = mock(InRequest.class);
	InResponse response = mock(InResponse.class);
	given(this.systemInput.read(InRequest.class)).willReturn(request);
	given(this.handler.handle(eq(request), any())).willReturn(response);
	File tempFolder = this.temporaryFolder.newFolder();
	String dir = StringUtils.cleanPath(tempFolder.getPath());
	this.command.run(new DefaultApplicationArguments(new String[] { "in", dir }));
	verify(this.handler).handle(eq(request), this.directoryCaptor.capture());
	verify(this.systemOutput).write(response);
	assertThat(this.directoryCaptor.getValue().getFile()).isEqualTo(tempFolder);
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:14,代码来源:InCommandTests.java

示例12: runShouldCallHandler

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Test
public void runShouldCallHandler() throws Exception {
	OutRequest request = mock(OutRequest.class);
	OutResponse response = mock(OutResponse.class);
	given(this.systemInput.read(OutRequest.class)).willReturn(request);
	given(this.handler.handle(eq(request), any())).willReturn(response);
	File tempFolder = this.temporaryFolder.newFolder();
	String dir = StringUtils.cleanPath(tempFolder.getPath());
	this.command.run(new DefaultApplicationArguments(new String[] { "out", dir }));
	verify(this.handler).handle(eq(request), this.directoryCaptor.capture());
	verify(this.systemOutput).write(response);
	assertThat(this.directoryCaptor.getValue().getFile()).isEqualTo(tempFolder);
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:14,代码来源:OutCommandTests.java

示例13: createFromArgsShouldUseArgument

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Test
public void createFromArgsShouldUseArgument() throws Exception {
	File file = this.temporaryFolder.newFolder();
	String path = StringUtils.cleanPath(file.getPath());
	ApplicationArguments args = new DefaultApplicationArguments(
			new String[] { "in", path });
	Directory directory = Directory.fromArgs(args);
	assertThat(directory.getFile()).isEqualTo(file);
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:10,代码来源:DirectoryTests.java

示例14: getConfigLocations

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
 * Subclasses can override this method to return the locations of their
 * config files, unless they override {@link #contextKey()} and
 * {@link #loadContext(Object)} instead.
 * <p>A plain path will be treated as class path location, e.g.:
 * "org/springframework/whatever/foo.xml". Note however that you may prefix
 * path locations with standard Spring resource prefixes. Therefore, a
 * config location path prefixed with "classpath:" with behave the same as a
 * plain path, but a config location such as
 * "file:/some/path/path/location/appContext.xml" will be treated as a
 * filesystem location.
 * <p>The default implementation builds config locations for the config paths
 * specified through {@link #getConfigPaths()}.
 * @return an array of config locations
 * @see #getConfigPaths()
 * @see org.springframework.core.io.ResourceLoader#getResource(String)
 */
protected String[] getConfigLocations() {
	String[] paths = getConfigPaths();
	String[] locations = new String[paths.length];
	for (int i = 0; i < paths.length; i++) {
		String path = paths[i];
		if (path.startsWith("/")) {
			locations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path;
		}
		else {
			locations[i] = ResourceUtils.CLASSPATH_URL_PREFIX +
					StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(getClass()) + "/" + path);
		}
	}
	return locations;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:33,代码来源:AbstractSingleSpringContextTests.java

示例15: cleanPath

import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private static String cleanPath(String path) {
	path = StringUtils.cleanPath(path);
	path = (path.startsWith("/") ? path : "/" + path);
	return path;
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:6,代码来源:DeployableFileArtifact.java


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