/** * Gets the local temporary file copy of a distributed cache files. * * @param name distributed cache file name * @return local temporary file copy of a distributed cache file. */ public File getCachedFile(String name) { return context.getDistributedCache().getFile(name); }
@Override public String map(Integer value) throws Exception { final Path testFile = getRuntimeContext().getDistributedCache().getFile("test_data").toPath(); final Path testDir = getRuntimeContext().getDistributedCache().getFile("test_dir").toPath(); if (testFile.toAbsolutePath().toString().equals(initialPath)) { throw new RuntimeException(String.format("Operator should access copy from cache rather than the " + "initial file. Input file path: %s. Cache file path: %s", initialPath, testFile)); } long testFileSize = Files.size(testFile); if (testFileSize != fileSize) { throw new RuntimeException(String.format("File size does not match. Expected:%s Actual:%s", fileSize, testFileSize)); } if (testDir.toAbsolutePath().toString().equals(initialDirPath)) { throw new RuntimeException(String.format("Operator should access copy from cache rather than the " + "initial dir. Input dir path: %s. Cache dir path: %s", initialDirPath, testDir)); } try (Stream<Path> files = Files.list(testDir)) { if (files.map(Path::getFileName).map(Path::toString).noneMatch(path -> path.equals(containedFileName))) { throw new RuntimeException(String.format("Cached directory %s should not be empty.", testDir)); } } return Files.readAllLines(testFile) .stream() .collect(Collectors.joining("\n")); } }
@Override public void open(Configuration conf) throws IOException { File file = getRuntimeContext().getDistributedCache().getFile("cache_test"); try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String tempString; while ((tempString = reader.readLine()) != null) { wordList.add(tempString); } } }
receiver.open(outputFile); String path = function.getRuntimeContext().getDistributedCache().getFile(FLINK_PYTHON_DC_ID).getAbsolutePath();
@Override public void open(Configuration parameters) throws Exception{ File file = getRuntimeContext().getDistributedCache().getFile(testName); BufferedReader reader = new BufferedReader(new FileReader(file)); String output = reader.readLine(); reader.close(); assertEquals(output, testString); }
if (!jythonInitialized) { String path = context.getDistributedCache().getFile(PythonConstants.FLINK_PYTHON_DC_ID).getAbsolutePath();
/** * Gets the local temporary file copy of a distributed cache files. * * @param name distributed cache file name * @return local temporary file copy of a distributed cache file. */ @Override public File getCachedFile(String name) { return context.getDistributedCache().getFile(name); }