@Test public void notExistTest() { Assertions.assertThatThrownBy(() -> LoadModelUtils.getModelFilePath(Paths.get("not_exist"))) .isInstanceOf(ModelLoadingException.class) .hasMessageContaining("should be a directory"); }
public static Path getModelFilePath(final Path modelDirectoryPath) throws ModelLoadingException { final File modelDirectoryFile = modelDirectoryPath.toFile(); if (!modelDirectoryFile.exists() || modelDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelDirectoryFile.canExecute()) { final String errorMsg = String.format("Lacking execute permissions in directory [%s]", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final Path binaryDirectoryPath = modelDirectoryPath.resolve(MODEL_FOLDER); final File binaryDirectoryFile = binaryDirectoryPath.toFile(); if (!binaryDirectoryFile.exists() || binaryDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!binaryDirectoryFile.canExecute() || !binaryDirectoryFile.canRead()) { final String errorMsg = String.format("Cannot read the contents of the directory [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File[] files = binaryDirectoryFile.listFiles(); if (files == null || files.length != 1) { final String errorMsg = String.format("There should be exactly one file inside [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File modelFile = files[0]; if (modelFile.isDirectory()) { final String errorMsg = String.format("The path [%s] should be a file", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelFile.canRead()) { final String errorMsg = String.format("Cannot open the model file for reading [%s]", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } return modelFile.toPath(); }
LoadModelUtils { public static Path getModelFilePath(final Path modelDirectoryPath) throws ModelLoadingException { final File modelDirectoryFile = modelDirectoryPath.toFile(); if (!modelDirectoryFile.exists() || modelDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelDirectoryFile.canExecute()) { final String errorMsg = String.format("Lacking execute permissions in directory [%s]", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final Path binaryDirectoryPath = modelDirectoryPath.resolve(MODEL_FOLDER); final File binaryDirectoryFile = binaryDirectoryPath.toFile(); if (!binaryDirectoryFile.exists() || binaryDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!binaryDirectoryFile.canExecute() || !binaryDirectoryFile.canRead()) { final String errorMsg = String.format("Cannot read the contents of the directory [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File[] files = binaryDirectoryFile.listFiles(); if (files == null || files.length != 1) { final String errorMsg = String.format("There should be exactly one file inside [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File modelFile = files[0]; if (modelFile.isDirectory()) { final String errorMsg = String.format("The path [%s] should be a file", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelFile.canRead()) { final String errorMsg = String.format("Cannot open the model file for reading [%s]", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } return modelFile.toPath(); } }
LoadModelUtils { public static Path getModelFilePath(final Path modelDirectoryPath) throws ModelLoadingException { final File modelDirectoryFile = modelDirectoryPath.toFile(); if (!modelDirectoryFile.exists() || modelDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelDirectoryFile.canExecute()) { final String errorMsg = String.format("Lacking execute permissions in directory [%s]", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final Path binaryDirectoryPath = modelDirectoryPath.resolve(MODEL_FOLDER); final File binaryDirectoryFile = binaryDirectoryPath.toFile(); if (!binaryDirectoryFile.exists() || binaryDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!binaryDirectoryFile.canExecute() || !binaryDirectoryFile.canRead()) { final String errorMsg = String.format("Cannot read the contents of the directory [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File[] files = binaryDirectoryFile.listFiles(); if (files == null || files.length != 1) { final String errorMsg = String.format("There should be exactly one file inside [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File modelFile = files[0]; if (modelFile.isDirectory()) { final String errorMsg = String.format("The path [%s] should be a file", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelFile.canRead()) { final String errorMsg = String.format("Cannot open the model file for reading [%s]", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } return modelFile.toPath(); } private  LoadModelUtils(); }
LoadModelUtils { public static Path getModelFilePath(final Path modelDirectoryPath) throws ModelLoadingException { final File modelDirectoryFile = modelDirectoryPath.toFile(); if (!modelDirectoryFile.exists() || modelDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelDirectoryFile.canExecute()) { final String errorMsg = String.format("Lacking execute permissions in directory [%s]", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final Path binaryDirectoryPath = modelDirectoryPath.resolve(MODEL_FOLDER); final File binaryDirectoryFile = binaryDirectoryPath.toFile(); if (!binaryDirectoryFile.exists() || binaryDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!binaryDirectoryFile.canExecute() || !binaryDirectoryFile.canRead()) { final String errorMsg = String.format("Cannot read the contents of the directory [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File[] files = binaryDirectoryFile.listFiles(); if (files == null || files.length != 1) { final String errorMsg = String.format("There should be exactly one file inside [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File modelFile = files[0]; if (modelFile.isDirectory()) { final String errorMsg = String.format("The path [%s] should be a file", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelFile.canRead()) { final String errorMsg = String.format("Cannot open the model file for reading [%s]", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } return modelFile.toPath(); } private  LoadModelUtils(); static Path getModelFilePath(final Path modelDirectoryPath); }
LoadModelUtils { public static Path getModelFilePath(final Path modelDirectoryPath) throws ModelLoadingException { final File modelDirectoryFile = modelDirectoryPath.toFile(); if (!modelDirectoryFile.exists() || modelDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelDirectoryFile.canExecute()) { final String errorMsg = String.format("Lacking execute permissions in directory [%s]", modelDirectoryPath); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final Path binaryDirectoryPath = modelDirectoryPath.resolve(MODEL_FOLDER); final File binaryDirectoryFile = binaryDirectoryPath.toFile(); if (!binaryDirectoryFile.exists() || binaryDirectoryFile.isFile()) { final String errorMsg = String.format("The path [%s] should be a directory", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!binaryDirectoryFile.canExecute() || !binaryDirectoryFile.canRead()) { final String errorMsg = String.format("Cannot read the contents of the directory [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File[] files = binaryDirectoryFile.listFiles(); if (files == null || files.length != 1) { final String errorMsg = String.format("There should be exactly one file inside [%s]", binaryDirectoryFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } final File modelFile = files[0]; if (modelFile.isDirectory()) { final String errorMsg = String.format("The path [%s] should be a file", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } if (!modelFile.canRead()) { final String errorMsg = String.format("Cannot open the model file for reading [%s]", modelFile.getAbsoluteFile()); logger.error(errorMsg); throw new ModelLoadingException(errorMsg); } return modelFile.toPath(); } private  LoadModelUtils(); static Path getModelFilePath(final Path modelDirectoryPath); static final String MODEL_FOLDER; }