
de.alpharogroup.file.properties.PropertiesFileUtils Maven / Gradle / Ivy
The newest version!
/**
* The MIT License
*
* Copyright (C) 2007 Asterios Raptis
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.alpharogroup.file.properties;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import de.alpharogroup.file.copy.CopyFileUtils;
import de.alpharogroup.file.read.ReadFileUtils;
import de.alpharogroup.file.search.FileSearchUtils;
import de.alpharogroup.lang.PropertiesUtils;
public class PropertiesFileUtils
{
/**
* Gets the redundant keys in properties files from the given directory. The search is recursive
* and finds all properties files. The result is a map with key the properties file and the
* found redundant keys as a map.
*
* @param dirToSearch
* the dir to search
* @return the redundant keys
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static Map>> getRedundantKeys(final File dirToSearch)
throws IOException
{
final List foundFiles = FileSearchUtils.findAllFiles(dirToSearch,
FileSearchUtils.getSearchFilePattern("properties"));
final Map> linesMap = new LinkedHashMap<>();
final Map>> fileMap = new LinkedHashMap<>();
for (final File file : foundFiles)
{
final List lines = PropertiesFileUtils.removeComments(file);
final Properties p = PropertiesUtils.loadProperties(file);
for (final Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy