mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
17.00.2015 c30a94191c13bc775c189f2f32bf90ef1bbdcbbf
In Utils.wrapText(), use early exit
1 files modified
41 ■■■■■ changed files
opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java 41 ●●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
@@ -57,9 +57,7 @@
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.RDN;
/**
 * This class provides utility functions for all the client side tools.
 */
/** This class provides utility functions for all the client side tools. */
public final class Utils {
    /** Platform appropriate line separator. */
@@ -71,9 +69,7 @@
     */
    public static final String OBFUSCATED_VALUE = "******";
    /**
     * The maximum number of times we try to confirm.
     */
    /** The maximum number of times we try to confirm. */
    public static final int CONFIRMATION_MAX_TRIES = 5;
    /**
@@ -97,16 +93,11 @@
    private static final String COMMENT_SHELL_UNIX = "# ";
    private static final String COMMENT_BATCH_WINDOWS = "rem ";
    /**
     * The String used to write comments in a shell (or batch) script.
     */
    /** The String used to write comments in a shell (or batch) script. */
    public static final String SHELL_COMMENT_SEPARATOR = OperatingSystem.isWindows() ? COMMENT_BATCH_WINDOWS
            : COMMENT_SHELL_UNIX;
    /**
     * The column at which to wrap long lines of output in the command-line
     * tools.
     */
    /** The column at which to wrap long lines of output in the command-line tools. */
    public static final int MAX_LINE_WIDTH;
    static {
        int columns = 80;
@@ -304,6 +295,10 @@
     * @return The wrapped text.
     */
    public static String wrapText(final String text, int width, final int indent) {
        if (text == null) {
            return "";
        }
        // Calculate the real width and indentation padding.
        width -= indent;
        final StringBuilder pb = new StringBuilder();
@@ -313,7 +308,6 @@
        final String padding = pb.toString();
        final StringBuilder buffer = new StringBuilder();
        if (text != null) {
            final StringTokenizer lineTokenizer = new StringTokenizer(text, "\r\n", true);
            while (lineTokenizer.hasMoreTokens()) {
                final String line = lineTokenizer.nextToken();
@@ -339,12 +333,10 @@
                                delimBuffer.append(word);
                            }
                        } else if (word.length() > width) {
                            // This is a long word that can't be wrapped, so
                            // we'll just have to make do.
                        // This is a long word that can't be wrapped,
                        // so we'll just have to make do.
                            if (lineBuffer.length() > 0) {
                                buffer.append(padding);
                                buffer.append(lineBuffer);
                                buffer.append(EOL);
                            buffer.append(padding).append(lineBuffer).append(EOL);
                                lineBuffer = new StringBuilder();
                            }
                            buffer.append(padding);
@@ -363,8 +355,7 @@
                                delimBuffer = new StringBuilder();
                            }
                        } else {
                            // It's not a space, so see if we can fit it on the
                            // current line.
                        // It's not a space, so see if we can fit it on the current line.
                            final int newLineLength =
                                    lineBuffer.length() + delimBuffer.length() + word.length();
                            if (newLineLength < width) {
@@ -377,9 +368,7 @@
                            } else {
                                // It doesn't fit on the line, so end the
                                // current line and start a new one.
                                buffer.append(padding);
                                buffer.append(lineBuffer);
                                buffer.append(EOL);
                            buffer.append(padding).append(lineBuffer).append(EOL);
                                lineBuffer = new StringBuilder();
                                lineBuffer.append(word);
@@ -397,7 +386,6 @@
                    buffer.append(lineBuffer);
                }
            }
        }
        return buffer.toString();
    }
@@ -531,7 +519,6 @@
        return parentFile != null && parentFile.canWrite();
    }
    /** Prevent instantiation. */
    private Utils() {
        // Do nothing.
@@ -600,7 +587,7 @@
     * @return The String that can be used to represent a given host name in a LDAP URL.
     */
    public static String getHostNameForLdapUrl(String host) {
        if (host != null && host.indexOf(":") != -1) {
        if (host != null && host.contains(":")) {
            // Assume an IPv6 address has been specified and adds the brackets
            // for the URL.
            host = host.trim();