Adjusted byte array method to remove most of magic numbers. 15/3015/2
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 22 Nov 2013 14:06:05 +0000 (15:06 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 22 Nov 2013 15:42:55 +0000 (16:42 +0100)
Change-Id: I6227e2f710cd2d396c69ce9502bb57da7442677f
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
29 files changed:
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPNotificationMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/MessageUtil.java
concepts/src/test/java/org/opendaylight/protocol/concepts/BandwidthTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/AbstractMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractObjectWithTlvsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/Type1LabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/WavebandSwitchingLabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROAsNumberSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROIpPrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROSRLGSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
util/src/main/java/org/opendaylight/protocol/util/ByteArray.java
util/src/test/java/org/opendaylight/protocol/util/ByteArrayTest.java

index c40ffb67e8105023acc4e05e9aa3e2ff40383a90..7de065201428bd6c0065a53d2223d67092d36e3f 100644 (file)
@@ -365,6 +365,8 @@ public final class LinkstateNlriParser implements NlriParser {
        }
 
        public static byte[] serializeNlri(final CLinkstateDestination destination) {
+               final byte[] typeBytes = ByteArray.intToBytes(destination.getNlriType().getIntValue(), TYPE_LENGTH);
+
                // FIXME: BUG-108: finish this
                throw new UnsupportedOperationException("BUG-108: not implemented");
        }
index 54b92d3e9fe2d4f13acb3e65292709ba5ba36d43..d078394bc07a15127aaeccb2955a9ded69dd536b 100644 (file)
@@ -50,9 +50,9 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
 
                final byte[] msgBody = (ntf.getData() == null) ? new byte[ERROR_SIZE] : new byte[ERROR_SIZE + ntf.getData().length];
 
-               msgBody[0] = ByteArray.intToBytes(ntf.getErrorCode())[Integer.SIZE / Byte.SIZE - 1];
+               msgBody[0] = UnsignedBytes.checkedCast(ntf.getErrorCode());
 
-               msgBody[1] = ByteArray.intToBytes(ntf.getErrorSubcode())[Integer.SIZE / Byte.SIZE - 1];
+               msgBody[1] = UnsignedBytes.checkedCast(ntf.getErrorSubcode());
 
                if (ntf.getData() != null) {
                        System.arraycopy(ntf.getData(), 0, msgBody, ERROR_SIZE, ntf.getData().length);
index 3eced158a9eb78eed255223cec4701c22d7326a0..ba6385171cbd1d8bb17a24bbec2da978c81b80d7 100644 (file)
@@ -94,7 +94,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                int offset = 0;
 
-               msgBody[offset] = ByteArray.intToBytes(BGP_VERSION)[(Integer.SIZE / Byte.SIZE) - 1];
+               msgBody[offset] = UnsignedBytes.checkedCast(BGP_VERSION);
                offset += VERSION_SIZE;
 
                // When our AS number does not fit into two bytes, we report it as AS_TRANS
@@ -103,16 +103,16 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                        openAS = AS_TRANS;
                }
 
-               System.arraycopy(ByteArray.longToBytes(openAS), 6, msgBody, offset, AS_SIZE);
+               System.arraycopy(ByteArray.longToBytes(openAS, AS_SIZE), 0, msgBody, offset, AS_SIZE);
                offset += AS_SIZE;
 
-               System.arraycopy(ByteArray.intToBytes(open.getHoldTimer()), 2, msgBody, offset, HOLD_TIME_SIZE);
+               System.arraycopy(ByteArray.intToBytes(open.getHoldTimer(), HOLD_TIME_SIZE), 0, msgBody, offset, HOLD_TIME_SIZE);
                offset += HOLD_TIME_SIZE;
 
                System.arraycopy(Ipv4Util.bytesForAddress(open.getBgpIdentifier()), 0, msgBody, offset, BGP_ID_SIZE);
                offset += BGP_ID_SIZE;
 
-               msgBody[offset] = ByteArray.intToBytes(optParamsLength)[Integer.SIZE / Byte.SIZE - 1];
+               msgBody[offset] = UnsignedBytes.checkedCast(optParamsLength);
 
                int index = MIN_MSG_LENGTH;
                if (optParams != null) {
@@ -145,8 +145,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                        throw BGPDocumentedException.badMessageLength("Open message too small.", messageLength);
                }
                if (UnsignedBytes.toInt(body[0]) != BGP_VERSION) {
-                       throw new BGPDocumentedException("BGP Protocol version " + UnsignedBytes.toInt(body[0]) + " not supported.", BGPError.VERSION_NOT_SUPPORTED, ByteArray.subByte(
-                                       ByteArray.intToBytes(BGP_VERSION), 2, 2));
+                       throw new BGPDocumentedException("BGP Protocol version " + UnsignedBytes.toInt(body[0]) + " not supported.", BGPError.VERSION_NOT_SUPPORTED);
                }
 
                int offset = VERSION_SIZE;
index f976affd6f74135f1dfe89af4cde528c043deded..e158c10ccc4d6aae1fde87826afc9ecc58f83883 100644 (file)
@@ -36,7 +36,6 @@ public final class As4CapabilityHandler implements CapabilityParser, CapabilityS
        }
 
        private static byte[] putAS4BytesParameterValue(final CAs4Bytes param) {
-               return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), Long.SIZE / Byte.SIZE
-                               - AS4_LENGTH, AS4_LENGTH);
+               return ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue(), AS4_LENGTH);
        }
 }
\ No newline at end of file
index 890c5e4d22a8c72fc1066d2f7ce6813a20760712..fc500ee880951f1a59ee231cbdb3655c51a63ced 100644 (file)
@@ -36,8 +36,8 @@ public final class MessageUtil {
                final byte[] retBytes = new byte[COMMON_HEADER_LENGTH + body.length];
 
                Arrays.fill(retBytes, 0, MARKER_LENGTH, UnsignedBytes.MAX_VALUE);
-               System.arraycopy(ByteArray.intToBytes(body.length + COMMON_HEADER_LENGTH), Integer.SIZE / Byte.SIZE - LENGTH_FIELD_LENGTH,
-                               retBytes, MARKER_LENGTH, LENGTH_FIELD_LENGTH);
+               System.arraycopy(ByteArray.intToBytes(body.length + COMMON_HEADER_LENGTH, LENGTH_FIELD_LENGTH), 0, retBytes, MARKER_LENGTH,
+                               LENGTH_FIELD_LENGTH);
 
                retBytes[MARKER_LENGTH + LENGTH_FIELD_LENGTH] = UnsignedBytes.checkedCast(type);
                ByteArray.copyWhole(body, retBytes, COMMON_HEADER_LENGTH);
index 6fced21e9dae2ce2d8ce9e2be6d2d737f9b02cbe..6fed7a34e1ff32bfe61b42c0ca14a13bca55fcff 100644 (file)
@@ -27,10 +27,10 @@ public class BandwidthTest {
 
        @Before
        public void setUp() {
-               this.b1 = new Bandwidth(ByteArray.intToBytes(1000));
-               this.b2 = new Bandwidth(ByteArray.intToBytes(2000));
-               this.b3 = new Bandwidth(ByteArray.intToBytes(2000));
-               this.b4 = new Bandwidth(ByteArray.intToBytes(100));
+               this.b1 = new Bandwidth(ByteArray.intToBytes(1000, 4));
+               this.b2 = new Bandwidth(ByteArray.intToBytes(2000, 4));
+               this.b3 = new Bandwidth(ByteArray.intToBytes(2000, 4));
+               this.b4 = new Bandwidth(ByteArray.intToBytes(100, 4));
        }
 
        @Test
index 46dbb3fae01dafc2c1a32fae3d9a6bd5a16ceb18..d9a963960f60251fe6b957a05ba276253542473a 100644 (file)
@@ -83,8 +83,8 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
                }
 
                // objLength
-               System.arraycopy(ByteArray.intToBytes(valueBytes.length + COMMON_OBJECT_HEADER_LENGTH), Integer.SIZE / Byte.SIZE
-                               - OBJ_LENGTH_F_LENGTH, retBytes, OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH);
+               System.arraycopy(ByteArray.intToBytes(valueBytes.length + COMMON_OBJECT_HEADER_LENGTH, OBJ_LENGTH_F_LENGTH), 0, retBytes,
+                               OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH);
 
                ByteArray.copyWhole(valueBytes, retBytes, COMMON_OBJECT_HEADER_LENGTH);
                return retBytes;
index d09ad9da999e431c56a2cc570b7cd0a7eab1b978..07bedc66164bbb91d64d53946c2c102034b39fd6 100644 (file)
@@ -74,11 +74,11 @@ public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, O
 
                final TlvSerializer serializer = this.tlvReg.getTlvSerializer(tlv);
 
-               final byte[] typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - TLV_TYPE_F_LENGTH));
+               final byte[] typeBytes = ByteArray.intToBytes(serializer.getType(), TLV_TYPE_F_LENGTH);
 
                final byte[] valueBytes = serializer.serializeTlv(tlv);
 
-               final byte[] lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - TLV_LENGTH_F_LENGTH);
+               final byte[] lengthBytes = ByteArray.intToBytes(valueBytes.length, TLV_LENGTH_F_LENGTH);
 
                final byte[] bytes = new byte[TLV_HEADER_LENGTH + valueBytes.length + getPadding(TLV_HEADER_LENGTH + valueBytes.length, PADDED_TO)];
 
index 6642900ba90775d33e530c495b4f2ec5b2938f71..fe501ca3ab7016a0ae63918c305c8a8319024ceb 100644 (file)
@@ -96,9 +96,12 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<LspaBuild
 
                final byte[] retBytes = new byte[TLVS_F_OFFSET];
 
-               System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny().getValue()), 4, retBytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH);
-               System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny().getValue()), 4, retBytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH);
-               System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll().getValue()), 4, retBytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH);
+               System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny().getValue(), EXC_ANY_F_LENGTH), 0, retBytes, EXC_ANY_F_OFFSET,
+                               EXC_ANY_F_LENGTH);
+               System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny().getValue(), INC_ANY_F_LENGTH), 0, retBytes, INC_ANY_F_OFFSET,
+                               INC_ANY_F_LENGTH);
+               System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll().getValue(), INC_ALL_F_LENGTH), 0, retBytes, INC_ALL_F_OFFSET,
+                               INC_ALL_F_LENGTH);
                retBytes[SET_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getSetupPriority());
                retBytes[HOLD_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getHoldPriority());
 
index c175185dcbe6ebed21fd388d9d85fef5d399e52f..efbf5ee44a9eb767941e24af40076bf084e9d59e 100644 (file)
@@ -107,11 +107,11 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
                final RpBuilder builder = new RpBuilder();
                builder.setIgnore(header.isIgnore());
 
-               //FIXME : change binary files
-               //if (!header.isProcessingRule()) {
-               //LOG.debug("Processed bit not set on RP OBJECT, ignoring it");
-               //      return null;
-               //}
+               // FIXME : change binary files
+               // if (!header.isProcessingRule()) {
+               // LOG.debug("Processed bit not set on RP OBJECT, ignoring it");
+               // return null;
+               // }
 
                builder.setProcessingRule(header.isProcessingRule());
 
@@ -164,8 +164,7 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
                final byte[] retBytes = new byte[TLVS_OFFSET + tlvs.length + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_PRI_MF_LENGTH), retBytes, FLAGS_PRI_MF_OFFSET);
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(rPObj.getRequestId().getValue()), (Long.SIZE / Byte.SIZE)
-                               - RID_F_LENGTH, RID_F_LENGTH), retBytes, RID_F_OFFSET);
+               ByteArray.copyWhole(ByteArray.longToBytes(rPObj.getRequestId().getValue(), RID_F_LENGTH), retBytes, RID_F_OFFSET);
                if (tlvs.length != 0) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
                }
index 7a19b6266fe388d0e293707442a9bdd622939d7b..252d63eeaaee6d600d7dc2c223a7f12389d79a68 100644 (file)
@@ -77,7 +77,7 @@ public final class PCEPSrpObjectParser extends AbstractObjectWithTlvsParser<SrpB
                        throw new IllegalArgumentException("Min/Max values for SRP ID are reserved.");
                }
                final byte[] retBytes = new byte[MIN_SIZE];
-               System.arraycopy(ByteArray.intToBytes(id.intValue()), 0, retBytes, FLAGS_SIZE, SRP_ID_SIZE);
+               System.arraycopy(ByteArray.intToBytes(id.intValue(), SRP_ID_SIZE), 0, retBytes, FLAGS_SIZE, SRP_ID_SIZE);
                return retBytes;
        }
 
index 666af449dfb47a28fd5dfa6134dd8dd1445dd97f..32f4c3562aaa35821c77b6b01adc0c2f374a3d5e 100644 (file)
@@ -111,8 +111,8 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
                ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
 
                for (int i = 0; i < requestIDs.size(); i++) {
-                       System.arraycopy(ByteArray.longToBytes(requestIDs.get(i).getValue()), 4, retBytes, REQ_LIST_ITEM_LENGTH * i
-                                       + REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH);
+                       System.arraycopy(ByteArray.longToBytes(requestIDs.get(i).getValue(), REQ_LIST_ITEM_LENGTH), 0, retBytes, REQ_LIST_ITEM_LENGTH
+                                       * i + REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH);
                }
                assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
                return retBytes;
index e39d7713e1c01b9113b83f2830efea90bdfbfd31..b1cf7da4f3b1097b034f08fa979eafcba7c8585e 100644 (file)
@@ -56,8 +56,8 @@ public class EROAsNumberSubobjectParser implements EROSubobjectParser, EROSubobj
 
                final SubobjectType s = subobject.getSubobjectType();
 
-               System.arraycopy(ByteArray.longToBytes(((AsNumberSubobject) s).getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH,
-                               retBytes, AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
+               System.arraycopy(ByteArray.longToBytes(((AsNumberSubobject) s).getAsNumber().getValue(), AS_NUMBER_LENGTH), 0, retBytes,
+                               AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
 
                return retBytes;
        }
index 19bbe79b8c337c55db98a7482e60e9e9c4cfdc35..4a1dd49fcc1da1a6f936bbd52d42d91ba0a2363f 100644 (file)
@@ -61,9 +61,8 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
                byte[] retBytes;
                retBytes = new byte[CONTENT_LENGTH];
                final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
-                               ROUTER_ID_NUMBER_OFFSET);
-               System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
+               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId(), ROUTER_ID_NUMBER_LENGTH), retBytes, ROUTER_ID_NUMBER_OFFSET);
+               System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId(), INTERFACE_ID_NUMBER_LENGTH), 0, retBytes,
                                INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
                return retBytes;
        }
index 371ae41f26bd5e3dec64ce5922aee8e00555b534..c077cfa08f48bef8b6644755ebfa5752b5a883aa 100644 (file)
@@ -74,9 +74,8 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
                flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
                flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
                retBytes[0] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
-                               ROUTER_ID_NUMBER_OFFSET);
-               System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
+               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId(), ROUTER_ID_NUMBER_LENGTH), retBytes, ROUTER_ID_NUMBER_OFFSET);
+               System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId(), INTERFACE_ID_NUMBER_LENGTH), 0, retBytes,
                                INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
                return retBytes;
        }
index 314f8beae843ec0c99bca6e6dcfa3e482711a07e..14733e94556cbe914f7d7ae3706da412737fa581 100644 (file)
@@ -40,7 +40,7 @@ public class Type1LabelParser implements LabelParser, LabelSerializer {
                if (!(subobject instanceof Type1Label)) {
                        throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass() + ". Needed Type1Label.");
                }
-               return ByteArray.subByte(ByteArray.longToBytes(((Type1Label) subobject).getType1Label().longValue()), 4, LABEL_LENGTH);
+               return ByteArray.longToBytes(((Type1Label) subobject).getType1Label().longValue(), LABEL_LENGTH);
        }
 
        @Override
index 41e6dfce3d613127e24e00b62c36aa0c02bcbbcb..01cf194fc162ae3e37027dad08e7aa969eff255f 100644 (file)
@@ -55,9 +55,10 @@ public class WavebandSwitchingLabelParser implements LabelParser, LabelSerialize
                }
                final byte[] retBytes = new byte[CONTENT_LENGTH];
                final WavebandSwitchingLabel obj = (WavebandSwitchingLabel) subobject;
-               System.arraycopy(ByteArray.intToBytes(obj.getWavebandId().intValue()), 0, retBytes, 0, WAVEB_F_LENGTH);
-               System.arraycopy(ByteArray.intToBytes(obj.getStartLabel().intValue()), 0, retBytes, WAVEB_F_LENGTH, START_F_LENGTH);
-               System.arraycopy(ByteArray.intToBytes(obj.getEndLabel().intValue()), 0, retBytes, WAVEB_F_LENGTH + START_F_LENGTH, END_F_LENGTH);
+               System.arraycopy(ByteArray.intToBytes(obj.getWavebandId().intValue(), WAVEB_F_LENGTH), 0, retBytes, 0, WAVEB_F_LENGTH);
+               System.arraycopy(ByteArray.intToBytes(obj.getStartLabel().intValue(), START_F_LENGTH), 0, retBytes, WAVEB_F_LENGTH, START_F_LENGTH);
+               System.arraycopy(ByteArray.intToBytes(obj.getEndLabel().intValue(), END_F_LENGTH), 0, retBytes, WAVEB_F_LENGTH + START_F_LENGTH,
+                               END_F_LENGTH);
                return retBytes;
        }
 
index 34cd6262ec40ca4d7c0a5718be63504baca64ec1..d715bf95572c55bf829bfaa950b09e0bae26827e 100644 (file)
@@ -51,8 +51,8 @@ public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobj
                }
                final byte[] retBytes = new byte[CONTENT_LENGTH];
                final AsNumberSubobject obj = (AsNumberSubobject) subobject.getSubobjectType();
-               System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes,
-                               AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
+               System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue(), AS_NUMBER_LENGTH), 0, retBytes, AS_NUMBER_OFFSET,
+                               AS_NUMBER_LENGTH);
                return retBytes;
        }
 
index e2862ee7d7a4ebcc83ab8825655a23453b72cb63..bbf1f967e8fbbb70455420e25afb94707837a397 100644 (file)
@@ -87,13 +87,13 @@ public class XROIpPrefixSubobjectParser implements XROSubobjectParser, XROSubobj
                if (prefix.getIpv4Prefix() != null) {
                        final byte[] retBytes = new byte[CONTENT4_LENGTH];
                        ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, IP_F_OFFSET);
-                       retBytes[PREFIX4_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       retBytes[PREFIX4_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
                        retBytes[ATTRIBUTE4_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
                        return retBytes;
                } else {
                        final byte[] retBytes = new byte[CONTENT6_LENGTH];
                        ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, IP_F_OFFSET);
-                       retBytes[PREFIX6_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       retBytes[PREFIX6_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
                        retBytes[ATTRIBUTE6_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
                        return retBytes;
                }
index 460a2d38f130246f065e8733d144c080172e6299..ce640d1a226d5584da632b2c2d4bd7810063d654 100644 (file)
@@ -64,8 +64,7 @@ public class XROSRLGSubobjectParser implements XROSubobjectParser, XROSubobjectS
                retBytes = new byte[CONTENT_LENGTH];
                final SrlgSubobject specObj = (SrlgSubobject) subobject.getSubobjectType();
 
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getSrlgId().getValue()), 4, SRLG_ID_NUMBER_LENGTH), retBytes,
-                               SRLG_ID_NUMBER_OFFSET);
+               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getSrlgId().getValue(), SRLG_ID_NUMBER_LENGTH), retBytes, SRLG_ID_NUMBER_OFFSET);
                retBytes[ATTRIBUTE_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
 
                return retBytes;
index 87f201709b7311044c82bad7beaa429c12963740..26bf0a5624009e673c632e14dfe4d268e5d8ad68 100644 (file)
@@ -69,9 +69,8 @@ public class XROUnnumberedInterfaceSubobjectParser implements XROSubobjectParser
                final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
 
                retBytes[ATTRIBUTE_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
-                               ROUTER_ID_NUMBER_OFFSET);
-               System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
+               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId(), ROUTER_ID_NUMBER_LENGTH), retBytes, ROUTER_ID_NUMBER_OFFSET);
+               System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId(), INTERFACE_ID_NUMBER_LENGTH), 0, retBytes,
                                INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
                return retBytes;
        }
index 526f3a07e716c52ef5bc3fcae3122ca1846b6178..872789512d3dea263001bb1df021f16944bcc613 100644 (file)
@@ -99,9 +99,9 @@ public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {
                        final Ipv4 ipv4 = (Ipv4) afi;
                        ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelSenderAddress()), bytes, offset);
                        offset += IP4_F_LENGTH;
-                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+                       ByteArray.copyWhole(ByteArray.longToBytes(lsp.getLspId().getValue(), LSP_ID_F_LENGTH), bytes, offset);
                        offset += LSP_ID_F_LENGTH;
-                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+                       ByteArray.copyWhole(ByteArray.intToBytes(lsp.getTunnelId().getValue(), TUNNEL_ID_F_LENGTH), bytes, offset);
                        offset += TUNNEL_ID_F_LENGTH;
                        ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()), bytes, offset);
                        return bytes;
@@ -110,9 +110,9 @@ public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {
                        final Ipv6 ipv6 = (Ipv6) afi;
                        ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelSenderAddress()), bytes, offset);
                        offset += IP6_F_LENGTH;
-                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+                       ByteArray.copyWhole(ByteArray.longToBytes(lsp.getLspId().getValue(), LSP_ID_F_LENGTH), bytes, offset);
                        offset += LSP_ID_F_LENGTH;
-                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+                       ByteArray.copyWhole(ByteArray.intToBytes(lsp.getTunnelId().getValue(), TUNNEL_ID_F_LENGTH), bytes, offset);
                        offset += TUNNEL_ID_F_LENGTH;
                        ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()), bytes, offset);
                        return bytes;
index 39cecb0baa9f000371cd8d16ddccb6543eeb19dd..de73cafe1060644e363f227352f873b5a2bf4021 100644 (file)
@@ -35,7 +35,7 @@ public class LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
                        throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
                }
                final LspErrorCode lsp = (LspErrorCode) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), UPDATE_ERR_CODE_LENGTH, UPDATE_ERR_CODE_LENGTH);
+               return ByteArray.longToBytes(lsp.getErrorCode(), UPDATE_ERR_CODE_LENGTH);
        }
 
        @Override
index 646c5b7737fb99b0b4a215ee4f13a362a0719d8a..aeca92b5e4aa586cfd114768f121840d18da4e24 100644 (file)
@@ -40,9 +40,9 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
                final Order otlv = (Order) tlv;
                final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
                int offset = 0;
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH), bytes, offset);
+               ByteArray.copyWhole(ByteArray.longToBytes(otlv.getDelete(), ORDR_DEL_LENGTH), bytes, offset);
                offset += ORDR_DEL_LENGTH;
-               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH), bytes, offset);
+               ByteArray.copyWhole(ByteArray.longToBytes(otlv.getSetup(), ORDR_SETUP_LENGTH), bytes, offset);
                return bytes;
        }
 
index e65c70fbfe77cb6591f6e92b997a676947085fda..49b536871fdf67efc21521ac93409245266e519d 100644 (file)
@@ -35,7 +35,7 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
                        throw new IllegalArgumentException("OverloadedTlv is mandatory.");
                }
                final OverloadDuration odt = (OverloadDuration) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), OVERLOADED_DURATION_LENGTH, OVERLOADED_DURATION_LENGTH);
+               return ByteArray.longToBytes(odt.getDuration(), OVERLOADED_DURATION_LENGTH);
        }
 
        @Override
index 823644be2c7b6b1321c151811a274f22882699cb..3281a5bd027ce9f9c5b503c4647ade4ac2d5854b 100644 (file)
@@ -119,9 +119,9 @@ public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
        }
 
        private byte[] serializerUserError(final UserError ue) {
-               final byte[] enterprise = ByteArray.subByte(ByteArray.longToBytes(ue.getEnterprise().getValue()), 4, ENTERPRISE_F_LENGTH);
+               final byte[] enterprise = ByteArray.longToBytes(ue.getEnterprise().getValue(), ENTERPRISE_F_LENGTH);
                final byte suborg = UnsignedBytes.checkedCast(ue.getSubOrg());
-               final byte[] value = ByteArray.subByte(ByteArray.intToBytes(ue.getValue()), 2, USER_VALUE_F_LENGTH);
+               final byte[] value = ByteArray.intToBytes(ue.getValue(), USER_VALUE_F_LENGTH);
                final byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
                final byte descLen = UnsignedBytes.checkedCast(desc.length);
                // TODO: if we have any subobjects
@@ -189,7 +189,7 @@ public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
                offset += FLAGS_F_LENGTH;
                bytes[offset] = UnsignedBytes.checkedCast(rsvp.getCode());
                offset += ERROR_CODE_F_LENGTH;
-               final byte[] value = ByteArray.subByte(ByteArray.intToBytes(rsvp.getValue().intValue()), 2, ERROR_VALUE_F_LENGTH);
+               final byte[] value = ByteArray.intToBytes(rsvp.getValue().intValue(), ERROR_VALUE_F_LENGTH);
                ByteArray.copyWhole(value, bytes, offset);
                return bytes;
        }
index 4c92d19c4eeccd444a8fd13c6e4411f8e1f30a66..69604c7b6313d95b0eb9dd85b8945ce3da38a912 100644 (file)
@@ -36,7 +36,7 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
                        throw new IllegalArgumentException("ReqMissingTlv is mandatory.");
                }
                final ReqMissing req = (ReqMissing) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), REQ_ID_LENGTH, REQ_ID_LENGTH);
+               return ByteArray.longToBytes(req.getRequestId().getValue(), REQ_ID_LENGTH);
        }
 
        @Override
index 40b9be86960e457fb74c029a5c8b0fefc6226176..a9e1f082f8b2e8586236523038c24cb762fd70d5 100644 (file)
@@ -212,10 +212,21 @@ public final class ByteArray {
         * @return parsed array of bytes with length of Integer.SIZE/Byte.SIZE
         */
        public static byte[] intToBytes(final int num) {
-               final ByteBuffer bytesBuffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
-               bytesBuffer.putInt(num);
+               return intToBytes(num, Integer.SIZE / Byte.SIZE);
+       }
 
-               return bytesBuffer.array();
+       /**
+        * Parses integer to array of bytes
+        * 
+        * @param num integer to be parsed
+        * @param size desired byte array length
+        * @return parsed array of bytes with length of size
+        */
+       public static byte[] intToBytes(final int num, final int size) {
+               final int finalSize = Integer.SIZE / Byte.SIZE;
+               final ByteBuffer bytesBuffer = ByteBuffer.allocate(finalSize);
+               bytesBuffer.putInt(num);
+               return ByteArray.subByte(bytesBuffer.array(), finalSize - size, size);
        }
 
        /**
@@ -224,11 +235,22 @@ public final class ByteArray {
         * @param num long to be parsed
         * @return parsed array of bytes with length of Long.SIZE/Byte.SIZE
         */
-       public static byte[] longToBytes(final long num) {
-               final ByteBuffer bytesBuffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
-               bytesBuffer.putLong(num);
+       public static byte[] longToBytes(final int num) {
+               return longToBytes(num, Long.SIZE / Byte.SIZE);
+       }
 
-               return bytesBuffer.array();
+       /**
+        * Parses long to array of bytes
+        * 
+        * @param num long to be parsed
+        * @param size desired byte array length
+        * @return parsed array of bytes with length of size
+        */
+       public static byte[] longToBytes(final long num, final int size) {
+               final int finalSize = Long.SIZE / Byte.SIZE;
+               final ByteBuffer bytesBuffer = ByteBuffer.allocate(finalSize);
+               bytesBuffer.putLong(num);
+               return ByteArray.subByte(bytesBuffer.array(), finalSize - size, size);
        }
 
        /**
index 54f1f639e2152f20d35f3c25758e13df53b08b24..06d2ea9448a7ac13e30b04d4cfde619cf645d3db 100644 (file)
@@ -44,32 +44,32 @@ public class ByteArrayTest {
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testSubByte2(){
+       public void testSubByte2() {
                ByteArray.subByte(new byte[0], 2, 2);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testSubByte3(){
+       public void testSubByte3() {
                ByteArray.subByte(this.before, 2, -1);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testSubByte4(){
+       public void testSubByte4() {
                ByteArray.subByte(this.before, -1, 2);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testSubByte5(){
+       public void testSubByte5() {
                ByteArray.subByte(this.before, 9, 2);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testSubByte6(){
+       public void testSubByte6() {
                ByteArray.subByte(this.before, 2, 19);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testSubByte7(){
+       public void testSubByte7() {
                ByteArray.subByte(this.before, 2, 7);
        }
 
@@ -84,17 +84,17 @@ public class ByteArrayTest {
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCutBytes2(){
+       public void testCutBytes2() {
                ByteArray.cutBytes(new byte[0], 5);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCutBytes3(){
+       public void testCutBytes3() {
                ByteArray.cutBytes(this.before, 9);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCutBytes4(){
+       public void testCutBytes4() {
                ByteArray.cutBytes(this.before, 0);
        }
 
@@ -179,21 +179,23 @@ public class ByteArrayTest {
 
        @Test
        public void testIntToBytes() {
-               assertEquals(Integer.MAX_VALUE, ByteArray.bytesToInt(ByteArray.intToBytes(Integer.MAX_VALUE)));
-               assertEquals(Integer.MIN_VALUE, ByteArray.bytesToInt(ByteArray.intToBytes(Integer.MIN_VALUE)));
-               assertEquals(5, ByteArray.bytesToInt(ByteArray.intToBytes(5)));
+               assertEquals(Integer.MAX_VALUE, ByteArray.bytesToInt(ByteArray.intToBytes(Integer.MAX_VALUE, Integer.SIZE / Byte.SIZE)));
+               assertEquals(Integer.MIN_VALUE, ByteArray.bytesToInt(ByteArray.intToBytes(Integer.MIN_VALUE, Integer.SIZE / Byte.SIZE)));
+               assertEquals(2, ByteArray.intToBytes(12, 2).length);
+               assertArrayEquals(new byte[] { 0, 12 }, ByteArray.intToBytes(12, 2));
+               assertEquals(5, ByteArray.bytesToInt(ByteArray.intToBytes(5, 2)));
        }
 
        @Test
        public void testLongToBytes_bytesToLong() {
-               assertEquals(Long.MAX_VALUE, ByteArray.bytesToLong(ByteArray.longToBytes(Long.MAX_VALUE)));
-               assertEquals(Long.MIN_VALUE, ByteArray.bytesToLong(ByteArray.longToBytes(Long.MIN_VALUE)));
-               assertEquals(5, ByteArray.bytesToLong(ByteArray.longToBytes(5)));
+               assertEquals(Long.MAX_VALUE, ByteArray.bytesToLong(ByteArray.longToBytes(Long.MAX_VALUE, Long.SIZE / Byte.SIZE)));
+               assertEquals(Long.MIN_VALUE, ByteArray.bytesToLong(ByteArray.longToBytes(Long.MIN_VALUE, Long.SIZE / Byte.SIZE)));
+               assertArrayEquals(new byte[] { 0, 0, 5 }, ByteArray.longToBytes(5L, 3));
+               assertEquals(5, ByteArray.bytesToLong(ByteArray.longToBytes(5, 2)));
        }
 
        /**
-        * if less than 4 bytes are converted, zero bytes should be appendet at the
-        * buffer's start
+        * if less than 4 bytes are converted, zero bytes should be appendet at the buffer's start
         */
        @Test
        public void testBytesToLong_prependingZeros() {
@@ -201,26 +203,25 @@ public class ByteArrayTest {
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testBytesToInt(){
+       public void testBytesToInt() {
                final byte[] b = new byte[Integer.SIZE + 1];
                ByteArray.bytesToInt(b);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testBytesToShort2(){
+       public void testBytesToShort2() {
                final byte[] b = new byte[Short.SIZE + 1];
                ByteArray.bytesToInt(b);
        }
 
        @Test
-       public void testBytes(){
-               assertTrue(ByteArray.bytesToInt(new byte[]{ 0, 0, 0, 15}) == 15);
-               assertEquals(Float.valueOf((float) 1.4E-45), Float.valueOf(ByteArray.bytesToFloat(new byte[]{ 0, 0, 0, 1})));
+       public void testBytes() {
+               assertTrue(ByteArray.bytesToInt(new byte[] { 0, 0, 0, 15 }) == 15);
+               assertEquals(Float.valueOf((float) 1.4E-45), Float.valueOf(ByteArray.bytesToFloat(new byte[] { 0, 0, 0, 1 })));
                assertEquals(Long.valueOf(16613001005322L), Long.valueOf(ByteArray.bytesToLong(this.before)));
-               assertEquals(Short.valueOf((short) 1), Short.valueOf(ByteArray.bytesToShort(new byte[]{0, 1})));
+               assertEquals(Short.valueOf((short) 1), Short.valueOf(ByteArray.bytesToShort(new byte[] { 0, 1 })));
        }
 
-
        @Test
        public void testCopyBitRange() {
                assertEquals((byte) 10, ByteArray.copyBitsRange((byte) 0x28, 2, 4));
@@ -233,27 +234,27 @@ public class ByteArrayTest {
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCopyBitsRange2(){
+       public void testCopyBitsRange2() {
                ByteArray.copyBitsRange((byte) 0x28, -1, 4);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCopyBitsRange3(){
+       public void testCopyBitsRange3() {
                ByteArray.copyBitsRange((byte) 0x28, 1, 187);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCopyBitsRange4(){
+       public void testCopyBitsRange4() {
                ByteArray.copyBitsRange((byte) 0x28, 1, 40);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCopyBitsRange5(){
+       public void testCopyBitsRange5() {
                ByteArray.copyBitsRange((byte) 0x28, 28, 2);
        }
 
        @Test(expected = IllegalArgumentException.class)
-       public void testCopyBitsRange6(){
+       public void testCopyBitsRange6() {
                ByteArray.copyBitsRange((byte) 0x28, 2, -2);
        }
 
@@ -274,7 +275,7 @@ public class ByteArrayTest {
        }
 
        @Test(expected = ArrayIndexOutOfBoundsException.class)
-       public void testCopyWhole2(){
+       public void testCopyWhole2() {
                ByteArray.copyWhole(new byte[0], new byte[1], 2);
        }
 
@@ -319,7 +320,8 @@ public class ByteArrayTest {
 
        @Test
        public void testBytesToHexString() {
-               final byte[] b = new byte[] { 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, };
+               final byte[] b = new byte[] { 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01,
+                               0x16, };
                final String expected = "01 16 01 16 01 16 01 16  01 16 01 16 01 16 01 16\n01 16 ";
                assertEquals(expected, ByteArray.bytesToHexString(b));
        }
@@ -344,21 +346,21 @@ public class ByteArrayTest {
 
        @Test
        public void testFindByteSequence() {
-               final byte[] bytes = new byte[] { (byte)36, (byte)41, (byte)55, (byte)101, (byte)38 };
-               final byte[] sequence1 = new byte[] { (byte)36, (byte)41 };
+               final byte[] bytes = new byte[] { (byte) 36, (byte) 41, (byte) 55, (byte) 101, (byte) 38 };
+               final byte[] sequence1 = new byte[] { (byte) 36, (byte) 41 };
 
                assertEquals(0, ByteArray.findByteSequence(bytes, sequence1));
 
-               final byte[] sequence2 = new byte[] { (byte)55, (byte)38 };
+               final byte[] sequence2 = new byte[] { (byte) 55, (byte) 38 };
 
                assertEquals(-1, ByteArray.findByteSequence(bytes, sequence2));
 
-               final byte[] sequence3 = new byte[] { (byte)101, (byte)38 };
+               final byte[] sequence3 = new byte[] { (byte) 101, (byte) 38 };
 
                assertEquals(3, ByteArray.findByteSequence(bytes, sequence3));
 
                try {
-                       ByteArray.findByteSequence(bytes, new byte[]  { (byte)36, (byte)41, (byte)55, (byte)101, (byte)38, (byte)66 });
+                       ByteArray.findByteSequence(bytes, new byte[] { (byte) 36, (byte) 41, (byte) 55, (byte) 101, (byte) 38, (byte) 66 });
                } catch (final IllegalArgumentException e) {
                        assertEquals("Sequence to be found is longer than the given byte array.", e.getMessage());
                }
@@ -366,7 +368,7 @@ public class ByteArrayTest {
 
        @Test
        public void testMaskBytes() {
-               final byte[] bytes = new byte[] {(byte)0xAC, (byte)0xA8, (byte)0x1F, (byte)0x08 };
+               final byte[] bytes = new byte[] { (byte) 0xAC, (byte) 0xA8, (byte) 0x1F, (byte) 0x08 };
                try {
                        ByteArray.maskBytes(bytes, 48);
                } catch (final IllegalArgumentException e) {
@@ -375,7 +377,7 @@ public class ByteArrayTest {
 
                assertArrayEquals(bytes, ByteArray.maskBytes(bytes, 32));
 
-               assertArrayEquals(new byte[] { (byte)0xAC, (byte)0x80, 0, 0}, ByteArray.maskBytes(bytes, 10));
+               assertArrayEquals(new byte[] { (byte) 0xAC, (byte) 0x80, 0, 0 }, ByteArray.maskBytes(bytes, 10));
        }
 
 }