| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,12 @@ | |||
| 1 | 1 | package org.msgpack.core; | |
| 2 | 2 | ||
| 3 | - import static org.msgpack.core.Preconditions.*; | ||
| 3 | + import static org.msgpack.core.Preconditions.checkArgument; | ||
| 4 | 4 | ||
| 5 | 5 | /** | |
| 6 | 6 | * Header of the Extension types | |
| 7 | 7 | */ | |
| 8 | - public class ExtensionTypeHeader { | ||
| 8 | + public class ExtensionTypeHeader | ||
| 9 | + { | ||
| 9 | 10 | private final byte type; | |
| 10 | 11 | private final int length; | |
| 11 | 12 | ||
@@ -21,45 +22,52 @@ public class ExtensionTypeHeader { | |||
| 21 | 22 | * ... | |
| 22 | 23 | * } | |
| 23 | 24 | * </pre> | |
| 25 | + * | ||
| 24 | 26 | * @param type extension type (byte). You can check the valid byte range with {@link #checkedCastToByte(int)} method. | |
| 25 | 27 | * @param length extension type data length | |
| 26 | 28 | */ | |
| 27 | - public ExtensionTypeHeader(byte type, int length) { | ||
| 29 | + public ExtensionTypeHeader(byte type, int length) | ||
| 30 | + { | ||
| 28 | 31 | checkArgument(length >= 0, "length must be >= 0"); | |
| 29 | 32 | this.type = type; | |
| 30 | 33 | this.length = length; | |
| 31 | 34 | } | |
| 32 | 35 | ||
| 33 | - public static byte checkedCastToByte(int code) { | ||
| 36 | + public static byte checkedCastToByte(int code) | ||
| 37 | + { | ||
| 34 | 38 | checkArgument(Byte.MIN_VALUE <= code && code <= Byte.MAX_VALUE, "Extension type code must be within the range of byte"); | |
| 35 | 39 | return (byte) code; | |
| 36 | 40 | } | |
| 37 | 41 | ||
| 38 | - public byte getType() { | ||
| 42 | + public byte getType() | ||
| 43 | + { | ||
| 39 | 44 | return type; | |
| 40 | 45 | } | |
| 41 | 46 | ||
| 42 | - public int getLength() { | ||
| 47 | + public int getLength() | ||
| 48 | + { | ||
| 43 | 49 | return length; | |
| 44 | 50 | } | |
| 45 | 51 | ||
| 46 | 52 | @Override | |
| 47 | - public int hashCode() { | ||
| 53 | + public int hashCode() | ||
| 54 | + { | ||
| 48 | 55 | return (type + 31) * 31 + length; | |
| 49 | 56 | } | |
| 50 | 57 | ||
| 51 | 58 | @Override | |
| 52 | - public boolean equals(Object obj) { | ||
| 53 | - if(obj instanceof ExtensionTypeHeader) { | ||
| 59 | + public boolean equals(Object obj) | ||
| 60 | + { | ||
| 61 | + if (obj instanceof ExtensionTypeHeader) { | ||
| 54 | 62 | ExtensionTypeHeader other = (ExtensionTypeHeader) obj; | |
| 55 | 63 | return this.type == other.type && this.length == other.length; | |
| 56 | 64 | } | |
| 57 | 65 | return false; | |
| 58 | 66 | } | |
| 59 | 67 | ||
| 60 | 68 | @Override | |
| 61 | - public String toString() { | ||
| 69 | + public String toString() | ||
| 70 | + { | ||
| 62 | 71 | return String.format("ExtensionTypeHeader(type:%d, length:%,d)", type, length); | |
| 63 | 72 | } | |
| 64 | - | ||
| 65 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,12 +4,11 @@ | |||
| 4 | 4 | import org.msgpack.core.annotations.VisibleForTesting; | |
| 5 | 5 | import org.msgpack.value.ValueType; | |
| 6 | 6 | ||
| 7 | - | ||
| 8 | 7 | /** | |
| 9 | 8 | * Describes the list of the message format types defined in the MessagePack specification. | |
| 10 | 9 | */ | |
| 11 | - public enum MessageFormat { | ||
| 12 | - | ||
| 10 | + public enum MessageFormat | ||
| 11 | + { | ||
| 13 | 12 | // INT7 | |
| 14 | 13 | POSFIXINT(ValueType.INTEGER), | |
| 15 | 14 | // MAP4 | |
@@ -50,52 +49,59 @@ public enum MessageFormat { | |||
| 50 | 49 | ARRAY32(ValueType.ARRAY), | |
| 51 | 50 | MAP16(ValueType.MAP), | |
| 52 | 51 | MAP32(ValueType.MAP), | |
| 53 | - NEGFIXINT(ValueType.INTEGER) | ||
| 54 | - ; | ||
| 52 | + NEGFIXINT(ValueType.INTEGER); | ||
| 55 | 53 | ||
| 54 | + private static final MessageFormat[] formatTable = new MessageFormat[256]; | ||
| 56 | 55 | private final ValueType valueType; | |
| 57 | 56 | ||
| 58 | - private MessageFormat(ValueType valueType) { | ||
| 57 | + private MessageFormat(ValueType valueType) | ||
| 58 | + { | ||
| 59 | 59 | this.valueType = valueType; | |
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | 62 | /** | |
| 63 | 63 | * Retruns the ValueType corresponding to this MessageFormat | |
| 64 | + * | ||
| 64 | 65 | * @return value type | |
| 65 | 66 | * @throws MessageFormatException if this == NEVER_USED type | |
| 66 | 67 | */ | |
| 67 | - public ValueType getValueType() throws MessageFormatException { | ||
| 68 | - if(this == NEVER_USED) | ||
| 68 | + public ValueType getValueType() | ||
| 69 | + throws MessageFormatException | ||
| 70 | + { | ||
| 71 | + if (this == NEVER_USED) { | ||
| 69 | 72 | throw new MessageFormatException("Cannot convert NEVER_USED to ValueType"); | |
| 73 | + } | ||
| 70 | 74 | return valueType; | |
| 71 | 75 | } | |
| 72 | 76 | ||
| 73 | - private final static MessageFormat[] formatTable = new MessageFormat[256]; | ||
| 74 | - | ||
| 75 | 77 | static { | |
| 76 | 78 | // Preparing a look up table for converting byte values into MessageFormat types | |
| 77 | - for(int b = 0; b <= 0xFF; ++b) { | ||
| 79 | + for (int b = 0; b <= 0xFF; ++b) { | ||
| 78 | 80 | MessageFormat mf = toMessageFormat((byte) b); | |
| 79 | 81 | formatTable[b] = mf; | |
| 80 | 82 | } | |
| 81 | 83 | } | |
| 82 | 84 | ||
| 83 | 85 | /** | |
| 84 | 86 | * Returns a MessageFormat type of the specified byte value | |
| 87 | + * | ||
| 85 | 88 | * @param b MessageFormat of the given byte | |
| 86 | 89 | * @return | |
| 87 | 90 | */ | |
| 88 | - public static MessageFormat valueOf(final byte b) { | ||
| 91 | + public static MessageFormat valueOf(final byte b) | ||
| 92 | + { | ||
| 89 | 93 | return formatTable[b & 0xFF]; | |
| 90 | 94 | } | |
| 91 | 95 | ||
| 92 | 96 | /** | |
| 93 | 97 | * Converting a byte value into MessageFormat. For faster performance, use {@link #valueOf} | |
| 98 | + * | ||
| 94 | 99 | * @param b MessageFormat of the given byte | |
| 95 | 100 | * @return | |
| 96 | 101 | */ | |
| 97 | 102 | @VisibleForTesting | |
| 98 | - static MessageFormat toMessageFormat(final byte b) { | ||
| 103 | + static MessageFormat toMessageFormat(final byte b) | ||
| 104 | + { | ||
| 99 | 105 | if (Code.isPosFixInt(b)) { | |
| 100 | 106 | return POSFIXINT; | |
| 101 | 107 | } | |
@@ -177,5 +183,4 @@ static MessageFormat toMessageFormat(final byte b) { | |||
| 177 | 183 | return NEVER_USED; | |
| 178 | 184 | } | |
| 179 | 185 | } | |
| 180 | - | ||
| 181 | 186 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,18 +18,21 @@ | |||
| 18 | 18 | /** | |
| 19 | 19 | * Thrown when the input message pack format is invalid | |
| 20 | 20 | */ | |
| 21 | - public class MessageFormatException extends MessagePackException { | ||
| 22 | - | ||
| 23 | - public MessageFormatException(Throwable e) { | ||
| 21 | + public class MessageFormatException | ||
| 22 | + extends MessagePackException | ||
| 23 | + { | ||
| 24 | + public MessageFormatException(Throwable e) | ||
| 25 | + { | ||
| 24 | 26 | super(e); | |
| 25 | 27 | } | |
| 26 | 28 | ||
| 27 | - | ||
| 28 | - public MessageFormatException(String message) { | ||
| 29 | + public MessageFormatException(String message) | ||
| 30 | + { | ||
| 29 | 31 | super(message); | |
| 30 | 32 | } | |
| 31 | 33 | ||
| 32 | - public MessageFormatException(String message, Throwable cause) { | ||
| 34 | + public MessageFormatException(String message, Throwable cause) | ||
| 35 | + { | ||
| 33 | 36 | super(message, cause); | |
| 34 | 37 | } | |
| 35 | 38 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,35 +17,41 @@ | |||
| 17 | 17 | ||
| 18 | 18 | import java.math.BigInteger; | |
| 19 | 19 | ||
| 20 | - | ||
| 21 | 20 | /** | |
| 22 | 21 | * This error is thrown when the user tries to read an integer value | |
| 23 | 22 | * using a smaller types. For example, calling MessageUnpacker.unpackInt() for an integer value | |
| 24 | 23 | * that is larger than Integer.MAX_VALUE will cause this exception. | |
| 25 | 24 | */ | |
| 26 | - public class MessageIntegerOverflowException extends MessageTypeException { | ||
| 25 | + public class MessageIntegerOverflowException | ||
| 26 | + extends MessageTypeException | ||
| 27 | + { | ||
| 27 | 28 | private final BigInteger bigInteger; | |
| 28 | 29 | ||
| 29 | - public MessageIntegerOverflowException(BigInteger bigInteger) { | ||
| 30 | + public MessageIntegerOverflowException(BigInteger bigInteger) | ||
| 31 | + { | ||
| 30 | 32 | super(); | |
| 31 | 33 | this.bigInteger = bigInteger; | |
| 32 | 34 | } | |
| 33 | 35 | ||
| 34 | - public MessageIntegerOverflowException(long value) { | ||
| 36 | + public MessageIntegerOverflowException(long value) | ||
| 37 | + { | ||
| 35 | 38 | this(BigInteger.valueOf(value)); | |
| 36 | 39 | } | |
| 37 | 40 | ||
| 38 | - public MessageIntegerOverflowException(String message, BigInteger bigInteger) { | ||
| 41 | + public MessageIntegerOverflowException(String message, BigInteger bigInteger) | ||
| 42 | + { | ||
| 39 | 43 | super(message); | |
| 40 | 44 | this.bigInteger = bigInteger; | |
| 41 | 45 | } | |
| 42 | 46 | ||
| 43 | - public BigInteger getBigInteger() { | ||
| 47 | + public BigInteger getBigInteger() | ||
| 48 | + { | ||
| 44 | 49 | return bigInteger; | |
| 45 | 50 | } | |
| 46 | 51 | ||
| 47 | 52 | @Override | |
| 48 | - public String getMessage() { | ||
| 53 | + public String getMessage() | ||
| 54 | + { | ||
| 49 | 55 | return bigInteger.toString(); | |
| 50 | 56 | } | |
| 51 | 57 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments