The new java file operations

public static Boolean checkFileExist (String filePath) {
        LOGGER.info("checkFileExist the input filePath {}", filePath);
        Path classJarPath = Paths.get(filePath);
        
        return Files.exists(classJarPath, LinkOption.NOFOLLOW_LINKS);
    }
    
 // 每次上传的时候
    public static void prepareFile(String globalVersion) throws IOException {
        
        FlinkThpoolInitializer flinkThPoolInitializer = SpringContextUtils.getBean("flinkThPoolInitializer", FlinkThpoolInitializer.class);
        
        String coreSizeStr = flinkThPoolInitializer.getProperties().getProperty("corePoolSize");
        Integer coreSize = Integer.valueOf(coreSizeStr);
        
        String emptyFileStr = flinkThPoolInitializer.getProperties().getProperty("emptyFile");
        
        String newFile = StringConstant.LINUX_JOB_DIRSUFFIX + emptyFileStr;
        Path newpath = Paths.get(newFile);
        
        File emptyFile = newpath.toFile();
        emptyFile.createNewFile(); // 创建辅助空文件
        String tmpJarFileName = "";
//        String globalVersion = httpForeignIntefaceConfigInitializer.getProperties().getProperty("Flink.JarName");
        String originalJarPath = StringConstant.LINUX_JOB_FILESUFFIX + globalVersion ;
        Path pathToAddFile = emptyFile.toPath();
        Map<String, String> env = new HashMap<>();
        env.put("create", "true");
        for (int i = 0; i <coreSize; i ++) {// begin from 0 
            String UUID = UUID.randomUUID () toString () the replaceAll ( "-", "");.. 
            tmpJarFileName originalJarPath.substring = (0, 4) + "-upgrade" + i + ".jar" - originalJarPath.length (); 
            use this file // create an intermediate file submitted to the task; FileUtils.copyFile (new new file (originalJarPath), new new file (tmpJarFileName)) 
            Path = Paths.get path (tmpJarFileName); 
            the URI URI = URI.create ( "JAR:" + path.toUri ()); 
            the try (FS = FileSystems.newFileSystem the FileSystem (URI, the env)) {// file to the secondary air uuid empty file is written and writes a file to ensure that the intermediate jar file using the same batch of different between 
                the Path fs.getPath NF = ( "the EMPTYFILE"); 
                Files.copy (pathToAddFile, NF, StandardCopyOption.REPLACE_EXISTING);
                Writer writer = Files.newBufferedWriter(nf, StandardCharsets.UTF_8, StandardOpenOption.CREATE);
                writer.write(uuid);
                writer.close();
            }
        }
    }

  

Guess you like

Origin www.cnblogs.com/juniorMa/p/12190445.html