| | |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | | |
| | | import static java.nio.charset.StandardCharsets.ISO_8859_1; |
| | | import static java.nio.charset.StandardCharsets.UTF_8; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.io.StringReader; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.charset.CharacterCodingException; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | |
| | | try { |
| | | final Properties argumentProperties = new Properties(); |
| | | final String scriptName = getScriptName(); |
| | | final Properties p = new Properties(); |
| | | try (final FileInputStream fis = new FileInputStream(propertiesFilePath)) { |
| | | p.load(fis); |
| | | } |
| | | final Properties p = loadPropertiesFile(propertiesFilePath); |
| | | |
| | | for (final Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) { |
| | | final String currentPropertyName = (String) e.nextElement(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Reads a properties file as UTF-8, or as ISO-8859-1, which earlier releases used, when it is |
| | | * not valid UTF-8. A backslash keeps its meaning in the properties format and must be doubled. |
| | | */ |
| | | private static Properties loadPropertiesFile(final String path) throws IOException { |
| | | final byte[] content = Files.readAllBytes(Paths.get(path)); |
| | | // A UTF-8 byte order mark is skipped before decoding, so that the ISO-8859-1 fallback skips it too. |
| | | final int bom = content.length >= 3 && content[0] == (byte) 0xEF && content[1] == (byte) 0xBB |
| | | && content[2] == (byte) 0xBF ? 3 : 0; |
| | | String text; |
| | | try { |
| | | text = UTF_8.newDecoder().decode(ByteBuffer.wrap(content, bom, content.length - bom)).toString(); |
| | | } catch (final CharacterCodingException e) { |
| | | text = new String(content, bom, content.length - bom, ISO_8859_1); |
| | | } |
| | | final Properties properties = new Properties(); |
| | | properties.load(new StringReader(text)); |
| | | return properties; |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the argument with the specified long identifier. |
| | | * |
| | | * @param longID |
| | |
| | | final boolean requirePropertiesFile) throws ArgumentException { |
| | | Properties argumentProperties = null; |
| | | |
| | | try (final FileInputStream fis = new FileInputStream(propertiesFile)) { |
| | | final Properties p = new Properties(); |
| | | p.load(fis); |
| | | argumentProperties = p; |
| | | try { |
| | | argumentProperties = loadPropertiesFile(propertiesFile); |
| | | } catch (final Exception e) { |
| | | if (requirePropertiesFile) { |
| | | final LocalizableMessage message = |