HBASE-26369 Fix checkstyle issues for KeyValue and ByteBufferUtils (#3785) (#3765)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
NishthaShah 2021-10-22 19:51:20 +05:30 committed by GitHub
parent 1253121db2
commit 73e5e03c04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 199 additions and 191 deletions

View File

@ -94,7 +94,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion * Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion
* of KeyValue only. * of KeyValue only.
* @deprecated Use {@link CellComparator#getInstance()} instead. Deprecated for hbase 2.0, remove for hbase 3.0. * @deprecated Use {@link CellComparator#getInstance()} instead. Deprecated for hbase 2.0,
* remove for hbase 3.0.
*/ */
@Deprecated @Deprecated
public static final KVComparator COMPARATOR = new KVComparator(); public static final KVComparator COMPARATOR = new KVComparator();
@ -261,7 +262,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Cannot rely on enum ordinals . They change if item is removed or moved. * Cannot rely on enum ordinals . They change if item is removed or moved.
* Do our own codes. * Do our own codes.
* @param b * @param b the kv serialized byte[] to process
* @return Type associated with passed code. * @return Type associated with passed code.
*/ */
public static Type codeToType(final byte b) { public static Type codeToType(final byte b) {
@ -352,7 +353,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param bytes byte array * @param bytes byte array
* @param offset offset to start of the KeyValue * @param offset offset to start of the KeyValue
* @param length length of the KeyValue * @param length length of the KeyValue
* @param ts * @param ts timestamp
*/ */
public KeyValue(final byte[] bytes, final int offset, final int length, long ts) { public KeyValue(final byte[] bytes, final int offset, final int length, long ts) {
this(bytes, offset, length, null, 0, 0, null, 0, 0, ts, Type.Maximum, null, 0, 0, null); this(bytes, offset, length, null, 0, 0, null, 0, 0, ts, Type.Maximum, null, 0, 0, null);
@ -364,7 +365,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* Constructs KeyValue structure filled with null value. * Constructs KeyValue structure filled with null value.
* Sets type to {@link KeyValue.Type#Maximum} * Sets type to {@link KeyValue.Type#Maximum}
* @param row - row key (arbitrary byte array) * @param row - row key (arbitrary byte array)
* @param timestamp * @param timestamp version timestamp
*/ */
public KeyValue(final byte [] row, final long timestamp) { public KeyValue(final byte [] row, final long timestamp) {
this(row, null, null, timestamp, Type.Maximum, null); this(row, null, null, timestamp, Type.Maximum, null);
@ -373,7 +374,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Constructs KeyValue structure filled with null value. * Constructs KeyValue structure filled with null value.
* @param row - row key (arbitrary byte array) * @param row - row key (arbitrary byte array)
* @param timestamp * @param timestamp version timestamp
*/ */
public KeyValue(final byte [] row, final long timestamp, Type type) { public KeyValue(final byte [] row, final long timestamp, Type type) {
this(row, null, null, timestamp, type, null); this(row, null, null, timestamp, type, null);
@ -410,7 +411,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param qualifier column qualifier * @param qualifier column qualifier
* @param timestamp version timestamp * @param timestamp version timestamp
* @param type key type * @param type key type
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, Type type) { final byte[] qualifier, final long timestamp, Type type) {
@ -424,7 +425,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param qualifier column qualifier * @param qualifier column qualifier
* @param timestamp version timestamp * @param timestamp version timestamp
* @param value column value * @param value column value
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, final byte[] value) { final byte[] qualifier, final long timestamp, final byte[] value) {
@ -439,7 +440,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param value column value * @param value column value
* @param tags tags * @param tags tags
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, final byte[] value, final byte[] qualifier, final long timestamp, final byte[] value,
@ -455,7 +456,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param value column value * @param value column value
* @param tags tags non-empty list of tags or null * @param tags tags non-empty list of tags or null
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, final byte[] value, final byte[] qualifier, final long timestamp, final byte[] value,
@ -475,7 +476,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param type key type * @param type key type
* @param value column value * @param value column value
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, Type type, final byte[] qualifier, final long timestamp, Type type,
@ -494,7 +495,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param type key type * @param type key type
* @param value column value * @param value column value
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, Type type, final byte[] qualifier, final long timestamp, Type type,
@ -511,7 +512,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param type key type * @param type key type
* @param value column value * @param value column value
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte[] row, final byte[] family, public KeyValue(final byte[] row, final byte[] family,
final byte[] qualifier, final long timestamp, Type type, final byte[] qualifier, final long timestamp, Type type,
@ -532,7 +533,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param value column value * @param value column value
* @param voffset value offset * @param voffset value offset
* @param vlength value length * @param vlength value length
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(byte [] row, byte [] family, public KeyValue(byte [] row, byte [] family,
byte [] qualifier, int qoffset, int qlength, long timestamp, Type type, byte [] qualifier, int qoffset, int qlength, long timestamp, Type type,
@ -544,17 +545,17 @@ public class KeyValue implements ExtendedCell, Cloneable {
} }
/** /**
* @param row * @param row row key
* @param family * @param family family name
* @param qualifier * @param qualifier qualifier name
* @param qoffset * @param qoffset qualifier offset
* @param qlength * @param qlength qualifier length
* @param timestamp * @param timestamp version timestamp
* @param type * @param type key type
* @param value * @param value column value
* @param voffset * @param voffset value offset
* @param vlength * @param vlength value length
* @param tags * @param tags tags
*/ */
public KeyValue(byte [] row, byte [] family, public KeyValue(byte [] row, byte [] family,
byte [] qualifier, int qoffset, int qlength, long timestamp, Type type, byte [] qualifier, int qoffset, int qlength, long timestamp, Type type,
@ -570,7 +571,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* <p> * <p>
* Column is split into two fields, family and qualifier. * Column is split into two fields, family and qualifier.
* @param row row key * @param row row key
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte [] row, final int roffset, final int rlength, public KeyValue(final byte [] row, final int roffset, final int rlength,
final byte [] family, final int foffset, final int flength, final byte [] family, final int foffset, final int flength,
@ -607,18 +608,14 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @throws IllegalArgumentException an illegal value was passed or there is insufficient space * @throws IllegalArgumentException an illegal value was passed or there is insufficient space
* remaining in the buffer * remaining in the buffer
*/ */
public KeyValue(byte [] buffer, final int boffset, public KeyValue(byte[] buffer, final int boffset, final byte[] row, final int roffset,
final byte [] row, final int roffset, final int rlength, final int rlength, final byte[] family, final int foffset, final int flength,
final byte [] family, final int foffset, final int flength, final byte[] qualifier, final int qoffset, final int qlength, final long timestamp,
final byte [] qualifier, final int qoffset, final int qlength, final Type type, final byte[] value, final int voffset, final int vlength, final Tag[] tags) {
final long timestamp, final Type type,
final byte [] value, final int voffset, final int vlength,
final Tag[] tags) {
this.bytes = buffer; this.bytes = buffer;
this.length = writeByteArray(buffer, boffset, this.length =
row, roffset, rlength, writeByteArray(buffer, boffset, row, roffset, rlength, family, foffset, flength, qualifier,
family, foffset, flength, qualifier, qoffset, qlength, qoffset, qlength, timestamp, type, value, voffset, vlength, tags);
timestamp, type, value, voffset, vlength, tags);
this.offset = boffset; this.offset = boffset;
} }
@ -641,7 +638,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param voffset value offset * @param voffset value offset
* @param vlength value length * @param vlength value length
* @param tags tags * @param tags tags
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final byte [] row, final int roffset, final int rlength, public KeyValue(final byte [] row, final int roffset, final int rlength,
final byte [] family, final int foffset, final int flength, final byte [] family, final int foffset, final int flength,
@ -657,21 +654,21 @@ public class KeyValue implements ExtendedCell, Cloneable {
} }
/** /**
* @param row * @param row row key
* @param roffset * @param roffset row offset
* @param rlength * @param rlength row length
* @param family * @param family family name
* @param foffset * @param foffset fammily offset
* @param flength * @param flength family length
* @param qualifier * @param qualifier column qualifier
* @param qoffset * @param qoffset qualifier offset
* @param qlength * @param qlength qualifier length
* @param timestamp * @param timestamp version timestamp
* @param type * @param type key type
* @param value * @param value column value
* @param voffset * @param voffset value offset
* @param vlength * @param vlength value length
* @param tags * @param tags input tags
*/ */
public KeyValue(final byte [] row, final int roffset, final int rlength, public KeyValue(final byte [] row, final int roffset, final int rlength,
final byte [] family, final int foffset, final int flength, final byte [] family, final int foffset, final int flength,
@ -697,7 +694,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param type key type * @param type key type
* @param vlength value length * @param vlength value length
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final int rlength, public KeyValue(final int rlength,
final int flength, final int flength,
@ -718,8 +715,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @param timestamp version timestamp * @param timestamp version timestamp
* @param type key type * @param type key type
* @param vlength value length * @param vlength value length
* @param tagsLength * @param tagsLength length of the tags
* @throws IllegalArgumentException * @throws IllegalArgumentException an illegal value was passed
*/ */
public KeyValue(final int rlength, public KeyValue(final int rlength,
final int flength, final int flength,
@ -755,12 +752,12 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Create an empty byte[] representing a KeyValue * Create an empty byte[] representing a KeyValue
* All lengths are preset and can be filled in later. * All lengths are preset and can be filled in later.
* @param rlength * @param rlength row length
* @param flength * @param flength family length
* @param qlength * @param qlength qualifier length
* @param timestamp * @param timestamp version timestamp
* @param type * @param type key type
* @param vlength * @param vlength value length
* @return The newly created byte array. * @return The newly created byte array.
*/ */
private static byte[] createEmptyByteArray(final int rlength, int flength, private static byte[] createEmptyByteArray(final int rlength, int flength,
@ -1101,7 +1098,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Clones a KeyValue. This creates a copy, re-allocating the buffer. * Clones a KeyValue. This creates a copy, re-allocating the buffer.
* @return Fully copied clone of this KeyValue * @return Fully copied clone of this KeyValue
* @throws CloneNotSupportedException * @throws CloneNotSupportedException if cloning of keyValue is not supported
*/ */
@Override @Override
public KeyValue clone() throws CloneNotSupportedException { public KeyValue clone() throws CloneNotSupportedException {
@ -1189,7 +1186,9 @@ public class KeyValue implements ExtendedCell, Cloneable {
* @return Key as a String. * @return Key as a String.
*/ */
public static String keyToString(final byte [] b, final int o, final int l) { public static String keyToString(final byte [] b, final int o, final int l) {
if (b == null) return ""; if (b == null) {
return "";
}
int rowlength = Bytes.toShort(b, o); int rowlength = Bytes.toShort(b, o);
String row = Bytes.toStringBinary(b, o + Bytes.SIZEOF_SHORT, rowlength); String row = Bytes.toStringBinary(b, o + Bytes.SIZEOF_SHORT, rowlength);
int columnoffset = o + Bytes.SIZEOF_SHORT + 1 + rowlength; int columnoffset = o + Bytes.SIZEOF_SHORT + 1 + rowlength;
@ -1581,8 +1580,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
} }
/** /**
* @param b * @param b the kv serialized byte[] to process
* @param delimiter * @param delimiter input delimeter to fetch index from start
* @return Index of delimiter having started from start of <code>b</code> * @return Index of delimiter having started from start of <code>b</code>
* moving rightward. * moving rightward.
*/ */
@ -1603,8 +1602,10 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Find index of passed delimiter walking from end of buffer backwards. * Find index of passed delimiter walking from end of buffer backwards.
* @param b * @param b the kv serialized byte[] to process
* @param delimiter * @param offset the offset in the byte[]
* @param length the length in the byte[]
* @param delimiter input delimeter to fetch index from end
* @return Index of delimiter * @return Index of delimiter
*/ */
public static int getDelimiterInReverse(final byte [] b, final int offset, public static int getDelimiterInReverse(final byte [] b, final int offset,
@ -1765,8 +1766,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Compares the only the user specified portion of a Key. This is overridden by MetaComparator. * Compares the only the user specified portion of a Key. This is overridden by MetaComparator.
* @param left * @param left left cell to compare row key
* @param right * @param right right cell to compare row key
* @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller * @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller
*/ */
protected int compareRowKey(final Cell left, final Cell right) { protected int compareRowKey(final Cell left, final Cell right) {
@ -1776,12 +1777,12 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Compares left to right assuming that left,loffset,llength and right,roffset,rlength are * Compares left to right assuming that left,loffset,llength and right,roffset,rlength are
* full KVs laid out in a flat byte[]s. * full KVs laid out in a flat byte[]s.
* @param left * @param left the left kv serialized byte[] to be compared with
* @param loffset * @param loffset the offset in the left byte[]
* @param llength * @param llength the length in the left byte[]
* @param right * @param right the right kv serialized byte[] to be compared with
* @param roffset * @param roffset the offset in the right byte[]
* @param rlength * @param rlength the length in the right byte[]
* @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller * @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller
*/ */
public int compareFlatKey(byte[] left, int loffset, int llength, public int compareFlatKey(byte[] left, int loffset, int llength,
@ -1877,8 +1878,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
} }
/** /**
* @param left * @param left left cell to compare rows for
* @param right * @param right right cell to compare rows for
* @return Result comparing rows. * @return Result comparing rows.
*/ */
public int compareRows(final Cell left, final Cell right) { public int compareRows(final Cell left, final Cell right) {
@ -1888,12 +1889,12 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Get the b[],o,l for left and right rowkey portions and compare. * Get the b[],o,l for left and right rowkey portions and compare.
* @param left * @param left the left kv serialized byte[] to be compared with
* @param loffset * @param loffset the offset in the left byte[]
* @param llength * @param llength the length in the left byte[]
* @param right * @param right the right kv serialized byte[] to be compared with
* @param roffset * @param roffset the offset in the right byte[]
* @param rlength * @param rlength the length in the right byte[]
* @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller * @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller
*/ */
public int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset, public int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset,
@ -1906,19 +1907,16 @@ public class KeyValue implements ExtendedCell, Cloneable {
return CellComparatorImpl.COMPARATOR.compareColumns(left, right); return CellComparatorImpl.COMPARATOR.compareColumns(left, right);
} }
protected int compareColumns( protected int compareColumns(byte[] left, int loffset, int llength, final int lfamilylength,
byte [] left, int loffset, int llength, final int lfamilylength, byte[] right, int roffset, int rlength, final int rfamilylength) {
byte [] right, int roffset, int rlength, final int rfamilylength) {
// Compare family portion first. // Compare family portion first.
int diff = Bytes.compareTo(left, loffset, lfamilylength, int diff = Bytes.compareTo(left, loffset, lfamilylength, right, roffset, rfamilylength);
right, roffset, rfamilylength);
if (diff != 0) { if (diff != 0) {
return diff; return diff;
} }
// Compare qualifier portion // Compare qualifier portion
return Bytes.compareTo(left, loffset + lfamilylength, return Bytes.compareTo(left, loffset + lfamilylength, llength - lfamilylength, right,
llength - lfamilylength, roffset + rfamilylength, rlength - rfamilylength);
right, roffset + rfamilylength, rlength - rfamilylength);
} }
static int compareTimestamps(final long ltimestamp, final long rtimestamp) { static int compareTimestamps(final long ltimestamp, final long rtimestamp) {
@ -1936,13 +1934,13 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Overridden * Overridden
* @param commonPrefix * @param commonPrefix location of expected common prefix
* @param left * @param left the left kv serialized byte[] to be compared with
* @param loffset * @param loffset the offset in the left byte[]
* @param llength * @param llength the length in the left byte[]
* @param right * @param right the right kv serialized byte[] to be compared with
* @param roffset * @param roffset the offset in the byte[]
* @param rlength * @param rlength the length in the right byte[]
* @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller * @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller
*/ */
@Override // SamePrefixComparator @Override // SamePrefixComparator
@ -2083,8 +2081,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
} }
/** /**
* Compares the row and column of two keyvalues for equality * Compares the row and column of two keyvalues for equality
* @param left * @param left left cell to compare row and column
* @param right * @param right right cell to compare row and column
* @return True if same row and column. * @return True if same row and column.
*/ */
public boolean matchingRowColumn(final Cell left, public boolean matchingRowColumn(final Cell left,
@ -2121,8 +2119,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Compares the row of two keyvalues for equality * Compares the row of two keyvalues for equality
* @param left * @param left left cell to compare row
* @param right * @param right right cell to compare row
* @return True if rows match. * @return True if rows match.
*/ */
public boolean matchingRows(final Cell left, final Cell right) { public boolean matchingRows(final Cell left, final Cell right) {
@ -2132,10 +2130,10 @@ public class KeyValue implements ExtendedCell, Cloneable {
} }
/** /**
* @param left * @param left left cell to compare row
* @param lrowlength * @param lrowlength left row length
* @param right * @param right right cell to compare row
* @param rrowlength * @param rrowlength right row length
* @return True if rows match. * @return True if rows match.
*/ */
private boolean matchingRows(final Cell left, final short lrowlength, private boolean matchingRows(final Cell left, final short lrowlength,
@ -2179,8 +2177,8 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* This is a HFile block index key optimization. * This is a HFile block index key optimization.
* @param leftKey * @param leftKey byte array for left Key
* @param rightKey * @param rightKey byte array for right Key
* @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller * @return 0 if equal, &lt;0 if left smaller, &gt;0 if right smaller
* @deprecated Since 0.99.2; * @deprecated Since 0.99.2;
*/ */
@ -2262,7 +2260,7 @@ public class KeyValue implements ExtendedCell, Cloneable {
* backing bytes copied from the steam. * backing bytes copied from the steam.
* @return KeyValue created by deserializing from <code>in</code> OR if we find a length * @return KeyValue created by deserializing from <code>in</code> OR if we find a length
* of zero, we will return null which can be useful marking a stream as done. * of zero, we will return null which can be useful marking a stream as done.
* @throws IOException * @throws IOException if any IO error happen
*/ */
public static KeyValue create(final DataInput in) throws IOException { public static KeyValue create(final DataInput in) throws IOException {
return create(in.readInt(), in); return create(in.readInt(), in);
@ -2270,16 +2268,18 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Create a KeyValue reading <code>length</code> from <code>in</code> * Create a KeyValue reading <code>length</code> from <code>in</code>
* @param length * @param length length of the Key
* @param in * @param in Input to read from
* @return Created KeyValue OR if we find a length of zero, we will return null which * @return Created KeyValue OR if we find a length of zero, we will return null which
* can be useful marking a stream as done. * can be useful marking a stream as done.
* @throws IOException * @throws IOException if any IO error happen
*/ */
public static KeyValue create(int length, final DataInput in) throws IOException { public static KeyValue create(int length, final DataInput in) throws IOException {
if (length <= 0) { if (length <= 0) {
if (length == 0) return null; if (length == 0) {
return null;
}
throw new IOException("Failed read " + length + " bytes, stream corrupt?"); throw new IOException("Failed read " + length + " bytes, stream corrupt?");
} }
@ -2291,10 +2291,10 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* Write out a KeyValue in the manner in which we used to when KeyValue was a Writable. * Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.
* @param kv * @param kv the KeyValue on which write is being requested
* @param out * @param out OutputStream to write keyValue to
* @return Length written on stream * @return Length written on stream
* @throws IOException * @throws IOException if any IO error happen
* @see #create(DataInput) for the inverse function * @see #create(DataInput) for the inverse function
*/ */
public static long write(final KeyValue kv, final DataOutput out) throws IOException { public static long write(final KeyValue kv, final DataOutput out) throws IOException {
@ -2310,11 +2310,11 @@ public class KeyValue implements ExtendedCell, Cloneable {
* Write out a KeyValue in the manner in which we used to when KeyValue was a Writable but do * Write out a KeyValue in the manner in which we used to when KeyValue was a Writable but do
* not require a {@link DataOutput}, just take plain {@link OutputStream} * not require a {@link DataOutput}, just take plain {@link OutputStream}
* Named <code>oswrite</code> so does not clash with {@link #write(KeyValue, DataOutput)} * Named <code>oswrite</code> so does not clash with {@link #write(KeyValue, DataOutput)}
* @param kv * @param kv the KeyValue on which write is being requested
* @param out * @param out OutputStream to write keyValue to
* @param withTags * @param withTags boolean value indicating write is with Tags or not
* @return Length written on stream * @return Length written on stream
* @throws IOException * @throws IOException if any IO error happen
* @see #create(DataInput) for the inverse function * @see #create(DataInput) for the inverse function
* @see #write(KeyValue, DataOutput) * @see #write(KeyValue, DataOutput)
* @see KeyValueUtil#oswrite(Cell, OutputStream, boolean) * @see KeyValueUtil#oswrite(Cell, OutputStream, boolean)
@ -2431,9 +2431,9 @@ public class KeyValue implements ExtendedCell, Cloneable {
/** /**
* A setter that helps to avoid object creation every time and whenever * A setter that helps to avoid object creation every time and whenever
* there is a need to create new KeyOnlyKeyValue. * there is a need to create new KeyOnlyKeyValue.
* @param key * @param key Key to set
* @param offset * @param offset Offset of the Key
* @param length * @param length length of the Key
*/ */
public void setKey(byte[] key, int offset, int length) { public void setKey(byte[] key, int offset, int length) {
this.bytes = key; this.bytes = key;

View File

@ -393,8 +393,7 @@ public final class ByteBufferUtils {
* @return Number of bytes written. * @return Number of bytes written.
* @throws IOException on stream error * @throws IOException on stream error
*/ */
public static int putCompressedInt(OutputStream out, final int value) public static int putCompressedInt(OutputStream out, final int value) throws IOException {
throws IOException {
int i = 0; int i = 0;
int tmpvalue = value; int tmpvalue = value;
do { do {
@ -411,12 +410,12 @@ public final class ByteBufferUtils {
/** /**
* Put in output stream 32 bit integer (Big Endian byte order). * Put in output stream 32 bit integer (Big Endian byte order).
*
* @param out Where to put integer. * @param out Where to put integer.
* @param value Value of integer. * @param value Value of integer.
* @throws IOException On stream error. * @throws IOException On stream error.
*/ */
public static void putInt(OutputStream out, final int value) public static void putInt(OutputStream out, final int value) throws IOException {
throws IOException {
// We have writeInt in ByteBufferOutputStream so that it can directly write // We have writeInt in ByteBufferOutputStream so that it can directly write
// int to underlying // int to underlying
// ByteBuffer in one step. // ByteBuffer in one step.
@ -571,7 +570,7 @@ public final class ByteBufferUtils {
/** /**
* Read integer from stream coded in 7 bits and increment position. * Read integer from stream coded in 7 bits and increment position.
* @return the integer that has been read * @return the integer that has been read
* @throws IOException * @throws IOException on stream error
*/ */
public static int readCompressedInt(InputStream input) public static int readCompressedInt(InputStream input)
throws IOException { throws IOException {
@ -606,7 +605,7 @@ public final class ByteBufferUtils {
* Read long which was written to fitInBytes bytes and increment position. * Read long which was written to fitInBytes bytes and increment position.
* @param fitInBytes In how many bytes given long is stored. * @param fitInBytes In how many bytes given long is stored.
* @return The value of parsed long. * @return The value of parsed long.
* @throws IOException * @throws IOException on stream error
*/ */
public static long readLong(InputStream in, final int fitInBytes) public static long readLong(InputStream in, final int fitInBytes)
throws IOException { throws IOException {
@ -687,11 +686,11 @@ public final class ByteBufferUtils {
/** /**
* Copy from one buffer to another from given offset. This will be absolute positional copying and * Copy from one buffer to another from given offset. This will be absolute positional copying and
* won't affect the position of any of the buffers. * won't affect the position of any of the buffers.
* @param in * @param in input bytebuffer
* @param out * @param out destination bytebuffer
* @param sourceOffset * @param sourceOffset offset of source buffer
* @param destinationOffset * @param destinationOffset offset of destination buffer
* @param length * @param length the number of bytes to copy
*/ */
public static void copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out, int sourceOffset, public static void copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out, int sourceOffset,
int destinationOffset, int length) { int destinationOffset, int length) {
@ -864,9 +863,9 @@ public final class ByteBufferUtils {
/** /**
* Copy the given number of bytes from specified offset into a new byte[] * Copy the given number of bytes from specified offset into a new byte[]
* @param buffer * @param buffer input bytebuffer to read
* @param offset * @param offset input offset where Bytes are
* @param length * @param length the number of bytes to read
* @return a new byte[] containing the bytes in the specified range * @return a new byte[] containing the bytes in the specified range
*/ */
public static byte[] toBytes(ByteBuffer buffer, int offset, int length) { public static byte[] toBytes(ByteBuffer buffer, int offset, int length) {
@ -885,7 +884,9 @@ public final class ByteBufferUtils {
// Since we're often comparing adjacent sorted data, // Since we're often comparing adjacent sorted data,
// it's usual to have equal arrays except for the very last byte // it's usual to have equal arrays except for the very last byte
// so check that first // so check that first
if (toByte(buf1, o1 + l1 - 1) != toByte(buf2, o2 + l2 - 1)) return false; if (toByte(buf1, o1 + l1 - 1) != toByte(buf2, o2 + l2 - 1)) {
return false;
}
return compareTo(buf1, o1, l1, buf2, o2, l2) == 0; return compareTo(buf1, o1, l1, buf2, o2, l2) == 0;
} }
@ -917,7 +918,9 @@ public final class ByteBufferUtils {
// Since we're often comparing adjacent sorted data, // Since we're often comparing adjacent sorted data,
// it's usual to have equal arrays except for the very last byte // it's usual to have equal arrays except for the very last byte
// so check that first // so check that first
if (toByte(buf1, o1 + l1 - 1) != buf2[o2 + l2 - 1]) return false; if (toByte(buf1, o1 + l1 - 1) != buf2[o2 + l2 - 1]) {
return false;
}
return compareTo(buf1, o1, l1, buf2, o2, l2) == 0; return compareTo(buf1, o1, l1, buf2, o2, l2) == 0;
} }
@ -979,8 +982,8 @@ public final class ByteBufferUtils {
/** /**
* Reads a short value at the given buffer's offset. * Reads a short value at the given buffer's offset.
* @param buffer * @param buffer input byte buffer to read
* @param offset * @param offset input offset where short is
* @return short value at offset * @return short value at offset
*/ */
public static short toShort(ByteBuffer buffer, int offset) { public static short toShort(ByteBuffer buffer, int offset) {
@ -996,8 +999,8 @@ public final class ByteBufferUtils {
/** /**
* Reads an int value at the given buffer's offset. * Reads an int value at the given buffer's offset.
* @param buffer * @param buffer input byte buffer to read
* @param offset * @param offset input offset where int is
* @return int value at offset * @return int value at offset
*/ */
public static int toInt(ByteBuffer buffer, int offset) { public static int toInt(ByteBuffer buffer, int offset) {
@ -1029,8 +1032,8 @@ public final class ByteBufferUtils {
/** /**
* Reads a long value at the given buffer's offset. * Reads a long value at the given buffer's offset.
* @param buffer * @param buffer input byte buffer to read
* @param offset * @param offset input offset where Long is
* @return long value at offset * @return long value at offset
*/ */
public static long toLong(ByteBuffer buffer, int offset) { public static long toLong(ByteBuffer buffer, int offset) {
@ -1053,7 +1056,7 @@ public final class ByteBufferUtils {
/** /**
* Reads a double value at the given buffer's offset. * Reads a double value at the given buffer's offset.
* @param buffer * @param buffer input byte buffer to read
* @param offset offset where double is * @param offset offset where double is
* @return double value at offset * @return double value at offset
*/ */
@ -1063,8 +1066,8 @@ public final class ByteBufferUtils {
/** /**
* Reads a BigDecimal value at the given buffer's offset. * Reads a BigDecimal value at the given buffer's offset.
* @param buffer * @param buffer input bytebuffer to read
* @param offset * @param offset input offset
* @return BigDecimal value at offset * @return BigDecimal value at offset
*/ */
public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) { public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) {
@ -1117,10 +1120,10 @@ public final class ByteBufferUtils {
/** /**
* Copies the bytes from given array's offset to length part into the given buffer. Puts the bytes * Copies the bytes from given array's offset to length part into the given buffer. Puts the bytes
* to buffer's current position. This also advances the position in the 'out' buffer by 'length' * to buffer's current position. This also advances the position in the 'out' buffer by 'length'
* @param out * @param out output bytebuffer to copy to
* @param in * @param in input array to copy from
* @param inOffset * @param inOffset input offset to copy from
* @param length * @param length the number of bytes to copy
*/ */
public static void copyFromArrayToBuffer(ByteBuffer out, byte[] in, int inOffset, int length) { public static void copyFromArrayToBuffer(ByteBuffer out, byte[] in, int inOffset, int length) {
if (out.hasArray()) { if (out.hasArray()) {
@ -1138,11 +1141,12 @@ public final class ByteBufferUtils {
/** /**
* Copies bytes from given array's offset to length part into the given buffer. Puts the bytes * Copies bytes from given array's offset to length part into the given buffer. Puts the bytes
* to buffer's given position. This doesn't affact the position of buffer. * to buffer's given position. This doesn't affect the position of buffer.
* @param out * @param out output bytebuffer to copy to
* @param in * @param outOffset output buffer offset
* @param inOffset * @param in input array to copy from
* @param length * @param inOffset input offset to copy from
* @param length the number of bytes to copy
*/ */
public static void copyFromArrayToBuffer(ByteBuffer out, int outOffset, byte[] in, int inOffset, public static void copyFromArrayToBuffer(ByteBuffer out, int outOffset, byte[] in, int inOffset,
int length) { int length) {
@ -1159,12 +1163,12 @@ public final class ByteBufferUtils {
/** /**
* Copies specified number of bytes from given offset of 'in' ByteBuffer to * Copies specified number of bytes from given offset of 'in' ByteBuffer to
* the array. This doesn't affact the position of buffer. * the array. This doesn't affect the position of buffer.
* @param out * @param out output array to copy input bytebuffer to
* @param in * @param in input bytebuffer to copy from
* @param sourceOffset * @param sourceOffset offset of source bytebuffer
* @param destinationOffset * @param destinationOffset offset of destination array
* @param length * @param length the number of bytes to copy
*/ */
public static void copyFromBufferToArray(byte[] out, ByteBuffer in, int sourceOffset, public static void copyFromBufferToArray(byte[] out, ByteBuffer in, int sourceOffset,
int destinationOffset, int length) { int destinationOffset, int length) {
@ -1188,7 +1192,9 @@ public final class ByteBufferUtils {
*/ */
public static byte[] copyOfRange(ByteBuffer original, int from, int to) { public static byte[] copyOfRange(ByteBuffer original, int from, int to) {
int newLength = to - from; int newLength = to - from;
if (newLength < 0) throw new IllegalArgumentException(from + " > " + to); if (newLength < 0) {
throw new IllegalArgumentException(from + " > " + to);
}
byte[] copy = new byte[newLength]; byte[] copy = new byte[newLength];
ByteBufferUtils.copyFromBufferToArray(copy, original, from, 0, newLength); ByteBufferUtils.copyFromBufferToArray(copy, original, from, 0, newLength);
return copy; return copy;
@ -1198,10 +1204,12 @@ public final class ByteBufferUtils {
public static String toStringBinary(final ByteBuffer b, int off, int len) { public static String toStringBinary(final ByteBuffer b, int off, int len) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
// Just in case we are passed a 'len' that is > buffer length... // Just in case we are passed a 'len' that is > buffer length...
if (off >= b.capacity()) if (off >= b.capacity()) {
return result.toString(); return result.toString();
if (off + len > b.capacity()) }
if (off + len > b.capacity()) {
len = b.capacity() - off; len = b.capacity() - off;
}
for (int i = off; i < off + len; ++i) { for (int i = off; i < off + len; ++i) {
int ch = b.get(i) & 0xFF; int ch = b.get(i) & 0xFF;
if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')