本文整理了Java中io.grpc.Metadata.name()
方法的一些代码示例,展示了Metadata.name()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.name()
方法的具体详情如下:
包路径:io.grpc.Metadata
类名称:Metadata
方法名:name
暂无
代码示例来源:origin: io.grpc/grpc-core
/**
* Returns set of all keys in store.
*
* @return unmodifiable Set of keys
*/
@SuppressWarnings("deprecation") // The String ctor is deprecated, but fast.
public Set<String> keys() {
if (isEmpty()) {
return Collections.emptySet();
}
Set<String> ks = new HashSet<String>(size);
for (int i = 0; i < size; i++) {
ks.add(new String(name(i), 0 /* hibyte */));
}
// immutable in case we decide to change the implementation later.
return Collections.unmodifiableSet(ks);
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Returns set of all keys in store.
*
* @return unmodifiable Set of keys
*/
@SuppressWarnings("deprecation") // The String ctor is deprecated, but fast.
public Set<String> keys() {
if (isEmpty()) {
return Collections.emptySet();
}
Set<String> ks = new HashSet<String>(size);
for (int i = 0; i < size; i++) {
ks.add(new String(name(i), 0 /* hibyte */));
}
// immutable in case we decide to change the implementation later.
return Collections.unmodifiableSet(ks);
}
代码示例来源:origin: io.grpc/grpc-core
@SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0
@Override
public String toString() {
StringBuilder sb = new StringBuilder("Metadata(");
for (int i = 0; i < size; i++) {
if (i != 0) {
sb.append(',');
}
String headerName = new String(name(i), US_ASCII);
sb.append(headerName).append('=');
if (headerName.endsWith(BINARY_HEADER_SUFFIX)) {
sb.append(BASE64_ENCODING_OMIT_PADDING.encode(value(i)));
} else {
String headerValue = new String(value(i), US_ASCII);
sb.append(headerValue);
}
}
return sb.append(')').toString();
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Merge values from the given set of keys into this set of metadata. If a key is present in keys,
* then all of the associated values will be copied over.
*
* @param other The source of the new key values.
* @param keys The subset of matching key we want to copy, if they exist in the source.
*/
public void merge(Metadata other, Set<Key<?>> keys) {
Preconditions.checkNotNull(other, "other");
// Use ByteBuffer for equals and hashCode.
Map<ByteBuffer, Key<?>> asciiKeys = new HashMap<ByteBuffer, Key<?>>(keys.size());
for (Key<?> key : keys) {
asciiKeys.put(ByteBuffer.wrap(key.asciiName()), key);
}
for (int i = 0; i < other.size; i++) {
ByteBuffer wrappedNamed = ByteBuffer.wrap(other.name(i));
if (asciiKeys.containsKey(wrappedNamed)) {
maybeExpand();
name(size, other.name(i));
value(size, other.value(i));
size++;
}
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
@SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0
@Override
public String toString() {
StringBuilder sb = new StringBuilder("Metadata(");
for (int i = 0; i < size; i++) {
if (i != 0) {
sb.append(',');
}
String headerName = new String(name(i), US_ASCII);
sb.append(headerName).append('=');
if (headerName.endsWith(BINARY_HEADER_SUFFIX)) {
sb.append(BaseEncoding.base64().encode(value(i)));
} else {
String headerValue = new String(value(i), US_ASCII);
sb.append(headerValue);
}
}
return sb.append(')').toString();
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Returns true if a value is defined for the given key.
*
* <p>This is done by linear search, so if it is followed by {@link #get} or {@link #getAll},
* prefer calling them directly and checking the return value against {@code null}.
*/
public boolean containsKey(Key<?> key) {
for (int i = 0; i < size; i++) {
if (bytesEqual(key.asciiName(), name(i))) {
return true;
}
}
return false;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Returns true if a value is defined for the given key.
*
* <p>This is done by linear search, so if it is followed by {@link #get} or {@link #getAll},
* prefer calling them directly and checking the return value against {@code null}.
*/
public boolean containsKey(Key<?> key) {
for (int i = 0; i < size; i++) {
if (bytesEqual(key.asciiName(), name(i))) {
return true;
}
}
return false;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Merge values from the given set of keys into this set of metadata. If a key is present in keys,
* then all of the associated values will be copied over.
*
* @param other The source of the new key values.
* @param keys The subset of matching key we want to copy, if they exist in the source.
*/
public void merge(Metadata other, Set<Key<?>> keys) {
Preconditions.checkNotNull(other, "other");
// Use ByteBuffer for equals and hashCode.
Map<ByteBuffer, Key<?>> asciiKeys = new HashMap<ByteBuffer, Key<?>>(keys.size());
for (Key<?> key : keys) {
asciiKeys.put(ByteBuffer.wrap(key.asciiName()), key);
}
for (int i = 0; i < other.size; i++) {
ByteBuffer wrappedNamed = ByteBuffer.wrap(other.name(i));
if (asciiKeys.containsKey(wrappedNamed)) {
maybeExpand();
name(size, other.name(i));
value(size, other.value(i));
size++;
}
}
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Returns all the metadata entries named 'name', in the order they were received, parsed as T, or
* null if there are none. The iterator is not guaranteed to be "live." It may or may not be
* accurate if Metadata is mutated.
*/
@Nullable
public <T> Iterable<T> getAll(final Key<T> key) {
for (int i = 0; i < size; i++) {
if (bytesEqual(key.asciiName(), name(i))) {
return new IterableAt<T>(key, i);
}
}
return null;
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Adds the {@code key, value} pair. If {@code key} already has values, {@code value} is added to
* the end. Duplicate values for the same key are permitted.
*
* @throws NullPointerException if key or value is null
*/
public <T> void put(Key<T> key, T value) {
Preconditions.checkNotNull(key, "key");
Preconditions.checkNotNull(value, "value");
maybeExpand();
name(size, key.asciiName());
value(size, key.toBytes(value));
size++;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Returns all the metadata entries named 'name', in the order they were received, parsed as T, or
* null if there are none. The iterator is not guaranteed to be "live." It may or may not be
* accurate if Metadata is mutated.
*/
@Nullable
public <T> Iterable<T> getAll(final Key<T> key) {
for (int i = 0; i < size; i++) {
if (bytesEqual(key.asciiName(), name(i))) {
return new IterableAt<T>(key, i);
}
}
return null;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/** Remove all values for the given key. If there were no values, {@code null} is returned. */
public <T> Iterable<T> removeAll(Key<T> key) {
if (isEmpty()) {
return null;
}
int writeIdx = 0;
int readIdx = 0;
List<T> ret = null;
for (; readIdx < size; readIdx++) {
if (bytesEqual(key.asciiName(), name(readIdx))) {
ret = ret != null ? ret : new ArrayList<T>();
ret.add(key.parseBytes(value(readIdx)));
continue;
}
name(writeIdx, name(readIdx));
value(writeIdx, value(readIdx));
writeIdx++;
}
int newSize = writeIdx;
// Multiply by two since namesAndValues is interleaved.
Arrays.fill(namesAndValues, writeIdx * 2, len(), null);
size = newSize;
return ret;
}
代码示例来源:origin: io.grpc/grpc-core
/** Remove all values for the given key. If there were no values, {@code null} is returned. */
public <T> Iterable<T> removeAll(Key<T> key) {
if (isEmpty()) {
return null;
}
int writeIdx = 0;
int readIdx = 0;
List<T> ret = null;
for (; readIdx < size; readIdx++) {
if (bytesEqual(key.asciiName(), name(readIdx))) {
ret = ret != null ? ret : new ArrayList<T>();
ret.add(key.parseBytes(value(readIdx)));
continue;
}
name(writeIdx, name(readIdx));
value(writeIdx, value(readIdx));
writeIdx++;
}
int newSize = writeIdx;
// Multiply by two since namesAndValues is interleaved.
Arrays.fill(namesAndValues, writeIdx * 2, len(), null);
size = newSize;
return ret;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Returns the last metadata entry added with the name 'name' parsed as T.
*
* @return the parsed metadata entry or null if there are none.
*/
@Nullable
public <T> T get(Key<T> key) {
for (int i = size - 1; i >= 0; i--) {
if (bytesEqual(key.asciiName(), name(i))) {
return key.parseBytes(value(i));
}
}
return null;
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Remove all values for the given key without returning them. This is a minor performance
* optimization if you do not need the previous values.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4691")
public <T> void discardAll(Key<T> key) {
if (isEmpty()) {
return;
}
int writeIdx = 0;
int readIdx = 0;
for (; readIdx < size; readIdx++) {
if (bytesEqual(key.asciiName(), name(readIdx))) {
continue;
}
name(writeIdx, name(readIdx));
value(writeIdx, value(readIdx));
writeIdx++;
}
int newSize = writeIdx;
// Multiply by two since namesAndValues is interleaved.
Arrays.fill(namesAndValues, writeIdx * 2, len(), null);
size = newSize;
}
代码示例来源:origin: io.grpc/grpc-core
Preconditions.checkNotNull(value, "value");
for (int i = 0; i < size; i++) {
if (!bytesEqual(key.asciiName(), name(i))) {
continue;
System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen);
size -= 1;
name(size, null);
value(size, null);
return true;
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Remove all values for the given key without returning them. This is a minor performance
* optimization if you do not need the previous values.
*/
@ExperimentalApi
public <T> void discardAll(Key<T> key) {
if (isEmpty()) {
return;
}
int writeIdx = 0;
int readIdx = 0;
for (; readIdx < size; readIdx++) {
if (bytesEqual(key.asciiName(), name(readIdx))) {
continue;
}
name(writeIdx, name(readIdx));
value(writeIdx, value(readIdx));
writeIdx++;
}
int newSize = writeIdx;
// Multiply by two since namesAndValues is interleaved.
Arrays.fill(namesAndValues, writeIdx * 2, len(), null);
size = newSize;
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Returns the last metadata entry added with the name 'name' parsed as T.
*
* @return the parsed metadata entry or null if there are none.
*/
@Nullable
public <T> T get(Key<T> key) {
for (int i = size - 1; i >= 0; i--) {
if (bytesEqual(key.asciiName(), name(i))) {
return key.parseBytes(value(i));
}
}
return null;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
Preconditions.checkNotNull(value, "value");
for (int i = 0; i < size; i++) {
if (!bytesEqual(key.asciiName(), name(i))) {
continue;
System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen);
size -= 1;
name(size, null);
value(size, null);
return true;
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Adds the {@code key, value} pair. If {@code key} already has values, {@code value} is added to
* the end. Duplicate values for the same key are permitted.
*
* @throws NullPointerException if key or value is null
*/
public <T> void put(Key<T> key, T value) {
Preconditions.checkNotNull(key, "key");
Preconditions.checkNotNull(value, "value");
maybeExpand();
name(size, key.asciiName());
value(size, key.toBytes(value));
size++;
}
内容来源于网络,如有侵权,请联系作者删除!