org.apache.fluo.api.data.Bytes类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中org.apache.fluo.api.data.Bytes类的一些代码示例,展示了Bytes类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes类的具体详情如下:
包路径:org.apache.fluo.api.data.Bytes
类名称:Bytes

Bytes介绍

[英]Represents bytes in Fluo. Bytes is an immutable wrapper around a byte array. Bytes always copies on creation and never lets its internal byte array escape. Its modeled after Java's String which is an immutable wrapper around a char array. It was created because there is nothing in Java like it at the moment. Its very nice having this immutable type, it avoids having to do defensive copies to ensure correctness. Maybe one day Java will have equivalents of String, StringBuilder, and Charsequence for bytes.

The reason Fluo did not use ByteBuffer is because its not immutable, even a read only ByteBuffer has a mutable position. This makes ByteBuffer unsuitable for place where an immutable data type is desirable, like a key for a map.

Bytes.EMPTY is used to represent a Bytes object with no data.
[中]表示Fluo中的字节。字节是围绕字节数组的不可变包装器。字节总是在创建时复制,从不让其内部字节数组转义。它以Java的字符串为模型,该字符串是围绕字符数组的不可变包装器。它之所以被创建,是因为目前Java中没有任何东西能与之媲美。拥有这种不可变类型非常好,它避免了必须进行防御拷贝以确保正确性。也许有一天Java将拥有字符串、StringBuilder和字节的Charsequence的等价物。
Fluo不使用ByteBuffer的原因是它不是不可变的,即使是只读ByteBuffer也有可变的位置。这使得ByteBuffer不适合于需要不可变数据类型的地方,比如地图的键。
字节。EMPTY用于表示没有数据的Bytes对象。

代码示例

代码示例来源:origin: org.apache.fluo/fluo-api

/**
 * @param row (will be UTF-8 encoded)
 * @param val (will be UTF-8 encoded)
 */
public RowColumnValue(CharSequence row, Column col, CharSequence val) {
 this.row = Bytes.of(row);
 this.col = col;
 this.val = Bytes.of(val);
}

代码示例来源:origin: apache/fluo

/**
 * @return this
 */
public FluoKeyValueGenerator setRow(Bytes row) {
 this.row = row.toArray();
 return this;
}

代码示例来源:origin: org.apache.fluo/fluo-api

/**
 * Retrieves Row in RowColumn as a String using UTF-8 encoding.
 *
 * @return Row
 */
public String getsRow() {
 return row.toString();
}

代码示例来源:origin: org.apache.rya/rya.pcj.fluo.app

private static boolean hasHash(Bytes prefixBytes, Bytes row) {
  for (int i = prefixBytes.length() + 1; i < prefixBytes.length() + HASH_LEN; i++) {
    byte b = row.byteAt(i);
    boolean isAlphaNum = (b >= 'a' && b <= 'z') || (b >= '0' && b <= '9');
    if (!isAlphaNum) {
      return false;
    }
  }
  if (row.byteAt(prefixBytes.length()) != ':' || row.byteAt(prefixBytes.length() + HASH_LEN + 1) != ':') {
    return false;
  }
  return true;
}

代码示例来源:origin: org.apache.rya/rya.pcj.fluo.app

/**
   * Removes the triple prefix and returns the new value as a byte array.
   * @param prefixedTriple - serialized RyaStatement with prepended triple prefix, converted to Bytes
   * @return - serialized {@link RyaStatement} in byte array form
   */
  public static byte[] removeTriplePrefixAndConvertToByteArray(Bytes prefixedTriple) {
    checkNotNull(prefixedTriple);
    return prefixedTriple.subSequence(TRIPLE_PREFIX_BYTES.length(), prefixedTriple.length()).toArray();
  }
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

/**
 * @return Returns input with prefix and hash stripped from beginning.
 */
public Bytes removeHash(Bytes row) {
 Preconditions.checkArgument(row.length() >= prefixBytes.length() + 5,
   "Row is shorter than expected " + row);
 Preconditions.checkArgument(row.subSequence(0, prefixBytes.length()).equals(prefixBytes),
   "Row does not have expected prefix " + row);
 Preconditions.checkArgument(hasHash(row), "Row does not have expected hash " + row);
 return row.subSequence(prefixBytes.length() + 5, row.length());
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

public RowHasher(String prefix) {
 this.prefix = prefix;
 this.prefixBytes = Bytes.of(prefix + ":");
 builders = ThreadLocal.withInitial(() -> {
  BytesBuilder bb = Bytes.builder(prefixBytes.length() + 5 + 32);
  bb.append(prefixBytes);
  return bb;
 });
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

ExportBucket(TransactionBase tx, Bytes bucketRow) {
 this.ttx = new TypeLayer(new StringEncoder()).wrap(tx);
 int colonLoc = -1;
 for (int i = 0; i < bucketRow.length(); i++) {
  if (bucketRow.byteAt(i) == ':') {
   colonLoc = i;
   break;
  }
 }
 Preconditions.checkArgument(colonLoc != -1 && colonLoc != bucketRow.length(),
   "Invalid bucket row " + bucketRow);
 Preconditions.checkArgument(bucketRow.byteAt(bucketRow.length() - 1) == ':',
   "Invalid bucket row " + bucketRow);
 this.bucketRow = bucketRow.subSequence(0, bucketRow.length() - 1);
 this.qid = bucketRow.subSequence(0, colonLoc).toString();
}

代码示例来源:origin: org.apache.rya/rya.pcj.fluo.app

/**
 * @return Returns input with prefix and hash stripped from beginning.
 */
public static Bytes removeHash(Bytes prefixBytes, Bytes row) {
  checkNotNull(prefixBytes);
  checkNotNull(row);
  checkArgument(row.length() >= prefixBytes.length() + 6, "Row is shorter than expected " + row);
  checkArgument(row.subSequence(0, prefixBytes.length()).equals(prefixBytes),
      "Row does not have expected prefix " + row);
  checkArgument(hasHash(prefixBytes, row), "Row does not have expected hash " + row);
  BytesBuilder builder = Bytes.builder();
  builder.append(prefixBytes);
  builder.append("_");
  builder.append(row.subSequence(prefixBytes.length() + 6, row.length()));
  return builder.toBytes();
}

代码示例来源:origin: apache/fluo

public static void increment(TransactionBase tx, Bytes row, Column col, int val) {
 int prev = 0;
 String prevStr = tx.get(row, col, ZERO).toString();
 prev = Integer.parseInt(prevStr);
 tx.set(row, col, Bytes.of(prev + val + ""));
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

@Override
public boolean equals(Object o) {
 if (o instanceof RowRange) {
  RowRange or = (RowRange) o;
  return start.equals(or.start) && end.equals(or.end);
 }
 return false;
}

代码示例来源:origin: apache/fluo

public LockValue(byte[] enc) {
 List<Bytes> fields = ByteArrayUtil.split(enc);
 if (fields.size() != 6) {
  throw new IllegalArgumentException("more fields than expected");
 }
 this.prow = fields.get(0);
 this.pcol = new Column(fields.get(1), fields.get(2), fields.get(3));
 this.isWrite = (fields.get(4).byteAt(0) & 0x1) == 0x1;
 this.isDelete = (fields.get(4).byteAt(0) & 0x2) == 0x2;
 this.isTrigger = (fields.get(4).byteAt(0) & 0x4) == 0x4;
 this.transactor = ByteArrayUtil.decodeLong(fields.get(5).toArray());
}

代码示例来源:origin: org.apache.fluo/fluo-api

public BytesBuilder append(Bytes b) {
 ensureCapacity(len + b.length);
 System.arraycopy(b.data, b.offset, ba, len, b.length);
 len += b.length();
 return this;
}

代码示例来源:origin: org.apache.fluo/fluo-core

public static void put(Environment env, Mutation m, Column col, long ts, byte[] val) {
  ColumnVisibility cv;
  if (env != null) {
   cv = env.getSharedResources().getVisCache().getCV(col.getVisibility());
  } else if (col.getVisibility().length() == 0) {
   cv = VisibilityCache.EMPTY_VIS;
  } else {
   cv = new ColumnVisibility(ByteUtil.toText(col.getVisibility()));
  }

  m.put(col.getFamily().toArray(), col.getQualifier().toArray(), cv, ts, val);
 }
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

/**
 * Computes the minimial row for a bucket
 */
private Bytes getMinimalRow() {
 return Bytes.builder(bucketRow.length() + 1).append(bucketRow).append(':').toBytes();
}

代码示例来源:origin: apache/fluo

public static void deserialize(Consumer<Bytes> splitConsumer, byte[] serializedSplits) {
 try {
  ByteArrayInputStream bais = new ByteArrayInputStream(serializedSplits);
  GZIPInputStream gzis = new GZIPInputStream(bais);
  DataInputStream dis = new DataInputStream(gzis);
  int numSplits = dis.readInt();
  BytesBuilder builder = Bytes.builder();
  for (int i = 0; i < numSplits; i++) {
   int len = dis.readInt();
   builder.setLength(0);
   builder.append(dis, len);
   splitConsumer.accept(builder.toBytes());
  }
 } catch (IOException e) {
  throw new UncheckedIOException(e);
 }
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

private static long decodeSeq(Bytes seq) {
 return (((long) seq.byteAt(0) << 56) + ((long) (seq.byteAt(1) & 255) << 48)
   + ((long) (seq.byteAt(2) & 255) << 40) + ((long) (seq.byteAt(3) & 255) << 32)
   + ((long) (seq.byteAt(4) & 255) << 24) + ((seq.byteAt(5) & 255) << 16)
   + ((seq.byteAt(6) & 255) << 8) + ((seq.byteAt(7) & 255) << 0));
}

代码示例来源:origin: org.apache.fluo/fluo-recipes-core

public void add(long seq, byte[] key, byte[] value) {
 BytesBuilder builder = Bytes.builder(bucketRow.length() + 1 + key.length + 8).append(bucketRow)
   .append(':').append(key);
 encSeq(builder, seq);
 ttx.set(builder.toBytes(), EXPORT_COL, Bytes.of(value));
}

代码示例来源:origin: apache/incubator-rya

private static boolean hasHash(Bytes prefixBytes, Bytes row) {
  for (int i = prefixBytes.length() + 1; i < prefixBytes.length() + HASH_LEN; i++) {
    byte b = row.byteAt(i);
    boolean isAlphaNum = (b >= 'a' && b <= 'z') || (b >= '0' && b <= '9');
    if (!isAlphaNum) {
      return false;
    }
  }
  if (row.byteAt(prefixBytes.length()) != ':' || row.byteAt(prefixBytes.length() + HASH_LEN + 1) != ':') {
    return false;
  }
  return true;
}

代码示例来源:origin: apache/incubator-rya

/**
 * @return Returns input with prefix and hash stripped from beginning.
 */
public static Bytes removeHash(Bytes prefixBytes, Bytes row) {
  checkNotNull(prefixBytes);
  checkNotNull(row);
  checkArgument(row.length() >= prefixBytes.length() + 6, "Row is shorter than expected " + row);
  checkArgument(row.subSequence(0, prefixBytes.length()).equals(prefixBytes),
      "Row does not have expected prefix " + row);
  checkArgument(hasHash(prefixBytes, row), "Row does not have expected hash " + row);
  BytesBuilder builder = Bytes.builder();
  builder.append(prefixBytes);
  builder.append("_");
  builder.append(row.subSequence(prefixBytes.length() + 6, row.length()));
  return builder.toBytes();
}

相关文章