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

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

Introduction

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

Prototype

@Override
public int getLength() 

Source Link

Document

Returns the number of bytes in the byte array

Usage

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 w  w  w .j a  va 2 s. com
 *          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//from   ww w . j  a  v a 2  s . co 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
 *
 *///from w w  w .  j a v  a2  s .c om
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);
    }
}

From source file:org.apache.accumulo.core.file.rfile.bcfile.Utils.java

License:Apache License

/**
 * Write a String as a VInt n, followed by n Bytes as in Text format.
 *//*  ww  w  . j  a  va2 s .c  om*/
public static void writeString(DataOutput out, String s) throws IOException {
    if (s != null) {
        Text text = new Text(s);
        byte[] buffer = text.getBytes();
        int len = text.getLength();
        writeVInt(out, len);
        out.write(buffer, 0, len);
    } else {
        writeVInt(out, -1);
    }
}

From source file:org.apache.accumulo.core.iterators.conf.ColumnSet.java

License:Apache License

static void encode(StringBuilder sb, Text t) {
    for (int i = 0; i < t.getLength(); i++) {
        int b = (0xff & t.getBytes()[i]);

        // very inefficient code
        if ((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || b == '_'
                || b == '-') {
            sb.append((char) b);
        } else {/*from   ww  w  . ja  va 2 s . c  o  m*/
            sb.append('%');
            sb.append(String.format("%02x", b));
        }
    }
}

From source file:org.apache.accumulo.core.iterators.filter.VisibilityFilter.java

License:Apache License

public boolean accept(Key k, Value v) {
    Text testVis = k.getColumnVisibility(tmpVis);

    if (testVis.getLength() == 0 && defaultVisibility.getLength() == 0)
        return true;
    else if (testVis.getLength() == 0)
        testVis = defaultVisibility;//from  w  w w.ja v  a 2s .c o  m

    Boolean b = (Boolean) cache.get(testVis);
    if (b != null)
        return b;

    try {
        Boolean bb = ve.evaluate(new ColumnVisibility(testVis));
        cache.put(new Text(testVis), bb);
        return bb;
    } catch (VisibilityParseException e) {
        log.error("Parse Error", e);
        return false;
    }
}

From source file:org.apache.accumulo.core.iterators.system.VisibilityFilter.java

License:Apache License

@Override
public boolean accept(Key k, Value v) {
    Text testVis = k.getColumnVisibility(tmpVis);

    if (testVis.getLength() == 0 && defaultVisibility.getLength() == 0)
        return true;
    else if (testVis.getLength() == 0)
        testVis = defaultVisibility;// w  ww  .j a  v a  2s  .c o m

    Boolean b = (Boolean) cache.get(testVis);
    if (b != null)
        return b;

    try {
        Boolean bb = ve.evaluate(new ColumnVisibility(testVis));
        cache.put(new Text(testVis), bb);
        return bb;
    } catch (VisibilityParseException e) {
        log.error("Parse Error", e);
        return false;
    } catch (BadArgumentException e) {
        log.error("Parse Error", e);
        return false;
    }
}

From source file:org.apache.accumulo.core.iterators.user.IndexedDocIterator.java

License:Apache License

@Override
protected Key buildKey(Text partition, Text term, Text docID) {
    Text colq = new Text(term);
    colq.append(nullByte, 0, 1);/*from  www. ja  va  2  s  .  c o m*/
    colq.append(docID.getBytes(), 0, docID.getLength());
    colq.append(nullByte, 0, 1);
    return new Key(partition, indexColf, colq);
}

From source file:org.apache.accumulo.core.iterators.user.IndexedDocIterator.java

License:Apache License

protected Key buildDocKey() {
    if (log.isTraceEnabled())
        log.trace("building doc key for " + currentPartition + " " + currentDocID);
    int zeroIndex = currentDocID.find("\0");
    if (zeroIndex < 0)
        throw new IllegalArgumentException("bad current docID");
    Text colf = new Text(docColf);
    colf.append(nullByte, 0, 1);//from w  w  w.  j  a  v  a2  s .  c o m
    colf.append(currentDocID.getBytes(), 0, zeroIndex);
    docColfSet = Collections
            .singleton((ByteSequence) new ArrayByteSequence(colf.getBytes(), 0, colf.getLength()));
    if (log.isTraceEnabled())
        log.trace(zeroIndex + " " + currentDocID.getLength());
    Text colq = new Text();
    colq.set(currentDocID.getBytes(), zeroIndex + 1, currentDocID.getLength() - zeroIndex - 1);
    Key k = new Key(currentPartition, colf, colq);
    if (log.isTraceEnabled())
        log.trace("built doc key for seek: " + k.toString());
    return k;
}