/* * Copyright (c) 2020 Pantheon Technologies, s.r.o. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.java.api.generator.test; import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; final class FileSearchUtil { private FileSearchUtil() { // Hidden on purpose } static boolean findInFile(final File file, final String searchText) throws FileNotFoundException { try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { final String nextLine = scanner.nextLine(); if (nextLine.contains(searchText)) { return true; } } } return false; } static Map getFiles(final File path) { return getFiles(path, new HashMap<>()); } private static Map getFiles(final File path, final Map files) { final File [] dirFiles = path.listFiles(); for (File file : dirFiles) { if (file.isDirectory()) { return getFiles(file, files); } files.put(file.getName(), file); } return files; } }