diff --git a/src/main/java/com/neovisionaries/ws/client/DeflateUtil.java b/src/main/java/com/neovisionaries/ws/client/DeflateUtil.java
index 99f691f..e7a22b3 100644
--- a/src/main/java/com/neovisionaries/ws/client/DeflateUtil.java
+++ b/src/main/java/com/neovisionaries/ws/client/DeflateUtil.java
@@ -16,6 +16,8 @@
package com.neovisionaries.ws.client;
+import java.util.Arrays;
+
/**
* Utility methods for DEFLATE (RFC 1951).
*/
@@ -83,7 +85,7 @@ public static void readDynamicTables(
private static void readCodeLengths(
- ByteArray input, int bitIndex[], int[] codeLengths,
+ ByteArray input, int[] bitIndex, int[] codeLengths,
Huffman codeLengthHuffman) throws FormatException
{
// 3.2.7 Compression with dynamic Huffman codes (BTYPE=10)
@@ -130,8 +132,8 @@ private static void readCodeLengths(
default:
// Bad code length.
String message = String.format(
- "[%s] Bad code length '%d' at the bit index '%d'.",
- DeflateUtil.class.getSimpleName(), codeLength, bitIndex);
+ "[%s] Bad code length '%d' at the bit index '%s'.",
+ DeflateUtil.class.getSimpleName(), codeLength, Arrays.toString(bitIndex));
throw new FormatException(message);
}
diff --git a/src/main/java/com/neovisionaries/ws/client/HandshakeReader.java b/src/main/java/com/neovisionaries/ws/client/HandshakeReader.java
index ad7c9b7..9aeb8f6 100644
--- a/src/main/java/com/neovisionaries/ws/client/HandshakeReader.java
+++ b/src/main/java/com/neovisionaries/ws/client/HandshakeReader.java
@@ -438,7 +438,7 @@ private void validateAccept(StatusLine statusLine, Map> hea
return;
}
- if (expected.equals(actual) == false)
+ if (expected != null && !expected.equals(actual))
{
// The value of 'Sec-WebSocket-Accept' header is different from the expected one.
throw new OpeningHandshakeException(
diff --git a/src/main/java/com/neovisionaries/ws/client/Huffman.java b/src/main/java/com/neovisionaries/ws/client/Huffman.java
index 2639e0e..3759768 100644
--- a/src/main/java/com/neovisionaries/ws/client/Huffman.java
+++ b/src/main/java/com/neovisionaries/ws/client/Huffman.java
@@ -43,7 +43,7 @@ public Huffman(int[] codeLensFromSym)
// Create a table to convert code values int symbols.
int[] codeValsFromCodeLen = (int[])out[0];
- int maxCodeVal = ((Integer)out[1]).intValue();
+ int maxCodeVal = (Integer) out[1];
mSymsFromCodeVal = createSymsFromCodeVal(codeLensFromSym, codeValsFromCodeLen, maxCodeVal);
}
@@ -70,9 +70,7 @@ private static int[] createCountsFromCodeLen(int[] codeLensFromSym, int maxCodeL
// Count the number of entries for each code length.
// This corresponds to the step 1 in 3.2.2. of RFC 1951.
- for (int symbol = 0; symbol < codeLensFromSym.length; ++symbol)
- {
- int codeLength = codeLensFromSym[symbol];
+ for (int codeLength : codeLensFromSym) {
++countsFromCodeLen[codeLength];
}
@@ -106,7 +104,7 @@ private static int[] createMaxCodeValsFromCodeLen(int[] countsFromCodeLen, int m
}
out[0] = codeValsFromCodeLen;
- out[1] = Integer.valueOf(maxCodeVal);
+ out[1] = maxCodeVal;
return maxCodeValsFromCodeLen;
}
diff --git a/src/main/java/com/neovisionaries/ws/client/ListenerManager.java b/src/main/java/com/neovisionaries/ws/client/ListenerManager.java
index bd6e773..0d1299b 100644
--- a/src/main/java/com/neovisionaries/ws/client/ListenerManager.java
+++ b/src/main/java/com/neovisionaries/ws/client/ListenerManager.java
@@ -151,10 +151,7 @@ private List getSynchronizedListeners()
List copiedListeners =
new ArrayList(mListeners.size());
- for (WebSocketListener listener : mListeners)
- {
- copiedListeners.add(listener);
- }
+ copiedListeners.addAll(mListeners);
// Synchronize.
mCopiedListeners = copiedListeners;
diff --git a/src/main/java/com/neovisionaries/ws/client/Misc.java b/src/main/java/com/neovisionaries/ws/client/Misc.java
index 097bb97..46c2de2 100644
--- a/src/main/java/com/neovisionaries/ws/client/Misc.java
+++ b/src/main/java/com/neovisionaries/ws/client/Misc.java
@@ -251,11 +251,9 @@ public static int min(int[] values)
{
int min = Integer.MAX_VALUE;
- for (int i = 0; i < values.length; ++i)
- {
- if (values[i] < min)
- {
- min = values[i];
+ for (int value : values) {
+ if (value < min) {
+ min = value;
}
}
@@ -270,11 +268,9 @@ public static int max(int[] values)
{
int max = Integer.MIN_VALUE;
- for (int i = 0; i < values.length; ++i)
- {
- if (max < values[i])
- {
- max = values[i];
+ for (int value : values) {
+ if (max < value) {
+ max = value;
}
}
diff --git a/src/main/java/com/neovisionaries/ws/client/OkHostnameVerifier.java b/src/main/java/com/neovisionaries/ws/client/OkHostnameVerifier.java
index 798adcf..24592b5 100644
--- a/src/main/java/com/neovisionaries/ws/client/OkHostnameVerifier.java
+++ b/src/main/java/com/neovisionaries/ws/client/OkHostnameVerifier.java
@@ -58,7 +58,6 @@ final class OkHostnameVerifier implements HostnameVerifier {
private OkHostnameVerifier() {
}
- @Override
public boolean verify(String host, SSLSession session) {
try {
Certificate[] certificates = session.getPeerCertificates();
@@ -83,8 +82,8 @@ static boolean verifyAsIpAddress(String host) {
*/
private boolean verifyIpAddress(String ipAddress, X509Certificate certificate) {
List altNames = getSubjectAltNames(certificate, ALT_IPA_NAME);
- for (int i = 0, size = altNames.size(); i < size; i++) {
- if (ipAddress.equalsIgnoreCase(altNames.get(i))) {
+ for (String altName : altNames) {
+ if (ipAddress.equalsIgnoreCase(altName)) {
return true;
}
}
@@ -98,9 +97,9 @@ private boolean verifyHostName(String hostName, X509Certificate certificate) {
hostName = hostName.toLowerCase(Locale.US);
boolean hasDns = false;
List altNames = getSubjectAltNames(certificate, ALT_DNS_NAME);
- for (int i = 0, size = altNames.size(); i < size; i++) {
+ for (String altName : altNames) {
hasDns = true;
- if (verifyHostName(hostName, altNames.get(i))) {
+ if (verifyHostName(hostName, altName)) {
return true;
}
}
diff --git a/src/main/java/com/neovisionaries/ws/client/WebSocketFrame.java b/src/main/java/com/neovisionaries/ws/client/WebSocketFrame.java
index 4032dfc..c65ab98 100644
--- a/src/main/java/com/neovisionaries/ws/client/WebSocketFrame.java
+++ b/src/main/java/com/neovisionaries/ws/client/WebSocketFrame.java
@@ -745,9 +745,8 @@ private void appendPayloadBinary(StringBuilder builder)
return;
}
- for (int i = 0; i < mPayload.length; ++i)
- {
- builder.append(String.format("%02X ", (0xFF & mPayload[i])));
+ for (byte b : mPayload) {
+ builder.append(String.format("%02X ", (0xFF & b)));
}
if (mPayload.length != 0)
@@ -1199,7 +1198,8 @@ private static List split(WebSocketFrame frame, int maxPayloadSi
// Generate the first frame using the existing WebSocketFrame instance.
// Note that the reserved bit 1 and the opcode are untouched.
- byte[] payload = Arrays.copyOf(originalPayload, maxPayloadSize);
+ byte[] payload = new byte[maxPayloadSize];
+ System.arraycopy(originalPayload, 0, payload, 0, Math.min(originalPayload.length, maxPayloadSize));
frame.setFin(false).setPayload(payload);
frames.add(frame);
@@ -1207,7 +1207,8 @@ private static List split(WebSocketFrame frame, int maxPayloadSi
{
// Prepare the payload of the next continuation frame.
int to = Math.min(from + maxPayloadSize, originalPayload.length);
- payload = Arrays.copyOfRange(originalPayload, from, to);
+ assert (to - from) >= 0;
+ System.arraycopy(originalPayload, from, payload, 0, Math.min(originalPayload.length - from, to - from));
// Create a continuation frame.
WebSocketFrame cont = WebSocketFrame.createContinuationFrame(payload);