o Fixed missing javadocs o Fixed sonarlint warnings Project: http://git-wip-us.apache.org/repos/asf/mina/repo Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/3ff1bf1a Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/3ff1bf1a Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/3ff1bf1a
Branch: refs/heads/2.0 Commit: 3ff1bf1aaa626809c0356536298507d798e9082a Parents: 9f00651 850bc14 Author: Emmanuel Lécharny <elecha...@symas.com> Authored: Fri Dec 9 11:15:18 2016 +0100 Committer: Emmanuel Lécharny <elecha...@symas.com> Committed: Fri Dec 9 11:15:18 2016 +0100 ---------------------------------------------------------------------- .../apache/mina/proxy/event/IoSessionEvent.java | 42 ++++++----- .../mina/proxy/event/IoSessionEventQueue.java | 10 ++- .../mina/proxy/event/IoSessionEventType.java | 36 +++++++--- .../apache/mina/proxy/filter/ProxyFilter.java | 2 +- .../proxy/filter/ProxyHandshakeIoBuffer.java | 4 ++ .../mina/proxy/session/ProxyIoSession.java | 6 +- .../session/ProxyIoSessionInitializer.java | 15 ++++ .../apache/mina/proxy/utils/ByteUtilities.java | 24 ++++--- .../mina/proxy/utils/IoBufferDecoder.java | 37 +++++++++- .../mina/proxy/utils/StringUtilities.java | 31 ++++---- .../apache/mina/util/AvailablePortFinder.java | 14 +--- .../org/apache/mina/util/CopyOnWriteMap.java | 38 ++++++---- .../mina/util/DefaultExceptionMonitor.java | 2 +- .../org/apache/mina/util/ExceptionMonitor.java | 6 +- .../apache/mina/util/ExpirationListener.java | 8 ++- .../java/org/apache/mina/util/ExpiringMap.java | 76 ++++++++++++++++++++ .../org/apache/mina/util/IdentityHashSet.java | 16 ++++- .../mina/util/LazyInitializedCacheMap.java | 33 ++++++++- .../org/apache/mina/util/LazyInitializer.java | 2 + .../org/apache/mina/util/Log4jXmlFormatter.java | 19 ++--- .../java/org/apache/mina/util/MapBackedSet.java | 31 ++++++++ .../java/org/apache/mina/util/Transform.java | 55 ++++++++------ 22 files changed, 388 insertions(+), 119 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java index 785e3d7,785e3d7..ad7bb2e --- a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java @@@ -32,7 -32,7 +32,7 @@@ import org.slf4j.LoggerFactory * @since MINA 2.0.0-M3 */ public class IoSessionEvent { -- private final static Logger logger = LoggerFactory.getLogger(IoSessionEvent.class); ++ private static final Logger logger = LoggerFactory.getLogger(IoSessionEvent.class); /** * The next filter in the chain. @@@ -63,7 -63,7 +63,7 @@@ * @param session the session * @param type the event type */ -- public IoSessionEvent(final NextFilter nextFilter, final IoSession session, final IoSessionEventType type) { ++ public IoSessionEvent(NextFilter nextFilter, IoSession session, IoSessionEventType type) { this.nextFilter = nextFilter; this.session = session; this.type = type; @@@ -77,7 -77,7 +77,7 @@@ * @param session the session * @param status the idle status */ -- public IoSessionEvent(final NextFilter nextFilter, final IoSession session, final IdleStatus status) { ++ public IoSessionEvent(NextFilter nextFilter, IoSession session, IdleStatus status) { this(nextFilter, session, IoSessionEventType.IDLE); this.status = status; } @@@ -100,21 -100,21 +100,24 @@@ * @param status the idle status should only be non null only if the event type is * {@link IoSessionEventType#IDLE} */ -- private static void deliverEvent(final NextFilter nextFilter, final IoSession session, -- final IoSessionEventType type, final IdleStatus status) { ++ private static void deliverEvent(NextFilter nextFilter, IoSession session, ++ IoSessionEventType type, IdleStatus status) { switch (type) { -- case CREATED: -- nextFilter.sessionCreated(session); -- break; -- case OPENED: -- nextFilter.sessionOpened(session); -- break; -- case IDLE: -- nextFilter.sessionIdle(session, status); -- break; -- case CLOSED: -- nextFilter.sessionClosed(session); -- break; ++ case CREATED: ++ nextFilter.sessionCreated(session); ++ break; ++ ++ case OPENED: ++ nextFilter.sessionOpened(session); ++ break; ++ ++ case IDLE: ++ nextFilter.sessionIdle(session, status); ++ break; ++ ++ case CLOSED: ++ nextFilter.sessionClosed(session); ++ break; } } @@@ -129,6 -129,6 +132,7 @@@ sb.append(" - [ ").append(session); sb.append(", ").append(type); sb.append(']'); ++ return sb.toString(); } @@@ -147,14 -147,14 +151,14 @@@ } /** -- * @return the session on which the event occured. ++ * @return the session on which the event occurred. */ public IoSession getSession() { return session; } /** -- * @return the event type that occured. ++ * @return the event type that occurred. */ public IoSessionEventType getType() { return type; http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java index 0f02918,0f02918..33b09ce --- a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java @@@ -35,7 -35,7 +35,7 @@@ import org.slf4j.LoggerFactory * @since MINA 2.0.0-M3 */ public class IoSessionEventQueue { -- private final static Logger logger = LoggerFactory.getLogger(IoSessionEventQueue.class); ++ private static final Logger logger = LoggerFactory.getLogger(IoSessionEventQueue.class); /** * The proxy session object. @@@ -45,8 -45,8 +45,13 @@@ /** * Queue of session events which occurred before the proxy handshake had completed. */ -- private Queue<IoSessionEvent> sessionEventsQueue = new LinkedList<IoSessionEvent>(); ++ private Queue<IoSessionEvent> sessionEventsQueue = new LinkedList<>(); ++ /** ++ * Creates a new proxyIoSession instance ++ * ++ * @param proxyIoSession The proxy session instance ++ */ public IoSessionEventQueue(ProxyIoSession proxyIoSession) { this.proxyIoSession = proxyIoSession; } @@@ -79,6 -79,6 +84,7 @@@ if (proxyIoSession.getRequest() instanceof SocksProxyRequest) { // No reconnection used evt.deliverEvent(); ++ return; } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java index a499ae7,a499ae7..fe8a047 --- a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java @@@ -26,7 -26,7 +26,17 @@@ package org.apache.mina.proxy.event * @since MINA 2.0.0-M3 */ public enum IoSessionEventType { -- CREATED(1), OPENED(2), IDLE(3), CLOSED(4); ++ /** Session created */ ++ CREATED(1), ++ ++ /** Session opened */ ++ OPENED(2), ++ ++ /** Session Idling */ ++ IDLE(3), ++ ++ /** Session closed*/ ++ CLOSED(4); /** * The event type id. @@@ -50,16 -50,16 +60,20 @@@ @Override public String toString() { switch (this) { -- case CREATED: -- return "- CREATED event -"; -- case OPENED: -- return "- OPENED event -"; -- case IDLE: -- return "- IDLE event -"; -- case CLOSED: -- return "- CLOSED event -"; -- default: -- return "- Event Id=" + id + " -"; ++ case CREATED: ++ return "- CREATED event -"; ++ ++ case OPENED: ++ return "- OPENED event -"; ++ ++ case IDLE: ++ return "- IDLE event -"; ++ ++ case CLOSED: ++ return "- CLOSED event -"; ++ ++ default: ++ return "- Event Id=" + id + " -"; } } } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java index 8b1880c,8b1880c..d0e9e11 --- a/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java @@@ -55,7 -55,7 +55,7 @@@ import org.slf4j.LoggerFactory * @since MINA 2.0.0-M3 */ public class ProxyFilter extends IoFilterAdapter { -- private final static Logger LOGGER = LoggerFactory.getLogger(ProxyFilter.class); ++ private static final Logger LOGGER = LoggerFactory.getLogger(ProxyFilter.class); /** * Create a new {@link ProxyFilter}. http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java index 77babbb,77babbb..5bcdaef --- a/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java @@@ -30,6 -30,6 +30,10 @@@ import org.apache.mina.core.buffer.IoBu * @since MINA 2.0.0-M3 */ public class ProxyHandshakeIoBuffer extends IoBufferWrapper { ++ /** ++ * Creates a new ProxyHandshakeIoBuffer instance ++ * @param buf The wrapped buffer ++ */ public ProxyHandshakeIoBuffer(final IoBuffer buf) { super(buf); } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java index c589a86,c589a86..1eecb3c --- a/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java @@@ -40,10 -40,10 +40,10 @@@ import org.apache.mina.proxy.handlers.h * @since MINA 2.0.0-M3 */ public class ProxyIoSession { ++ /** The proxy session name */ ++ public static final String PROXY_SESSION = ProxyConnector.class.getName() + ".ProxySession"; -- public final static String PROXY_SESSION = ProxyConnector.class.getName() + ".ProxySession"; -- -- private final static String DEFAULT_ENCODING = "ISO-8859-1"; ++ private static final String DEFAULT_ENCODING = "ISO-8859-1"; /** * The list contains the authentication methods to use. http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java index 1c8e357,1c8e357..78116a3 --- a/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java @@@ -27,6 -27,6 +27,8 @@@ import org.apache.mina.core.session.IoS * ProxyIoSessionInitializer.java - {@link IoSessionInitializer} wrapper class to inject the * {@link ProxyIoSession} object that contains all the attributes of the target connection * into the {@link IoSession}. ++ * ++ * @param <T> The Connection Future type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * @since MINA 2.0.0-M3 @@@ -36,16 -36,16 +38,29 @@@ public class ProxyIoSessionInitializer< private final ProxyIoSession proxyIoSession; ++ /** ++ * Creates a new ProxyIoSessionInitializer instance ++ * ++ * @param wrappedSessionInitializer The wrapped session initializer ++ * @param proxyIoSession The ProxyIoSession instance ++ */ public ProxyIoSessionInitializer(final IoSessionInitializer<T> wrappedSessionInitializer, final ProxyIoSession proxyIoSession) { this.wrappedSessionInitializer = wrappedSessionInitializer; this.proxyIoSession = proxyIoSession; } ++ /** ++ * @return The ProxyIoSession instance ++ */ public ProxyIoSession getProxySession() { return proxyIoSession; } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void initializeSession(final IoSession session, T future) { if (wrappedSessionInitializer != null) { wrappedSessionInitializer.initializeSession(session, future); http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java index c03d642,c03d642..b663ee8 --- a/mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java @@@ -28,7 -28,7 +28,9 @@@ import java.io.UnsupportedEncodingExcep * @since MINA 2.0.0-M3 */ public class ByteUtilities { -- ++ private ByteUtilities(){ ++ } ++ /** * Returns the integer represented by up to 4 bytes in network byte order. * @@@ -93,7 -93,7 +95,7 @@@ * @param v the short to write * @return the Short in a byte[] */ -- public final static byte[] writeShort(short v) { ++ public static final byte[] writeShort(short v) { return writeShort(v, new byte[2], 0); } @@@ -106,7 -106,7 +108,7 @@@ * @param offset the offset at which to start writing in the array * @return the Short in a byte[] */ -- public final static byte[] writeShort(short v, byte[] b, int offset) { ++ public static final byte[] writeShort(short v, byte[] b, int offset) { b[offset] = (byte) v; b[offset + 1] = (byte) (v >> 8); @@@ -119,7 -119,7 +121,7 @@@ * @param v the int to write * @return the Int in a byte[] */ -- public final static byte[] writeInt(int v) { ++ public static final byte[] writeInt(int v) { return writeInt(v, new byte[4], 0); } @@@ -132,7 -132,7 +134,7 @@@ * @param offset the offset at which to start writing in the array * @return the Int in a byte[] */ -- public final static byte[] writeInt(int v, byte[] b, int offset) { ++ public static final byte[] writeInt(int v, byte[] b, int offset) { b[offset] = (byte) v; b[offset + 1] = (byte) (v >> 8); b[offset + 2] = (byte) (v >> 16); @@@ -151,7 -151,7 +153,7 @@@ * @param length the number of bytes on which to operate * (should be a multiple of 4) */ -- public final static void changeWordEndianess(byte[] b, int offset, int length) { ++ public static final void changeWordEndianess(byte[] b, int offset, int length) { byte tmp; for (int i = offset; i < offset + length; i += 4) { @@@ -174,7 -174,7 +176,7 @@@ * @param length the number of bytes on which to operate * (should be a multiple of 2) */ -- public final static void changeByteEndianess(byte[] b, int offset, int length) { ++ public static final void changeByteEndianess(byte[] b, int offset, int length) { byte tmp; for (int i = offset; i < offset + length; i += 2) { @@@ -192,7 -192,7 +194,7 @@@ * @return the result byte array * @throws UnsupportedEncodingException if the string is not an OEM string */ -- public final static byte[] getOEMStringAsByteArray(String s) throws UnsupportedEncodingException { ++ public static final byte[] getOEMStringAsByteArray(String s) throws UnsupportedEncodingException { return s.getBytes("ASCII"); } @@@ -203,7 -203,7 +205,7 @@@ * @return the result byte array * @throws UnsupportedEncodingException if the string is not an UTF-16LE string */ -- public final static byte[] getUTFStringAsByteArray(String s) throws UnsupportedEncodingException { ++ public static final byte[] getUTFStringAsByteArray(String s) throws UnsupportedEncodingException { return s.getBytes("UTF-16LE"); } @@@ -217,7 -217,7 +219,7 @@@ * @return the encoded string as a byte array * @throws UnsupportedEncodingException if encoding fails */ -- public final static byte[] encodeString(String s, boolean useUnicode) throws UnsupportedEncodingException { ++ public static final byte[] encodeString(String s, boolean useUnicode) throws UnsupportedEncodingException { if (useUnicode) { return getUTFStringAsByteArray(s); } @@@ -326,7 -326,7 +328,7 @@@ * @param testFlag the flag we search the presence of * @return true if testFlag is present in the flagset, false otherwise. */ -- public final static boolean isFlagSet(int flagSet, int testFlag) { ++ public static final boolean isFlagSet(int flagSet, int testFlag) { return (flagSet & testFlag) > 0; } } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java index 148a98a,148a98a..e7a8da4 --- a/mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java @@@ -49,7 -49,7 +49,7 @@@ public class IoBufferDecoder private IoBuffer delimiter; /** -- * The currently matched bytes of the delimiter. ++ * The number of matched delimiters. */ private int matchCount = 0; @@@ -68,34 -68,34 +68,67 @@@ decodedBuffer = null; } ++ /** ++ * @return The current content length of decoded data if in ++ * content-length mode. ++ */ public int getContentLength() { return contentLength; } ++ /** ++ * Sets the content-length ++ * ++ * @param contentLength current content length of decoded data ++ */ public void setContentLength(int contentLength) { this.contentLength = contentLength; } ++ /** ++ * @return The number of matched delimiters. ++ */ public int getMatchCount() { return matchCount; } ++ /** ++ * Sets the match count ++ * ++ * @param matchCount The number of matched delimiters. ++ */ public void setMatchCount(int matchCount) { this.matchCount = matchCount; } ++ /** ++ * @return The decoded data ++ */ public IoBuffer getDecodedBuffer() { return decodedBuffer; } ++ /** ++ * Sets the decoded data buffer ++ * ++ * @param decodedBuffer The decoded data ++ */ public void setDecodedBuffer(IoBuffer decodedBuffer) { this.decodedBuffer = decodedBuffer; } ++ /** ++ * @return The delimiter ++ */ public IoBuffer getDelimiter() { return delimiter; } ++ /** ++ * Sets the delimiter ++ * ++ * @param delimiter The delimiter ++ */ public void setDelimiter(IoBuffer delimiter) { this.delimiter = delimiter; } @@@ -221,8 -221,8 +254,10 @@@ while (in.hasRemaining()) { byte b = in.get(); ++ if (delimiter.get(matchCount) == b) { matchCount++; ++ if (matchCount == delimiter.limit()) { // Found a match. int pos = in.position(); http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java index 48b2dc1,48b2dc1..efd0b4d --- a/mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java @@@ -36,7 -36,7 +36,9 @@@ import javax.security.sasl.SaslExceptio * @since MINA 2.0.0-M3 */ public class StringUtilities { -- ++ private StringUtilities(){ ++ } ++ /** * A directive is a parameter of the digest authentication process. * Returns the value of a directive from the map. If mandatory is true and the @@@ -49,9 -49,9 +51,10 @@@ * @throws AuthenticationException if mandatory is true and if * directivesMap.get(directive) == null */ -- public static String getDirectiveValue(HashMap<String, String> directivesMap, String directive, boolean mandatory) ++ public static String getDirectiveValue(Map<String, String> directivesMap, String directive, boolean mandatory) throws AuthenticationException { String value = directivesMap.get(directive); ++ if (value == null) { if (mandatory) { throw new AuthenticationException("\"" + directive + "\" mandatory directive is missing"); @@@ -71,8 -71,8 +74,9 @@@ * @param sb the output buffer * @param directive the directive name to look for */ -- public static void copyDirective(HashMap<String, String> directives, StringBuilder sb, String directive) { ++ public static void copyDirective(Map<String, String> directives, StringBuilder sb, String directive) { String directiveValue = directives.get(directive); ++ if (directiveValue != null) { sb.append(directive).append(" = \"").append(directiveValue).append("\", "); } @@@ -88,8 -88,8 +92,9 @@@ * @param directive the directive name * @return the value of the copied directive */ -- public static String copyDirective(HashMap<String, String> src, HashMap<String, String> dst, String directive) { ++ public static String copyDirective(Map<String, String> src, Map<String, String> dst, String directive) { String directiveValue = src.get(directive); ++ if (directiveValue != null) { dst.put(directive, directiveValue); } @@@ -105,8 -105,8 +110,8 @@@ * @return A Map containing the aprsed directives * @throws SaslException if the String cannot be parsed according to RFC 2831 */ -- public static HashMap<String, String> parseDirectives(byte[] buf) throws SaslException { -- HashMap<String, String> map = new HashMap<String, String>(); ++ public static Map<String, String> parseDirectives(byte[] buf) throws SaslException { ++ Map<String, String> map = new HashMap<>(); boolean gettingKey = true; boolean gettingQuotedValue = false; boolean expectSeparator = false; @@@ -116,6 -116,6 +121,7 @@@ ByteArrayOutputStream value = new ByteArrayOutputStream(10); int i = skipLws(buf, 0); ++ while (i < buf.length) { bch = buf[i]; @@@ -165,6 -165,6 +171,7 @@@ if (bch == '\\') { // quoted-pair = "\" CHAR ==> CHAR ++i; // Skip escape ++ if (i < buf.length) { value.write(buf[i]); ++i; // Advance @@@ -221,7 -221,7 +228,7 @@@ * @throws SaslException if either the key or the value is null or * if the key already has a value. */ -- private static void extractDirective(HashMap<String, String> map, String key, String value) throws SaslException { ++ private static void extractDirective(Map<String, String> map, String key, String value) throws SaslException { if (map.get(key) != null) { throw new SaslException("Peer sent more than one " + key + " directive"); } @@@ -239,10 -239,10 +246,10 @@@ */ public static boolean isLws(byte b) { switch (b) { -- case 13: // US-ASCII CR, carriage return -- case 10: // US-ASCII LF, line feed -- case 32: // US-ASCII SP, space -- case 9: // US-ASCII HT, horizontal-tab ++ case 13: // US-ASCII CR, carriage return ++ case 10: // US-ASCII LF, line feed ++ case 32: // US-ASCII SP, space ++ case 9: // US-ASCII HT, horizontal-tab return true; } @@@ -321,7 -321,7 +328,7 @@@ List<String> values = headers.get(key); if (values == null) { -- values = new ArrayList<String>(1); ++ values = new ArrayList<>(1); headers.put(key, values); } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java index e0564b9,e0564b9..4147066 --- a/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java +++ b/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java @@@ -67,17 -67,17 +67,9 @@@ public class AvailablePortFinder * @throws NoSuchElementException if there are no ports available */ public static int getNextAvailable() { -- ServerSocket serverSocket = null; -- -- try { ++ try (ServerSocket serverSocket = new ServerSocket(0)){ // Here, we simply return an available port found by the system -- serverSocket = new ServerSocket(0); -- int port = serverSocket.getLocalPort(); -- -- // Don't forget to close the socket... -- serverSocket.close(); -- -- return port; ++ return serverSocket.getLocalPort(); } catch (IOException ioe) { throw new NoSuchElementException(ioe.getMessage()); } @@@ -157,7 -157,7 +149,7 @@@ throw new IllegalArgumentException("Invalid port range: " + fromPort + " ~ " + toPort); } -- Set<Integer> result = new TreeSet<Integer>(); ++ Set<Integer> result = new TreeSet<>(); for (int i = fromPort; i <= toPort; i++) { ServerSocket s = null; http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java index 75bddd6,75bddd6..bc86e98 --- a/mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java +++ b/mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java @@@ -32,6 -32,6 +32,9 @@@ import java.util.Set * cases in which the primary function is to read data from the Map, not to * modify the Map. Therefore the operations that do not cause a change to this * class happen quickly and concurrently. ++ * ++ * @param <K> The key type ++ * @param <V> The value type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@@ -40,20 -40,20 +43,18 @@@ public class CopyOnWriteMap<K, V> imple /** * Creates a new instance of CopyOnWriteMap. -- * */ public CopyOnWriteMap() { -- internalMap = new HashMap<K, V>(); ++ internalMap = new HashMap<>(); } /** * Creates a new instance of CopyOnWriteMap with the specified initial size * -- * @param initialCapacity -- * The initial size of the Map. ++ * @param initialCapacity The initial size of the Map. */ public CopyOnWriteMap(int initialCapacity) { -- internalMap = new HashMap<K, V>(initialCapacity); ++ internalMap = new HashMap<>(initialCapacity); } /** @@@ -61,12 -61,12 +62,11 @@@ * initial data being held by this map is contained in * the supplied map. * -- * @param data -- * A Map containing the initial contents to be placed into ++ * @param data A Map containing the initial contents to be placed into * this class. */ public CopyOnWriteMap(Map<K, V> data) { -- internalMap = new HashMap<K, V>(data); ++ internalMap = new HashMap<>(data); } /** @@@ -74,11 -74,11 +74,13 @@@ * * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ ++ @Override public V put(K key, V value) { synchronized (this) { -- Map<K, V> newMap = new HashMap<K, V>(internalMap); ++ Map<K, V> newMap = new HashMap<>(internalMap); V val = newMap.put(key, value); internalMap = newMap; ++ return val; } } @@@ -89,11 -89,11 +91,13 @@@ * * @see java.util.Map#remove(java.lang.Object) */ ++ @Override public V remove(Object key) { synchronized (this) { -- Map<K, V> newMap = new HashMap<K, V>(internalMap); ++ Map<K, V> newMap = new HashMap<>(internalMap); V val = newMap.remove(key); internalMap = newMap; ++ return val; } } @@@ -104,9 -104,9 +108,10 @@@ * * @see java.util.Map#putAll(java.util.Map) */ ++ @Override public void putAll(Map<? extends K, ? extends V> newData) { synchronized (this) { -- Map<K, V> newMap = new HashMap<K, V>(internalMap); ++ Map<K, V> newMap = new HashMap<>(internalMap); newMap.putAll(newData); internalMap = newMap; } @@@ -117,9 -117,9 +122,10 @@@ * * @see java.util.Map#clear() */ ++ @Override public void clear() { synchronized (this) { -- internalMap = new HashMap<K, V>(); ++ internalMap = new HashMap<>(); } } @@@ -132,6 -132,6 +138,7 @@@ * * @see java.util.Map#size() */ ++ @Override public int size() { return internalMap.size(); } @@@ -141,6 -141,6 +148,7 @@@ * * @see java.util.Map#isEmpty() */ ++ @Override public boolean isEmpty() { return internalMap.isEmpty(); } @@@ -151,6 -151,6 +159,7 @@@ * * @see java.util.Map#containsKey(java.lang.Object) */ ++ @Override public boolean containsKey(Object key) { return internalMap.containsKey(key); } @@@ -161,6 -161,6 +170,7 @@@ * * @see java.util.Map#containsValue(java.lang.Object) */ ++ @Override public boolean containsValue(Object value) { return internalMap.containsValue(value); } @@@ -171,6 -171,6 +181,7 @@@ * * @see java.util.Map#get(java.lang.Object) */ ++ @Override public V get(Object key) { return internalMap.get(key); } @@@ -178,6 -178,6 +189,7 @@@ /** * This method will return a read-only {@link Set}. */ ++ @Override public Set<K> keySet() { return internalMap.keySet(); } @@@ -185,6 -185,6 +197,7 @@@ /** * This method will return a read-only {@link Collection}. */ ++ @Override public Collection<V> values() { return internalMap.values(); } @@@ -192,6 -192,6 +205,7 @@@ /** * This method will return a read-only {@link Set}. */ ++ @Override public Set<Entry<K, V>> entrySet() { return internalMap.entrySet(); } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java index 7b9d595,7b9d595..989b9b8 --- a/mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java +++ b/mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java @@@ -33,7 -33,7 +33,7 @@@ import org.slf4j.LoggerFactory * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public class DefaultExceptionMonitor extends ExceptionMonitor { -- private final static Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMonitor.class); ++ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMonitor.class); /** * {@inheritDoc} http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java index 97cc621,97cc621..da5b644 --- a/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java +++ b/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java @@@ -51,10 -51,10 +51,10 @@@ public abstract class ExceptionMonitor */ public static void setInstance(ExceptionMonitor monitor) { if (monitor == null) { -- monitor = new DefaultExceptionMonitor(); ++ instance = new DefaultExceptionMonitor(); ++ } else { ++ instance = monitor; } -- -- instance = monitor; } /** http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java index ec56817,ec56817..51b7673 --- a/mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java +++ b/mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java @@@ -21,10 -21,10 +21,16 @@@ package org.apache.mina.util /** * A listener for expired object events. ++ * ++ * @param <E> The event type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> -- * TODO Make this a inner interface of ExpiringMap */ public interface ExpirationListener<E> { ++ /** ++ * Adds a given event to the listener ++ * ++ * @param expiredObject The expired event ++ */ void expired(E expiredObject); } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java index 3243a61,3243a61..2c7df2d --- a/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java +++ b/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java @@@ -31,6 -31,6 +31,9 @@@ import java.util.concurrent.locks.Reent * A map with expiration. This class contains a worker thread that will * periodically check this class in order to determine if any objects * should be removed based on the provided time-to-live value. ++ * ++ * @param <K> The key type ++ * @param <V> The value type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@@ -90,6 -90,6 +93,10 @@@ public class ExpiringMap<K, V> implemen expirer.setExpirationInterval(expirationInterval); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V put(K key, V value) { ExpiringObject answer = delegate.put(key, new ExpiringObject(key, value, System.currentTimeMillis())); @@@ -100,6 -100,6 +107,10 @@@ return answer.getValue(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V get(Object key) { ExpiringObject object = delegate.get(key); @@@ -112,6 -112,6 +123,10 @@@ return null; } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V remove(Object key) { ExpiringObject answer = delegate.remove(key); if (answer == null) { @@@ -121,62 -121,62 +136,117 @@@ return answer.getValue(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public boolean containsKey(Object key) { return delegate.containsKey(key); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public boolean containsValue(Object value) { return delegate.containsValue(value); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public int size() { return delegate.size(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public boolean isEmpty() { return delegate.isEmpty(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void clear() { delegate.clear(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public int hashCode() { return delegate.hashCode(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public Set<K> keySet() { return delegate.keySet(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean equals(Object obj) { return delegate.equals(obj); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void putAll(Map<? extends K, ? extends V> inMap) { for (Entry<? extends K, ? extends V> e : inMap.entrySet()) { this.put(e.getKey(), e.getValue()); } } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public Collection<V> values() { throw new UnsupportedOperationException(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public Set<Map.Entry<K, V>> entrySet() { throw new UnsupportedOperationException(); } ++ /** ++ * Adds a listener in the expiration listeners ++ * ++ * @param listener The listener to add ++ */ public void addExpirationListener(ExpirationListener<V> listener) { expirationListeners.add(listener); } ++ /** ++ * Removes a listener from the expiration listeners ++ * ++ * @param listener The listener to remove ++ */ public void removeExpirationListener(ExpirationListener<V> listener) { expirationListeners.remove(listener); } ++ /** ++ * @return The Expirer instance ++ */ public Expirer getExpirer() { return expirer; } @@@ -298,6 -298,6 +368,10 @@@ expirerThread.setDaemon(true); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void run() { while (running) { processExpires(); @@@ -354,6 -354,6 +428,7 @@@ */ public void startExpiringIfNotStarted() { stateLock.readLock().lock(); ++ try { if (running) { return; @@@ -363,6 -363,6 +438,7 @@@ } stateLock.writeLock().lock(); ++ try { if (!running) { running = true; http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java index c59e41e,c59e41e..a6e5e13 --- a/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java +++ b/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java @@@ -25,21 -25,21 +25,35 @@@ import java.util.Set /** * An {@link IdentityHashMap}-backed {@link Set}. ++ * ++ * @param <E> The element type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public class IdentityHashSet<E> extends MapBackedSet<E> { -- private static final long serialVersionUID = 6948202189467167147L; ++ /** ++ * Creates a new IdentityHashSet instance ++ */ public IdentityHashSet() { super(new IdentityHashMap<E, Boolean>()); } ++ /** ++ * Creates a new IdentityHashSet instance ++ * ++ * @param expectedMaxSize The maximum size for the map ++ */ public IdentityHashSet(int expectedMaxSize) { super(new IdentityHashMap<E, Boolean>(expectedMaxSize)); } ++ /** ++ * Creates a new IdentityHashSet instance ++ * ++ * @param c The elements to put in the map ++ */ public IdentityHashSet(Collection<E> c) { super(new IdentityHashMap<E, Boolean>(), c); } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java index 68742fa,68742fa..d38fc61 --- a/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java +++ b/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java @@@ -37,6 -37,6 +37,9 @@@ import org.apache.mina.core.buffer.IoBu * {@link UnsupportedOperationException} on each method that is not intended to * be called by user code for performance reasons. * ++ * @param <K> The key type ++ * @param <V> The value type ++ * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * @since MINA 2.0.0-M2 */ @@@ -50,10 -50,10 +53,19 @@@ public class LazyInitializedCacheMap<K public class NoopInitializer extends LazyInitializer<V> { private V value; ++ /** ++ * Create a new NoopInitializer instance ++ * ++ * @param value The value stored in this initializer ++ */ public NoopInitializer(V value) { this.value = value; } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V init() { return value; } @@@ -64,7 -64,7 +76,7 @@@ * {@link ConcurrentHashMap}. */ public LazyInitializedCacheMap() { -- this.cache = new ConcurrentHashMap<K, LazyInitializer<V>>(); ++ this.cache = new ConcurrentHashMap<>(); } /** @@@ -73,15 -73,15 +85,17 @@@ * * @param map The map to use as a cache */ -- public LazyInitializedCacheMap(final ConcurrentHashMap<K, LazyInitializer<V>> map) { ++ public LazyInitializedCacheMap(ConcurrentHashMap<K, LazyInitializer<V>> map) { this.cache = map; } /** * {@inheritDoc} */ ++ @Override public V get(Object key) { LazyInitializer<V> c = cache.get(key); ++ if (c != null) { return c.get(); } @@@ -92,8 -92,8 +106,10 @@@ /** * {@inheritDoc} */ ++ @Override public V remove(Object key) { LazyInitializer<V> c = cache.remove(key); ++ if (c != null) { return c.get(); } @@@ -120,8 -120,8 +136,10 @@@ */ public V putIfAbsent(K key, LazyInitializer<V> value) { LazyInitializer<V> v = cache.get(key); ++ if (v == null) { v = cache.putIfAbsent(key, value); ++ if (v == null) { return value.get(); } @@@ -133,8 -133,8 +151,10 @@@ /** * {@inheritDoc} */ ++ @Override public V put(K key, V value) { LazyInitializer<V> c = cache.put(key, new NoopInitializer(value)); ++ if (c != null) { return c.get(); } @@@ -146,6 -146,6 +166,7 @@@ * Throws {@link UnsupportedOperationException} as this method would imply * performance drops. */ ++ @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } @@@ -154,6 -154,6 +175,7 @@@ * Throws {@link UnsupportedOperationException} as this method would imply * performance drops. */ ++ @Override public Collection<V> values() { throw new UnsupportedOperationException(); } @@@ -162,6 -162,6 +184,7 @@@ * Throws {@link UnsupportedOperationException} as this method would imply * performance drops. */ ++ @Override public Set<java.util.Map.Entry<K, V>> entrySet() { throw new UnsupportedOperationException(); } @@@ -169,6 -169,6 +192,7 @@@ /** * {@inheritDoc} */ ++ @Override public void putAll(Map<? extends K, ? extends V> m) { for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) { cache.put(e.getKey(), new NoopInitializer(e.getValue())); @@@ -185,6 -185,6 +209,7 @@@ /** * {@inheritDoc} */ ++ @Override public void clear() { cache.clear(); } @@@ -192,6 -192,6 +217,7 @@@ /** * {@inheritDoc} */ ++ @Override public boolean containsKey(Object key) { return cache.containsKey(key); } @@@ -199,6 -199,6 +225,7 @@@ /** * {@inheritDoc} */ ++ @Override public boolean isEmpty() { return cache.isEmpty(); } @@@ -206,6 -206,6 +233,7 @@@ /** * {@inheritDoc} */ ++ @Override public Set<K> keySet() { return cache.keySet(); } @@@ -213,6 -213,6 +241,7 @@@ /** * {@inheritDoc} */ ++ @Override public int size() { return cache.size(); } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java index 924feea,924feea..ccc1684 --- a/mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java +++ b/mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java @@@ -24,6 -24,6 +24,8 @@@ package org.apache.mina.util * fully initialized when requested to. It allows to avoid loosing time when * early initializing unnecessary objects. * ++ * @param <V> The value type ++ * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * @since MINA 2.0.0-M2 */ http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java index 455fe0f,455fe0f..7dc1449 --- a/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java +++ b/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java @@@ -46,11 -46,11 +46,11 @@@ import org.slf4j.MDC */ public class Log4jXmlFormatter extends Formatter { -- private final int DEFAULT_SIZE = 256; ++ private static final int DEFAULT_SIZE = 256; -- private final int UPPER_LIMIT = 2048; ++ private static final int UPPER_LIMIT = 2048; -- private StringBuffer buf = new StringBuffer(DEFAULT_SIZE); ++ private StringBuilder buf = new StringBuilder(DEFAULT_SIZE); private boolean locationInfo = false; @@@ -99,10 -99,10 +99,11 @@@ // Reset working buffer. If the buffer is too large, then we need a new // one in order to avoid the penalty of creating a large array. if (buf.capacity() > UPPER_LIMIT) { -- buf = new StringBuffer(DEFAULT_SIZE); ++ buf = new StringBuilder(DEFAULT_SIZE); } else { buf.setLength(0); } ++ buf.append("<log4j:event logger=\""); buf.append(Transform.escapeTags(record.getLoggerName())); buf.append("\" timestamp=\""); @@@ -122,12 -122,12 +123,15 @@@ if (record.getThrown() != null) { String[] s = Transform.getThrowableStrRep(record.getThrown()); ++ if (s != null) { buf.append("<log4j:throwable><![CDATA["); ++ for (String value : s) { Transform.appendEscapingCDATA(buf, value); buf.append("\r\n"); } ++ buf.append("]]></log4j:throwable>\r\n"); } } @@@ -146,13 -146,13 +150,13 @@@ if (contextMap != null) { Set<String> keySet = contextMap.keySet(); -- if ((keySet != null) && (keySet.size() > 0)) { ++ if ((keySet != null) && !keySet.isEmpty()) { buf.append("<log4j:properties>\r\n"); Object[] keys = keySet.toArray(); Arrays.sort(keys); for (Object key1 : keys) { -- String key = (key1 == null ? "" : key1.toString()); ++ String key = key1 == null ? "" : key1.toString(); Object val = contextMap.get(key); if (val != null) { @@@ -167,11 -167,11 +171,10 @@@ buf.append("</log4j:properties>\r\n"); } } -- } ++ buf.append("</log4j:event>\r\n\r\n"); return buf.toString(); } -- } http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java index 9198bc2,9198bc2..77d201b --- a/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java +++ b/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java @@@ -28,6 -28,6 +28,8 @@@ import java.util.Set /** * A {@link Map}-backed {@link Set}. ++ * ++ * @param <E> The element stored in the set * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@@ -37,40 -37,40 +39,69 @@@ public class MapBackedSet<E> extends Ab protected final Map<E, Boolean> map; ++ /** ++ * Creates a new MapBackedSet instance ++ * ++ * @param map The map that we want to back ++ */ public MapBackedSet(Map<E, Boolean> map) { this.map = map; } ++ /** ++ * Creates a new MapBackedSet instance ++ * ++ * @param map The map that we want to back ++ * @param c The elements we want to add in the map ++ */ public MapBackedSet(Map<E, Boolean> map, Collection<E> c) { this.map = map; addAll(c); } ++ /** ++ * {@inheritDoc} ++ */ @Override public int size() { return map.size(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean contains(Object o) { return map.containsKey(o); } ++ /** ++ * {@inheritDoc} ++ */ @Override public Iterator<E> iterator() { return map.keySet().iterator(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean add(E o) { return map.put(o, Boolean.TRUE) == null; } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean remove(Object o) { return map.remove(o) != null; } ++ /** ++ * {@inheritDoc} ++ */ @Override public void clear() { map.clear(); http://git-wip-us.apache.org/repos/asf/mina/blob/3ff1bf1a/mina-core/src/main/java/org/apache/mina/util/Transform.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/Transform.java index ee52a20,ee52a20..90e9b42 --- a/mina-core/src/main/java/org/apache/mina/util/Transform.java +++ b/mina-core/src/main/java/org/apache/mina/util/Transform.java @@@ -54,14 -54,14 +54,11 @@@ public class Transform * @param input The text to be converted. * @return The input string with the special characters replaced. * */ -- static public String escapeTags(final String input) { ++ public static String escapeTags(String input) { // Check if the string is null, zero length or devoid of special characters // if so, return what was sent in. -- if (input == null -- || input.length() == 0 -- || (input.indexOf('"') == -1 && input.indexOf('&') == -1 && input.indexOf('<') == -1 && input -- .indexOf('>') == -1)) { ++ if (input == null || input.length() == 0) { return input; } @@@ -69,22 -69,22 +66,33 @@@ char ch; int len = input.length(); ++ for (int i = 0; i < len; i++) { ch = input.charAt(i); -- if (ch > '>') { -- buf.append(ch); -- } else if (ch == '<') { -- buf.append("<"); -- } else if (ch == '>') { -- buf.append(">"); -- } else if (ch == '&') { -- buf.append("&"); -- } else if (ch == '"') { -- buf.append("""); -- } else { -- buf.append(ch); ++ ++ switch ( ch ) ++ { ++ case '<' : ++ buf.append("<"); ++ break; ++ ++ case '>' : ++ buf.append(">"); ++ break; ++ ++ case '&' : ++ buf.append("&"); ++ break; ++ ++ case '"' : ++ buf.append("""); ++ break; ++ ++ default : ++ buf.append(ch); } } ++ return buf.toString(); } @@@ -97,23 -97,23 +105,27 @@@ * section are the responsibility of the calling method. * @param str The String that is inserted into an existing CDATA Section within buf. * */ -- static public void appendEscapingCDATA(final StringBuffer buf, final String str) { ++ public static void appendEscapingCDATA(final StringBuilder buf, final String str) { if (str != null) { int end = str.indexOf(CDATA_END); ++ if (end < 0) { buf.append(str); } else { int start = 0; ++ while (end > -1) { buf.append(str.substring(start, end)); buf.append(CDATA_EMBEDED_END); start = end + CDATA_END_LEN; ++ if (start < str.length()) { end = str.indexOf(CDATA_END, start); } else { return; } } ++ buf.append(str.substring(start)); } } @@@ -130,9 -130,9 +142,11 @@@ throwable.printStackTrace(pw); pw.flush(); LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString())); -- ArrayList<String> lines = new ArrayList<String>(); ++ ArrayList<String> lines = new ArrayList<>(); ++ try { String line = reader.readLine(); ++ while (line != null) { lines.add(line); line = reader.readLine(); @@@ -140,9 -140,9 +154,10 @@@ } catch (IOException ex) { lines.add(ex.toString()); } ++ String[] rep = new String[lines.size()]; lines.toArray(rep); ++ return rep; } -- }