Author: violetagg Date: Wed Feb 8 08:06:38 2017 New Revision: 1782116 URL: http://svn.apache.org/viewvc?rev=1782116&view=rev Log: Format the code. No functional changes.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java?rev=1782116&r1=1782115&r2=1782116&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java Wed Feb 8 08:06:38 2017 @@ -42,8 +42,7 @@ import org.apache.tomcat.util.res.String */ public abstract class WsFrameBase { - private static final StringManager sm = - StringManager.getManager(WsFrameBase.class); + private static final StringManager sm = StringManager.getManager(WsFrameBase.class); // Connection level attributes protected final WsSession wsSession; @@ -88,10 +87,8 @@ public abstract class WsFrameBase { public WsFrameBase(WsSession wsSession, Transformation transformation) { inputBuffer = ByteBuffer.allocate(Constants.DEFAULT_BUFFER_SIZE); inputBuffer.position(0).limit(0); - messageBufferBinary = - ByteBuffer.allocate(wsSession.getMaxBinaryMessageBufferSize()); - messageBufferText = - CharBuffer.allocate(wsSession.getMaxTextMessageBufferSize()); + messageBufferBinary = ByteBuffer.allocate(wsSession.getMaxBinaryMessageBufferSize()); + messageBufferText = CharBuffer.allocate(wsSession.getMaxTextMessageBufferSize()); this.wsSession = wsSession; Transformation finalTransformation; if (isMasked()) { @@ -151,8 +148,7 @@ public abstract class WsFrameBase { if (!transformation.validateRsv(rsv, opCode)) { throw new WsIOException(new CloseReason( CloseCodes.PROTOCOL_ERROR, - sm.getString("wsFrame.wrongRsv", Integer.valueOf(rsv), - Integer.valueOf(opCode)))); + sm.getString("wsFrame.wrongRsv", Integer.valueOf(rsv), Integer.valueOf(opCode)))); } if (Util.isControl(opCode)) { @@ -166,8 +162,7 @@ public abstract class WsFrameBase { opCode != Constants.OPCODE_CLOSE) { throw new WsIOException(new CloseReason( CloseCodes.PROTOCOL_ERROR, - sm.getString("wsFrame.invalidOpCode", - Integer.valueOf(opCode)))); + sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode)))); } } else { if (continuationExpected) { @@ -199,8 +194,7 @@ public abstract class WsFrameBase { } else { throw new WsIOException(new CloseReason( CloseCodes.PROTOCOL_ERROR, - sm.getString("wsFrame.invalidOpCode", - Integer.valueOf(opCode)))); + sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode)))); } } catch (IllegalStateException ise) { // Thrown if the session is already closed @@ -267,8 +261,7 @@ public abstract class WsFrameBase { if (payloadLength > 125) { throw new WsIOException(new CloseReason( CloseCodes.PROTOCOL_ERROR, - sm.getString("wsFrame.controlPayloadTooBig", - Long.valueOf(payloadLength)))); + sm.getString("wsFrame.controlPayloadTooBig", Long.valueOf(payloadLength)))); } if (!fin) { throw new WsIOException(new CloseReason( @@ -329,8 +322,8 @@ public abstract class WsFrameBase { if (controlBufferBinary.remaining() > 1) { code = controlBufferBinary.getShort(); if (controlBufferBinary.remaining() > 0) { - CoderResult cr = utf8DecoderControl.decode( - controlBufferBinary, controlBufferText, true); + CoderResult cr = utf8DecoderControl.decode(controlBufferBinary, + controlBufferText, true); if (cr.isError()) { controlBufferBinary.clear(); controlBufferText.clear(); @@ -351,8 +344,7 @@ public abstract class WsFrameBase { wsSession.getBasicRemote().sendPong(controlBufferBinary); } } else if (opCode == Constants.OPCODE_PONG) { - MessageHandler.Whole<PongMessage> mhPong = - wsSession.getPongMessageHandler(); + MessageHandler.Whole<PongMessage> mhPong = wsSession.getPongMessageHandler(); if (mhPong != null) { try { mhPong.onMessage(new WsPongMessage(controlBufferBinary)); @@ -367,8 +359,7 @@ public abstract class WsFrameBase { controlBufferBinary.clear(); throw new WsIOException(new CloseReason( CloseCodes.PROTOCOL_ERROR, - sm.getString("wsFrame.invalidOpCode", - Integer.valueOf(opCode)))); + sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode)))); } controlBufferBinary.clear(); newFrame(); @@ -379,10 +370,8 @@ public abstract class WsFrameBase { @SuppressWarnings("unchecked") protected void sendMessageText(boolean last) throws WsIOException { if (textMsgHandler instanceof WrappedMessageHandler) { - long maxMessageSize = - ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize(); - if (maxMessageSize > -1 && - messageBufferText.remaining() > maxMessageSize) { + long maxMessageSize = ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize(); + if (maxMessageSize > -1 && messageBufferText.remaining() > maxMessageSize) { throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG, sm.getString("wsFrame.messageTooBig", Long.valueOf(messageBufferText.remaining()), @@ -392,12 +381,12 @@ public abstract class WsFrameBase { try { if (textMsgHandler instanceof MessageHandler.Partial<?>) { - ((MessageHandler.Partial<String>) textMsgHandler).onMessage( - messageBufferText.toString(), last); + ((MessageHandler.Partial<String>) textMsgHandler) + .onMessage(messageBufferText.toString(), last); } else { // Caller ensures last == true if this branch is used - ((MessageHandler.Whole<String>) textMsgHandler).onMessage( - messageBufferText.toString()); + ((MessageHandler.Whole<String>) textMsgHandler) + .onMessage(messageBufferText.toString()); } } catch (Throwable t) { handleThrowableOnSend(t); @@ -415,8 +404,8 @@ public abstract class WsFrameBase { // Convert bytes to UTF-8 messageBufferBinary.flip(); while (true) { - CoderResult cr = utf8DecoderMessage.decode( - messageBufferBinary, messageBufferText, false); + CoderResult cr = utf8DecoderMessage.decode(messageBufferBinary, messageBufferText, + false); if (cr.isError()) { throw new WsIOException(new CloseReason( CloseCodes.NOT_CONSISTENT, @@ -458,8 +447,8 @@ public abstract class WsFrameBase { // Frame is fully received // Convert bytes to UTF-8 while (true) { - CoderResult cr = utf8DecoderMessage.decode(messageBufferBinary, - messageBufferText, last); + CoderResult cr = utf8DecoderMessage.decode(messageBufferBinary, messageBufferText, + last); if (cr.isError()) { throw new WsIOException(new CloseReason( CloseCodes.NOT_CONSISTENT, @@ -520,14 +509,12 @@ public abstract class WsFrameBase { if (!usePartial()) { CloseReason cr = new CloseReason(CloseCodes.TOO_BIG, sm.getString("wsFrame.bufferTooSmall", - Integer.valueOf( - messageBufferBinary.capacity()), + Integer.valueOf(messageBufferBinary.capacity()), Long.valueOf(payloadLength))); throw new WsIOException(cr); } messageBufferBinary.flip(); - ByteBuffer copy = - ByteBuffer.allocate(messageBufferBinary.limit()); + ByteBuffer copy = ByteBuffer.allocate(messageBufferBinary.limit()); copy.put(messageBufferBinary); copy.flip(); sendMessageBinary(copy, false); @@ -542,8 +529,7 @@ public abstract class WsFrameBase { // - the message is complete if (usePartial() || !continuationExpected) { messageBufferBinary.flip(); - ByteBuffer copy = - ByteBuffer.allocate(messageBufferBinary.limit()); + ByteBuffer copy = ByteBuffer.allocate(messageBufferBinary.limit()); copy.put(messageBufferBinary); copy.flip(); sendMessageBinary(copy, !continuationExpected); @@ -572,11 +558,9 @@ public abstract class WsFrameBase { @SuppressWarnings("unchecked") - protected void sendMessageBinary(ByteBuffer msg, boolean last) - throws WsIOException { + protected void sendMessageBinary(ByteBuffer msg, boolean last) throws WsIOException { if (binaryMsgHandler instanceof WrappedMessageHandler) { - long maxMessageSize = - ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize(); + long maxMessageSize = ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize(); if (maxMessageSize > -1 && msg.remaining() > maxMessageSize) { throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG, sm.getString("wsFrame.messageTooBig", @@ -591,7 +575,7 @@ public abstract class WsFrameBase { // Caller ensures last == true if this branch is used ((MessageHandler.Whole<ByteBuffer>) binaryMsgHandler).onMessage(msg); } - } catch(Throwable t) { + } catch (Throwable t) { handleThrowableOnSend(t); } } @@ -674,11 +658,9 @@ public abstract class WsFrameBase { } - protected static long byteArrayToLong(byte[] b, int start, int len) - throws IOException { + protected static long byteArrayToLong(byte[] b, int start, int len) throws IOException { if (len > 8) { - throw new IOException(sm.getString("wsFrame.byteToLongFail", - Long.valueOf(len))); + throw new IOException(sm.getString("wsFrame.byteToLongFail", Long.valueOf(len))); } int shift = 0; long result = 0; @@ -754,8 +736,7 @@ public abstract class WsFrameBase { // opCode is ignored as the transformation is the same for all // opCodes // rsv is ignored as it known to be zero at this point - long toWrite = Math.min( - payloadLength - payloadWritten, inputBuffer.remaining()); + long toWrite = Math.min(payloadLength - payloadWritten, inputBuffer.remaining()); toWrite = Math.min(toWrite, dest.remaining()); int orgLimit = inputBuffer.limit(); Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java?rev=1782116&r1=1782115&r2=1782116&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java Wed Feb 8 08:06:38 2017 @@ -31,16 +31,15 @@ import org.apache.tomcat.util.res.String public class WsFrameClient extends WsFrameBase { private final Log log = LogFactory.getLog(WsFrameClient.class); - private static final StringManager sm = - StringManager.getManager(WsFrameClient.class); + private static final StringManager sm = StringManager.getManager(WsFrameClient.class); private final AsyncChannelWrapper channel; - private final CompletionHandler<Integer,Void> handler; + private final CompletionHandler<Integer, Void> handler; // Not final as it may need to be re-sized private volatile ByteBuffer response; - public WsFrameClient(ByteBuffer response, AsyncChannelWrapper channel, - WsSession wsSession, Transformation transformation) { + public WsFrameClient(ByteBuffer response, AsyncChannelWrapper channel, WsSession wsSession, + Transformation transformation) { super(wsSession, transformation); this.response = response; this.channel = channel; @@ -92,8 +91,7 @@ public class WsFrameClient extends WsFra if (t instanceof WsIOException) { cr = ((WsIOException) t).getCloseReason(); } else { - cr = new CloseReason( - CloseCodes.CLOSED_ABNORMALLY, t.getMessage()); + cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY, t.getMessage()); } try { @@ -116,9 +114,7 @@ public class WsFrameClient extends WsFra return log; } - - private class WsFrameClientCompletionHandler - implements CompletionHandler<Integer,Void> { + private class WsFrameClientCompletionHandler implements CompletionHandler<Integer, Void> { @Override public void completed(Integer result, Void attachment) { @@ -152,8 +148,8 @@ public class WsFrameClient extends WsFra public void failed(Throwable exc, Void attachment) { if (exc instanceof ReadBufferOverflowException) { // response will be empty if this exception is thrown - response = ByteBuffer.allocate( - ((ReadBufferOverflowException) exc).getMinBufferSize()); + response = ByteBuffer + .allocate(((ReadBufferOverflowException) exc).getMinBufferSize()); response.flip(); try { processSocketRead(); Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1782116&r1=1782115&r2=1782116&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Wed Feb 8 08:06:38 2017 @@ -57,8 +57,7 @@ public class WsSession implements Sessio // An ellipsis is a single character that looks like three periods in a row // and is used to indicate a continuation. - private static final byte[] ELLIPSIS_BYTES = - "\u2026".getBytes(StandardCharsets.UTF_8); + private static final byte[] ELLIPSIS_BYTES = "\u2026".getBytes(StandardCharsets.UTF_8); // An ellipsis is three bytes in UTF-8 private static final int ELLIPSIS_BYTES_LEN = ELLIPSIS_BYTES.length; @@ -74,14 +73,14 @@ public class WsSession implements Sessio private final ClassLoader applicationClassLoader; private final WsWebSocketContainer webSocketContainer; private final URI requestUri; - private final Map<String,List<String>> requestParameterMap; + private final Map<String, List<String>> requestParameterMap; private final String queryString; private final Principal userPrincipal; private final EndpointConfig endpointConfig; private final List<Extension> negotiatedExtensions; private final String subProtocol; - private final Map<String,String> pathParameters; + private final Map<String, String> pathParameters; private final boolean secure; private final String httpSessionId; private final String id; @@ -93,14 +92,12 @@ public class WsSession implements Sessio private volatile MessageHandler.Whole<PongMessage> pongMessageHandler = null; private volatile State state = State.OPEN; private final Object stateLock = new Object(); - private final Map<String,Object> userProperties = new ConcurrentHashMap<>(); - private volatile int maxBinaryMessageBufferSize = - Constants.DEFAULT_BUFFER_SIZE; - private volatile int maxTextMessageBufferSize = - Constants.DEFAULT_BUFFER_SIZE; + private final Map<String, Object> userProperties = new ConcurrentHashMap<>(); + private volatile int maxBinaryMessageBufferSize = Constants.DEFAULT_BUFFER_SIZE; + private volatile int maxTextMessageBufferSize = Constants.DEFAULT_BUFFER_SIZE; private volatile long maxIdleTimeout = 0; private volatile long lastActive = System.currentTimeMillis(); - private Map<FutureToSendHandler,FutureToSendHandler> futures = new ConcurrentHashMap<>(); + private Map<FutureToSendHandler, FutureToSendHandler> futures = new ConcurrentHashMap<>(); /** * Creates a new WebSocket session for communication between the two @@ -140,9 +137,9 @@ public class WsSession implements Sessio public WsSession(Endpoint localEndpoint, WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, - URI requestUri, Map<String,List<String>> requestParameterMap, + URI requestUri, Map<String, List<String>> requestParameterMap, String queryString, Principal userPrincipal, String httpSessionId, - List<Extension> negotiatedExtensions, String subProtocol, Map<String,String> pathParameters, + List<Extension> negotiatedExtensions, String subProtocol, Map<String, String> pathParameters, boolean secure, EndpointConfig endpointConfig) throws DeploymentException { this.localEndpoint = localEndpoint; this.wsRemoteEndpoint = wsRemoteEndpoint; @@ -151,14 +148,10 @@ public class WsSession implements Sessio this.remoteEndpointBasic = new WsRemoteEndpointBasic(wsRemoteEndpoint); this.webSocketContainer = wsWebSocketContainer; applicationClassLoader = Thread.currentThread().getContextClassLoader(); - wsRemoteEndpoint.setSendTimeout( - wsWebSocketContainer.getDefaultAsyncSendTimeout()); - this.maxBinaryMessageBufferSize = - webSocketContainer.getDefaultMaxBinaryMessageBufferSize(); - this.maxTextMessageBufferSize = - webSocketContainer.getDefaultMaxTextMessageBufferSize(); - this.maxIdleTimeout = - webSocketContainer.getDefaultMaxSessionIdleTimeout(); + wsRemoteEndpoint.setSendTimeout(wsWebSocketContainer.getDefaultAsyncSendTimeout()); + this.maxBinaryMessageBufferSize = webSocketContainer.getDefaultMaxBinaryMessageBufferSize(); + this.maxTextMessageBufferSize = webSocketContainer.getDefaultMaxTextMessageBufferSize(); + this.maxIdleTimeout = webSocketContainer.getDefaultMaxSessionIdleTimeout(); this.requestUri = requestUri; if (requestParameterMap == null) { this.requestParameterMap = Collections.emptyMap(); @@ -242,48 +235,44 @@ public class WsSession implements Sessio // arbitrary objects with MessageHandlers and can wrap MessageHandlers // just as easily. - Set<MessageHandlerResult> mhResults = - Util.getMessageHandlers(target, listener, endpointConfig, this); + Set<MessageHandlerResult> mhResults = Util.getMessageHandlers(target, listener, + endpointConfig, this); for (MessageHandlerResult mhResult : mhResults) { switch (mhResult.getType()) { - case TEXT: { - if (textMessageHandler != null) { - throw new IllegalStateException( - sm.getString("wsSession.duplicateHandlerText")); - } - textMessageHandler = mhResult.getHandler(); - break; + case TEXT: { + if (textMessageHandler != null) { + throw new IllegalStateException(sm.getString("wsSession.duplicateHandlerText")); } - case BINARY: { - if (binaryMessageHandler != null) { - throw new IllegalStateException( - sm.getString("wsSession.duplicateHandlerBinary")); - } - binaryMessageHandler = mhResult.getHandler(); - break; + textMessageHandler = mhResult.getHandler(); + break; + } + case BINARY: { + if (binaryMessageHandler != null) { + throw new IllegalStateException( + sm.getString("wsSession.duplicateHandlerBinary")); } - case PONG: { - if (pongMessageHandler != null) { - throw new IllegalStateException( - sm.getString("wsSession.duplicateHandlerPong")); - } - MessageHandler handler = mhResult.getHandler(); - if (handler instanceof MessageHandler.Whole<?>) { - pongMessageHandler = - (MessageHandler.Whole<PongMessage>) handler; - } else { - throw new IllegalStateException( - sm.getString("wsSession.invalidHandlerTypePong")); - } - - break; + binaryMessageHandler = mhResult.getHandler(); + break; + } + case PONG: { + if (pongMessageHandler != null) { + throw new IllegalStateException(sm.getString("wsSession.duplicateHandlerPong")); } - default: { - throw new IllegalArgumentException(sm.getString( - "wsSession.unknownHandlerType", listener, - mhResult.getType())); + MessageHandler handler = mhResult.getHandler(); + if (handler instanceof MessageHandler.Whole<?>) { + pongMessageHandler = (MessageHandler.Whole<PongMessage>) handler; + } else { + throw new IllegalStateException( + sm.getString("wsSession.invalidHandlerTypePong")); } + + break; + } + default: { + throw new IllegalArgumentException( + sm.getString("wsSession.unknownHandlerType", listener, mhResult.getType())); + } } } } @@ -324,20 +313,17 @@ public class WsSession implements Sessio } boolean removed = false; - if (wrapped.equals(textMessageHandler) || - listener.equals(textMessageHandler)) { + if (wrapped.equals(textMessageHandler) || listener.equals(textMessageHandler)) { textMessageHandler = null; removed = true; } - if (wrapped.equals(binaryMessageHandler) || - listener.equals(binaryMessageHandler)) { + if (wrapped.equals(binaryMessageHandler) || listener.equals(binaryMessageHandler)) { binaryMessageHandler = null; removed = true; } - if (wrapped.equals(pongMessageHandler) || - listener.equals(pongMessageHandler)) { + if (wrapped.equals(pongMessageHandler) || listener.equals(pongMessageHandler)) { pongMessageHandler = null; removed = true; } @@ -629,29 +615,26 @@ public class WsSession implements Sessio * @param msg The message * @param reason The reason */ - protected static void appendCloseReasonWithTruncation(ByteBuffer msg, - String reason) { + protected static void appendCloseReasonWithTruncation(ByteBuffer msg, String reason) { // Once the close code has been added there are a maximum of 123 bytes // left for the reason phrase. If it is truncated then care needs to be // taken to ensure the bytes are not truncated in the middle of a // multi-byte UTF-8 character. byte[] reasonBytes = reason.getBytes(StandardCharsets.UTF_8); - if (reasonBytes.length <= 123) { + if (reasonBytes.length <= 123) { // No need to truncate msg.put(reasonBytes); } else { // Need to truncate int remaining = 123 - ELLIPSIS_BYTES_LEN; int pos = 0; - byte[] bytesNext = reason.substring(pos, pos + 1).getBytes( - StandardCharsets.UTF_8); + byte[] bytesNext = reason.substring(pos, pos + 1).getBytes(StandardCharsets.UTF_8); while (remaining >= bytesNext.length) { msg.put(bytesNext); remaining -= bytesNext.length; pos++; - bytesNext = reason.substring(pos, pos + 1).getBytes( - StandardCharsets.UTF_8); + bytesNext = reason.substring(pos, pos + 1).getBytes(StandardCharsets.UTF_8); } msg.put(ELLIPSIS_BYTES); } @@ -707,7 +690,7 @@ public class WsSession implements Sessio @Override - public Map<String,List<String>> getRequestParameterMap() { + public Map<String, List<String>> getRequestParameterMap() { checkState(); return requestParameterMap; } @@ -728,7 +711,7 @@ public class WsSession implements Sessio @Override - public Map<String,String> getPathParameters() { + public Map<String, String> getPathParameters() { checkState(); return pathParameters; } @@ -741,7 +724,7 @@ public class WsSession implements Sessio @Override - public Map<String,Object> getUserProperties() { + public Map<String, Object> getUserProperties() { checkState(); return userProperties; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org