@Override public SingleByteBuff putInt(int value) { ByteBufferUtils.putInt(this.buf, value); return this; }
/** * Writes an <code>int</code> to the underlying output stream as four * bytes, high byte first. * @param i the <code>int</code> to write * @throws IOException if an I/O error occurs. */ @Override public void writeInt(int i) throws IOException { checkSizeAndGrow(Bytes.SIZEOF_INT); ByteBufferUtils.putInt(this.curBuf, i); }
@Override public int write(OutputStream out, boolean withTags) throws IOException { int lenToWrite = getSerializedSize(withTags); ByteBufferUtils.putInt(out, keyOnlyBuffer.length); ByteBufferUtils.putInt(out, valueLength); // Write key out.write(keyOnlyBuffer); // Write value out.write(this.valueBuffer, this.valueOffset, this.valueLength); if (withTags && this.tagsLength > 0) { // 2 bytes tags length followed by tags bytes // tags length is serialized with 2 bytes only(short way) even if the type is int. // As this is non -ve numbers, we save the sign bit. See HBASE-11437 out.write((byte) (0xff & (this.tagsLength >> 8))); out.write((byte) (0xff & this.tagsLength)); out.write(this.tagsBuffer, this.tagsOffset, this.tagsLength); } return lenToWrite; }
private int createCellReference(ByteBufferKeyValue cell, ByteBuffer idxBuffer, int idxOffset) { int offset = idxOffset; int dataChunkID = cell.getChunkId(); offset = ByteBufferUtils.putInt(idxBuffer, offset, dataChunkID); // write data chunk id offset = ByteBufferUtils.putInt(idxBuffer, offset, cell.getOffset()); // offset offset = ByteBufferUtils.putInt(idxBuffer, offset, cell.getSerializedSize()); // length offset = ByteBufferUtils.putLong(idxBuffer, offset, cell.getSequenceId()); // seqId return offset; }
/** * Made into a static method so as to reuse the logic within * ValueAndTagRewriteByteBufferExtendedCell */ static int write(OutputStream out, boolean withTags, Cell cell, byte[] value, byte[] tags) throws IOException { int valLen = value == null ? 0 : value.length; ByteBufferUtils.putInt(out, KeyValueUtil.keyLength(cell));// Key length ByteBufferUtils.putInt(out, valLen);// Value length int len = 2 * Bytes.SIZEOF_INT; len += writeFlatKey(cell, out);// Key if (valLen > 0) { out.write(value);// Value } len += valLen; if (withTags && tags != null) { // Write the tagsLength 2 bytes out.write((byte) (0xff & (tags.length >> 8))); out.write((byte) (0xff & tags.length)); out.write(tags); len += KeyValue.TAGS_LENGTH_SIZE + tags.length; } return len; }
@Override public int write(OutputStream out, boolean withTags) throws IOException { int lenToWrite = getSerializedSize(withTags); ByteBufferUtils.putInt(out, keyBuffer.capacity()); ByteBufferUtils.putInt(out, valueLength); // Write key out.write(keyBuffer.array()); // Write value ByteBufferUtils.copyBufferToStream(out, this.valueBuffer, this.valueOffset, this.valueLength); if (withTags && this.tagsLength > 0) { // 2 bytes tags length followed by tags bytes // tags length is serialized with 2 bytes only(short way) even if the type is int. // As this is non -ve numbers, we save the sign bit. See HBASE-11437 out.write((byte) (0xff & (this.tagsLength >> 8))); out.write((byte) (0xff & this.tagsLength)); ByteBufferUtils.copyBufferToStream(out, this.tagsBuffer, this.tagsOffset, this.tagsLength); } return lenToWrite; }
/** * 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} * Named <code>oswrite</code> so does not clash with {@link #write(KeyValue, DataOutput)} * @param kv * @param out * @param withTags * @return Length written on stream * @throws IOException * @see #create(DataInput) for the inverse function * @see #write(KeyValue, DataOutput) * @see KeyValueUtil#oswrite(Cell, OutputStream, boolean) * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. * Instead use {@link #write(OutputStream, boolean)} */ @Deprecated public static long oswrite(final KeyValue kv, final OutputStream out, final boolean withTags) throws IOException { ByteBufferUtils.putInt(out, kv.getSerializedSize(withTags)); return (long) kv.write(out, withTags) + Bytes.SIZEOF_INT; }
@Override public void write(Cell cell) throws IOException { checkFlushed(); // Do not write tags over RPC ByteBufferUtils.putInt(this.out, KeyValueUtil.getSerializedSize(cell, false)); KeyValueUtil.oswrite(cell, out, false); } }
@Override public void write(Cell cell) throws IOException { checkFlushed(); // Write tags ByteBufferUtils.putInt(this.out, KeyValueUtil.getSerializedSize(cell, true)); KeyValueUtil.oswrite(cell, out, true); } }
/** * Made into a static method so as to reuse the logic * within ValueAndTagRewriteByteBufferExtendedCell */ static void write(ByteBuffer buf, int offset, Cell cell, byte[] value, byte[] tags) { offset = ByteBufferUtils.putInt(buf, offset, KeyValueUtil.keyLength(cell));// Key length offset = ByteBufferUtils.putInt(buf, offset, value.length);// Value length offset = KeyValueUtil.appendKeyTo(cell, buf, offset); ByteBufferUtils.copyFromArrayToBuffer(buf, offset, value, 0, value.length); offset += value.length; int tagsLen = tags == null ? 0 : tags.length; if (tagsLen > 0) { offset = ByteBufferUtils.putAsShort(buf, offset, tagsLen); ByteBufferUtils.copyFromArrayToBuffer(buf, offset, tags, 0, tagsLen); } }
@Override public void write(Cell cell) throws IOException { checkFlushed(); // Make sure to write tags into WAL ByteBufferUtils.putInt(this.out, KeyValueUtil.getSerializedSize(cell, true)); KeyValueUtil.oswrite(cell, this.out, true); } }
private void testPutInt(int value) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ByteBufferUtils.putInt(baos, value); } catch (IOException e) { throw new RuntimeException("Bug in putIn()", e); } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputStream dis = new DataInputStream(bais); try { assertEquals(dis.readInt(), value); } catch (IOException e) { throw new RuntimeException("Bug in test!", e); } }
/** * Copy the Cell content into the passed buf in KeyValue serialization format. */ public static int appendTo(Cell cell, ByteBuffer buf, int offset, boolean withTags) { offset = ByteBufferUtils.putInt(buf, offset, keyLength(cell));// Key length offset = ByteBufferUtils.putInt(buf, offset, cell.getValueLength());// Value length offset = appendKeyTo(cell, buf, offset); offset = CellUtil.copyValueTo(cell, buf, offset);// Value bytes int tagsLength = cell.getTagsLength(); if (withTags && (tagsLength > 0)) { offset = ByteBufferUtils.putAsShort(buf, offset, tagsLength);// Tags length offset = PrivateCellUtil.copyTagsTo(cell, buf, offset);// Tags bytes } return offset; }
private static void writeToCOS(Message result, Message header, int totalSize, ByteBuffer pbBuf) throws IOException { ByteBufferUtils.putInt(pbBuf, totalSize); // create COS that works on BB CodedOutputStream cos = CodedOutputStream.newInstance(pbBuf); if (header != null) { cos.writeMessageNoTag(header); } if (result != null) { cos.writeMessageNoTag(result); } cos.flush(); cos.checkNoSpaceLeft(); }
for (KeyValue kv : keyValues) { DataOutputStream os = new DataOutputStream(byteArrayOutputStream); ByteBufferUtils.putInt(os, KeyValueUtil.getSerializedSize(kv, true)); KeyValueUtil.oswrite(kv, os, true);
chunkArray[chunkArrayIdx++] = idxChunk; idxOffset = ByteBufferUtils.putInt(idxBuffer, idxOffset, dataChunk.getId()); // write data chunk id idxOffset = ByteBufferUtils.putInt(idxBuffer, idxOffset, dataStartOfset); // offset idxOffset = ByteBufferUtils.putInt(idxBuffer, idxOffset, kv.getSerializedSize()); // length