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


Java FileSystem.mkdirs方法代码示例

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


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

示例1: createSavepointDirectory

import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类
/**
 * Creates a savepoint directory.
 *
 * @param baseDirectory Base target directory for the savepoint
 * @param jobId Optional JobID the savepoint belongs to
 * @return The created savepoint directory
 * @throws IOException FileSystem operation failures are forwarded
 */
public static String createSavepointDirectory(@Nonnull String baseDirectory, @Nullable JobID jobId) throws IOException {
	final Path basePath = new Path(baseDirectory);
	final FileSystem fs = basePath.getFileSystem();

	final String prefix;
	if (jobId == null) {
		prefix = "savepoint-";
	} else {
		prefix = String.format("savepoint-%s-", jobId.toString().substring(0, 6));
	}

	Exception latestException = null;

	// Try to create a FS output stream
	for (int attempt = 0; attempt < 10; attempt++) {
		Path path = new Path(basePath, FileUtils.getRandomFilename(prefix));

		try {
			if (fs.mkdirs(path)) {
				return path.toString();
			}
		} catch (Exception e) {
			latestException = e;
		}
	}

	throw new IOException("Failed to create savepoint directory at " + baseDirectory, latestException);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:37,代码来源:SavepointStore.java

示例2: FileSystemBlobStore

import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类
public FileSystemBlobStore(FileSystem fileSystem, String storagePath) throws IOException {
	this.fileSystem = checkNotNull(fileSystem);
	this.basePath = checkNotNull(storagePath) + "/blob";

	LOG.info("Creating highly available BLOB storage directory at {}", basePath);

	fileSystem.mkdirs(new Path(basePath));
	LOG.debug("Created highly available BLOB storage directory at {}", basePath);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:10,代码来源:FileSystemBlobStore.java

示例3: copy

import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类
public static void copy(Path sourcePath, Path targetPath, boolean executable) throws IOException {
	// TODO rewrite this to make it participate in the closable registry and the lifecycle of a task.
	// we unwrap the file system to get raw streams without safety net
	FileSystem sFS = FileSystem.getUnguardedFileSystem(sourcePath.toUri());
	FileSystem tFS = FileSystem.getUnguardedFileSystem(targetPath.toUri());
	if (!tFS.exists(targetPath)) {
		if (sFS.getFileStatus(sourcePath).isDir()) {
			tFS.mkdirs(targetPath);
			FileStatus[] contents = sFS.listStatus(sourcePath);
			for (FileStatus content : contents) {
				String distPath = content.getPath().toString();
				if (content.isDir()) {
					if (distPath.endsWith("/")) {
						distPath = distPath.substring(0, distPath.length() - 1);
					}
				}
				String localPath = targetPath.toString() + distPath.substring(distPath.lastIndexOf("/"));
				copy(content.getPath(), new Path(localPath), executable);
			}
		} else {
			try (FSDataOutputStream lfsOutput = tFS.create(targetPath, FileSystem.WriteMode.NO_OVERWRITE); FSDataInputStream fsInput = sFS.open(sourcePath)) {
				IOUtils.copyBytes(fsInput, lfsOutput);
				//noinspection ResultOfMethodCallIgnored
				new File(targetPath.toString()).setExecutable(executable);
			} catch (IOException ioe) {
				LOG.error("could not copy file to local file cache.", ioe);
			}
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:31,代码来源:FileCache.java

示例4: createBasePath

import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类
protected Path createBasePath(FileSystem fs, Path checkpointDirectory, JobID jobID) throws IOException {
	Path dir = new Path(checkpointDirectory, jobID.toString());
	fs.mkdirs(dir);
	return dir;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:6,代码来源:FsCheckpointStreamFactory.java

示例5: unzipPythonLibrary

import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类
private static void unzipPythonLibrary(Path targetDir) throws IOException {
	FileSystem targetFs = targetDir.getFileSystem();
	ClassLoader classLoader = PythonPlanBinder.class.getClassLoader();
	ZipInputStream zis = new ZipInputStream(classLoader.getResourceAsStream("python-source.zip"));
	ZipEntry entry = zis.getNextEntry();
	while (entry != null) {
		String fileName = entry.getName();
		Path newFile = new Path(targetDir, fileName);
		if (entry.isDirectory()) {
			targetFs.mkdirs(newFile);
		} else {
			try {
				LOG.debug("Unzipping to {}.", newFile);
				FSDataOutputStream fsDataOutputStream = targetFs.create(newFile, FileSystem.WriteMode.NO_OVERWRITE);
				IOUtils.copyBytes(zis, fsDataOutputStream, false);
			} catch (Exception e) {
				zis.closeEntry();
				zis.close();
				throw new IOException("Failed to unzip flink python library.", e);
			}
		}

		zis.closeEntry();
		entry = zis.getNextEntry();
	}
	zis.closeEntry();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:28,代码来源:PythonPlanBinder.java

示例6: testDeletePathIfEmpty

import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类
/**
 * Test that {@link FileUtils#deletePathIfEmpty(FileSystem, Path)} deletes the path if it is
 * empty. A path can only be empty if it is a directory which does not contain any
 * files/directories.
 */
@Test
public void testDeletePathIfEmpty() throws IOException {
	final Path basePath = new Path(hdfsURI);
	final Path directory = new Path(basePath, UUID.randomUUID().toString());
	final Path directoryFile = new Path(directory, UUID.randomUUID().toString());
	final Path singleFile = new Path(basePath, UUID.randomUUID().toString());

	FileSystem fs = basePath.getFileSystem();

	fs.mkdirs(directory);

	byte[] data = "HDFSTest#testDeletePathIfEmpty".getBytes(ConfigConstants.DEFAULT_CHARSET);

	for (Path file: Arrays.asList(singleFile, directoryFile)) {
		org.apache.flink.core.fs.FSDataOutputStream outputStream = fs.create(file, FileSystem.WriteMode.OVERWRITE);
		outputStream.write(data);
		outputStream.close();
	}

	// verify that the files have been created
	assertTrue(fs.exists(singleFile));
	assertTrue(fs.exists(directoryFile));

	// delete the single file
	assertFalse(FileUtils.deletePathIfEmpty(fs, singleFile));
	assertTrue(fs.exists(singleFile));

	// try to delete the non-empty directory
	assertFalse(FileUtils.deletePathIfEmpty(fs, directory));
	assertTrue(fs.exists(directory));

	// delete the file contained in the directory
	assertTrue(fs.delete(directoryFile, false));

	// now the deletion should work
	assertTrue(FileUtils.deletePathIfEmpty(fs, directory));
	assertFalse(fs.exists(directory));
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:44,代码来源:HDFSTest.java


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