Example usage for org.apache.hadoop.io Text getBytes

List of usage examples for org.apache.hadoop.io Text getBytes

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text getBytes.

Prototype

@Override
public byte[] getBytes() 

Source Link

Document

Returns the raw bytes; however, only data up to #getLength() is valid.

Usage

From source file:org.apache.accumulo.core.data.KeyBuilderTest.java

License:Apache License

@Test
public void testKeyHeterogeneous() {
    Key keyBuilt = Key.builder().row(rowText).family(familyBytes).qualifier("foo").build();
    Text fooText = new Text("foo");
    Key keyExpected = new Key(rowText.getBytes(), 0, rowText.getLength(), familyBytes, 0, familyBytes.length,
            fooText.getBytes(), 0, fooText.getLength(), EMPTY_BYTES, 0, 0, Long.MAX_VALUE);
    assertEquals(keyExpected, keyBuilt);
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

/**
 * Creates a new mutation. A defensive copy is made.
 *
 * @param row//  ww  w.j ava  2s.c o m
 *          row ID
 */
public Mutation(Text row) {
    this(row.getBytes(), 0, row.getLength());
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

/**
 * Creates a new mutation. A defensive copy is made.
 *
 * @param row//from   w  w w.  j av  a  2  s.  co m
 *          row ID
 * @param initialBufferSize
 *          the initial size, in bytes, of the internal buffer for serializing
 * @since 1.7.0
 */
public Mutation(Text row, int initialBufferSize) {
    this(row.getBytes(), 0, row.getLength(), initialBufferSize);
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val) {
    put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val, val.length);
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted, Text val) {
    put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val.getBytes(),
            val.getLength());
}

From source file:org.apache.accumulo.core.data.OldMutation.java

License:Apache License

public OldMutation(Text row) {
    this.row = new byte[row.getLength()];
    System.arraycopy(row.getBytes(), 0, this.row, 0, row.getLength());
    buffer = new ByteBuffer();
}

From source file:org.apache.accumulo.core.data.OldMutation.java

License:Apache License

private void put(Text t) {
    buffer.add(t.getLength());
    buffer.add(t.getBytes(), 0, t.getLength());
}

From source file:org.apache.accumulo.core.data.Range.java

License:Apache License

/**
 * Returns a Text that sorts just after all Texts beginning with a prefix.
 *
 * @param prefix/*from ww w .  j ava  2  s .c  o  m*/
 *          to follow
 * @return prefix that immediately follows the given prefix when sorted, or null if no prefix can follow (i.e., the string is all 0xff bytes)
 */
public static Text followingPrefix(Text prefix) {
    byte[] prefixBytes = prefix.getBytes();

    // find the last byte in the array that is not 0xff
    int changeIndex = prefix.getLength() - 1;
    while (changeIndex >= 0 && prefixBytes[changeIndex] == (byte) 0xff)
        changeIndex--;
    if (changeIndex < 0)
        return null;

    // copy prefix bytes into new array
    byte[] newBytes = new byte[changeIndex + 1];
    System.arraycopy(prefixBytes, 0, newBytes, 0, changeIndex + 1);

    // increment the selected byte
    newBytes[changeIndex]++;
    return new Text(newBytes);
}

From source file:org.apache.accumulo.core.data.Value.java

License:Apache License

/**
 * Creates a Value using the bytes of the Text. Makes a copy, does not use the byte array from the Text.
 *
 * @param text//  w w  w.  j av a2  s.c  o m
 *          may not be null
 *
 * @since 1.8.0
 */
public Value(Text text) {
    this(text.getBytes(), 0, text.getLength());
}

From source file:org.apache.accumulo.core.dataImpl.KeyExtent.java

License:Apache License

/**
 * Populates the extent's fields based on a flatted extent
 *
 *///  ww  w  . java  2 s. c o  m
private void decodeMetadataRow(Text flattenedExtent) {
    int semiPos = -1;
    int ltPos = -1;

    for (int i = 0; i < flattenedExtent.getLength(); i++) {
        if (flattenedExtent.getBytes()[i] == ';' && semiPos < 0) {
            // want the position of the first semicolon
            semiPos = i;
        }

        if (flattenedExtent.getBytes()[i] == '<') {
            ltPos = i;
        }
    }

    if (semiPos < 0 && ltPos < 0) {
        throw new IllegalArgumentException("Metadata row does not contain ; or <  " + flattenedExtent);
    }

    if (semiPos < 0) {

        if (ltPos != flattenedExtent.getLength() - 1) {
            throw new IllegalArgumentException("< must come at end of Metadata row  " + flattenedExtent);
        }

        String decodedString = new String(
                Arrays.copyOfRange(flattenedExtent.getBytes(), 0, flattenedExtent.getLength() - 1), UTF_8);
        TableId tableId = TableId.of(decodedString);
        this.setTableId(tableId);
        this.setEndRow(null, false, false);
    } else {

        TableId tableId = TableId
                .of(new String(Arrays.copyOfRange(flattenedExtent.getBytes(), 0, semiPos), UTF_8));

        Text endRow = new Text();
        endRow.set(flattenedExtent.getBytes(), semiPos + 1, flattenedExtent.getLength() - (semiPos + 1));

        this.setTableId(tableId);

        this.setEndRow(endRow, false, false);
    }
}