本文整理了Java中java.nio.file.Path.startsWith()
方法的一些代码示例,展示了Path.startsWith()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.startsWith()
方法的具体详情如下:
包路径:java.nio.file.Path
类名称:Path
方法名:startsWith
暂无
代码示例来源:origin: apache/groovy
@Override
public boolean startsWith(String other) {
return delegate.startsWith(other);
}
代码示例来源:origin: neo4j/neo4j
public static boolean isSameOrChildPath( Path parent, Path candidate )
{
Path normalizedCandidate = candidate.normalize();
Path normalizedParent = parent.normalize();
return normalizedCandidate.startsWith( normalizedParent );
}
代码示例来源:origin: Tencent/tinker
public boolean isPrimaryDex(File dexFile) {
Path dexFilePath = dexFile.toPath();
Path parentPath = config.mTempUnzipOldDir.toPath();
if (!dexFilePath.startsWith(parentPath)) {
parentPath = config.mTempUnzipNewDir.toPath();
}
return DexFormat.DEX_IN_JAR_NAME.equals(parentPath.relativize(dexFilePath).toString().replace('\\', '/'));
}
}
代码示例来源:origin: SonarSource/sonarqube
private static void verifyInsideTargetDirectory(ZipEntry entry, Path entryPath, Path targetDirNormalizedPath) {
if (!entryPath.normalize().startsWith(targetDirNormalizedPath)) {
// vulnerability - trying to create a file outside the target directory
throw new IllegalStateException("Unzipping an entry outside the target directory is not allowed: " + entry.getName());
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation(minSdk = KITKAT)
protected static String getStorageState(File directory) {
Path directoryPath = directory.toPath();
for (Map.Entry<Path, String> entry : storageState.entrySet()) {
if (directoryPath.startsWith(entry.getKey())) {
return entry.getValue();
}
}
return null;
}
代码示例来源:origin: robolectric/robolectric
@Implementation(minSdk = LOLLIPOP)
protected static String getExternalStorageState(File directory) {
Path directoryPath = directory.toPath();
for (Map.Entry<Path, String> entry : storageState.entrySet()) {
if (directoryPath.startsWith(entry.getKey())) {
return entry.getValue();
}
}
return null;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* A check if a file path is a descendant of a parent path
* @param forParent the parent the child should be a descendant of
* @param potentialChild the path to check
* @return true if so
* @throws IOException for invalid paths
* @since 2.80
* @see InvalidPathException
*/
public static boolean isDescendant(File forParent, File potentialChild) throws IOException {
Path child = fileToPath(potentialChild.getAbsoluteFile()).normalize();
Path parent = fileToPath(forParent.getAbsoluteFile()).normalize();
return child.startsWith(parent);
}
代码示例来源:origin: apache/incubator-druid
public static void validateZipOutputFile(
String sourceFilename,
final File outFile,
final File outDir
) throws IOException
{
// check for evil zip exploit that allows writing output to arbitrary directories
final File canonicalOutFile = outFile.getCanonicalFile();
final String canonicalOutDir = outDir.getCanonicalPath();
if (!canonicalOutFile.toPath().startsWith(canonicalOutDir)) {
throw new ISE(
"Unzipped output path[%s] of sourceFile[%s] does not start with outDir[%s].",
canonicalOutFile,
sourceFilename,
canonicalOutDir
);
}
}
代码示例来源:origin: uber/okbuck
public static String getRelativePath(File root, File f) {
Path fPath = f.toPath().toAbsolutePath();
Path rootPath = root.toPath().toAbsolutePath();
if (fPath.startsWith(rootPath)) {
return rootPath.relativize(fPath).toString();
} else {
throw new IllegalStateException(fPath + " must be located inside " + rootPath);
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public boolean accept( File file )
{
Path path = file.toPath();
if ( !path.toAbsolutePath().startsWith( indexRoot ) )
{
// This file isn't even under the schema/index root directory
return false;
}
Path schemaPath = indexRoot.relativize( path );
int nameCount = schemaPath.getNameCount();
// - schema/index/lucene/.....
boolean isPureLuceneProviderFile = nameCount >= 1 && schemaPath.getName( 0 ).toString().equals( "lucene" );
// - schema/index/lucene_native-x.y/<indexId>/lucene-x.y/x/.....
boolean isFusionLuceneProviderFile = nameCount >= 3 && schemaPath.getName( 2 ).toString().startsWith( "lucene-" );
return !isPureLuceneProviderFile && !isFusionLuceneProviderFile;
}
}
代码示例来源:origin: neo4j/neo4j
public static boolean isSameOrChildFile( File parent, File candidate )
{
Path canonicalCandidate = canonicalPath( candidate );
Path canonicalParentPath = canonicalPath( parent );
return canonicalCandidate.startsWith( canonicalParentPath );
}
代码示例来源:origin: apache/ignite
/**
* @param path Path to resolve only relative to IGNITE_HOME.
* @return Resolved path as file, or {@code null} if path cannot be resolved.
* @throws IOException If failed to resolve path.
*/
public static File resolveIgnitePath(String path) throws IOException {
File folder = U.resolveIgnitePath(path);
if (folder == null)
return null;
if (!folder.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).startsWith(Paths.get(U.getIgniteHome())))
return null;
return folder;
}
代码示例来源:origin: debezium/debezium
/**
* Verify that the supplied file or directory is within the test data directory.
*
* @param path the path to the file or directory; may not be null
* @return true if inside the test data directory, or false otherwise
*/
public static boolean inTestDataDir(Path path) {
Path target = FileSystems.getDefault().getPath(dataDir()).toAbsolutePath();
return path.toAbsolutePath().startsWith(target);
}
}
代码示例来源:origin: org.assertj/assertj-core
public void assertStartsWithRaw(final AssertionInfo info, final Path actual, final Path other) {
assertNotNull(info, actual);
assertExpectedStartPathIsNotNull(other);
if (!actual.startsWith(other)) throw failures.failure(info, shouldStartWith(actual, other));
}
代码示例来源:origin: org.assertj/assertj-core
public void assertStartsWith(final AssertionInfo info, final Path actual, final Path start) {
assertNotNull(info, actual);
assertExpectedStartPathIsNotNull(start);
final Path canonicalActual;
try {
canonicalActual = actual.toRealPath();
} catch (IOException e) {
throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e);
}
final Path canonicalOther;
try {
canonicalOther = start.toRealPath();
} catch (IOException e) {
throw new PathsException(FAILED_TO_RESOLVE_ARGUMENT_REAL_PATH, e);
}
if (!canonicalActual.startsWith(canonicalOther)) throw failures.failure(info, shouldStartWith(actual, start));
}
代码示例来源:origin: joel-costigliola/assertj-core
public void assertStartsWithRaw(final AssertionInfo info, final Path actual, final Path other) {
assertNotNull(info, actual);
assertExpectedStartPathIsNotNull(other);
if (!actual.startsWith(other)) throw failures.failure(info, shouldStartWith(actual, other));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateTempDirectoryWithDirectoryBlocking() {
FileSystem fs = vertx.fileSystem();
String tempDirectory = fs.createTempDirectoryBlocking(testDir, "project", null);
Path path = Paths.get(tempDirectory);
assertTrue(Files.exists(Paths.get(tempDirectory)));
assertTrue(path.startsWith(testDir));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateTempFileWithDirectoryBlocking() {
FileSystem fs = vertx.fileSystem();
String tempFile = fs.createTempFileBlocking(testDir, "project", ".tmp", null);
assertNotNull(tempFile);
Path path = Paths.get(tempFile);
assertTrue(Files.exists(path));
assertTrue(path.startsWith(testDir));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateTempDirectoryWithDirectory() {
FileSystem fs = vertx.fileSystem();
fs.createTempDirectory(testDir, "project", null, onSuccess(tempDirectory -> {
Path path = Paths.get(tempDirectory);
assertTrue(Files.exists(path));
assertTrue(path.startsWith(testDir));
complete();
}));
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateTempFileWithDirectory() {
FileSystem fs = vertx.fileSystem();
fs.createTempFile(testDir, "project", ".tmp", null, onSuccess(tempFile -> {
assertNotNull(tempFile);
Path path = Paths.get(tempFile);
assertTrue(Files.exists(path));
assertTrue(path.startsWith(testDir));
complete();
}));
await();
}
内容来源于网络,如有侵权,请联系作者删除!