UserTransactionID(final byte[] encodedForm) { super(encodedForm); // first byte is the header if (encodedForm[0] != 0x01) { throw wrongFormat(); } final int totalEncodedLength = encodedForm.length; // second byte of the encoded form is the length of the nodename bytes final int nodeNameLength = encodedForm[1]; if (nodeNameLength <= 0) { throw wrongFormat(); } // next bytes are the nodename try { nodeName = new String(encodedForm, 2, nodeNameLength, "UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } if (totalEncodedLength < nodeNameLength + 4) { throw wrongFormat(); } // the rest is the unique ID //noinspection NumericOverflow this.id = (encodedForm[nodeNameLength + 2] & 0xff) << 24 | (encodedForm[nodeNameLength + 3] & 0xff) << 16 | (encodedForm[nodeNameLength + 4] & 0xff) << 8 | encodedForm[nodeNameLength + 5] & 0xff; }
private static byte[] encode(final String name, final int uniqueId) { final byte[] nameBytes; try { nameBytes = name.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } final int length = nameBytes.length; if (length > 255) { throw wrongFormat(); } final byte[] target = new byte[6 + length]; target[0] = 0x01; target[1] = (byte) length; System.arraycopy(nameBytes, 0, target, 2, length); target[2 + length] = (byte) (uniqueId >> 24); target[3 + length] = (byte) (uniqueId >> 16); target[4 + length] = (byte) (uniqueId >> 8); target[5 + length] = (byte) uniqueId; return target; }
UserTransactionID(final byte[] encodedForm) { super(encodedForm); // first byte is the header if (encodedForm[0] != 0x01) { throw wrongFormat(); } final int totalEncodedLength = encodedForm.length; // second byte of the encoded form is the length of the nodename bytes final int nodeNameLength = encodedForm[1]; if (nodeNameLength <= 0) { throw wrongFormat(); } // next bytes are the nodename try { nodeName = new String(encodedForm, 2, nodeNameLength, "UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } if (totalEncodedLength < nodeNameLength + 4) { throw wrongFormat(); } // the rest is the unique ID //noinspection NumericOverflow this.id = (encodedForm[nodeNameLength + 2] & 0xff) << 24 | (encodedForm[nodeNameLength + 3] & 0xff) << 16 | (encodedForm[nodeNameLength + 4] & 0xff) << 8 | encodedForm[nodeNameLength + 5] & 0xff; }
UserTransactionID(final byte[] encodedForm) { super(encodedForm); // first byte is the header if (encodedForm[0] != 0x01) { throw wrongFormat(); } final int totalEncodedLength = encodedForm.length; // second byte of the encoded form is the length of the nodename bytes final int nodeNameLength = encodedForm[1]; if (nodeNameLength <= 0) { throw wrongFormat(); } // next bytes are the nodename try { nodeName = new String(encodedForm, 2, nodeNameLength, "UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } if (totalEncodedLength < nodeNameLength + 4) { throw wrongFormat(); } // the rest is the unique ID //noinspection NumericOverflow this.id = (encodedForm[nodeNameLength + 2] & 0xff) << 24 | (encodedForm[nodeNameLength + 3] & 0xff) << 16 | (encodedForm[nodeNameLength + 4] & 0xff) << 8 | encodedForm[nodeNameLength + 5] & 0xff; }
private static byte[] encode(final String name, final int uniqueId) { final byte[] nameBytes; try { nameBytes = name.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } final int length = nameBytes.length; if (length > 255) { throw wrongFormat(); } final byte[] target = new byte[6 + length]; target[0] = 0x01; target[1] = (byte) length; System.arraycopy(nameBytes, 0, target, 2, length); target[2 + length] = (byte) (uniqueId >> 24); target[3 + length] = (byte) (uniqueId >> 16); target[4 + length] = (byte) (uniqueId >> 8); target[5 + length] = (byte) uniqueId; return target; }
private static byte[] encode(final String name, final int uniqueId) { final byte[] nameBytes; try { nameBytes = name.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } final int length = nameBytes.length; if (length > 255) { throw wrongFormat(); } final byte[] target = new byte[6 + length]; target[0] = 0x01; target[1] = (byte) length; System.arraycopy(nameBytes, 0, target, 2, length); target[2 + length] = (byte) (uniqueId >> 24); target[3 + length] = (byte) (uniqueId >> 16); target[4 + length] = (byte) (uniqueId >> 8); target[5 + length] = (byte) uniqueId; return target; }