本文整理了Java中org.apache.flink.util.FileUtils
类的一些代码示例,展示了FileUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils
类的具体详情如下:
包路径:org.apache.flink.util.FileUtils
类名称:FileUtils
[英]This is a utility class to deal files and directories. Contains utilities for recursive deletion and creation of temporary files.
[中]这是一个处理文件和目录的实用程序类。包含用于递归删除和创建临时文件的实用程序。
代码示例来源:origin: apache/flink
/**
* Deletes the given directory recursively, not reporting any I/O exceptions
* that occur.
*
* <p>This method is identical to {@link FileUtils#deleteDirectory(File)}, except that it
* swallows all exceptions and may leave the job quietly incomplete.
*
* @param directory The directory to delete.
*/
public static void deleteDirectoryQuietly(File directory) {
if (directory == null) {
return;
}
// delete and do not report if it fails
try {
deleteDirectory(directory);
} catch (Exception ignored) {}
}
代码示例来源:origin: apache/flink
@Override
public void close() throws IOException {
FileUtils.deleteFileOrDirectory(path.toFile());
}
}
代码示例来源:origin: apache/flink
private static void copyFile(Path source, Path targetDirectory, String name) throws IOException {
Path targetFilePath = new Path(targetDirectory, name);
deleteIfExists(targetFilePath);
FileUtils.copy(source, targetFilePath, true);
}
代码示例来源:origin: apache/flink
private static void insertCodeIntoFile(String code, File file) throws IOException {
String fileContent = FileUtils.readFileUtf8(file);
sb.append(line).append("\n");
FileUtils.writeFileUtf8(file, sb.toString());
代码示例来源:origin: apache/flink
Files.copy(new ByteArrayInputStream(testFileContent.getBytes(StandardCharsets.UTF_8)), compressDir.resolve(file3));
final Path zip = FileUtils.compressDirectory(
new Path(compressDir.resolve(originalDir).toString()),
new Path(compressDir.resolve(originalDir) + ".zip"));
FileUtils.expandDirectory(zip, new Path(extractDir.toAbsolutePath().toString()));
代码示例来源:origin: apache/flink
private static void writeBuffer(FileChannel fileChannel, int size, int channelIndex) throws IOException {
ByteBuffer data = ByteBuffer.allocate(size + 9);
data.order(ByteOrder.LITTLE_ENDIAN);
data.putInt(channelIndex);
data.putInt(size);
data.put((byte) 0);
for (int i = 0; i < size; i++) {
data.put((byte) i);
}
data.flip();
FileUtils.writeCompletely(fileChannel, data);
}
代码示例来源:origin: apache/flink
public String createTempFile(String fileName, String contents) throws IOException {
File f = createAndRegisterTempFile(fileName);
if (!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
}
f.createNewFile();
FileUtils.writeFileUtf8(f, contents);
return f.toURI().toString();
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
private Path getNewFilePath() {
return new Path(rootPath, FileUtils.getRandomFilename(prefix));
}
}
代码示例来源:origin: apache/flink
public static void addUserArtifactEntries(Collection<Tuple2<String, DistributedCache.DistributedCacheEntry>> userArtifacts, JobGraph jobGraph) {
if (!userArtifacts.isEmpty()) {
try {
java.nio.file.Path tmpDir = Files.createTempDirectory("flink-distributed-cache-" + jobGraph.getJobID());
for (Tuple2<String, DistributedCache.DistributedCacheEntry> originalEntry : userArtifacts) {
Path filePath = new Path(originalEntry.f1.filePath);
boolean isLocalDir = false;
try {
FileSystem sourceFs = filePath.getFileSystem();
isLocalDir = !sourceFs.isDistributedFS() && sourceFs.getFileStatus(filePath).isDir();
} catch (IOException ioe) {
LOG.warn("Could not determine whether {} denotes a local path.", filePath, ioe);
}
// zip local directories because we only support file uploads
DistributedCache.DistributedCacheEntry entry;
if (isLocalDir) {
Path zip = FileUtils.compressDirectory(filePath, new Path(tmpDir.toString(), filePath.getName() + ".zip"));
entry = new DistributedCache.DistributedCacheEntry(zip.toString(), originalEntry.f1.isExecutable, true);
} else {
entry = new DistributedCache.DistributedCacheEntry(filePath.toString(), originalEntry.f1.isExecutable, false);
}
jobGraph.addUserArtifact(originalEntry.f0, entry);
}
} catch (IOException ioe) {
throw new FlinkRuntimeException("Could not compress distributed-cache artifacts.", ioe);
}
}
}
代码示例来源:origin: apache/flink
FileUtils.writeCompletely(currentChannel, headBuffer);
FileUtils.writeCompletely(currentChannel, contents);
代码示例来源:origin: apache/flink
private String createInputData(String data) throws Exception {
File file = tempFolder.newFile("input");
FileUtils.writeFileUtf8(file, data);
return file.toURI().toString();
}
代码示例来源:origin: apache/flink
private static void insertCodeIntoFile(String code, File file) throws IOException {
String fileContent = FileUtils.readFileUtf8(file);
FileUtils.writeFileUtf8(file, sb.toString());
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
private Path getNewFilePath() {
return new Path(rootPath, FileUtils.getRandomFilename(prefix));
}
}
代码示例来源:origin: org.apache.flink/flink-optimizer
public static void addUserArtifactEntries(Collection<Tuple2<String, DistributedCache.DistributedCacheEntry>> userArtifacts, JobGraph jobGraph) {
if (!userArtifacts.isEmpty()) {
try {
java.nio.file.Path tmpDir = Files.createTempDirectory("flink-distributed-cache-" + jobGraph.getJobID());
for (Tuple2<String, DistributedCache.DistributedCacheEntry> originalEntry : userArtifacts) {
Path filePath = new Path(originalEntry.f1.filePath);
boolean isLocalDir = false;
try {
FileSystem sourceFs = filePath.getFileSystem();
isLocalDir = !sourceFs.isDistributedFS() && sourceFs.getFileStatus(filePath).isDir();
} catch (IOException ioe) {
LOG.warn("Could not determine whether {} denotes a local path.", filePath, ioe);
}
// zip local directories because we only support file uploads
DistributedCache.DistributedCacheEntry entry;
if (isLocalDir) {
Path zip = FileUtils.compressDirectory(filePath, new Path(tmpDir.toString(), filePath.getName() + ".zip"));
entry = new DistributedCache.DistributedCacheEntry(zip.toString(), originalEntry.f1.isExecutable, true);
} else {
entry = new DistributedCache.DistributedCacheEntry(filePath.toString(), originalEntry.f1.isExecutable, false);
}
jobGraph.addUserArtifact(originalEntry.f0, entry);
}
} catch (IOException ioe) {
throw new FlinkRuntimeException("Could not compress distributed-cache artifacts.", ioe);
}
}
}
代码示例来源:origin: apache/flink
private void cleanInstanceBasePath() {
LOG.info("Deleting existing instance base directory {}.", instanceBasePath);
try {
FileUtils.deleteDirectory(instanceBasePath);
} catch (IOException ex) {
LOG.warn("Could not delete instance base path for RocksDB: " + instanceBasePath, ex);
}
}
代码示例来源:origin: apache/flink
private static void cleanDirectoryInternal(File directory) throws IOException {
if (directory.isDirectory()) {
final File[] files = directory.listFiles();
if (files == null) {
// directory does not exist any more or no permissions
if (directory.exists()) {
throw new IOException("Failed to list contents of " + directory);
} else {
throw new FileNotFoundException(directory.toString());
}
}
// remove all files in the directory
for (File file : files) {
if (file != null) {
deleteFileOrDirectory(file);
}
}
}
else if (directory.exists()) {
throw new IOException(directory + " is not a directory but a regular file");
}
else {
// else does not exist at all
throw new FileNotFoundException(directory.toString());
}
}
代码示例来源:origin: apache/flink
private static BufferOrEvent generateAndWriteEvent(FileChannel fileChannel, Random rnd, int numberOfChannels) throws IOException {
long magicNumber = rnd.nextLong();
byte[] data = new byte[rnd.nextInt(1000)];
rnd.nextBytes(data);
TestEvent evt = new TestEvent(magicNumber, data);
int channelIndex = rnd.nextInt(numberOfChannels);
ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(evt);
ByteBuffer header = ByteBuffer.allocate(9);
header.order(ByteOrder.LITTLE_ENDIAN);
header.putInt(channelIndex);
header.putInt(serializedEvent.remaining());
header.put((byte) 1);
header.flip();
FileUtils.writeCompletely(fileChannel, header);
FileUtils.writeCompletely(fileChannel, serializedEvent);
return new BufferOrEvent(evt, channelIndex);
}
代码示例来源:origin: apache/flink
@Before
public void before() throws Exception{
final File folder = tempFolder.newFolder();
final File resultFile = new File(folder, UUID.randomUUID().toString());
resultPath = resultFile.toURI().toString();
File verticesFile = tempFolder.newFile();
FileUtils.writeFileUtf8(verticesFile, PageRankData.VERTICES);
File edgesFile = tempFolder.newFile();
FileUtils.writeFileUtf8(edgesFile, PageRankData.EDGES);
verticesPath = verticesFile.toURI().toString();
edgesPath = edgesFile.toURI().toString();
}
代码示例来源:origin: apache/flink
private static void copyFile(Path source, Path targetDirectory, String name) throws IOException {
Path targetFilePath = new Path(targetDirectory, name);
deleteIfExists(targetFilePath);
FileUtils.copy(source, targetFilePath, true);
}
代码示例来源:origin: org.apache.flink/flink-runtime
private Path getNewFilePath() {
return new Path(rootPath, FileUtils.getRandomFilename(prefix));
}
}
内容来源于网络,如有侵权,请联系作者删除!