broker/test/Utils: code formatter used

This commit is contained in:
Andreas Mager
2017-02-01 17:13:41 +01:00
parent 00d7480e9b
commit ae43010da3
+19 -17
View File
@@ -13,6 +13,7 @@
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.moquette;
import io.netty.buffer.ByteBuf;
@@ -23,7 +24,6 @@ import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import io.netty.util.AttributeMap;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
/**
@@ -66,8 +66,7 @@ public class Utils {
}
/**
* Decode the variable remaining length as defined in MQTT v3.1 specification
* (section 2.1).
* Decode the variable remaining length as defined in MQTT v3.1 specification (section 2.1).
*
* @return the decoded length or -1 if needed more data to decode the length field.
*/
@@ -87,11 +86,10 @@ public class Utils {
}
/**
* Encode the value in the format defined in specification as variable length
* array.
* Encode the value in the format defined in specification as variable length array.
*
* @throws IllegalArgumentException if the value is not in the specification bounds
* [0..268435455].
* @throws IllegalArgumentException
* if the value is not in the specification bounds [0..268435455].
*/
static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException {
if (value > MAX_LENGTH_LIMIT || value < 0) {
@@ -113,8 +111,8 @@ public class Utils {
}
/**
* Load a string from the given buffer, reading first the two bytes of len
* and then the UTF-8 bytes of the string.
* Load a string from the given buffer, reading first the two bytes of len and then the UTF-8
* bytes of the string.
*
* @return the decoded string or null if NEED_DATA
*/
@@ -123,8 +121,9 @@ public class Utils {
}
/**
* Read a byte array from the buffer, use two bytes as length information followed by length bytes.
* */
* Read a byte array from the buffer, use two bytes as length information followed by length
* bytes.
*/
static byte[] readFixedLengthContent(ByteBuf in) throws UnsupportedEncodingException {
if (in.readableBytes() < 2) {
return null;
@@ -140,8 +139,7 @@ public class Utils {
}
/**
* Return the IoBuffer with string encoded as MSB, LSB and UTF-8 encoded
* string content.
* Return the IoBuffer with string encoded as MSB, LSB and UTF-8 encoded string content.
*/
public static ByteBuf encodeString(String str) {
byte[] raw;
@@ -170,10 +168,14 @@ public class Utils {
* Return the number of bytes to encode the given remaining length value
*/
static int numBytesToEncode(int len) {
if (0 <= len && len <= 127) return 1;
if (128 <= len && len <= 16383) return 2;
if (16384 <= len && len <= 2097151) return 3;
if (2097152 <= len && len <= 268435455) return 4;
if (0 <= len && len <= 127)
return 1;
if (128 <= len && len <= 16383)
return 2;
if (16384 <= len && len <= 2097151)
return 3;
if (2097152 <= len && len <= 268435455)
return 4;
throw new IllegalArgumentException("value shoul be in the range [0..268435455]");
}