Java Code Examples for org.apache.hadoop.hbase.util.Bytes#writeByteArray()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#writeByteArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableSnapshotInputFormatImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  TableSnapshotRegionSplit.Builder builder = TableSnapshotRegionSplit.newBuilder()
      .setTable(ProtobufUtil.toTableSchema(htd))
      .setRegion(ProtobufUtil.toRegionInfo(regionInfo));

  for (String location : locations) {
    builder.addLocations(location);
  }

  TableSnapshotRegionSplit split = builder.build();

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  split.writeTo(baos);
  baos.close();
  byte[] buf = baos.toByteArray();
  out.writeInt(buf.length);
  out.write(buf);

  Bytes.writeByteArray(out, Bytes.toBytes(scan));
  Bytes.writeByteArray(out, Bytes.toBytes(restoreDir));

}
 
Example 2
Source File: PColumnImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    Bytes.writeByteArray(output, name.getBytes());
    Bytes.writeByteArray(output, familyName == null ? ByteUtil.EMPTY_BYTE_ARRAY : familyName.getBytes());
    WritableUtils.writeVInt(output, dataType.ordinal());
    WritableUtils.writeVInt(output, maxLength == null ? NO_MAXLENGTH : maxLength);
    WritableUtils.writeVInt(output, scale == null ? NO_SCALE : scale);
    output.writeBoolean(nullable);
    WritableUtils.writeVInt(output, position);
    WritableUtils.writeVInt(output, ColumnModifier.toSystemValue(columnModifier));
}
 
Example 3
Source File: HBaseTableSplitBase.java    From SpyGlass with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
    LOG.debug("WRITE : " + this);

    Bytes.writeByteArray(out, this.m_tableName);
    Bytes.writeByteArray(out, Bytes.toBytes(this.m_regionLocation));
    Bytes.writeByteArray(out, Bytes.toBytes(this.m_regionName));
    Bytes.writeByteArray(out, Bytes.toBytes(this.m_sourceMode.name()));
    Bytes.writeByteArray(out, Bytes.toBytes(this.m_useSalt));

    switch (this.m_sourceMode) {
        case SCAN_RANGE:
            Bytes.writeByteArray(out, this.m_startRow);
            Bytes.writeByteArray(out, this.m_endRow);
            Bytes.writeByteArray(out, Bytes.toBytes(this.m_endRowInclusive));
            break;

        case GET_LIST:
            Bytes.writeByteArray(out, Bytes.toBytes(m_versions));
            Bytes.writeByteArray(out, Bytes.toBytes(this.m_keyList.size()));

            for (String k : this.m_keyList) {
                Bytes.writeByteArray(out, Bytes.toBytes(k));
            }
            break;
    }

    Bytes.writeByteArray(out, Bytes.toBytes(m_timestamp));

    LOG.debug("WROTE : " + out.toString());
}
 
Example 4
Source File: HBaseTableSplitRegional.java    From SpyGlass with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
	LOG.debug("REGIONAL WRITE : " + this);

       super.write(out);

	Bytes.writeByteArray(out, Bytes.toBytes(splits.size()));

	for (HBaseTableSplitGranular hbts : splits) {
		hbts.write(out);
	}

	LOG.debug("REGIONAL WROTE : " + out.toString());
}
 
Example 5
Source File: TableSplit.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the field values to the output.
 *
 * @param out  The output to write to.
 * @throws IOException When writing the values to the output fails.
 */
@Override
public void write(DataOutput out) throws IOException {
  WritableUtils.writeVInt(out, VERSION.code);
  Bytes.writeByteArray(out, tableName.getName());
  Bytes.writeByteArray(out, startRow);
  Bytes.writeByteArray(out, endRow);
  Bytes.writeByteArray(out, Bytes.toBytes(regionLocation));
  Bytes.writeByteArray(out, Bytes.toBytes(scan));
  WritableUtils.writeVLong(out, length);
  Bytes.writeByteArray(out, Bytes.toBytes(encodedRegionName));
}
 
Example 6
Source File: TablePermission.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  super.write(out);
  // Explicitly writing null to maintain se/deserialize backward compatibility.
  Bytes.writeByteArray(out, table == null ? null : table.getName());
  out.writeBoolean(family != null);
  if (family != null) {
    Bytes.writeByteArray(out, family);
  }
  out.writeBoolean(qualifier != null);
  if (qualifier != null) {
    Bytes.writeByteArray(out, qualifier);
  }
}
 
Example 7
Source File: ProjectedColumnExpression.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    schema.write(output);
    output.writeInt(position);
    Bytes.writeByteArray(output, name);
}
 
Example 8
Source File: MultiKeyValueComparisonFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    try {
        output.writeBoolean(allCFs);
        if (!allCFs) {
            Bytes.writeByteArray(output, essentialCF);
        }
    } catch (Throwable t) { // Catches incompatibilities during reading/writing and doesn't retry
        ServerUtil.throwIOException("MultiKeyValueComparisonFilter failed during writing", t);
    }
}
 
Example 9
Source File: PrefixByteEncoder.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Prefix encodes the byte array from offset to length into output stream. 
 * Instead of writing the entire byte array, only the portion of the byte array
 * that differs from the beginning of the previous byte array written is written.
 *  
 * @param out output stream to encode into
 * @param b byte array buffer
 * @param offset offset into byte array to start encoding
 * @param length length of byte array to encode
 * @throws IOException
 */
public void encode(DataOutput out, byte[] b, int offset, int length) throws IOException {
      int i = 0;
      int prevOffset = previous.getOffset();
      byte[] prevBytes = previous.get();
      int prevLength = previous.getLength();
      int minLength = prevLength < b.length ? prevLength : b.length;
      for(i = 0; (i < minLength) && (prevBytes[prevOffset + i] == b[offset + i]); i++);
      WritableUtils.writeVInt(out, i);
      Bytes.writeByteArray(out, b, offset + i, length - i);
      previous.set(b, offset, length);
      if (length > maxLength) {
          maxLength = length;
      }
}
 
Example 10
Source File: KeyValueColumnExpression.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    Bytes.writeByteArray(output, cf);
    Bytes.writeByteArray(output, cq);
}
 
Example 11
Source File: PTableImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    Bytes.writeByteArray(output, schemaName.getBytes());
    Bytes.writeByteArray(output, tableName.getBytes());
    WritableUtils.writeVInt(output, type.ordinal());
    if (type == PTableType.INDEX) {
        WritableUtils.writeVInt(output, state == null ? -1 : state.ordinal());
    }
    WritableUtils.writeVLong(output, sequenceNumber);
    output.writeLong(timeStamp);
    Bytes.writeByteArray(output, pkName == null ? ByteUtil.EMPTY_BYTE_ARRAY : pkName.getBytes());
    int offset = 0, nColumns = allColumns.size();
    if (bucketNum == null) {
        WritableUtils.writeVInt(output, NO_SALTING);
    } else {
        offset = 1;
        nColumns--;
        WritableUtils.writeVInt(output, bucketNum);
    }
    WritableUtils.writeVInt(output, nColumns);
    for (int i = offset; i < allColumns.size(); i++) {
        PColumn column = allColumns.get(i);
        column.write(output);
    }
    WritableUtils.writeVInt(output, indexes.size());
    for (PTable index: indexes) {
        index.write(output);
    }
    output.writeBoolean(isImmutableRows);
    stats.write(output);
    Bytes.writeByteArray(output, parentTableName == null ? ByteUtil.EMPTY_BYTE_ARRAY : parentTableName.getBytes());
    Bytes.writeByteArray(output, defaultFamilyName == null ? ByteUtil.EMPTY_BYTE_ARRAY : defaultFamilyName.getBytes());
    output.writeBoolean(disableWAL);
    output.writeBoolean(multiTenant);
    if (type == PTableType.VIEW) {
        output.writeByte(viewType.getSerializedValue());
        Bytes.writeByteArray(output, viewExpression == null ? ByteUtil.EMPTY_BYTE_ARRAY : PDataType.VARCHAR.toBytes(viewExpression));
        Bytes.writeByteArray(output, baseSchemaName == null ? ByteUtil.EMPTY_BYTE_ARRAY : baseSchemaName.getBytes());
        Bytes.writeByteArray(output, baseTableName.getBytes());
    }
}
 
Example 12
Source File: KeyValueColumnExpression.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    Bytes.writeByteArray(output, cf);
    Bytes.writeByteArray(output, cq);
}
 
Example 13
Source File: SimpleIndexKeyGenerator.java    From hbase-secondary-index with GNU General Public License v3.0 4 votes vote down vote up
/** {@inheritDoc} */
public void write(DataOutput out) throws IOException {
  Bytes.writeByteArray(out, column);
}
 
Example 14
Source File: NamespacePermission.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  super.write(out);
  Bytes.writeByteArray(out, Bytes.toBytes(namespace));
}
 
Example 15
Source File: TableSplit.java    From hbase with Apache License 2.0 4 votes vote down vote up
public void write(DataOutput out) throws IOException {
  Bytes.writeByteArray(out, this.m_tableName.getName());
  Bytes.writeByteArray(out, this.m_startRow);
  Bytes.writeByteArray(out, this.m_endRow);
  Bytes.writeByteArray(out, Bytes.toBytes(this.m_regionLocation));
}
 
Example 16
Source File: KeyValueColumnExpression.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    Bytes.writeByteArray(output, cf);
    Bytes.writeByteArray(output, cq);
}
 
Example 17
Source File: HFileBlockIndex.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Writes this chunk into the given output stream in the root block index
 * format. This format is similar to the {@link HFile} version 1 block
 * index format, except that we store on-disk size of the block instead of
 * its uncompressed size.
 *
 * @param out the data output stream to write the block index to. Typically
 *          a stream writing into an {@link HFile} block.
 * @throws IOException
 */
void writeRoot(DataOutput out) throws IOException {
  for (int i = 0; i < blockKeys.size(); ++i) {
    out.writeLong(blockOffsets.get(i));
    out.writeInt(onDiskDataSizes.get(i));
    Bytes.writeByteArray(out, blockKeys.get(i));
  }
}
 
Example 18
Source File: IndexedKeyValue.java    From phoenix with Apache License 2.0 2 votes vote down vote up
/**
 * Internal write the underlying data for the entry - this does not do any special prefixing. Writing should be done
 * via {@link KeyValueCodec#write(DataOutput, KeyValue)} to ensure consistent reading/writing of
 * {@link IndexedKeyValue}s.
 * 
 * @param out
 *            to write data to. Does not close or flush the passed object.
 * @throws IOException
 *             if there is a problem writing the underlying data
 */
void writeData(DataOutput out) throws IOException {
    Bytes.writeByteArray(out, this.indexTableName.get());
    MutationProto m = toMutationProto(this.mutation);
    Bytes.writeByteArray(out, m.toByteArray());
}
 
Example 19
Source File: IndexedKeyValue.java    From phoenix with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Internal write the underlying data for the entry - this does not do any special prefixing. Writing should be done
 * via {@link KeyValueCodec#write(DataOutput, KeyValue)} to ensure consistent reading/writing of
 * {@link IndexedKeyValue}s.
 * 
 * @param out
 *            to write data to. Does not close or flush the passed object.
 * @throws IOException
 *             if there is a problem writing the underlying data
 */
void writeData(DataOutput out) throws IOException {
    Bytes.writeByteArray(out, this.indexTableName.get());
    out.writeUTF(this.mutation.getClass().getName());
    this.mutation.write(out);
}
 
Example 20
Source File: IndexedKeyValue.java    From phoenix with Apache License 2.0 2 votes vote down vote up
/**
 * Internal write the underlying data for the entry - this does not do any special prefixing.
 * Writing should be done via {@link KeyValueCodec#write(DataOutput, KeyValue)} to ensure
 * consistent reading/writing of {@link IndexedKeyValue}s.
 * 
 * @param out
 *            to write data to. Does not close or flush the passed object.
 * @throws IOException
 *             if there is a problem writing the underlying data
 */
void writeData(DataOutput out) throws IOException {
    Bytes.writeByteArray(out, this.indexTableName.get());
    MutationProto m = toMutationProto(this.mutation);
    Bytes.writeByteArray(out, m.toByteArray());
}