/** * Creates a new mutation from a Thrift mutation. * * @param tmutation * Thrift mutation */ public Mutation(TMutation tmutation) { this.row = ByteBufferUtil.toBytes(tmutation.row); this.data = ByteBufferUtil.toBytes(tmutation.data); this.entries = tmutation.entries; this.values = ByteBufferUtil.toBytesList(tmutation.values); if (tmutation.isSetSources()) { this.replicationSources = new HashSet<>(tmutation.sources); } if (this.row == null) { throw new IllegalArgumentException("null row"); } if (this.data == null) { throw new IllegalArgumentException("null serialized data"); } }
/** * Creates a Value using the bytes in a buffer as the initial value. Makes a defensive copy. * * @param bytes * May not be null */ public Value(ByteBuffer bytes) { /* TODO ACCUMULO-2509 right now this uses the entire backing array, which must be accessible. */ this(toBytes(bytes), false); }
/** * Constructs a token from a copy of the password. Destroying the argument after construction will * not destroy the copy in this token, and destroying this token will only destroy the copy held * inside this token, not the argument. */ public PasswordToken(ByteBuffer password) { this.password = ByteBufferUtil.toBytes(password); }
public static List<byte[]> toBytesList(Collection<ByteBuffer> bytesList) { if (bytesList == null) return null; ArrayList<byte[]> result = new ArrayList<>(bytesList.size()); for (ByteBuffer bytes : bytesList) { result.add(toBytes(bytes)); } return result; }
public static void write(DataOutput out, ByteBuffer buffer) throws IOException { if (buffer.hasArray()) { out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { out.write(toBytes(buffer)); } }
public static String toString(ByteBuffer bytes) { if (bytes.hasArray()) { return new String(bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining(), UTF_8); } else { return new String(toBytes(bytes), UTF_8); } }
public static Text toText(ByteBuffer byteBuffer) { if (byteBuffer == null) return null; if (byteBuffer.hasArray()) { Text result = new Text(); result.set(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), byteBuffer.remaining()); return result; } else { return new Text(toBytes(byteBuffer)); } }
public static ByteArrayInputStream toByteArrayInputStream(ByteBuffer buffer) { if (buffer.hasArray()) { return new ByteArrayInputStream(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { return new ByteArrayInputStream(toBytes(buffer)); } } }
/** * Sets the column family of a mutation. * * @param colFam * column family * @return a QualifierOptions object, advancing the method chain */ @Override public QualifierOptions family(ByteBuffer colFam) { return family(ByteBufferUtil.toBytes(colFam)); }
/** * Sets the column qualifier of a mutation. * * @param colQual * column qualifier * @return a VisibilityOptions object, advancing the method chain */ @Override public VisibilityOptions qualifier(ByteBuffer colQual) { return qualifier(ByteBufferUtil.toBytes(colQual)); }
/** * Sets the column visibility of a mutation. * * @param colVis * column visibility * @return a TimestampOptions object, advancing the method chain */ @Override public TimestampOptions visibility(ByteBuffer colVis) { return visibility(ByteBufferUtil.toBytes(colVis)); }
/** * Ends method chain with a put of a ByteBuffer value * * @param val * value */ @Override public Mutation put(ByteBuffer val) { return put(ByteBufferUtil.toBytes(val), false); }
/** * Creates a new reader. * * @param buffer * byte buffer containing bytes to read */ public Reader(ByteBuffer buffer) { if (buffer.hasArray() && buffer.array().length == buffer.arrayOffset() + buffer.limit()) { offset = buffer.arrayOffset() + buffer.position(); data = buffer.array(); } else { offset = 0; data = ByteBufferUtil.toBytes(buffer); } }
/** * Creates a new sequence based on a byte buffer. If the byte buffer has an array, that array (and * the buffer's offset and limit) are used; otherwise, a new backing array is created and a * relative bulk get is performed to transfer the buffer's contents (starting at its current * position and not beyond its limit). * * @param buffer * byte buffer */ public ArrayByteSequence(ByteBuffer buffer) { if (buffer.hasArray()) { this.data = buffer.array(); this.offset = buffer.position() + buffer.arrayOffset(); this.length = buffer.remaining(); } else { this.offset = 0; this.data = ByteBufferUtil.toBytes(buffer); this.length = data.length; } }
/** * Write the split values to a tmp directory with unique name. Given that it is not known if the * supplied splits will be textual or binary, all splits will be encoded to enable proper handling * of binary data. */ private void writeSplitsToFileSystem(final FSDataOutputStream stream, final List<ByteBuffer> arguments, final int splitCount, final int splitOffset) throws IOException { for (int i = splitOffset; i < splitCount + splitOffset; i++) { byte[] splitBytes = ByteBufferUtil.toBytes(arguments.get(i)); String encodedSplit = Base64.getEncoder().encodeToString(splitBytes); stream.writeBytes(encodedSplit + '\n'); } }
public KeyExtent(TKeyExtent tke) { this.setTableId(Table.ID.of(new String(ByteBufferUtil.toBytes(tke.table), UTF_8))); this.setEndRow(tke.endRow == null ? null : new Text(ByteBufferUtil.toBytes(tke.endRow)), false, false); this.setPrevEndRow( tke.prevEndRow == null ? null : new Text(ByteBufferUtil.toBytes(tke.prevEndRow)), false, false); check(); }
/** * Constructs an authorization object from a list of string authorizations that have each already * been encoded as UTF-8 bytes. Warning: This method does not verify that each encoded string is * valid UTF-8. * * @param authorizations * list of authorizations, as strings encoded in UTF-8 and placed in buffers * @throws IllegalArgumentException * if authorizations is null * @see #Authorizations(String...) */ public Authorizations(List<ByteBuffer> authorizations) { checkArgument(authorizations != null, "authorizations is null"); for (ByteBuffer buffer : authorizations) { auths.add(new ArrayByteSequence(ByteBufferUtil.toBytes(buffer))); } checkAuths(); }
@Override public boolean isValidAuthorizations(String user, List<ByteBuffer> auths) { if (auths.isEmpty()) { // avoid deserializing auths from ZK cache return true; } Authorizations userauths = getCachedUserAuthorizations(user); for (ByteBuffer auth : auths) { if (!userauths.contains(ByteBufferUtil.toBytes(auth))) { return false; } } return true; } }
@Override public TConditionalSession startConditionalUpdate(TInfo tinfo, TCredentials credentials, List<ByteBuffer> authorizations, String tableIdStr, TDurability tdurabilty, String classLoaderContext) throws ThriftSecurityException, TException { Table.ID tableId = Table.ID.of(tableIdStr); Authorizations userauths = null; Namespace.ID namespaceId = getNamespaceId(credentials, tableId); if (!security.canConditionallyUpdate(credentials, tableId, namespaceId)) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); userauths = security.getUserAuthorizations(credentials); for (ByteBuffer auth : authorizations) if (!userauths.contains(ByteBufferUtil.toBytes(auth))) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS); ConditionalSession cs = new ConditionalSession(credentials, new Authorizations(authorizations), tableId, DurabilityImpl.fromThrift(tdurabilty)); long sid = sessionManager.createSession(cs, false); return new TConditionalSession(sid, lockID, sessionManager.getMaxIdleTime()); }