/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.flume.appender;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttr;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.status.StatusLogger;

/**
 * Agent Specification for FlumeAvroAppender.
 */
@Plugin(name = "Agent", category = "Core", printObject = true)
public final class Agent {

    private static final String DEFAULT_HOST = "localhost";

    private static final int DEFAULT_PORT = 35853;

    private static final Logger LOGGER = StatusLogger.getLogger();

    private final String host;

    private final int port;

    private Agent(final String host, final int port) {
        this.host = host;
        this.port = port;
    }

    /**
     * Retrieve the host name.
     * @return The name of the host.
     */
    public String getHost() {
        return host;
    }

    /**
     * Retrieve the port number.
     * @return The port number.
     */
    public int getPort() {
        return port;
    }

    @Override
    public String toString() {
        return "host=" + host + " port=" + port;
    }

    /**
     * Create an Agent.
     * @param host The host name.
     * @param port The port number.
     * @return The Agent.
     */
    @PluginFactory
    public static Agent createAgent(@PluginAttr("host") String host,
                                    @PluginAttr("port") final String port) {
        if (host == null) {
            host = DEFAULT_HOST;
        }

        int portNum;
        if (port != null) {
            try {
                portNum = Integer.parseInt(port);
            } catch (final Exception ex) {
                LOGGER.error("Error parsing port number " + port, ex);
                return null;
            }
        } else {
            portNum = DEFAULT_PORT;
        }
        return new Agent(host, portNum);
    }
}

@@ -1075,16 +1075,71 @@
 actory;%0A
+import org.apache.logging.log4j.core.helpers.Integers;%0A
 import o
@@ -2292,44 +2292,11 @@
 st,%0A
-                                    
+%09%09%09
 @Plu
@@ -2332,24 +2332,18 @@
 port) %7B%0A
-        
+%09%09
 if (host
@@ -2354,28 +2354,19 @@
 null) %7B%0A
-            
+%09%09%09
 host = D
@@ -2382,102 +2382,39 @@
 ST;%0A
-        %7D%0A%0A        int portNum;%0A        if (port != null) %7B%0A            try %7B%0A                
+%09%09%7D%0A%0A%09%09int portNum;%0A%09%09try %7B%0A%09%09%09
 port
@@ -2426,16 +2426,17 @@
  Integer
+s
 .parseIn
@@ -2441,31 +2441,35 @@
 Int(port
-);%0A            
+, DEFAULT_PORT);%0A%09%09
 %7D catch 
@@ -2491,32 +2491,19 @@
 n ex) %7B%0A
-                
+%09%09%09
 LOGGER.e
@@ -2553,122 +2553,30 @@
 x);%0A
-                return null;%0A            %7D%0A        %7D else %7B%0A            portNum = DEFAULT_PORT;%0A        %7D%0A        
+%09%09%09return null;%0A%09%09%7D%0A%09%09
 retu
@@ -2604,16 +2604,13 @@
 rtNum);%0A
-    
+%09
 %7D%0A%7D%0A

Simplify with Integers.parseInt().