Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* The MIT License
*
* Copyright (C) 2015 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 io.github.astrapi69.collections.properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.github.astrapi69.collections.list.ListFactory;
/**
* The Class {@link PropertiesExtensions} provides methods loading properties and other related
* operations for properties like find redundant values or getting all available languages from a
* bundle.
*/
public final class PropertiesExtensions
{
/**
* The constant PROPERTIES_COMMENT_PATTERN is the regex pattern for find comments in properties
* file
*/
public static final String PROPERTIES_COMMENT_PATTERN = "(?m)^\\s*(\\#|\\!)";
/**
* The constant PROPERTIES_DELIMITERS contains all valid delimiters for properties files
*/
public static final String[] PROPERTIES_DELIMITERS = { "=", ":", " " };
/**
* The constant SEARCH_FILE_PATTERN is a regex for searching java and html files
*/
public static final String SEARCH_FILE_PATTERN = "([^\\s]+(\\.(?i)(java|html|htm))$)";
private PropertiesExtensions()
{
}
/**
* Exports the given {@link InputStream} that represents a properties file to the given
* properties {@link OutputStream} that represents the output file. The flag xmlFile tells if
* the output shell be an xml file or a properties file.
*
* @param properties
* the properties to store
* @param outputStream
* the stream from the output properties file. If the file does not exists a new file
* will be created.
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void export(Properties properties, OutputStream outputStream) throws IOException
{
export(properties, outputStream, null);
}
/**
* Exports the given {@link InputStream} that represents a properties file to the given
* properties {@link OutputStream} that represents the output file.
*
* @param properties
* the properties to store
* @param outputStream
* the stream from the output properties file. If the file does not exists a new file
* will be created.
* @param inputStream
* the input stream
* @param comment
* the comment
* @param loadFromXML
* the flag that tells if the input shell be loaded from a XML file if true otherwise
* it will be loaded from a properties file
* @param storeToXML
* the flag that tells if the output shell be stored to a XML file if true otherwise
* it will be stored to a properties file
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void export(Properties properties, OutputStream outputStream,
InputStream inputStream, String comment, boolean loadFromXML, boolean storeToXML)
throws IOException
{ // create a new properties if given properties object is null
if (properties == null)
{
properties = new Properties();
}
// load from input stream if not null
if (inputStream != null)
{
if (loadFromXML)
{
properties.loadFromXML(inputStream);
}
else
{
properties.load(inputStream);
}
}
// store as xml or as normal properties format
if (storeToXML)
{
properties.storeToXML(outputStream, comment);
}
else
{
properties.store(outputStream, comment);
}
}
/**
* Exports the given {@link InputStream} that represents a properties file to the given
* properties {@link OutputStream} that represents the output file. The flag xmlFile tells if
* the output shell be an xml file or a properties file.
*
* @param properties
* the properties to store
* @param outputStream
* the stream from the output properties file. If the file does not exists a new file
* will be created.
* @param comment
* the comment
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void export(Properties properties, OutputStream outputStream, String comment)
throws IOException
{
export(properties, outputStream, null, comment, false, false);
}
/**
* Finds redundant values from the given Properties object and saves it to a Map.
*
* @param properties
* The Properties to check.
* @return A map that contains the redundant value as the key of the map and a List(as value of
* the map) of keys that have the redundant value.
*/
public static Map> findRedundantValues(final Properties properties)
{
final Map> reverseEntries = new LinkedHashMap<>();
for (final Map.Entry