id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
19,400
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/kafka/KafkaProperties.java
|
KafkaProperties.partitionKeyStrategy
|
@SuppressWarnings("unchecked")
public static <Message> Descriptor.Properties.Property<Message, PartitionKeyStrategy<Message>> partitionKeyStrategy() {
return PARTITION_KEY_STRATEGY;
}
|
java
|
@SuppressWarnings("unchecked")
public static <Message> Descriptor.Properties.Property<Message, PartitionKeyStrategy<Message>> partitionKeyStrategy() {
return PARTITION_KEY_STRATEGY;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"Message",
">",
"Descriptor",
".",
"Properties",
".",
"Property",
"<",
"Message",
",",
"PartitionKeyStrategy",
"<",
"Message",
">",
">",
"partitionKeyStrategy",
"(",
")",
"{",
"return",
"PARTITION_KEY_STRATEGY",
";",
"}"
] |
A PartitionKeyStrategy produces a key for each message published to a Kafka topic.
The key is used to determine on which topic's partition a message is published. It is guaranteed that messages
with the same key will arrive to the same partition, in the order they are published.
|
[
"A",
"PartitionKeyStrategy",
"produces",
"a",
"key",
"for",
"each",
"message",
"published",
"to",
"a",
"Kafka",
"topic",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/kafka/KafkaProperties.java#L24-L27
|
19,401
|
lagom/lagom
|
service/javadsl/client/src/main/java/com/lightbend/lagom/javadsl/client/CircuitBreakingServiceLocator.java
|
CircuitBreakingServiceLocator.doWithServiceImpl
|
protected <T> CompletionStage<Optional<T>> doWithServiceImpl(String name, Descriptor.Call<?, ?> serviceCall, Function<URI, CompletionStage<T>> block) {
return locate(name, serviceCall).thenCompose(uri -> {
return uri
.map(u -> block.apply(u).thenApply(Optional::of))
.orElseGet(() -> CompletableFuture.completedFuture(Optional.empty()));
});
}
|
java
|
protected <T> CompletionStage<Optional<T>> doWithServiceImpl(String name, Descriptor.Call<?, ?> serviceCall, Function<URI, CompletionStage<T>> block) {
return locate(name, serviceCall).thenCompose(uri -> {
return uri
.map(u -> block.apply(u).thenApply(Optional::of))
.orElseGet(() -> CompletableFuture.completedFuture(Optional.empty()));
});
}
|
[
"protected",
"<",
"T",
">",
"CompletionStage",
"<",
"Optional",
"<",
"T",
">",
">",
"doWithServiceImpl",
"(",
"String",
"name",
",",
"Descriptor",
".",
"Call",
"<",
"?",
",",
"?",
">",
"serviceCall",
",",
"Function",
"<",
"URI",
",",
"CompletionStage",
"<",
"T",
">",
">",
"block",
")",
"{",
"return",
"locate",
"(",
"name",
",",
"serviceCall",
")",
".",
"thenCompose",
"(",
"uri",
"->",
"{",
"return",
"uri",
".",
"map",
"(",
"u",
"->",
"block",
".",
"apply",
"(",
"u",
")",
".",
"thenApply",
"(",
"Optional",
"::",
"of",
")",
")",
".",
"orElseGet",
"(",
"(",
")",
"->",
"CompletableFuture",
".",
"completedFuture",
"(",
"Optional",
".",
"empty",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}"
] |
Do the given block with the given service looked up.
This is invoked by {@link #doWithService(String, Descriptor.Call, Function)}, after wrapping the passed in block
in a circuit breaker if configured to do so.
The default implementation just delegates to the {@link #locate(String, Descriptor.Call)} method, but this method
can be overridden if the service locator wants to inject other behaviour after the service call is complete.
@param name The service name.
@param serviceCall The service call that needs the service lookup.
@param block A block of code that will use the looked up service, typically, to make a call on that service.
@return A future of the result of the block, if the service lookup was successful.
|
[
"Do",
"the",
"given",
"block",
"with",
"the",
"given",
"service",
"looked",
"up",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/client/src/main/java/com/lightbend/lagom/javadsl/client/CircuitBreakingServiceLocator.java#L59-L65
|
19,402
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java
|
RequestHeader.withMethod
|
public RequestHeader withMethod(Method method) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
}
|
java
|
public RequestHeader withMethod(Method method) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
}
|
[
"public",
"RequestHeader",
"withMethod",
"(",
"Method",
"method",
")",
"{",
"return",
"new",
"RequestHeader",
"(",
"method",
",",
"uri",
",",
"protocol",
",",
"acceptedResponseProtocols",
",",
"principal",
",",
"headers",
",",
"lowercaseHeaders",
")",
";",
"}"
] |
Return a copy of this request header with the given method set.
@param method The method to set.
@return A copy of this request header.
|
[
"Return",
"a",
"copy",
"of",
"this",
"request",
"header",
"with",
"the",
"given",
"method",
"set",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java#L92-L94
|
19,403
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java
|
RequestHeader.withUri
|
public RequestHeader withUri(URI uri) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
}
|
java
|
public RequestHeader withUri(URI uri) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
}
|
[
"public",
"RequestHeader",
"withUri",
"(",
"URI",
"uri",
")",
"{",
"return",
"new",
"RequestHeader",
"(",
"method",
",",
"uri",
",",
"protocol",
",",
"acceptedResponseProtocols",
",",
"principal",
",",
"headers",
",",
"lowercaseHeaders",
")",
";",
"}"
] |
Return a copy of this request header with the given uri set.
@param uri The uri to set.
@return A copy of this request header.
|
[
"Return",
"a",
"copy",
"of",
"this",
"request",
"header",
"with",
"the",
"given",
"uri",
"set",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java#L102-L104
|
19,404
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java
|
RequestHeader.withAcceptedResponseProtocols
|
public RequestHeader withAcceptedResponseProtocols(PSequence<MessageProtocol> acceptedResponseProtocols) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
}
|
java
|
public RequestHeader withAcceptedResponseProtocols(PSequence<MessageProtocol> acceptedResponseProtocols) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
}
|
[
"public",
"RequestHeader",
"withAcceptedResponseProtocols",
"(",
"PSequence",
"<",
"MessageProtocol",
">",
"acceptedResponseProtocols",
")",
"{",
"return",
"new",
"RequestHeader",
"(",
"method",
",",
"uri",
",",
"protocol",
",",
"acceptedResponseProtocols",
",",
"principal",
",",
"headers",
",",
"lowercaseHeaders",
")",
";",
"}"
] |
Return a copy of this request header with the given accepted response protocols set.
@param acceptedResponseProtocols The accepted response protocols to set.
@return A copy of this request header.
|
[
"Return",
"a",
"copy",
"of",
"this",
"request",
"header",
"with",
"the",
"given",
"accepted",
"response",
"protocols",
"set",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java#L117-L119
|
19,405
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java
|
RequestHeader.withPrincipal
|
public RequestHeader withPrincipal(Principal principal) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, Optional.ofNullable(principal), headers, lowercaseHeaders);
}
|
java
|
public RequestHeader withPrincipal(Principal principal) {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, Optional.ofNullable(principal), headers, lowercaseHeaders);
}
|
[
"public",
"RequestHeader",
"withPrincipal",
"(",
"Principal",
"principal",
")",
"{",
"return",
"new",
"RequestHeader",
"(",
"method",
",",
"uri",
",",
"protocol",
",",
"acceptedResponseProtocols",
",",
"Optional",
".",
"ofNullable",
"(",
"principal",
")",
",",
"headers",
",",
"lowercaseHeaders",
")",
";",
"}"
] |
Return a copy of this request header with the principal set.
@param principal The principal to set.
@return A copy of this request header.
|
[
"Return",
"a",
"copy",
"of",
"this",
"request",
"header",
"with",
"the",
"principal",
"set",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java#L127-L129
|
19,406
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java
|
RequestHeader.clearPrincipal
|
public RequestHeader clearPrincipal() {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, Optional.empty(), headers, lowercaseHeaders);
}
|
java
|
public RequestHeader clearPrincipal() {
return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, Optional.empty(), headers, lowercaseHeaders);
}
|
[
"public",
"RequestHeader",
"clearPrincipal",
"(",
")",
"{",
"return",
"new",
"RequestHeader",
"(",
"method",
",",
"uri",
",",
"protocol",
",",
"acceptedResponseProtocols",
",",
"Optional",
".",
"empty",
"(",
")",
",",
"headers",
",",
"lowercaseHeaders",
")",
";",
"}"
] |
Return a copy of this request header with the principal cleared.
@return A copy of this request header.
|
[
"Return",
"a",
"copy",
"of",
"this",
"request",
"header",
"with",
"the",
"principal",
"cleared",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/RequestHeader.java#L137-L139
|
19,407
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/MessageHeader.java
|
MessageHeader.getHeader
|
public Optional<String> getHeader(String name) {
PSequence<String> values = lowercaseHeaders.get(name.toLowerCase(Locale.ENGLISH));
if (values == null || values.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(values.get(0));
}
}
|
java
|
public Optional<String> getHeader(String name) {
PSequence<String> values = lowercaseHeaders.get(name.toLowerCase(Locale.ENGLISH));
if (values == null || values.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(values.get(0));
}
}
|
[
"public",
"Optional",
"<",
"String",
">",
"getHeader",
"(",
"String",
"name",
")",
"{",
"PSequence",
"<",
"String",
">",
"values",
"=",
"lowercaseHeaders",
".",
"get",
"(",
"name",
".",
"toLowerCase",
"(",
"Locale",
".",
"ENGLISH",
")",
")",
";",
"if",
"(",
"values",
"==",
"null",
"||",
"values",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Optional",
".",
"of",
"(",
"values",
".",
"get",
"(",
"0",
")",
")",
";",
"}",
"}"
] |
Get the header with the given name.
The lookup is case insensitive.
@param name The name of the header.
@return The header value.
|
[
"Get",
"the",
"header",
"with",
"the",
"given",
"name",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/MessageHeader.java#L67-L74
|
19,408
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/Message.java
|
Message.get
|
@SuppressWarnings("unchecked")
public <Metadata> Optional<Metadata> get(MetadataKey<Metadata> key) {
return Optional.ofNullable((Metadata) metadataMap.get(key));
}
|
java
|
@SuppressWarnings("unchecked")
public <Metadata> Optional<Metadata> get(MetadataKey<Metadata> key) {
return Optional.ofNullable((Metadata) metadataMap.get(key));
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"Metadata",
">",
"Optional",
"<",
"Metadata",
">",
"get",
"(",
"MetadataKey",
"<",
"Metadata",
">",
"key",
")",
"{",
"return",
"Optional",
".",
"ofNullable",
"(",
"(",
"Metadata",
")",
"metadataMap",
".",
"get",
"(",
"key",
")",
")",
";",
"}"
] |
Get the metadata for the given metadata key.
@param key The key of the metadata.
@return The metadata, if found for that key.
|
[
"Get",
"the",
"metadata",
"for",
"the",
"given",
"metadata",
"key",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/Message.java#L40-L43
|
19,409
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/Message.java
|
Message.add
|
public <Metadata> Message<Payload> add(MetadataKey<Metadata> key, Metadata metadata) {
return new Message<>(payload, metadataMap.plus(key, metadata));
}
|
java
|
public <Metadata> Message<Payload> add(MetadataKey<Metadata> key, Metadata metadata) {
return new Message<>(payload, metadataMap.plus(key, metadata));
}
|
[
"public",
"<",
"Metadata",
">",
"Message",
"<",
"Payload",
">",
"add",
"(",
"MetadataKey",
"<",
"Metadata",
">",
"key",
",",
"Metadata",
"metadata",
")",
"{",
"return",
"new",
"Message",
"<>",
"(",
"payload",
",",
"metadataMap",
".",
"plus",
"(",
"key",
",",
"metadata",
")",
")",
";",
"}"
] |
Add a metadata key and value to this message.
@param key The key to add.
@param metadata The metadata to add.
@return A copy of this message with the key and value added.
|
[
"Add",
"a",
"metadata",
"key",
"and",
"value",
"to",
"this",
"message",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/Message.java#L52-L54
|
19,410
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/Message.java
|
Message.create
|
public static <Payload> Message<Payload> create(Payload payload) {
return new Message<>(payload, HashTreePMap.empty());
}
|
java
|
public static <Payload> Message<Payload> create(Payload payload) {
return new Message<>(payload, HashTreePMap.empty());
}
|
[
"public",
"static",
"<",
"Payload",
">",
"Message",
"<",
"Payload",
">",
"create",
"(",
"Payload",
"payload",
")",
"{",
"return",
"new",
"Message",
"<>",
"(",
"payload",
",",
"HashTreePMap",
".",
"empty",
"(",
")",
")",
";",
"}"
] |
Create a message with the given payload.
|
[
"Create",
"a",
"message",
"with",
"the",
"given",
"payload",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/broker/Message.java#L82-L84
|
19,411
|
lagom/lagom
|
service/javadsl/client/src/main/java/com/lightbend/lagom/internal/javadsl/BinderAccessor.java
|
BinderAccessor.binder
|
public static Binder binder(Object module) {
if (module instanceof AbstractModule) {
try {
Method method = AbstractModule.class.getDeclaredMethod("binder");
if (!method.isAccessible()) {
method.setAccessible(true);
}
return (Binder) method.invoke(module);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new IllegalArgumentException("Module must be an instance of AbstractModule");
}
}
|
java
|
public static Binder binder(Object module) {
if (module instanceof AbstractModule) {
try {
Method method = AbstractModule.class.getDeclaredMethod("binder");
if (!method.isAccessible()) {
method.setAccessible(true);
}
return (Binder) method.invoke(module);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new IllegalArgumentException("Module must be an instance of AbstractModule");
}
}
|
[
"public",
"static",
"Binder",
"binder",
"(",
"Object",
"module",
")",
"{",
"if",
"(",
"module",
"instanceof",
"AbstractModule",
")",
"{",
"try",
"{",
"Method",
"method",
"=",
"AbstractModule",
".",
"class",
".",
"getDeclaredMethod",
"(",
"\"binder\"",
")",
";",
"if",
"(",
"!",
"method",
".",
"isAccessible",
"(",
")",
")",
"{",
"method",
".",
"setAccessible",
"(",
"true",
")",
";",
"}",
"return",
"(",
"Binder",
")",
"method",
".",
"invoke",
"(",
"module",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Module must be an instance of AbstractModule\"",
")",
";",
"}",
"}"
] |
Get the binder from an AbstractModule.
|
[
"Get",
"the",
"binder",
"from",
"an",
"AbstractModule",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/client/src/main/java/com/lightbend/lagom/internal/javadsl/BinderAccessor.java#L20-L34
|
19,412
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.withCalls
|
public Descriptor withCalls(Call<?, ?>... calls) {
return replaceAllCalls(this.calls.plusAll(Arrays.asList(calls)));
}
|
java
|
public Descriptor withCalls(Call<?, ?>... calls) {
return replaceAllCalls(this.calls.plusAll(Arrays.asList(calls)));
}
|
[
"public",
"Descriptor",
"withCalls",
"(",
"Call",
"<",
"?",
",",
"?",
">",
"...",
"calls",
")",
"{",
"return",
"replaceAllCalls",
"(",
"this",
".",
"calls",
".",
"plusAll",
"(",
"Arrays",
".",
"asList",
"(",
"calls",
")",
")",
")",
";",
"}"
] |
Add the given service calls to this service.
@param calls The calls to add.
@return A copy of this descriptor with the new calls added.
|
[
"Add",
"the",
"given",
"service",
"calls",
"to",
"this",
"service",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L710-L712
|
19,413
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.replaceAllCalls
|
public Descriptor replaceAllCalls(PSequence<Call<?, ?>> calls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
java
|
public Descriptor replaceAllCalls(PSequence<Call<?, ?>> calls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
[
"public",
"Descriptor",
"replaceAllCalls",
"(",
"PSequence",
"<",
"Call",
"<",
"?",
",",
"?",
">",
">",
"calls",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"topicCalls",
")",
";",
"}"
] |
Replace all the service calls provided by this descriptor with the the given service calls.
@param calls The calls to replace the existing ones with.
@return A copy of this descriptor with the new calls.
|
[
"Replace",
"all",
"the",
"service",
"calls",
"provided",
"by",
"this",
"descriptor",
"with",
"the",
"the",
"given",
"service",
"calls",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L720-L722
|
19,414
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.replaceAllPathParamSerializers
|
public Descriptor replaceAllPathParamSerializers(PMap<Type, PathParamSerializer<?>> pathParamSerializers) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
java
|
public Descriptor replaceAllPathParamSerializers(PMap<Type, PathParamSerializer<?>> pathParamSerializers) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
[
"public",
"Descriptor",
"replaceAllPathParamSerializers",
"(",
"PMap",
"<",
"Type",
",",
"PathParamSerializer",
"<",
"?",
">",
">",
"pathParamSerializers",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"topicCalls",
")",
";",
"}"
] |
Replace all the path param serializers registered with this descriptor with the the given path param serializers.
@param pathParamSerializers The path param serializers to replace the existing ones with.
@return A copy of this descriptor with the new path param serializers.
|
[
"Replace",
"all",
"the",
"path",
"param",
"serializers",
"registered",
"with",
"this",
"descriptor",
"with",
"the",
"the",
"given",
"path",
"param",
"serializers",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L730-L732
|
19,415
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.replaceAllMessageSerializers
|
public Descriptor replaceAllMessageSerializers(PMap<Type, MessageSerializer<?, ?>> messageSerializers) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
java
|
public Descriptor replaceAllMessageSerializers(PMap<Type, MessageSerializer<?, ?>> messageSerializers) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
[
"public",
"Descriptor",
"replaceAllMessageSerializers",
"(",
"PMap",
"<",
"Type",
",",
"MessageSerializer",
"<",
"?",
",",
"?",
">",
">",
"messageSerializers",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"topicCalls",
")",
";",
"}"
] |
Replace all the message serializers registered with this descriptor with the the given message serializers.
@param messageSerializers The message serializers to replace the existing ones with.
@return A copy of this descriptor with the new message serializers.
|
[
"Replace",
"all",
"the",
"message",
"serializers",
"registered",
"with",
"this",
"descriptor",
"with",
"the",
"the",
"given",
"message",
"serializers",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L740-L742
|
19,416
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.replaceAllTopicCalls
|
public Descriptor replaceAllTopicCalls(PSequence<TopicCall<?>> topicCalls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
java
|
public Descriptor replaceAllTopicCalls(PSequence<TopicCall<?>> topicCalls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
[
"public",
"Descriptor",
"replaceAllTopicCalls",
"(",
"PSequence",
"<",
"TopicCall",
"<",
"?",
">",
">",
"topicCalls",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"topicCalls",
")",
";",
"}"
] |
Replace all the topic calls provided by this descriptor with the the given topic calls.
@param topicCalls The topic calls to replace the existing ones with.
@return A copy of this descriptor with the new topic calls.
|
[
"Replace",
"all",
"the",
"topic",
"calls",
"provided",
"by",
"this",
"descriptor",
"with",
"the",
"the",
"given",
"topic",
"calls",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L750-L752
|
19,417
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.withExceptionSerializer
|
public Descriptor withExceptionSerializer(ExceptionSerializer exceptionSerializer) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
java
|
public Descriptor withExceptionSerializer(ExceptionSerializer exceptionSerializer) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
[
"public",
"Descriptor",
"withExceptionSerializer",
"(",
"ExceptionSerializer",
"exceptionSerializer",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"topicCalls",
")",
";",
"}"
] |
Use the given exception serializer to serialize and deserialized exceptions handled by this service.
@param exceptionSerializer The exception handler to use.
@return A copy of this descriptor.
|
[
"Use",
"the",
"given",
"exception",
"serializer",
"to",
"serialize",
"and",
"deserialized",
"exceptions",
"handled",
"by",
"this",
"service",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L760-L762
|
19,418
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.withServiceAcls
|
public Descriptor withServiceAcls(ServiceAcl... acls) {
return replaceAllAcls(this.acls.plusAll(Arrays.asList(acls)));
}
|
java
|
public Descriptor withServiceAcls(ServiceAcl... acls) {
return replaceAllAcls(this.acls.plusAll(Arrays.asList(acls)));
}
|
[
"public",
"Descriptor",
"withServiceAcls",
"(",
"ServiceAcl",
"...",
"acls",
")",
"{",
"return",
"replaceAllAcls",
"(",
"this",
".",
"acls",
".",
"plusAll",
"(",
"Arrays",
".",
"asList",
"(",
"acls",
")",
")",
")",
";",
"}"
] |
Add the given manual ACLs.
If auto ACLs are configured, these will be added in addition to the auto ACLs.
@param acls The ACLs to add.
@return A copy of this descriptor.
|
[
"Add",
"the",
"given",
"manual",
"ACLs",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L798-L800
|
19,419
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.replaceAllAcls
|
public Descriptor replaceAllAcls(PSequence<ServiceAcl> acls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
java
|
public Descriptor replaceAllAcls(PSequence<ServiceAcl> acls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker, topicCalls);
}
|
[
"public",
"Descriptor",
"replaceAllAcls",
"(",
"PSequence",
"<",
"ServiceAcl",
">",
"acls",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"topicCalls",
")",
";",
"}"
] |
Replace all the ACLs with the given ACL sequence.
This will not replace ACLs generated by autoAcl, to disable autoAcl, turn it off.
@param acls The ACLs to use.
@return A copy of this descriptor.
|
[
"Replace",
"all",
"the",
"ACLs",
"with",
"the",
"given",
"ACL",
"sequence",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L810-L812
|
19,420
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java
|
Descriptor.withTopics
|
public Descriptor withTopics(TopicCall<?>... topicCalls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker,
this.topicCalls.plusAll(Arrays.asList(topicCalls)));
}
|
java
|
public Descriptor withTopics(TopicCall<?>... topicCalls) {
return new Descriptor(name, calls, pathParamSerializers, messageSerializers, serializerFactory, exceptionSerializer, autoAcl, acls, headerFilter, locatableService, circuitBreaker,
this.topicCalls.plusAll(Arrays.asList(topicCalls)));
}
|
[
"public",
"Descriptor",
"withTopics",
"(",
"TopicCall",
"<",
"?",
">",
"...",
"topicCalls",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"name",
",",
"calls",
",",
"pathParamSerializers",
",",
"messageSerializers",
",",
"serializerFactory",
",",
"exceptionSerializer",
",",
"autoAcl",
",",
"acls",
",",
"headerFilter",
",",
"locatableService",
",",
"circuitBreaker",
",",
"this",
".",
"topicCalls",
".",
"plusAll",
"(",
"Arrays",
".",
"asList",
"(",
"topicCalls",
")",
")",
")",
";",
"}"
] |
Add the given topic calls to this service.
@param topicCalls The topic calls to add.
@return A copy of this descriptor with the new calls added.
|
[
"Add",
"the",
"given",
"topic",
"calls",
"to",
"this",
"service",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/Descriptor.java#L870-L873
|
19,421
|
lagom/lagom
|
service/javadsl/broker/src/main/java/com/lightbend/lagom/javadsl/broker/TopicProducer.java
|
TopicProducer.singleStreamWithOffset
|
public static <Message> Topic<Message> singleStreamWithOffset(
Function<Offset, Source<Pair<Message, Offset>, ?>> eventStream) {
return taggedStreamWithOffset(SINGLETON_TAG, (tag, offset) -> eventStream.apply(offset));
}
|
java
|
public static <Message> Topic<Message> singleStreamWithOffset(
Function<Offset, Source<Pair<Message, Offset>, ?>> eventStream) {
return taggedStreamWithOffset(SINGLETON_TAG, (tag, offset) -> eventStream.apply(offset));
}
|
[
"public",
"static",
"<",
"Message",
">",
"Topic",
"<",
"Message",
">",
"singleStreamWithOffset",
"(",
"Function",
"<",
"Offset",
",",
"Source",
"<",
"Pair",
"<",
"Message",
",",
"Offset",
">",
",",
"?",
">",
">",
"eventStream",
")",
"{",
"return",
"taggedStreamWithOffset",
"(",
"SINGLETON_TAG",
",",
"(",
"tag",
",",
"offset",
")",
"->",
"eventStream",
".",
"apply",
"(",
"offset",
")",
")",
";",
"}"
] |
Publish a single stream.
This producer will ensure every element from the stream will be published at least once (usually only once),
using the message offsets to track where in the stream the producer is up to publishing.
@param eventStream A function to create the event stream given the last offset that was published.
@return The topic producer.
|
[
"Publish",
"a",
"single",
"stream",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/broker/src/main/java/com/lightbend/lagom/javadsl/broker/TopicProducer.java#L38-L41
|
19,422
|
lagom/lagom
|
service/javadsl/broker/src/main/java/com/lightbend/lagom/javadsl/broker/TopicProducer.java
|
TopicProducer.taggedStreamWithOffset
|
public static <Message, Event extends AggregateEvent<Event>> Topic<Message> taggedStreamWithOffset(
PSequence<AggregateEventTag<Event>> tags,
BiFunction<AggregateEventTag<Event>, Offset, Source<Pair<Message, Offset>, ?>> eventStream) {
return new TaggedOffsetTopicProducer<>(tags, eventStream);
}
|
java
|
public static <Message, Event extends AggregateEvent<Event>> Topic<Message> taggedStreamWithOffset(
PSequence<AggregateEventTag<Event>> tags,
BiFunction<AggregateEventTag<Event>, Offset, Source<Pair<Message, Offset>, ?>> eventStream) {
return new TaggedOffsetTopicProducer<>(tags, eventStream);
}
|
[
"public",
"static",
"<",
"Message",
",",
"Event",
"extends",
"AggregateEvent",
"<",
"Event",
">",
">",
"Topic",
"<",
"Message",
">",
"taggedStreamWithOffset",
"(",
"PSequence",
"<",
"AggregateEventTag",
"<",
"Event",
">",
">",
"tags",
",",
"BiFunction",
"<",
"AggregateEventTag",
"<",
"Event",
">",
",",
"Offset",
",",
"Source",
"<",
"Pair",
"<",
"Message",
",",
"Offset",
">",
",",
"?",
">",
">",
"eventStream",
")",
"{",
"return",
"new",
"TaggedOffsetTopicProducer",
"<>",
"(",
"tags",
",",
"eventStream",
")",
";",
"}"
] |
Publish a stream that is sharded across many tags.
The tags will be distributed around the cluster, ensuring that at most one event stream for each tag is
being published at a particular time.
This producer will ensure every element from each tags stream will be published at least once (usually only
once), using the message offsets to track where in the stream the producer is up to publishing.
@param tags The tags to publish.
@param eventStream A function event stream for a given shard given the last offset that was published.
@return The topic producer.
|
[
"Publish",
"a",
"stream",
"that",
"is",
"sharded",
"across",
"many",
"tags",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/broker/src/main/java/com/lightbend/lagom/javadsl/broker/TopicProducer.java#L61-L65
|
19,423
|
lagom/lagom
|
service/javadsl/broker/src/main/java/com/lightbend/lagom/javadsl/broker/TopicProducer.java
|
TopicProducer.taggedStreamWithOffset
|
public static <Message, Event extends AggregateEvent<Event>> Topic<Message> taggedStreamWithOffset(
AggregateEventShards<Event> shards,
BiFunction<AggregateEventTag<Event>, Offset, Source<Pair<Message, Offset>, ?>> eventStream) {
return new TaggedOffsetTopicProducer<>(shards.allTags(), eventStream);
}
|
java
|
public static <Message, Event extends AggregateEvent<Event>> Topic<Message> taggedStreamWithOffset(
AggregateEventShards<Event> shards,
BiFunction<AggregateEventTag<Event>, Offset, Source<Pair<Message, Offset>, ?>> eventStream) {
return new TaggedOffsetTopicProducer<>(shards.allTags(), eventStream);
}
|
[
"public",
"static",
"<",
"Message",
",",
"Event",
"extends",
"AggregateEvent",
"<",
"Event",
">",
">",
"Topic",
"<",
"Message",
">",
"taggedStreamWithOffset",
"(",
"AggregateEventShards",
"<",
"Event",
">",
"shards",
",",
"BiFunction",
"<",
"AggregateEventTag",
"<",
"Event",
">",
",",
"Offset",
",",
"Source",
"<",
"Pair",
"<",
"Message",
",",
"Offset",
">",
",",
"?",
">",
">",
"eventStream",
")",
"{",
"return",
"new",
"TaggedOffsetTopicProducer",
"<>",
"(",
"shards",
".",
"allTags",
"(",
")",
",",
"eventStream",
")",
";",
"}"
] |
Publish all tags of a stream that is sharded across many tags.
The tags will be distributed around the cluster, ensuring that at most one event stream for each tag is
being published at a particular time.
This producer will ensure every element from each tags stream will be published at least once (usually only
once), using the message offsets to track where in the stream the producer is up to publishing.
@param shards The tags to publish.
@param eventStream A function event stream for a given shard given the last offset that was published.
@return The topic producer.
|
[
"Publish",
"all",
"tags",
"of",
"a",
"stream",
"that",
"is",
"sharded",
"across",
"many",
"tags",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/broker/src/main/java/com/lightbend/lagom/javadsl/broker/TopicProducer.java#L81-L85
|
19,424
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/TransportErrorCode.java
|
TransportErrorCode.fromHttp
|
public static TransportErrorCode fromHttp(int code) {
TransportErrorCode builtIn = HTTP_ERROR_CODE_MAP.get(code);
if (builtIn == null) {
if (code > 599 || code < 100) {
throw new IllegalArgumentException("Invalid http status code: " + code);
} else if (code < 400) {
throw new IllegalArgumentException("Invalid http error code: " + code);
} else {
return new TransportErrorCode(code, 4000 + code, "Unknown error code");
}
} else {
return builtIn;
}
}
|
java
|
public static TransportErrorCode fromHttp(int code) {
TransportErrorCode builtIn = HTTP_ERROR_CODE_MAP.get(code);
if (builtIn == null) {
if (code > 599 || code < 100) {
throw new IllegalArgumentException("Invalid http status code: " + code);
} else if (code < 400) {
throw new IllegalArgumentException("Invalid http error code: " + code);
} else {
return new TransportErrorCode(code, 4000 + code, "Unknown error code");
}
} else {
return builtIn;
}
}
|
[
"public",
"static",
"TransportErrorCode",
"fromHttp",
"(",
"int",
"code",
")",
"{",
"TransportErrorCode",
"builtIn",
"=",
"HTTP_ERROR_CODE_MAP",
".",
"get",
"(",
"code",
")",
";",
"if",
"(",
"builtIn",
"==",
"null",
")",
"{",
"if",
"(",
"code",
">",
"599",
"||",
"code",
"<",
"100",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid http status code: \"",
"+",
"code",
")",
";",
"}",
"else",
"if",
"(",
"code",
"<",
"400",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid http error code: \"",
"+",
"code",
")",
";",
"}",
"else",
"{",
"return",
"new",
"TransportErrorCode",
"(",
"code",
",",
"4000",
"+",
"code",
",",
"\"Unknown error code\"",
")",
";",
"}",
"}",
"else",
"{",
"return",
"builtIn",
";",
"}",
"}"
] |
Get a transport error code from the given HTTP error code.
@param code The HTTP error code, must be between 400 and 599 inclusive.
@return The transport error code.
@throws IllegalArgumentException if the HTTP code was not between 400 and 599.
|
[
"Get",
"a",
"transport",
"error",
"code",
"from",
"the",
"given",
"HTTP",
"error",
"code",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/TransportErrorCode.java#L142-L155
|
19,425
|
lagom/lagom
|
service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/TransportErrorCode.java
|
TransportErrorCode.fromWebSocket
|
public static TransportErrorCode fromWebSocket(int code) {
TransportErrorCode builtIn = WEBSOCKET_ERROR_CODE_MAP.get(code);
if (builtIn == null) {
if (code < 0 || code > 65535) {
throw new IllegalArgumentException("Invalid WebSocket status code: " + code);
} else if (code >= 4400 && code <= 4599) {
return new TransportErrorCode(code - 4000, code, "Unknown error code");
} else {
return new TransportErrorCode(404, code, "Unknown error code");
}
} else {
return builtIn;
}
}
|
java
|
public static TransportErrorCode fromWebSocket(int code) {
TransportErrorCode builtIn = WEBSOCKET_ERROR_CODE_MAP.get(code);
if (builtIn == null) {
if (code < 0 || code > 65535) {
throw new IllegalArgumentException("Invalid WebSocket status code: " + code);
} else if (code >= 4400 && code <= 4599) {
return new TransportErrorCode(code - 4000, code, "Unknown error code");
} else {
return new TransportErrorCode(404, code, "Unknown error code");
}
} else {
return builtIn;
}
}
|
[
"public",
"static",
"TransportErrorCode",
"fromWebSocket",
"(",
"int",
"code",
")",
"{",
"TransportErrorCode",
"builtIn",
"=",
"WEBSOCKET_ERROR_CODE_MAP",
".",
"get",
"(",
"code",
")",
";",
"if",
"(",
"builtIn",
"==",
"null",
")",
"{",
"if",
"(",
"code",
"<",
"0",
"||",
"code",
">",
"65535",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid WebSocket status code: \"",
"+",
"code",
")",
";",
"}",
"else",
"if",
"(",
"code",
">=",
"4400",
"&&",
"code",
"<=",
"4599",
")",
"{",
"return",
"new",
"TransportErrorCode",
"(",
"code",
"-",
"4000",
",",
"code",
",",
"\"Unknown error code\"",
")",
";",
"}",
"else",
"{",
"return",
"new",
"TransportErrorCode",
"(",
"404",
",",
"code",
",",
"\"Unknown error code\"",
")",
";",
"}",
"}",
"else",
"{",
"return",
"builtIn",
";",
"}",
"}"
] |
Get a transport error code from the given WebSocket close code.
@param code The WebSocket close code, must be between 0 and 65535 inclusive.
@return The transport error code.
@throws IllegalArgumentException if the code is not an unsigned 2 byte integer.
|
[
"Get",
"a",
"transport",
"error",
"code",
"from",
"the",
"given",
"WebSocket",
"close",
"code",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/service/javadsl/api/src/main/java/com/lightbend/lagom/javadsl/api/transport/TransportErrorCode.java#L164-L177
|
19,426
|
lagom/lagom
|
docs/manual/java/guide/cluster/code/docs/home/persistence/Post4.java
|
Post4.becomePostAdded
|
private Behavior becomePostAdded(BlogState newState) {
BehaviorBuilder b = newBehaviorBuilder(newState);
b.setCommandHandler(ChangeBody.class,
(cmd, ctx) -> ctx.thenPersist(new BodyChanged(entityId(), cmd.getBody()), evt ->
ctx.reply(Done.getInstance())));
b.setEventHandler(BodyChanged.class, evt -> state().withBody(evt.getBody()));
//#publish
b.setCommandHandler(Publish.class,
(cmd, ctx) -> ctx.thenPersist(new PostPublished(entityId()), evt -> {
ctx.reply(Done.getInstance());
publishedTopic.publish(evt);
}));
//#publish
b.setEventHandler(PostPublished.class, evt ->
new BlogState(state().getContent(), true));
return b.build();
}
|
java
|
private Behavior becomePostAdded(BlogState newState) {
BehaviorBuilder b = newBehaviorBuilder(newState);
b.setCommandHandler(ChangeBody.class,
(cmd, ctx) -> ctx.thenPersist(new BodyChanged(entityId(), cmd.getBody()), evt ->
ctx.reply(Done.getInstance())));
b.setEventHandler(BodyChanged.class, evt -> state().withBody(evt.getBody()));
//#publish
b.setCommandHandler(Publish.class,
(cmd, ctx) -> ctx.thenPersist(new PostPublished(entityId()), evt -> {
ctx.reply(Done.getInstance());
publishedTopic.publish(evt);
}));
//#publish
b.setEventHandler(PostPublished.class, evt ->
new BlogState(state().getContent(), true));
return b.build();
}
|
[
"private",
"Behavior",
"becomePostAdded",
"(",
"BlogState",
"newState",
")",
"{",
"BehaviorBuilder",
"b",
"=",
"newBehaviorBuilder",
"(",
"newState",
")",
";",
"b",
".",
"setCommandHandler",
"(",
"ChangeBody",
".",
"class",
",",
"(",
"cmd",
",",
"ctx",
")",
"->",
"ctx",
".",
"thenPersist",
"(",
"new",
"BodyChanged",
"(",
"entityId",
"(",
")",
",",
"cmd",
".",
"getBody",
"(",
")",
")",
",",
"evt",
"->",
"ctx",
".",
"reply",
"(",
"Done",
".",
"getInstance",
"(",
")",
")",
")",
")",
";",
"b",
".",
"setEventHandler",
"(",
"BodyChanged",
".",
"class",
",",
"evt",
"->",
"state",
"(",
")",
".",
"withBody",
"(",
"evt",
".",
"getBody",
"(",
")",
")",
")",
";",
"//#publish",
"b",
".",
"setCommandHandler",
"(",
"Publish",
".",
"class",
",",
"(",
"cmd",
",",
"ctx",
")",
"->",
"ctx",
".",
"thenPersist",
"(",
"new",
"PostPublished",
"(",
"entityId",
"(",
")",
")",
",",
"evt",
"->",
"{",
"ctx",
".",
"reply",
"(",
"Done",
".",
"getInstance",
"(",
")",
")",
";",
"publishedTopic",
".",
"publish",
"(",
"evt",
")",
";",
"}",
")",
")",
";",
"//#publish",
"b",
".",
"setEventHandler",
"(",
"PostPublished",
".",
"class",
",",
"evt",
"->",
"new",
"BlogState",
"(",
"state",
"(",
")",
".",
"getContent",
"(",
")",
",",
"true",
")",
")",
";",
"return",
"b",
".",
"build",
"(",
")",
";",
"}"
] |
Behavior can be changed in the event handlers.
|
[
"Behavior",
"can",
"be",
"changed",
"in",
"the",
"event",
"handlers",
"."
] |
3763055a9d1aace793a5d970f4e688aea61b1a5a
|
https://github.com/lagom/lagom/blob/3763055a9d1aace793a5d970f4e688aea61b1a5a/docs/manual/java/guide/cluster/code/docs/home/persistence/Post4.java#L59-L80
|
19,427
|
google/flogger
|
google/src/main/java/com/google/common/flogger/GoogleLogger.java
|
GoogleLogger.forEnclosingClass
|
public static GoogleLogger forEnclosingClass() {
// NOTE: It is _vital_ that the call to "caller finder" is made directly inside the static
// factory method. See getCallerFinder() for more information.
String loggingClass = Platform.getCallerFinder().findLoggingClass(GoogleLogger.class);
return new GoogleLogger(Platform.getBackend(loggingClass));
}
|
java
|
public static GoogleLogger forEnclosingClass() {
// NOTE: It is _vital_ that the call to "caller finder" is made directly inside the static
// factory method. See getCallerFinder() for more information.
String loggingClass = Platform.getCallerFinder().findLoggingClass(GoogleLogger.class);
return new GoogleLogger(Platform.getBackend(loggingClass));
}
|
[
"public",
"static",
"GoogleLogger",
"forEnclosingClass",
"(",
")",
"{",
"// NOTE: It is _vital_ that the call to \"caller finder\" is made directly inside the static",
"// factory method. See getCallerFinder() for more information.",
"String",
"loggingClass",
"=",
"Platform",
".",
"getCallerFinder",
"(",
")",
".",
"findLoggingClass",
"(",
"GoogleLogger",
".",
"class",
")",
";",
"return",
"new",
"GoogleLogger",
"(",
"Platform",
".",
"getBackend",
"(",
"loggingClass",
")",
")",
";",
"}"
] |
Returns a new Google specific logger instance using printf style message formatting.
|
[
"Returns",
"a",
"new",
"Google",
"specific",
"logger",
"instance",
"using",
"printf",
"style",
"message",
"formatting",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/google/src/main/java/com/google/common/flogger/GoogleLogger.java#L45-L50
|
19,428
|
google/flogger
|
google/src/main/java/com/google/common/flogger/GoogleLogger.java
|
GoogleLogger.forInjectedClassName
|
@Deprecated
public static GoogleLogger forInjectedClassName(String className) {
checkArgument(!className.isEmpty(), "injected class name is empty");
// The injected class name is in binary form (e.g. java/util/Map$Entry) to re-use
// constant pool entries.
return new GoogleLogger(Platform.getBackend(className.replace('/', '.')));
}
|
java
|
@Deprecated
public static GoogleLogger forInjectedClassName(String className) {
checkArgument(!className.isEmpty(), "injected class name is empty");
// The injected class name is in binary form (e.g. java/util/Map$Entry) to re-use
// constant pool entries.
return new GoogleLogger(Platform.getBackend(className.replace('/', '.')));
}
|
[
"@",
"Deprecated",
"public",
"static",
"GoogleLogger",
"forInjectedClassName",
"(",
"String",
"className",
")",
"{",
"checkArgument",
"(",
"!",
"className",
".",
"isEmpty",
"(",
")",
",",
"\"injected class name is empty\"",
")",
";",
"// The injected class name is in binary form (e.g. java/util/Map$Entry) to re-use",
"// constant pool entries.",
"return",
"new",
"GoogleLogger",
"(",
"Platform",
".",
"getBackend",
"(",
"className",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
")",
")",
";",
"}"
] |
Returns a new Google specific logger instance for the given class, using printf
style message formatting.
@deprecated prefer forEnclosingClass(); this method exists only to support
compile-time log site injection.
|
[
"Returns",
"a",
"new",
"Google",
"specific",
"logger",
"instance",
"for",
"the",
"given",
"class",
"using",
"printf",
"style",
"message",
"formatting",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/google/src/main/java/com/google/common/flogger/GoogleLogger.java#L59-L65
|
19,429
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/Tags.java
|
Tags.merge
|
public Tags merge(Tags other) {
// Dereference "other" first as a null pointer check so we cannot risk returning null later.
if (other.isEmpty()) {
return this;
}
if (this.isEmpty()) {
return other;
}
SortedMap<String, SortedSet<Object>> merged = new TreeMap<String, SortedSet<Object>>();
for (Map.Entry<String, SortedSet<Object>> e : map.entrySet()) {
SortedSet<Object> otherValues = other.map.get(e.getKey());
if (otherValues == null || e.getValue().containsAll(otherValues)) {
// Our values are a superset of the values in the other map, so just use them.
merged.put(e.getKey(), e.getValue());
} else if (otherValues.containsAll(e.getValue())) {
// The other map's values are a superset of ours, so just use them.
merged.put(e.getKey(), otherValues);
} else {
// Values exist in both maps and neither is a superset, so we really must merge.
SortedSet<Object> mergedValues = new TreeSet<Object>(e.getValue());
mergedValues.addAll(otherValues);
merged.put(e.getKey(), Collections.unmodifiableSortedSet(mergedValues));
}
}
for (Map.Entry<String, SortedSet<Object>> e : other.map.entrySet()) {
// Finally add those values that were only in the other map.
if (!map.containsKey(e.getKey())) {
merged.put(e.getKey(), e.getValue());
}
}
return new Tags(Collections.unmodifiableSortedMap(merged));
}
|
java
|
public Tags merge(Tags other) {
// Dereference "other" first as a null pointer check so we cannot risk returning null later.
if (other.isEmpty()) {
return this;
}
if (this.isEmpty()) {
return other;
}
SortedMap<String, SortedSet<Object>> merged = new TreeMap<String, SortedSet<Object>>();
for (Map.Entry<String, SortedSet<Object>> e : map.entrySet()) {
SortedSet<Object> otherValues = other.map.get(e.getKey());
if (otherValues == null || e.getValue().containsAll(otherValues)) {
// Our values are a superset of the values in the other map, so just use them.
merged.put(e.getKey(), e.getValue());
} else if (otherValues.containsAll(e.getValue())) {
// The other map's values are a superset of ours, so just use them.
merged.put(e.getKey(), otherValues);
} else {
// Values exist in both maps and neither is a superset, so we really must merge.
SortedSet<Object> mergedValues = new TreeSet<Object>(e.getValue());
mergedValues.addAll(otherValues);
merged.put(e.getKey(), Collections.unmodifiableSortedSet(mergedValues));
}
}
for (Map.Entry<String, SortedSet<Object>> e : other.map.entrySet()) {
// Finally add those values that were only in the other map.
if (!map.containsKey(e.getKey())) {
merged.put(e.getKey(), e.getValue());
}
}
return new Tags(Collections.unmodifiableSortedMap(merged));
}
|
[
"public",
"Tags",
"merge",
"(",
"Tags",
"other",
")",
"{",
"// Dereference \"other\" first as a null pointer check so we cannot risk returning null later.",
"if",
"(",
"other",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"this",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"other",
";",
"}",
"SortedMap",
"<",
"String",
",",
"SortedSet",
"<",
"Object",
">",
">",
"merged",
"=",
"new",
"TreeMap",
"<",
"String",
",",
"SortedSet",
"<",
"Object",
">",
">",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"SortedSet",
"<",
"Object",
">",
">",
"e",
":",
"map",
".",
"entrySet",
"(",
")",
")",
"{",
"SortedSet",
"<",
"Object",
">",
"otherValues",
"=",
"other",
".",
"map",
".",
"get",
"(",
"e",
".",
"getKey",
"(",
")",
")",
";",
"if",
"(",
"otherValues",
"==",
"null",
"||",
"e",
".",
"getValue",
"(",
")",
".",
"containsAll",
"(",
"otherValues",
")",
")",
"{",
"// Our values are a superset of the values in the other map, so just use them.",
"merged",
".",
"put",
"(",
"e",
".",
"getKey",
"(",
")",
",",
"e",
".",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"otherValues",
".",
"containsAll",
"(",
"e",
".",
"getValue",
"(",
")",
")",
")",
"{",
"// The other map's values are a superset of ours, so just use them.",
"merged",
".",
"put",
"(",
"e",
".",
"getKey",
"(",
")",
",",
"otherValues",
")",
";",
"}",
"else",
"{",
"// Values exist in both maps and neither is a superset, so we really must merge.",
"SortedSet",
"<",
"Object",
">",
"mergedValues",
"=",
"new",
"TreeSet",
"<",
"Object",
">",
"(",
"e",
".",
"getValue",
"(",
")",
")",
";",
"mergedValues",
".",
"addAll",
"(",
"otherValues",
")",
";",
"merged",
".",
"put",
"(",
"e",
".",
"getKey",
"(",
")",
",",
"Collections",
".",
"unmodifiableSortedSet",
"(",
"mergedValues",
")",
")",
";",
"}",
"}",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"SortedSet",
"<",
"Object",
">",
">",
"e",
":",
"other",
".",
"map",
".",
"entrySet",
"(",
")",
")",
"{",
"// Finally add those values that were only in the other map.",
"if",
"(",
"!",
"map",
".",
"containsKey",
"(",
"e",
".",
"getKey",
"(",
")",
")",
")",
"{",
"merged",
".",
"put",
"(",
"e",
".",
"getKey",
"(",
")",
",",
"e",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"return",
"new",
"Tags",
"(",
"Collections",
".",
"unmodifiableSortedMap",
"(",
"merged",
")",
")",
";",
"}"
] |
Merges two tags instances, combining values for any name contained in both.
|
[
"Merges",
"two",
"tags",
"instances",
"combining",
"values",
"for",
"any",
"name",
"contained",
"in",
"both",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/Tags.java#L261-L292
|
19,430
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/system/DefaultPlatform.java
|
DefaultPlatform.resolveAttribute
|
@Nullable
private static <T> T resolveAttribute(String attributeName, Class<T> type) {
String getter = readProperty(attributeName);
if (getter == null) {
return null;
}
int idx = getter.indexOf('#');
if (idx <= 0 || idx == getter.length() - 1) {
error("invalid getter (expected <class>#<method>): %s\n", getter);
return null;
}
return callStaticMethod(getter.substring(0, idx), getter.substring(idx + 1), type);
}
|
java
|
@Nullable
private static <T> T resolveAttribute(String attributeName, Class<T> type) {
String getter = readProperty(attributeName);
if (getter == null) {
return null;
}
int idx = getter.indexOf('#');
if (idx <= 0 || idx == getter.length() - 1) {
error("invalid getter (expected <class>#<method>): %s\n", getter);
return null;
}
return callStaticMethod(getter.substring(0, idx), getter.substring(idx + 1), type);
}
|
[
"@",
"Nullable",
"private",
"static",
"<",
"T",
">",
"T",
"resolveAttribute",
"(",
"String",
"attributeName",
",",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"String",
"getter",
"=",
"readProperty",
"(",
"attributeName",
")",
";",
"if",
"(",
"getter",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"int",
"idx",
"=",
"getter",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"idx",
"<=",
"0",
"||",
"idx",
"==",
"getter",
".",
"length",
"(",
")",
"-",
"1",
")",
"{",
"error",
"(",
"\"invalid getter (expected <class>#<method>): %s\\n\"",
",",
"getter",
")",
";",
"return",
"null",
";",
"}",
"return",
"callStaticMethod",
"(",
"getter",
".",
"substring",
"(",
"0",
",",
"idx",
")",
",",
"getter",
".",
"substring",
"(",
"idx",
"+",
"1",
")",
",",
"type",
")",
";",
"}"
] |
Helper to call a static no-arg getter to obtain an instance of a specified type. This is used
for platform aspects which are optional, but are expected to have a singleton available.
@return the return value of the specified static no-argument method, or null if the method
cannot be called or the returned value is of the wrong type.
|
[
"Helper",
"to",
"call",
"a",
"static",
"no",
"-",
"arg",
"getter",
"to",
"obtain",
"an",
"instance",
"of",
"a",
"specified",
"type",
".",
"This",
"is",
"used",
"for",
"platform",
"aspects",
"which",
"are",
"optional",
"but",
"are",
"expected",
"to",
"have",
"a",
"singleton",
"available",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/system/DefaultPlatform.java#L122-L134
|
19,431
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parser/DefaultPrintfMessageParser.java
|
DefaultPrintfMessageParser.wrapHexParameter
|
private static Parameter wrapHexParameter(final FormatOptions options, int index) {
// %h / %H is really just %x / %X on the hashcode.
return new Parameter(options, index) {
@Override
protected void accept(ParameterVisitor visitor, Object value) {
visitor.visit(value.hashCode(), FormatChar.HEX, getFormatOptions());
}
@Override
public String getFormat() {
return options.shouldUpperCase() ? "%H" : "%h";
}
};
}
|
java
|
private static Parameter wrapHexParameter(final FormatOptions options, int index) {
// %h / %H is really just %x / %X on the hashcode.
return new Parameter(options, index) {
@Override
protected void accept(ParameterVisitor visitor, Object value) {
visitor.visit(value.hashCode(), FormatChar.HEX, getFormatOptions());
}
@Override
public String getFormat() {
return options.shouldUpperCase() ? "%H" : "%h";
}
};
}
|
[
"private",
"static",
"Parameter",
"wrapHexParameter",
"(",
"final",
"FormatOptions",
"options",
",",
"int",
"index",
")",
"{",
"// %h / %H is really just %x / %X on the hashcode.",
"return",
"new",
"Parameter",
"(",
"options",
",",
"index",
")",
"{",
"@",
"Override",
"protected",
"void",
"accept",
"(",
"ParameterVisitor",
"visitor",
",",
"Object",
"value",
")",
"{",
"visitor",
".",
"visit",
"(",
"value",
".",
"hashCode",
"(",
")",
",",
"FormatChar",
".",
"HEX",
",",
"getFormatOptions",
"(",
")",
")",
";",
"}",
"@",
"Override",
"public",
"String",
"getFormat",
"(",
")",
"{",
"return",
"options",
".",
"shouldUpperCase",
"(",
")",
"?",
"\"%H\"",
":",
"\"%h\"",
";",
"}",
"}",
";",
"}"
] |
Static method so the anonymous synthetic parameter is static, rather than an inner class.
|
[
"Static",
"method",
"so",
"the",
"anonymous",
"synthetic",
"parameter",
"is",
"static",
"rather",
"than",
"an",
"inner",
"class",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parser/DefaultPrintfMessageParser.java#L103-L116
|
19,432
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/system/AbstractBackend.java
|
AbstractBackend.log
|
void log(LogRecord record, boolean wasForced) {
// Do the fast boolean check (which normally succeeds) before calling isLoggable().
if (!wasForced || logger.isLoggable(record.getLevel())) {
// Unforced log statements or forced log statements at or above the logger's level can be
// passed to the normal log(LogRecord) method.
logger.log(record);
} else {
// If logging has been forced for a log record which would otherwise be discarded, we cannot
// call our logger's log(LogRecord) method, so we must simulate its behavior in one of two
// ways.
// 1: Simulate the effect of calling the log(LogRecord) method directly (this is safe if the
// logger provided by the log manager was a normal Logger instance).
// 2: Obtain a "child" logger from the log manager which is set to log everything, and call
// its log(LogRecord) method instead (which should have the same overridden behavior and
// will still publish log records to our logger's handlers).
//
// In all cases we still call the filter (if one exists) even though we ignore the result.
// Use a local variable to avoid race conditions where the filter can be unset at any time.
Filter filter = logger.getFilter();
if (filter != null) {
filter.isLoggable(record);
}
if (logger.getClass() == Logger.class || cannotUseForcingLogger) {
// If the Logger instance is not a subclass, its log(LogRecord) method cannot have been
// overridden. That means it's safe to just publish the log record directly to handlers
// to avoid the loggability check, which would otherwise discard the forced log record.
publish(logger, record);
} else {
// Hopefully rare situation in which the logger is subclassed _and_ the log record would
// normally be discarded based on its level.
forceLoggingViaChildLogger(record);
}
}
}
|
java
|
void log(LogRecord record, boolean wasForced) {
// Do the fast boolean check (which normally succeeds) before calling isLoggable().
if (!wasForced || logger.isLoggable(record.getLevel())) {
// Unforced log statements or forced log statements at or above the logger's level can be
// passed to the normal log(LogRecord) method.
logger.log(record);
} else {
// If logging has been forced for a log record which would otherwise be discarded, we cannot
// call our logger's log(LogRecord) method, so we must simulate its behavior in one of two
// ways.
// 1: Simulate the effect of calling the log(LogRecord) method directly (this is safe if the
// logger provided by the log manager was a normal Logger instance).
// 2: Obtain a "child" logger from the log manager which is set to log everything, and call
// its log(LogRecord) method instead (which should have the same overridden behavior and
// will still publish log records to our logger's handlers).
//
// In all cases we still call the filter (if one exists) even though we ignore the result.
// Use a local variable to avoid race conditions where the filter can be unset at any time.
Filter filter = logger.getFilter();
if (filter != null) {
filter.isLoggable(record);
}
if (logger.getClass() == Logger.class || cannotUseForcingLogger) {
// If the Logger instance is not a subclass, its log(LogRecord) method cannot have been
// overridden. That means it's safe to just publish the log record directly to handlers
// to avoid the loggability check, which would otherwise discard the forced log record.
publish(logger, record);
} else {
// Hopefully rare situation in which the logger is subclassed _and_ the log record would
// normally be discarded based on its level.
forceLoggingViaChildLogger(record);
}
}
}
|
[
"void",
"log",
"(",
"LogRecord",
"record",
",",
"boolean",
"wasForced",
")",
"{",
"// Do the fast boolean check (which normally succeeds) before calling isLoggable().",
"if",
"(",
"!",
"wasForced",
"||",
"logger",
".",
"isLoggable",
"(",
"record",
".",
"getLevel",
"(",
")",
")",
")",
"{",
"// Unforced log statements or forced log statements at or above the logger's level can be",
"// passed to the normal log(LogRecord) method.",
"logger",
".",
"log",
"(",
"record",
")",
";",
"}",
"else",
"{",
"// If logging has been forced for a log record which would otherwise be discarded, we cannot",
"// call our logger's log(LogRecord) method, so we must simulate its behavior in one of two",
"// ways.",
"// 1: Simulate the effect of calling the log(LogRecord) method directly (this is safe if the",
"// logger provided by the log manager was a normal Logger instance).",
"// 2: Obtain a \"child\" logger from the log manager which is set to log everything, and call",
"// its log(LogRecord) method instead (which should have the same overridden behavior and",
"// will still publish log records to our logger's handlers).",
"//",
"// In all cases we still call the filter (if one exists) even though we ignore the result.",
"// Use a local variable to avoid race conditions where the filter can be unset at any time.",
"Filter",
"filter",
"=",
"logger",
".",
"getFilter",
"(",
")",
";",
"if",
"(",
"filter",
"!=",
"null",
")",
"{",
"filter",
".",
"isLoggable",
"(",
"record",
")",
";",
"}",
"if",
"(",
"logger",
".",
"getClass",
"(",
")",
"==",
"Logger",
".",
"class",
"||",
"cannotUseForcingLogger",
")",
"{",
"// If the Logger instance is not a subclass, its log(LogRecord) method cannot have been",
"// overridden. That means it's safe to just publish the log record directly to handlers",
"// to avoid the loggability check, which would otherwise discard the forced log record.",
"publish",
"(",
"logger",
",",
"record",
")",
";",
"}",
"else",
"{",
"// Hopefully rare situation in which the logger is subclassed _and_ the log record would",
"// normally be discarded based on its level.",
"forceLoggingViaChildLogger",
"(",
"record",
")",
";",
"}",
"}",
"}"
] |
loggability check.
|
[
"loggability",
"check",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/system/AbstractBackend.java#L71-L104
|
19,433
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/system/AbstractBackend.java
|
AbstractBackend.publish
|
private static void publish(Logger logger, LogRecord record) {
// Annoyingly this method appears to copy the array every time it is called, but there's
// nothing much we can do about this (and there could be synchronization issues even if we
// could access things directly because handlers can be changed at any time). Most of the
// time this returns the singleton empty array however, so it's not as bad as all that.
for (Handler handler : logger.getHandlers()) {
handler.publish(record);
}
if (logger.getUseParentHandlers()) {
logger = logger.getParent();
if (logger != null) {
publish(logger, record);
}
}
}
|
java
|
private static void publish(Logger logger, LogRecord record) {
// Annoyingly this method appears to copy the array every time it is called, but there's
// nothing much we can do about this (and there could be synchronization issues even if we
// could access things directly because handlers can be changed at any time). Most of the
// time this returns the singleton empty array however, so it's not as bad as all that.
for (Handler handler : logger.getHandlers()) {
handler.publish(record);
}
if (logger.getUseParentHandlers()) {
logger = logger.getParent();
if (logger != null) {
publish(logger, record);
}
}
}
|
[
"private",
"static",
"void",
"publish",
"(",
"Logger",
"logger",
",",
"LogRecord",
"record",
")",
"{",
"// Annoyingly this method appears to copy the array every time it is called, but there's",
"// nothing much we can do about this (and there could be synchronization issues even if we",
"// could access things directly because handlers can be changed at any time). Most of the",
"// time this returns the singleton empty array however, so it's not as bad as all that.",
"for",
"(",
"Handler",
"handler",
":",
"logger",
".",
"getHandlers",
"(",
")",
")",
"{",
"handler",
".",
"publish",
"(",
"record",
")",
";",
"}",
"if",
"(",
"logger",
".",
"getUseParentHandlers",
"(",
")",
")",
"{",
"logger",
"=",
"logger",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"logger",
"!=",
"null",
")",
"{",
"publish",
"(",
"logger",
",",
"record",
")",
";",
"}",
"}",
"}"
] |
rate limiting. Thus we don't have to care about using iterative methods vs recursion here.
|
[
"rate",
"limiting",
".",
"Thus",
"we",
"don",
"t",
"have",
"to",
"care",
"about",
"using",
"iterative",
"methods",
"vs",
"recursion",
"here",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/system/AbstractBackend.java#L123-L137
|
19,434
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/system/AbstractBackend.java
|
AbstractBackend.forceLoggingViaChildLogger
|
void forceLoggingViaChildLogger(LogRecord record) {
// Assume that nobody else will configure or manipulate loggers with this "secret" name.
Logger forcingLogger = getForcingLogger(logger);
// This logger can be garbage collected at any time, so we must always reset any configuration.
// This code is subject to a bunch of unlikely race conditions if the logger is manipulated
// while these checks are being made, but there is nothing we can really do about this (the
// setting of log levels is not protected by synchronizing the logger instance).
try {
forcingLogger.setLevel(Level.ALL);
} catch (SecurityException e) {
// If we're blocked from changing logging configuration then we cannot log "forced" log
// statements via the forcingLogger. Fall back to publishing them directly to the handlers
// (which may bypass logic present in an overridden log(LogRecord) method).
cannotUseForcingLogger = true;
// Log to the root logger to bypass any configuration that might drop this message.
Logger.getLogger("").log(Level.SEVERE,
"Forcing log statements with Flogger has been partially disabled.\n"
+ "The Flogger library cannot modify logger log levels, which is necessary to force"
+ " log statements. This is likely due to an installed SecurityManager.\n"
+ "Forced log statements will still be published directly to log handlers, but will"
+ " not be visible to the 'log(LogRecord)' method of Logger sub-classes.\n");
publish(logger, record);
return;
}
// Assume any custom behaviour in our logger instance also exists for a child logger.
forcingLogger.log(record);
}
|
java
|
void forceLoggingViaChildLogger(LogRecord record) {
// Assume that nobody else will configure or manipulate loggers with this "secret" name.
Logger forcingLogger = getForcingLogger(logger);
// This logger can be garbage collected at any time, so we must always reset any configuration.
// This code is subject to a bunch of unlikely race conditions if the logger is manipulated
// while these checks are being made, but there is nothing we can really do about this (the
// setting of log levels is not protected by synchronizing the logger instance).
try {
forcingLogger.setLevel(Level.ALL);
} catch (SecurityException e) {
// If we're blocked from changing logging configuration then we cannot log "forced" log
// statements via the forcingLogger. Fall back to publishing them directly to the handlers
// (which may bypass logic present in an overridden log(LogRecord) method).
cannotUseForcingLogger = true;
// Log to the root logger to bypass any configuration that might drop this message.
Logger.getLogger("").log(Level.SEVERE,
"Forcing log statements with Flogger has been partially disabled.\n"
+ "The Flogger library cannot modify logger log levels, which is necessary to force"
+ " log statements. This is likely due to an installed SecurityManager.\n"
+ "Forced log statements will still be published directly to log handlers, but will"
+ " not be visible to the 'log(LogRecord)' method of Logger sub-classes.\n");
publish(logger, record);
return;
}
// Assume any custom behaviour in our logger instance also exists for a child logger.
forcingLogger.log(record);
}
|
[
"void",
"forceLoggingViaChildLogger",
"(",
"LogRecord",
"record",
")",
"{",
"// Assume that nobody else will configure or manipulate loggers with this \"secret\" name.",
"Logger",
"forcingLogger",
"=",
"getForcingLogger",
"(",
"logger",
")",
";",
"// This logger can be garbage collected at any time, so we must always reset any configuration.",
"// This code is subject to a bunch of unlikely race conditions if the logger is manipulated",
"// while these checks are being made, but there is nothing we can really do about this (the",
"// setting of log levels is not protected by synchronizing the logger instance).",
"try",
"{",
"forcingLogger",
".",
"setLevel",
"(",
"Level",
".",
"ALL",
")",
";",
"}",
"catch",
"(",
"SecurityException",
"e",
")",
"{",
"// If we're blocked from changing logging configuration then we cannot log \"forced\" log",
"// statements via the forcingLogger. Fall back to publishing them directly to the handlers",
"// (which may bypass logic present in an overridden log(LogRecord) method).",
"cannotUseForcingLogger",
"=",
"true",
";",
"// Log to the root logger to bypass any configuration that might drop this message.",
"Logger",
".",
"getLogger",
"(",
"\"\"",
")",
".",
"log",
"(",
"Level",
".",
"SEVERE",
",",
"\"Forcing log statements with Flogger has been partially disabled.\\n\"",
"+",
"\"The Flogger library cannot modify logger log levels, which is necessary to force\"",
"+",
"\" log statements. This is likely due to an installed SecurityManager.\\n\"",
"+",
"\"Forced log statements will still be published directly to log handlers, but will\"",
"+",
"\" not be visible to the 'log(LogRecord)' method of Logger sub-classes.\\n\"",
")",
";",
"publish",
"(",
"logger",
",",
"record",
")",
";",
"return",
";",
"}",
"// Assume any custom behaviour in our logger instance also exists for a child logger.",
"forcingLogger",
".",
"log",
"(",
"record",
")",
";",
"}"
] |
subclasses of Logger to be used.
|
[
"subclasses",
"of",
"Logger",
"to",
"be",
"used",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/system/AbstractBackend.java#L142-L169
|
19,435
|
google/flogger
|
api/src/main/java/com/google/common/flogger/util/Checks.java
|
Checks.checkMetadataIdentifier
|
public static String checkMetadataIdentifier(String s) {
// Note that we avoid using regular expressions here, since we've not used it anywhere else
// thus far in Flogger (avoid it make it more likely that Flogger can be transpiled for things
// like GWT).
if (s.isEmpty()) {
throw new IllegalArgumentException("identifier must not be empty");
}
if (!isLetter(s.charAt(0))) {
throw new IllegalArgumentException("identifier must start with an ASCII letter: " + s);
}
for (int n = 1; n < s.length(); n++) {
char c = s.charAt(n);
if (!isLetter(c) && (c < '0' || c > '9') && c != '_') {
throw new IllegalArgumentException(
"identifier must contain only ASCII letters, digits or underscore: " + s);
}
}
return s;
}
|
java
|
public static String checkMetadataIdentifier(String s) {
// Note that we avoid using regular expressions here, since we've not used it anywhere else
// thus far in Flogger (avoid it make it more likely that Flogger can be transpiled for things
// like GWT).
if (s.isEmpty()) {
throw new IllegalArgumentException("identifier must not be empty");
}
if (!isLetter(s.charAt(0))) {
throw new IllegalArgumentException("identifier must start with an ASCII letter: " + s);
}
for (int n = 1; n < s.length(); n++) {
char c = s.charAt(n);
if (!isLetter(c) && (c < '0' || c > '9') && c != '_') {
throw new IllegalArgumentException(
"identifier must contain only ASCII letters, digits or underscore: " + s);
}
}
return s;
}
|
[
"public",
"static",
"String",
"checkMetadataIdentifier",
"(",
"String",
"s",
")",
"{",
"// Note that we avoid using regular expressions here, since we've not used it anywhere else",
"// thus far in Flogger (avoid it make it more likely that Flogger can be transpiled for things",
"// like GWT).",
"if",
"(",
"s",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"identifier must not be empty\"",
")",
";",
"}",
"if",
"(",
"!",
"isLetter",
"(",
"s",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"identifier must start with an ASCII letter: \"",
"+",
"s",
")",
";",
"}",
"for",
"(",
"int",
"n",
"=",
"1",
";",
"n",
"<",
"s",
".",
"length",
"(",
")",
";",
"n",
"++",
")",
"{",
"char",
"c",
"=",
"s",
".",
"charAt",
"(",
"n",
")",
";",
"if",
"(",
"!",
"isLetter",
"(",
"c",
")",
"&&",
"(",
"c",
"<",
"'",
"'",
"||",
"c",
">",
"'",
"'",
")",
"&&",
"c",
"!=",
"'",
"'",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"identifier must contain only ASCII letters, digits or underscore: \"",
"+",
"s",
")",
";",
"}",
"}",
"return",
"s",
";",
"}"
] |
Checks if the given string is a valid metadata identifier.
|
[
"Checks",
"if",
"the",
"given",
"string",
"is",
"a",
"valid",
"metadata",
"identifier",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/util/Checks.java#L42-L60
|
19,436
|
google/flogger
|
api/src/main/java/com/google/common/flogger/util/CallerFinder.java
|
CallerFinder.findCallerOf
|
@Nullable
public static StackTraceElement findCallerOf(Class<?> target, Throwable throwable, int skip) {
checkNotNull(target, "target");
checkNotNull(throwable, "throwable");
if (skip < 0) {
throw new IllegalArgumentException("skip count cannot be negative: " + skip);
}
// Getting the full stack trace is expensive, so avoid it where possible.
StackTraceElement[] stack = (stackGetter != null) ? null : throwable.getStackTrace();
// Note: To avoid having to reflect the getStackTraceDepth() method as well, we assume that we
// will find the caller on the stack and simply catch an exception if we fail (which should
// hardly ever happen).
boolean foundCaller = false;
try {
for (int index = skip; ; index++) {
StackTraceElement element =
(stackGetter != null)
? stackGetter.getStackTraceElement(throwable, index)
: stack[index];
if (target.getName().equals(element.getClassName())) {
foundCaller = true;
} else if (foundCaller) {
return element;
}
}
} catch (Exception e) {
// This should only happen is the caller was not found on the stack (getting exceptions from
// the stack trace method should never happen) and it should only be an
// IndexOutOfBoundsException, however we don't want _anything_ to be thrown from here.
// TODO(dbeaumont): Change to only catch IndexOutOfBoundsException and test _everything_.
return null;
}
}
|
java
|
@Nullable
public static StackTraceElement findCallerOf(Class<?> target, Throwable throwable, int skip) {
checkNotNull(target, "target");
checkNotNull(throwable, "throwable");
if (skip < 0) {
throw new IllegalArgumentException("skip count cannot be negative: " + skip);
}
// Getting the full stack trace is expensive, so avoid it where possible.
StackTraceElement[] stack = (stackGetter != null) ? null : throwable.getStackTrace();
// Note: To avoid having to reflect the getStackTraceDepth() method as well, we assume that we
// will find the caller on the stack and simply catch an exception if we fail (which should
// hardly ever happen).
boolean foundCaller = false;
try {
for (int index = skip; ; index++) {
StackTraceElement element =
(stackGetter != null)
? stackGetter.getStackTraceElement(throwable, index)
: stack[index];
if (target.getName().equals(element.getClassName())) {
foundCaller = true;
} else if (foundCaller) {
return element;
}
}
} catch (Exception e) {
// This should only happen is the caller was not found on the stack (getting exceptions from
// the stack trace method should never happen) and it should only be an
// IndexOutOfBoundsException, however we don't want _anything_ to be thrown from here.
// TODO(dbeaumont): Change to only catch IndexOutOfBoundsException and test _everything_.
return null;
}
}
|
[
"@",
"Nullable",
"public",
"static",
"StackTraceElement",
"findCallerOf",
"(",
"Class",
"<",
"?",
">",
"target",
",",
"Throwable",
"throwable",
",",
"int",
"skip",
")",
"{",
"checkNotNull",
"(",
"target",
",",
"\"target\"",
")",
";",
"checkNotNull",
"(",
"throwable",
",",
"\"throwable\"",
")",
";",
"if",
"(",
"skip",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"skip count cannot be negative: \"",
"+",
"skip",
")",
";",
"}",
"// Getting the full stack trace is expensive, so avoid it where possible.",
"StackTraceElement",
"[",
"]",
"stack",
"=",
"(",
"stackGetter",
"!=",
"null",
")",
"?",
"null",
":",
"throwable",
".",
"getStackTrace",
"(",
")",
";",
"// Note: To avoid having to reflect the getStackTraceDepth() method as well, we assume that we",
"// will find the caller on the stack and simply catch an exception if we fail (which should",
"// hardly ever happen).",
"boolean",
"foundCaller",
"=",
"false",
";",
"try",
"{",
"for",
"(",
"int",
"index",
"=",
"skip",
";",
";",
"index",
"++",
")",
"{",
"StackTraceElement",
"element",
"=",
"(",
"stackGetter",
"!=",
"null",
")",
"?",
"stackGetter",
".",
"getStackTraceElement",
"(",
"throwable",
",",
"index",
")",
":",
"stack",
"[",
"index",
"]",
";",
"if",
"(",
"target",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"element",
".",
"getClassName",
"(",
")",
")",
")",
"{",
"foundCaller",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"foundCaller",
")",
"{",
"return",
"element",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// This should only happen is the caller was not found on the stack (getting exceptions from",
"// the stack trace method should never happen) and it should only be an",
"// IndexOutOfBoundsException, however we don't want _anything_ to be thrown from here.",
"// TODO(dbeaumont): Change to only catch IndexOutOfBoundsException and test _everything_.",
"return",
"null",
";",
"}",
"}"
] |
Returns the stack trace element of the immediate caller of the specified class.
@param target the target class whose callers we are looking for.
@param throwable a new Throwable made at a known point in the call hierarchy.
@param skip the minimum number of calls known to have occurred between the first call to
the target class and the point at which the specified throwable was created. If in doubt,
specify zero here to avoid accidentally skipping past the caller. This is particularly
important for code which might be used in Android, since you cannot know whether a tool
such as Proguard has merged methods or classes and reduced the number of intermediate
stack frames.
@return the stack trace element representing the immediate caller of the specified class, or
null if no caller was found (due to incorrect target, wrong skip count or use of JNI).
|
[
"Returns",
"the",
"stack",
"trace",
"element",
"of",
"the",
"immediate",
"caller",
"of",
"the",
"specified",
"class",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/util/CallerFinder.java#L43-L76
|
19,437
|
google/flogger
|
api/src/main/java/com/google/common/flogger/util/CallerFinder.java
|
CallerFinder.getStackForCallerOf
|
@Nullable
public static StackTraceElement[] getStackForCallerOf(
Class<?> target, Throwable throwable, int maxDepth) {
checkNotNull(target, "target");
checkNotNull(throwable, "throwable");
if (maxDepth <= 0 && maxDepth != -1) {
throw new IllegalArgumentException("invalid maximum depth: " + maxDepth);
}
// Getting the full stack trace is expensive, so avoid it where possible.
StackTraceElement[] stack;
int depth;
if (stackGetter != null) {
stack = null;
depth = stackGetter.getStackTraceDepth(throwable);
} else {
stack = throwable.getStackTrace();
depth = stack.length;
}
boolean foundCaller = false;
// Note that previous versions of this code skipped some variable number of stack frames to
// account for "known" stack frames at the point this method was called. This was a minor
// performance optimization but turned out to be problematic in the face of things like
// Proguard, which can fold method/classes and change the number of intermediate stack frames.
// Now we just start at the immediate "parent" frame.
for (int index = 0; index < depth; index++) {
StackTraceElement element =
(stackGetter != null) ? stackGetter.getStackTraceElement(throwable, index) : stack[index];
if (target.getName().equals(element.getClassName())) {
foundCaller = true;
} else if (foundCaller) {
// There must be at least one element to add (maxDepth > 0 and n < depth).
int elementsToAdd = depth - index;
if (maxDepth > 0 && maxDepth < elementsToAdd) {
elementsToAdd = maxDepth;
}
StackTraceElement[] syntheticStack = new StackTraceElement[elementsToAdd];
syntheticStack[0] = element;
for (int n = 1; n < elementsToAdd; n++) {
syntheticStack[n] =
(stackGetter != null)
? stackGetter.getStackTraceElement(throwable, index + n)
: stack[index + n];
}
return syntheticStack;
}
}
return new StackTraceElement[0];
}
|
java
|
@Nullable
public static StackTraceElement[] getStackForCallerOf(
Class<?> target, Throwable throwable, int maxDepth) {
checkNotNull(target, "target");
checkNotNull(throwable, "throwable");
if (maxDepth <= 0 && maxDepth != -1) {
throw new IllegalArgumentException("invalid maximum depth: " + maxDepth);
}
// Getting the full stack trace is expensive, so avoid it where possible.
StackTraceElement[] stack;
int depth;
if (stackGetter != null) {
stack = null;
depth = stackGetter.getStackTraceDepth(throwable);
} else {
stack = throwable.getStackTrace();
depth = stack.length;
}
boolean foundCaller = false;
// Note that previous versions of this code skipped some variable number of stack frames to
// account for "known" stack frames at the point this method was called. This was a minor
// performance optimization but turned out to be problematic in the face of things like
// Proguard, which can fold method/classes and change the number of intermediate stack frames.
// Now we just start at the immediate "parent" frame.
for (int index = 0; index < depth; index++) {
StackTraceElement element =
(stackGetter != null) ? stackGetter.getStackTraceElement(throwable, index) : stack[index];
if (target.getName().equals(element.getClassName())) {
foundCaller = true;
} else if (foundCaller) {
// There must be at least one element to add (maxDepth > 0 and n < depth).
int elementsToAdd = depth - index;
if (maxDepth > 0 && maxDepth < elementsToAdd) {
elementsToAdd = maxDepth;
}
StackTraceElement[] syntheticStack = new StackTraceElement[elementsToAdd];
syntheticStack[0] = element;
for (int n = 1; n < elementsToAdd; n++) {
syntheticStack[n] =
(stackGetter != null)
? stackGetter.getStackTraceElement(throwable, index + n)
: stack[index + n];
}
return syntheticStack;
}
}
return new StackTraceElement[0];
}
|
[
"@",
"Nullable",
"public",
"static",
"StackTraceElement",
"[",
"]",
"getStackForCallerOf",
"(",
"Class",
"<",
"?",
">",
"target",
",",
"Throwable",
"throwable",
",",
"int",
"maxDepth",
")",
"{",
"checkNotNull",
"(",
"target",
",",
"\"target\"",
")",
";",
"checkNotNull",
"(",
"throwable",
",",
"\"throwable\"",
")",
";",
"if",
"(",
"maxDepth",
"<=",
"0",
"&&",
"maxDepth",
"!=",
"-",
"1",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid maximum depth: \"",
"+",
"maxDepth",
")",
";",
"}",
"// Getting the full stack trace is expensive, so avoid it where possible.",
"StackTraceElement",
"[",
"]",
"stack",
";",
"int",
"depth",
";",
"if",
"(",
"stackGetter",
"!=",
"null",
")",
"{",
"stack",
"=",
"null",
";",
"depth",
"=",
"stackGetter",
".",
"getStackTraceDepth",
"(",
"throwable",
")",
";",
"}",
"else",
"{",
"stack",
"=",
"throwable",
".",
"getStackTrace",
"(",
")",
";",
"depth",
"=",
"stack",
".",
"length",
";",
"}",
"boolean",
"foundCaller",
"=",
"false",
";",
"// Note that previous versions of this code skipped some variable number of stack frames to",
"// account for \"known\" stack frames at the point this method was called. This was a minor",
"// performance optimization but turned out to be problematic in the face of things like",
"// Proguard, which can fold method/classes and change the number of intermediate stack frames.",
"// Now we just start at the immediate \"parent\" frame.",
"for",
"(",
"int",
"index",
"=",
"0",
";",
"index",
"<",
"depth",
";",
"index",
"++",
")",
"{",
"StackTraceElement",
"element",
"=",
"(",
"stackGetter",
"!=",
"null",
")",
"?",
"stackGetter",
".",
"getStackTraceElement",
"(",
"throwable",
",",
"index",
")",
":",
"stack",
"[",
"index",
"]",
";",
"if",
"(",
"target",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"element",
".",
"getClassName",
"(",
")",
")",
")",
"{",
"foundCaller",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"foundCaller",
")",
"{",
"// There must be at least one element to add (maxDepth > 0 and n < depth).",
"int",
"elementsToAdd",
"=",
"depth",
"-",
"index",
";",
"if",
"(",
"maxDepth",
">",
"0",
"&&",
"maxDepth",
"<",
"elementsToAdd",
")",
"{",
"elementsToAdd",
"=",
"maxDepth",
";",
"}",
"StackTraceElement",
"[",
"]",
"syntheticStack",
"=",
"new",
"StackTraceElement",
"[",
"elementsToAdd",
"]",
";",
"syntheticStack",
"[",
"0",
"]",
"=",
"element",
";",
"for",
"(",
"int",
"n",
"=",
"1",
";",
"n",
"<",
"elementsToAdd",
";",
"n",
"++",
")",
"{",
"syntheticStack",
"[",
"n",
"]",
"=",
"(",
"stackGetter",
"!=",
"null",
")",
"?",
"stackGetter",
".",
"getStackTraceElement",
"(",
"throwable",
",",
"index",
"+",
"n",
")",
":",
"stack",
"[",
"index",
"+",
"n",
"]",
";",
"}",
"return",
"syntheticStack",
";",
"}",
"}",
"return",
"new",
"StackTraceElement",
"[",
"0",
"]",
";",
"}"
] |
Returns a synthetic stack trace starting at the immediate caller of the specified target.
@param target the class who caller the returned stack trace will start at.
@param throwable a new Throwable made at a known point in the call hierarchy.
@param maxDepth the maximum size of the returned stack (pass -1 for the complete stack).
@return a synthetic stack trace starting at the immediate caller of the specified target, or
the empty array if no caller was found (due to incorrect target, wrong skip count or use
of JNI).
|
[
"Returns",
"a",
"synthetic",
"stack",
"trace",
"starting",
"at",
"the",
"immediate",
"caller",
"of",
"the",
"specified",
"target",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/util/CallerFinder.java#L88-L135
|
19,438
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parser/MessageBuilder.java
|
MessageBuilder.build
|
public final T build() {
getParser().parseImpl(this);
// There was a gap in the parameters if either:
// 1) the mask had a gap, e.g. ..00110111
// 2) there were more than 32 parameters and the mask wasn't full.
// Gaps above the 32nd parameter are not detected.
if ((pmask & (pmask + 1)) != 0 || (maxIndex > 31 && pmask != -1)) {
int firstMissing = Integer.numberOfTrailingZeros(~pmask);
throw ParseException.generic(
String.format("unreferenced arguments [first missing index=%d]", firstMissing),
getMessage());
}
return buildImpl();
}
|
java
|
public final T build() {
getParser().parseImpl(this);
// There was a gap in the parameters if either:
// 1) the mask had a gap, e.g. ..00110111
// 2) there were more than 32 parameters and the mask wasn't full.
// Gaps above the 32nd parameter are not detected.
if ((pmask & (pmask + 1)) != 0 || (maxIndex > 31 && pmask != -1)) {
int firstMissing = Integer.numberOfTrailingZeros(~pmask);
throw ParseException.generic(
String.format("unreferenced arguments [first missing index=%d]", firstMissing),
getMessage());
}
return buildImpl();
}
|
[
"public",
"final",
"T",
"build",
"(",
")",
"{",
"getParser",
"(",
")",
".",
"parseImpl",
"(",
"this",
")",
";",
"// There was a gap in the parameters if either:",
"// 1) the mask had a gap, e.g. ..00110111",
"// 2) there were more than 32 parameters and the mask wasn't full.",
"// Gaps above the 32nd parameter are not detected.",
"if",
"(",
"(",
"pmask",
"&",
"(",
"pmask",
"+",
"1",
")",
")",
"!=",
"0",
"||",
"(",
"maxIndex",
">",
"31",
"&&",
"pmask",
"!=",
"-",
"1",
")",
")",
"{",
"int",
"firstMissing",
"=",
"Integer",
".",
"numberOfTrailingZeros",
"(",
"~",
"pmask",
")",
";",
"throw",
"ParseException",
".",
"generic",
"(",
"String",
".",
"format",
"(",
"\"unreferenced arguments [first missing index=%d]\"",
",",
"firstMissing",
")",
",",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"buildImpl",
"(",
")",
";",
"}"
] |
Builds a log message using the current message context.
@return the implementation specific result of parsing the current log message.
|
[
"Builds",
"a",
"log",
"message",
"using",
"the",
"current",
"message",
"context",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parser/MessageBuilder.java#L110-L123
|
19,439
|
google/flogger
|
api/src/main/java/com/google/common/flogger/FluentLogger.java
|
FluentLogger.forEnclosingClass
|
public static FluentLogger forEnclosingClass() {
// NOTE: It is _vital_ that the call to "caller finder" is made directly inside the static
// factory method. See getCallerFinder() for more information.
String loggingClass = Platform.getCallerFinder().findLoggingClass(FluentLogger.class);
return new FluentLogger(Platform.getBackend(loggingClass));
}
|
java
|
public static FluentLogger forEnclosingClass() {
// NOTE: It is _vital_ that the call to "caller finder" is made directly inside the static
// factory method. See getCallerFinder() for more information.
String loggingClass = Platform.getCallerFinder().findLoggingClass(FluentLogger.class);
return new FluentLogger(Platform.getBackend(loggingClass));
}
|
[
"public",
"static",
"FluentLogger",
"forEnclosingClass",
"(",
")",
"{",
"// NOTE: It is _vital_ that the call to \"caller finder\" is made directly inside the static",
"// factory method. See getCallerFinder() for more information.",
"String",
"loggingClass",
"=",
"Platform",
".",
"getCallerFinder",
"(",
")",
".",
"findLoggingClass",
"(",
"FluentLogger",
".",
"class",
")",
";",
"return",
"new",
"FluentLogger",
"(",
"Platform",
".",
"getBackend",
"(",
"loggingClass",
")",
")",
";",
"}"
] |
Returns a new logger instance which parses log messages using printf format for the enclosing
class using the system default logging backend.
|
[
"Returns",
"a",
"new",
"logger",
"instance",
"which",
"parses",
"log",
"messages",
"using",
"printf",
"format",
"for",
"the",
"enclosing",
"class",
"using",
"the",
"system",
"default",
"logging",
"backend",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/FluentLogger.java#L67-L72
|
19,440
|
google/flogger
|
api/src/main/java/com/google/common/flogger/LogContext.java
|
LogContext.logImpl
|
@SuppressWarnings("ReferenceEquality")
private void logImpl(String message, Object... args) {
this.args = args;
// Evaluate any (rare) LazyArg instances early. This may throw exceptions from user code, but
// it seems reasonable to propagate them in this case (they would have been thrown if the
// argument was evaluated at the call site anyway).
for (int n = 0; n < args.length; n++) {
if (args[n] instanceof LazyArg) {
args[n] = ((LazyArg<?>) args[n]).evaluate();
}
}
// Using "!=" is fast and sufficient here because the only real case this should be skipping
// is when we called log(String) or log(), which should not result in a template being created.
// DO NOT replace this with a string instance which can be interned, or use equals() here,
// since that could mistakenly treat other calls to log(String, Object...) incorrectly.
if (message != LITERAL_VALUE_MESSAGE) {
this.templateContext = new TemplateContext(getMessageParser(), message);
}
getLogger().write(this);
}
|
java
|
@SuppressWarnings("ReferenceEquality")
private void logImpl(String message, Object... args) {
this.args = args;
// Evaluate any (rare) LazyArg instances early. This may throw exceptions from user code, but
// it seems reasonable to propagate them in this case (they would have been thrown if the
// argument was evaluated at the call site anyway).
for (int n = 0; n < args.length; n++) {
if (args[n] instanceof LazyArg) {
args[n] = ((LazyArg<?>) args[n]).evaluate();
}
}
// Using "!=" is fast and sufficient here because the only real case this should be skipping
// is when we called log(String) or log(), which should not result in a template being created.
// DO NOT replace this with a string instance which can be interned, or use equals() here,
// since that could mistakenly treat other calls to log(String, Object...) incorrectly.
if (message != LITERAL_VALUE_MESSAGE) {
this.templateContext = new TemplateContext(getMessageParser(), message);
}
getLogger().write(this);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"ReferenceEquality\"",
")",
"private",
"void",
"logImpl",
"(",
"String",
"message",
",",
"Object",
"...",
"args",
")",
"{",
"this",
".",
"args",
"=",
"args",
";",
"// Evaluate any (rare) LazyArg instances early. This may throw exceptions from user code, but",
"// it seems reasonable to propagate them in this case (they would have been thrown if the",
"// argument was evaluated at the call site anyway).",
"for",
"(",
"int",
"n",
"=",
"0",
";",
"n",
"<",
"args",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"args",
"[",
"n",
"]",
"instanceof",
"LazyArg",
")",
"{",
"args",
"[",
"n",
"]",
"=",
"(",
"(",
"LazyArg",
"<",
"?",
">",
")",
"args",
"[",
"n",
"]",
")",
".",
"evaluate",
"(",
")",
";",
"}",
"}",
"// Using \"!=\" is fast and sufficient here because the only real case this should be skipping",
"// is when we called log(String) or log(), which should not result in a template being created.",
"// DO NOT replace this with a string instance which can be interned, or use equals() here,",
"// since that could mistakenly treat other calls to log(String, Object...) incorrectly.",
"if",
"(",
"message",
"!=",
"LITERAL_VALUE_MESSAGE",
")",
"{",
"this",
".",
"templateContext",
"=",
"new",
"TemplateContext",
"(",
"getMessageParser",
"(",
")",
",",
"message",
")",
";",
"}",
"getLogger",
"(",
")",
".",
"write",
"(",
"this",
")",
";",
"}"
] |
Make the backend logging call. This is the point at which we have paid the price of creating a
varargs array and doing any necessary auto-boxing.
|
[
"Make",
"the",
"backend",
"logging",
"call",
".",
"This",
"is",
"the",
"point",
"at",
"which",
"we",
"have",
"paid",
"the",
"price",
"of",
"creating",
"a",
"varargs",
"array",
"and",
"doing",
"any",
"necessary",
"auto",
"-",
"boxing",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/LogContext.java#L548-L567
|
19,441
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parameter/SimpleParameter.java
|
SimpleParameter.createParameterArray
|
private static SimpleParameter[] createParameterArray(FormatChar formatChar) {
SimpleParameter[] parameters = new SimpleParameter[MAX_CACHED_PARAMETERS];
for (int index = 0; index < MAX_CACHED_PARAMETERS; index++) {
parameters[index] = new SimpleParameter(index, formatChar, FormatOptions.getDefault());
}
return parameters;
}
|
java
|
private static SimpleParameter[] createParameterArray(FormatChar formatChar) {
SimpleParameter[] parameters = new SimpleParameter[MAX_CACHED_PARAMETERS];
for (int index = 0; index < MAX_CACHED_PARAMETERS; index++) {
parameters[index] = new SimpleParameter(index, formatChar, FormatOptions.getDefault());
}
return parameters;
}
|
[
"private",
"static",
"SimpleParameter",
"[",
"]",
"createParameterArray",
"(",
"FormatChar",
"formatChar",
")",
"{",
"SimpleParameter",
"[",
"]",
"parameters",
"=",
"new",
"SimpleParameter",
"[",
"MAX_CACHED_PARAMETERS",
"]",
";",
"for",
"(",
"int",
"index",
"=",
"0",
";",
"index",
"<",
"MAX_CACHED_PARAMETERS",
";",
"index",
"++",
")",
"{",
"parameters",
"[",
"index",
"]",
"=",
"new",
"SimpleParameter",
"(",
"index",
",",
"formatChar",
",",
"FormatOptions",
".",
"getDefault",
"(",
")",
")",
";",
"}",
"return",
"parameters",
";",
"}"
] |
Helper to make reusable default parameter instances for the commonest indices.
|
[
"Helper",
"to",
"make",
"reusable",
"default",
"parameter",
"instances",
"for",
"the",
"commonest",
"indices",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parameter/SimpleParameter.java#L50-L56
|
19,442
|
google/flogger
|
api/src/main/java/com/google/common/flogger/LoggerConfig.java
|
LoggerConfig.getConfig
|
public static LoggerConfig getConfig(String name) {
LoggerConfig config = strongRefMap.get(checkNotNull(name, "logger name"));
if (config == null) {
// Ignore race condition of multiple put as all instances are equivalent.
// TODO(dbeaumont): Add a check and warn if the map grows "too large".
config = new LoggerConfig(name);
strongRefMap.put(name, config);
}
return config;
}
|
java
|
public static LoggerConfig getConfig(String name) {
LoggerConfig config = strongRefMap.get(checkNotNull(name, "logger name"));
if (config == null) {
// Ignore race condition of multiple put as all instances are equivalent.
// TODO(dbeaumont): Add a check and warn if the map grows "too large".
config = new LoggerConfig(name);
strongRefMap.put(name, config);
}
return config;
}
|
[
"public",
"static",
"LoggerConfig",
"getConfig",
"(",
"String",
"name",
")",
"{",
"LoggerConfig",
"config",
"=",
"strongRefMap",
".",
"get",
"(",
"checkNotNull",
"(",
"name",
",",
"\"logger name\"",
")",
")",
";",
"if",
"(",
"config",
"==",
"null",
")",
"{",
"// Ignore race condition of multiple put as all instances are equivalent.",
"// TODO(dbeaumont): Add a check and warn if the map grows \"too large\".",
"config",
"=",
"new",
"LoggerConfig",
"(",
"name",
")",
";",
"strongRefMap",
".",
"put",
"(",
"name",
",",
"config",
")",
";",
"}",
"return",
"config",
";",
"}"
] |
Returns a configuration instance suitable for configuring a logger with the same name.
<p>This method obtains and wraps the underlying logger with the given name, retaining a strong
reference and making it safe to use for persistent configuration changes. Note that as it makes
very little sense to have a logger configuration object which wraps (and hides) an anonymous
logger instance, {@code null} names are disallowed.
@param name the name of the logger to be configured via this API.
|
[
"Returns",
"a",
"configuration",
"instance",
"suitable",
"for",
"configuring",
"a",
"logger",
"with",
"the",
"same",
"name",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/LoggerConfig.java#L127-L136
|
19,443
|
google/flogger
|
api/src/main/java/com/google/common/flogger/AbstractLogger.java
|
AbstractLogger.write
|
final void write(LogData data) {
checkNotNull(data, "data");
try {
backend.log(data);
} catch (RuntimeException error) {
try {
backend.handleError(error, data);
} catch (LoggingException allowed) {
// Bypass the catch-all if the exception is deliberately created during error handling.
throw allowed;
} catch (RuntimeException wtf) {
System.err.println("logging error: " + wtf.getMessage());
wtf.printStackTrace(System.err);
}
}
}
|
java
|
final void write(LogData data) {
checkNotNull(data, "data");
try {
backend.log(data);
} catch (RuntimeException error) {
try {
backend.handleError(error, data);
} catch (LoggingException allowed) {
// Bypass the catch-all if the exception is deliberately created during error handling.
throw allowed;
} catch (RuntimeException wtf) {
System.err.println("logging error: " + wtf.getMessage());
wtf.printStackTrace(System.err);
}
}
}
|
[
"final",
"void",
"write",
"(",
"LogData",
"data",
")",
"{",
"checkNotNull",
"(",
"data",
",",
"\"data\"",
")",
";",
"try",
"{",
"backend",
".",
"log",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"error",
")",
"{",
"try",
"{",
"backend",
".",
"handleError",
"(",
"error",
",",
"data",
")",
";",
"}",
"catch",
"(",
"LoggingException",
"allowed",
")",
"{",
"// Bypass the catch-all if the exception is deliberately created during error handling.",
"throw",
"allowed",
";",
"}",
"catch",
"(",
"RuntimeException",
"wtf",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"logging error: \"",
"+",
"wtf",
".",
"getMessage",
"(",
")",
")",
";",
"wtf",
".",
"printStackTrace",
"(",
"System",
".",
"err",
")",
";",
"}",
"}",
"}"
] |
Invokes the logging backend to write a log statement.
|
[
"Invokes",
"the",
"logging",
"backend",
"to",
"write",
"a",
"log",
"statement",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/AbstractLogger.java#L134-L149
|
19,444
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/SimpleMessageFormatter.java
|
SimpleMessageFormatter.safeFormatTo
|
private static void safeFormatTo(Formattable value, StringBuilder out, FormatOptions options) {
// Only care about 3 specific flags for Formattable.
int formatFlags = options.getFlags() & (FLAG_LEFT_ALIGN | FLAG_UPPER_CASE | FLAG_SHOW_ALT_FORM);
if (formatFlags != 0) {
// TODO: Maybe re-order the options flags to make this step easier or use a lookup table.
// Note that reordering flags would require a rethink of how they are parsed.
formatFlags = ((formatFlags & FLAG_LEFT_ALIGN) != 0 ? FormattableFlags.LEFT_JUSTIFY : 0)
| ((formatFlags & FLAG_UPPER_CASE) != 0 ? FormattableFlags.UPPERCASE : 0)
| ((formatFlags & FLAG_SHOW_ALT_FORM) != 0 ? FormattableFlags.ALTERNATE : 0);
}
// We may need to undo an arbitrary amount of appending if there is an error.
int originalLength = out.length();
Formatter formatter = new Formatter(out, FORMAT_LOCALE);
try {
value.formatTo(formatter, formatFlags, options.getWidth(), options.getPrecision());
} catch (RuntimeException e) {
out.setLength(originalLength);
// We only use a StringBuilder to create the Formatter instance.
try {
formatter.out().append(getErrorString(value, e));
} catch (IOException impossible) { }
}
}
|
java
|
private static void safeFormatTo(Formattable value, StringBuilder out, FormatOptions options) {
// Only care about 3 specific flags for Formattable.
int formatFlags = options.getFlags() & (FLAG_LEFT_ALIGN | FLAG_UPPER_CASE | FLAG_SHOW_ALT_FORM);
if (formatFlags != 0) {
// TODO: Maybe re-order the options flags to make this step easier or use a lookup table.
// Note that reordering flags would require a rethink of how they are parsed.
formatFlags = ((formatFlags & FLAG_LEFT_ALIGN) != 0 ? FormattableFlags.LEFT_JUSTIFY : 0)
| ((formatFlags & FLAG_UPPER_CASE) != 0 ? FormattableFlags.UPPERCASE : 0)
| ((formatFlags & FLAG_SHOW_ALT_FORM) != 0 ? FormattableFlags.ALTERNATE : 0);
}
// We may need to undo an arbitrary amount of appending if there is an error.
int originalLength = out.length();
Formatter formatter = new Formatter(out, FORMAT_LOCALE);
try {
value.formatTo(formatter, formatFlags, options.getWidth(), options.getPrecision());
} catch (RuntimeException e) {
out.setLength(originalLength);
// We only use a StringBuilder to create the Formatter instance.
try {
formatter.out().append(getErrorString(value, e));
} catch (IOException impossible) { }
}
}
|
[
"private",
"static",
"void",
"safeFormatTo",
"(",
"Formattable",
"value",
",",
"StringBuilder",
"out",
",",
"FormatOptions",
"options",
")",
"{",
"// Only care about 3 specific flags for Formattable.",
"int",
"formatFlags",
"=",
"options",
".",
"getFlags",
"(",
")",
"&",
"(",
"FLAG_LEFT_ALIGN",
"|",
"FLAG_UPPER_CASE",
"|",
"FLAG_SHOW_ALT_FORM",
")",
";",
"if",
"(",
"formatFlags",
"!=",
"0",
")",
"{",
"// TODO: Maybe re-order the options flags to make this step easier or use a lookup table.",
"// Note that reordering flags would require a rethink of how they are parsed.",
"formatFlags",
"=",
"(",
"(",
"formatFlags",
"&",
"FLAG_LEFT_ALIGN",
")",
"!=",
"0",
"?",
"FormattableFlags",
".",
"LEFT_JUSTIFY",
":",
"0",
")",
"|",
"(",
"(",
"formatFlags",
"&",
"FLAG_UPPER_CASE",
")",
"!=",
"0",
"?",
"FormattableFlags",
".",
"UPPERCASE",
":",
"0",
")",
"|",
"(",
"(",
"formatFlags",
"&",
"FLAG_SHOW_ALT_FORM",
")",
"!=",
"0",
"?",
"FormattableFlags",
".",
"ALTERNATE",
":",
"0",
")",
";",
"}",
"// We may need to undo an arbitrary amount of appending if there is an error.",
"int",
"originalLength",
"=",
"out",
".",
"length",
"(",
")",
";",
"Formatter",
"formatter",
"=",
"new",
"Formatter",
"(",
"out",
",",
"FORMAT_LOCALE",
")",
";",
"try",
"{",
"value",
".",
"formatTo",
"(",
"formatter",
",",
"formatFlags",
",",
"options",
".",
"getWidth",
"(",
")",
",",
"options",
".",
"getPrecision",
"(",
")",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"out",
".",
"setLength",
"(",
"originalLength",
")",
";",
"// We only use a StringBuilder to create the Formatter instance.",
"try",
"{",
"formatter",
".",
"out",
"(",
")",
".",
"append",
"(",
"getErrorString",
"(",
"value",
",",
"e",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"impossible",
")",
"{",
"}",
"}",
"}"
] |
Returns a string representation of the user supplied formattable, accounting for any possible
runtime exceptions.
@param value the value to be formatted.
@return a best-effort string representation of the given value, even if exceptions were thrown.
|
[
"Returns",
"a",
"string",
"representation",
"of",
"the",
"user",
"supplied",
"formattable",
"accounting",
"for",
"any",
"possible",
"runtime",
"exceptions",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/SimpleMessageFormatter.java#L131-L153
|
19,445
|
google/flogger
|
log4j/src/main/java/com/google/common/flogger/backend/log4j/Log4jLoggerBackend.java
|
Log4jLoggerBackend.toLog4jLevel
|
static org.apache.log4j.Level toLog4jLevel(java.util.logging.Level level) {
if (level.intValue() >= java.util.logging.Level.SEVERE.intValue()) {
return org.apache.log4j.Level.ERROR;
} else if (level.intValue() >= java.util.logging.Level.WARNING.intValue()) {
return org.apache.log4j.Level.WARN;
} else if (level.intValue() >= java.util.logging.Level.INFO.intValue()) {
return org.apache.log4j.Level.INFO;
} else if (level.intValue() >= java.util.logging.Level.FINE.intValue()) {
return org.apache.log4j.Level.DEBUG;
}
return org.apache.log4j.Level.TRACE;
}
|
java
|
static org.apache.log4j.Level toLog4jLevel(java.util.logging.Level level) {
if (level.intValue() >= java.util.logging.Level.SEVERE.intValue()) {
return org.apache.log4j.Level.ERROR;
} else if (level.intValue() >= java.util.logging.Level.WARNING.intValue()) {
return org.apache.log4j.Level.WARN;
} else if (level.intValue() >= java.util.logging.Level.INFO.intValue()) {
return org.apache.log4j.Level.INFO;
} else if (level.intValue() >= java.util.logging.Level.FINE.intValue()) {
return org.apache.log4j.Level.DEBUG;
}
return org.apache.log4j.Level.TRACE;
}
|
[
"static",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
"toLog4jLevel",
"(",
"java",
".",
"util",
".",
"logging",
".",
"Level",
"level",
")",
"{",
"if",
"(",
"level",
".",
"intValue",
"(",
")",
">=",
"java",
".",
"util",
".",
"logging",
".",
"Level",
".",
"SEVERE",
".",
"intValue",
"(",
")",
")",
"{",
"return",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
".",
"ERROR",
";",
"}",
"else",
"if",
"(",
"level",
".",
"intValue",
"(",
")",
">=",
"java",
".",
"util",
".",
"logging",
".",
"Level",
".",
"WARNING",
".",
"intValue",
"(",
")",
")",
"{",
"return",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
".",
"WARN",
";",
"}",
"else",
"if",
"(",
"level",
".",
"intValue",
"(",
")",
">=",
"java",
".",
"util",
".",
"logging",
".",
"Level",
".",
"INFO",
".",
"intValue",
"(",
")",
")",
"{",
"return",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
".",
"INFO",
";",
"}",
"else",
"if",
"(",
"level",
".",
"intValue",
"(",
")",
">=",
"java",
".",
"util",
".",
"logging",
".",
"Level",
".",
"FINE",
".",
"intValue",
"(",
")",
")",
"{",
"return",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
".",
"DEBUG",
";",
"}",
"return",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
".",
"TRACE",
";",
"}"
] |
Converts java.util.logging.Level to org.apache.log4j.Level.
|
[
"Converts",
"java",
".",
"util",
".",
"logging",
".",
"Level",
"to",
"org",
".",
"apache",
".",
"log4j",
".",
"Level",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/log4j/src/main/java/com/google/common/flogger/backend/log4j/Log4jLoggerBackend.java#L26-L37
|
19,446
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parser/ParseException.java
|
ParseException.withBounds
|
public static ParseException withBounds(
String errorMessage, String logMessage, int start, int end) {
return new ParseException(msg(errorMessage, logMessage, start, end), logMessage);
}
|
java
|
public static ParseException withBounds(
String errorMessage, String logMessage, int start, int end) {
return new ParseException(msg(errorMessage, logMessage, start, end), logMessage);
}
|
[
"public",
"static",
"ParseException",
"withBounds",
"(",
"String",
"errorMessage",
",",
"String",
"logMessage",
",",
"int",
"start",
",",
"int",
"end",
")",
"{",
"return",
"new",
"ParseException",
"(",
"msg",
"(",
"errorMessage",
",",
"logMessage",
",",
"start",
",",
"end",
")",
",",
"logMessage",
")",
";",
"}"
] |
Creates a new parse exception for situations in which both the start and end positions of the
error are known.
@param errorMessage the user error message.
@param logMessage the original log message.
@param start the index of the first character in the invalid section of the log message.
@param end the index after the last character in the invalid section of the log message.
@return the parser exception.
|
[
"Creates",
"a",
"new",
"parse",
"exception",
"for",
"situations",
"in",
"which",
"both",
"the",
"start",
"and",
"end",
"positions",
"of",
"the",
"error",
"are",
"known",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parser/ParseException.java#L43-L46
|
19,447
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parser/ParseException.java
|
ParseException.atPosition
|
public static ParseException atPosition(String errorMessage, String logMessage, int position) {
return new ParseException(msg(errorMessage, logMessage, position, position + 1), logMessage);
}
|
java
|
public static ParseException atPosition(String errorMessage, String logMessage, int position) {
return new ParseException(msg(errorMessage, logMessage, position, position + 1), logMessage);
}
|
[
"public",
"static",
"ParseException",
"atPosition",
"(",
"String",
"errorMessage",
",",
"String",
"logMessage",
",",
"int",
"position",
")",
"{",
"return",
"new",
"ParseException",
"(",
"msg",
"(",
"errorMessage",
",",
"logMessage",
",",
"position",
",",
"position",
"+",
"1",
")",
",",
"logMessage",
")",
";",
"}"
] |
Creates a new parse exception for situations in which the position of the error is known.
@param errorMessage the user error message.
@param logMessage the original log message.
@param position the index of the invalid character in the log message.
@return the parser exception.
|
[
"Creates",
"a",
"new",
"parse",
"exception",
"for",
"situations",
"in",
"which",
"the",
"position",
"of",
"the",
"error",
"is",
"known",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parser/ParseException.java#L56-L58
|
19,448
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parser/ParseException.java
|
ParseException.withStartPosition
|
public static ParseException withStartPosition(
String errorMessage, String logMessage, int start) {
return new ParseException(msg(errorMessage, logMessage, start, -1), logMessage);
}
|
java
|
public static ParseException withStartPosition(
String errorMessage, String logMessage, int start) {
return new ParseException(msg(errorMessage, logMessage, start, -1), logMessage);
}
|
[
"public",
"static",
"ParseException",
"withStartPosition",
"(",
"String",
"errorMessage",
",",
"String",
"logMessage",
",",
"int",
"start",
")",
"{",
"return",
"new",
"ParseException",
"(",
"msg",
"(",
"errorMessage",
",",
"logMessage",
",",
"start",
",",
"-",
"1",
")",
",",
"logMessage",
")",
";",
"}"
] |
Creates a new parse exception for situations in which only the start position of the error is
known.
@param errorMessage the user error message.
@param logMessage the original log message.
@param start the index of the first character in the invalid section of the log message.
@return the parser exception.
|
[
"Creates",
"a",
"new",
"parse",
"exception",
"for",
"situations",
"in",
"which",
"only",
"the",
"start",
"position",
"of",
"the",
"error",
"is",
"known",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parser/ParseException.java#L69-L72
|
19,449
|
google/flogger
|
api/src/main/java/com/google/common/flogger/parser/ParseException.java
|
ParseException.msg
|
private static String msg(String errorMessage, String logMessage, int errorStart, int errorEnd) {
if (errorEnd < 0) {
errorEnd = logMessage.length();
}
StringBuilder out = new StringBuilder(errorMessage).append(": ");
if (errorStart > SNIPPET_LENGTH + ELLIPSIS.length()) {
out.append(ELLIPSIS).append(logMessage, errorStart - SNIPPET_LENGTH, errorStart);
} else {
out.append(logMessage, 0, errorStart);
}
out.append('[').append(logMessage.substring(errorStart, errorEnd)).append(']');
if (logMessage.length() - errorEnd > SNIPPET_LENGTH + ELLIPSIS.length()) {
out.append(logMessage, errorEnd, errorEnd + SNIPPET_LENGTH).append(ELLIPSIS);
} else {
out.append(logMessage, errorEnd, logMessage.length());
}
return out.toString();
}
|
java
|
private static String msg(String errorMessage, String logMessage, int errorStart, int errorEnd) {
if (errorEnd < 0) {
errorEnd = logMessage.length();
}
StringBuilder out = new StringBuilder(errorMessage).append(": ");
if (errorStart > SNIPPET_LENGTH + ELLIPSIS.length()) {
out.append(ELLIPSIS).append(logMessage, errorStart - SNIPPET_LENGTH, errorStart);
} else {
out.append(logMessage, 0, errorStart);
}
out.append('[').append(logMessage.substring(errorStart, errorEnd)).append(']');
if (logMessage.length() - errorEnd > SNIPPET_LENGTH + ELLIPSIS.length()) {
out.append(logMessage, errorEnd, errorEnd + SNIPPET_LENGTH).append(ELLIPSIS);
} else {
out.append(logMessage, errorEnd, logMessage.length());
}
return out.toString();
}
|
[
"private",
"static",
"String",
"msg",
"(",
"String",
"errorMessage",
",",
"String",
"logMessage",
",",
"int",
"errorStart",
",",
"int",
"errorEnd",
")",
"{",
"if",
"(",
"errorEnd",
"<",
"0",
")",
"{",
"errorEnd",
"=",
"logMessage",
".",
"length",
"(",
")",
";",
"}",
"StringBuilder",
"out",
"=",
"new",
"StringBuilder",
"(",
"errorMessage",
")",
".",
"append",
"(",
"\": \"",
")",
";",
"if",
"(",
"errorStart",
">",
"SNIPPET_LENGTH",
"+",
"ELLIPSIS",
".",
"length",
"(",
")",
")",
"{",
"out",
".",
"append",
"(",
"ELLIPSIS",
")",
".",
"append",
"(",
"logMessage",
",",
"errorStart",
"-",
"SNIPPET_LENGTH",
",",
"errorStart",
")",
";",
"}",
"else",
"{",
"out",
".",
"append",
"(",
"logMessage",
",",
"0",
",",
"errorStart",
")",
";",
"}",
"out",
".",
"append",
"(",
"'",
"'",
")",
".",
"append",
"(",
"logMessage",
".",
"substring",
"(",
"errorStart",
",",
"errorEnd",
")",
")",
".",
"append",
"(",
"'",
"'",
")",
";",
"if",
"(",
"logMessage",
".",
"length",
"(",
")",
"-",
"errorEnd",
">",
"SNIPPET_LENGTH",
"+",
"ELLIPSIS",
".",
"length",
"(",
")",
")",
"{",
"out",
".",
"append",
"(",
"logMessage",
",",
"errorEnd",
",",
"errorEnd",
"+",
"SNIPPET_LENGTH",
")",
".",
"append",
"(",
"ELLIPSIS",
")",
";",
"}",
"else",
"{",
"out",
".",
"append",
"(",
"logMessage",
",",
"errorEnd",
",",
"logMessage",
".",
"length",
"(",
")",
")",
";",
"}",
"return",
"out",
".",
"toString",
"(",
")",
";",
"}"
] |
Helper to format a human readable error message for this exception.
|
[
"Helper",
"to",
"format",
"a",
"human",
"readable",
"error",
"message",
"for",
"this",
"exception",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/parser/ParseException.java#L89-L106
|
19,450
|
google/flogger
|
log4j/src/main/java/com/google/common/flogger/backend/log4j/LogDataFormatter.java
|
LogDataFormatter.formatBadLogData
|
static void formatBadLogData(
RuntimeException error, LogData badLogData, SimpleLogHandler receiver) {
StringBuilder errorMsg =
new StringBuilder("LOGGING ERROR: ").append(error.getMessage()).append('\n');
int length = errorMsg.length();
try {
appendLogData(badLogData, errorMsg);
} catch (RuntimeException e) {
// Reset partially written buffer when an error occurs.
errorMsg.setLength(length);
errorMsg.append("Cannot append LogData: ").append(e);
}
// Re-target this log message as a warning (or above) since it indicates a real bug.
Level level =
badLogData.getLevel().intValue() < WARNING.intValue() ? WARNING : badLogData.getLevel();
receiver.handleFormattedLogMessage(level, errorMsg.toString(), error);
}
|
java
|
static void formatBadLogData(
RuntimeException error, LogData badLogData, SimpleLogHandler receiver) {
StringBuilder errorMsg =
new StringBuilder("LOGGING ERROR: ").append(error.getMessage()).append('\n');
int length = errorMsg.length();
try {
appendLogData(badLogData, errorMsg);
} catch (RuntimeException e) {
// Reset partially written buffer when an error occurs.
errorMsg.setLength(length);
errorMsg.append("Cannot append LogData: ").append(e);
}
// Re-target this log message as a warning (or above) since it indicates a real bug.
Level level =
badLogData.getLevel().intValue() < WARNING.intValue() ? WARNING : badLogData.getLevel();
receiver.handleFormattedLogMessage(level, errorMsg.toString(), error);
}
|
[
"static",
"void",
"formatBadLogData",
"(",
"RuntimeException",
"error",
",",
"LogData",
"badLogData",
",",
"SimpleLogHandler",
"receiver",
")",
"{",
"StringBuilder",
"errorMsg",
"=",
"new",
"StringBuilder",
"(",
"\"LOGGING ERROR: \"",
")",
".",
"append",
"(",
"error",
".",
"getMessage",
"(",
")",
")",
".",
"append",
"(",
"'",
"'",
")",
";",
"int",
"length",
"=",
"errorMsg",
".",
"length",
"(",
")",
";",
"try",
"{",
"appendLogData",
"(",
"badLogData",
",",
"errorMsg",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"// Reset partially written buffer when an error occurs.",
"errorMsg",
".",
"setLength",
"(",
"length",
")",
";",
"errorMsg",
".",
"append",
"(",
"\"Cannot append LogData: \"",
")",
".",
"append",
"(",
"e",
")",
";",
"}",
"// Re-target this log message as a warning (or above) since it indicates a real bug.",
"Level",
"level",
"=",
"badLogData",
".",
"getLevel",
"(",
")",
".",
"intValue",
"(",
")",
"<",
"WARNING",
".",
"intValue",
"(",
")",
"?",
"WARNING",
":",
"badLogData",
".",
"getLevel",
"(",
")",
";",
"receiver",
".",
"handleFormattedLogMessage",
"(",
"level",
",",
"errorMsg",
".",
"toString",
"(",
")",
",",
"error",
")",
";",
"}"
] |
Formats the log message in response to an exception during a previous logging attempt. A
synthetic error message is generated from the original log data and the given exception is set
as the cause. The level of this record is the maximum of WARNING or the original level.
|
[
"Formats",
"the",
"log",
"message",
"in",
"response",
"to",
"an",
"exception",
"during",
"a",
"previous",
"logging",
"attempt",
".",
"A",
"synthetic",
"error",
"message",
"is",
"generated",
"from",
"the",
"original",
"log",
"data",
"and",
"the",
"given",
"exception",
"is",
"set",
"as",
"the",
"cause",
".",
"The",
"level",
"of",
"this",
"record",
"is",
"the",
"maximum",
"of",
"WARNING",
"or",
"the",
"original",
"level",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/log4j/src/main/java/com/google/common/flogger/backend/log4j/LogDataFormatter.java#L44-L62
|
19,451
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/FormatOptions.java
|
FormatOptions.of
|
public static FormatOptions of(int flags, int width, int precision) {
if (!checkFlagConsistency(flags, width != UNSET)) {
throw new IllegalArgumentException("invalid flags: 0x" + Integer.toHexString(flags));
}
if ((width < 1 || width > MAX_ALLOWED_WIDTH) && width != UNSET) {
throw new IllegalArgumentException("invalid width: " + width);
}
if ((precision < 0 || precision > MAX_ALLOWED_PRECISION) && precision != UNSET) {
throw new IllegalArgumentException("invalid precision: " + precision);
}
return new FormatOptions(flags, width, precision);
}
|
java
|
public static FormatOptions of(int flags, int width, int precision) {
if (!checkFlagConsistency(flags, width != UNSET)) {
throw new IllegalArgumentException("invalid flags: 0x" + Integer.toHexString(flags));
}
if ((width < 1 || width > MAX_ALLOWED_WIDTH) && width != UNSET) {
throw new IllegalArgumentException("invalid width: " + width);
}
if ((precision < 0 || precision > MAX_ALLOWED_PRECISION) && precision != UNSET) {
throw new IllegalArgumentException("invalid precision: " + precision);
}
return new FormatOptions(flags, width, precision);
}
|
[
"public",
"static",
"FormatOptions",
"of",
"(",
"int",
"flags",
",",
"int",
"width",
",",
"int",
"precision",
")",
"{",
"if",
"(",
"!",
"checkFlagConsistency",
"(",
"flags",
",",
"width",
"!=",
"UNSET",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid flags: 0x\"",
"+",
"Integer",
".",
"toHexString",
"(",
"flags",
")",
")",
";",
"}",
"if",
"(",
"(",
"width",
"<",
"1",
"||",
"width",
">",
"MAX_ALLOWED_WIDTH",
")",
"&&",
"width",
"!=",
"UNSET",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid width: \"",
"+",
"width",
")",
";",
"}",
"if",
"(",
"(",
"precision",
"<",
"0",
"||",
"precision",
">",
"MAX_ALLOWED_PRECISION",
")",
"&&",
"precision",
"!=",
"UNSET",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid precision: \"",
"+",
"precision",
")",
";",
"}",
"return",
"new",
"FormatOptions",
"(",
"flags",
",",
"width",
",",
"precision",
")",
";",
"}"
] |
Creates a options instance with the given values.
|
[
"Creates",
"a",
"options",
"instance",
"with",
"the",
"given",
"values",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/FormatOptions.java#L137-L148
|
19,452
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/FormatOptions.java
|
FormatOptions.parse
|
public static FormatOptions parse(String message, int pos, int end, boolean isUpperCase)
throws ParseException {
// It is vital that we shortcut parsing and return the default instance here (rather than just
// creating a new instance with default values) because we check for it using '==' later).
// Also, it saves us thousands of otherwise unnecessary allocations.
if (pos == end && !isUpperCase) {
return DEFAULT;
}
// STEP 1: Parse flag bits.
int flags = isUpperCase ? FLAG_UPPER_CASE : 0;
char c;
while (true) {
if (pos == end) {
return new FormatOptions(flags, UNSET, UNSET);
}
c = message.charAt(pos++);
if (c < MIN_FLAG_VALUE || c > MAX_FLAG_VALUE) {
break;
}
int flagIdx = indexOfFlagCharacter(c);
if (flagIdx < 0) {
if (c == '.') {
// Edge case of something like "%.2f" (precision but no width).
return new FormatOptions(flags, UNSET, parsePrecision(message, pos, end));
}
throw ParseException.atPosition("invalid flag", message, pos - 1);
}
int flagBit = 1 << flagIdx;
if ((flags & flagBit) != 0) {
throw ParseException.atPosition("repeated flag", message, pos - 1);
}
flags |= flagBit;
}
// STEP 2: Parse width (which must start with [1-9]).
// We know that c > MAX_FLAG_VALUE, which is really just '0', so (c >= 1)
int widthStart = pos - 1;
if (c > '9') {
throw ParseException.atPosition("invalid flag", message, widthStart);
}
int width = c - '0';
while (true) {
if (pos == end) {
return new FormatOptions(flags, width, UNSET);
}
c = message.charAt(pos++);
if (c == '.') {
return new FormatOptions(flags, width, parsePrecision(message, pos, end));
}
int n = (char) (c - '0');
if (n >= 10) {
throw ParseException.atPosition("invalid width character", message, pos - 1);
}
width = (width * 10) + n;
if (width > MAX_ALLOWED_WIDTH) {
throw ParseException.withBounds("width too large", message, widthStart, end);
}
}
}
|
java
|
public static FormatOptions parse(String message, int pos, int end, boolean isUpperCase)
throws ParseException {
// It is vital that we shortcut parsing and return the default instance here (rather than just
// creating a new instance with default values) because we check for it using '==' later).
// Also, it saves us thousands of otherwise unnecessary allocations.
if (pos == end && !isUpperCase) {
return DEFAULT;
}
// STEP 1: Parse flag bits.
int flags = isUpperCase ? FLAG_UPPER_CASE : 0;
char c;
while (true) {
if (pos == end) {
return new FormatOptions(flags, UNSET, UNSET);
}
c = message.charAt(pos++);
if (c < MIN_FLAG_VALUE || c > MAX_FLAG_VALUE) {
break;
}
int flagIdx = indexOfFlagCharacter(c);
if (flagIdx < 0) {
if (c == '.') {
// Edge case of something like "%.2f" (precision but no width).
return new FormatOptions(flags, UNSET, parsePrecision(message, pos, end));
}
throw ParseException.atPosition("invalid flag", message, pos - 1);
}
int flagBit = 1 << flagIdx;
if ((flags & flagBit) != 0) {
throw ParseException.atPosition("repeated flag", message, pos - 1);
}
flags |= flagBit;
}
// STEP 2: Parse width (which must start with [1-9]).
// We know that c > MAX_FLAG_VALUE, which is really just '0', so (c >= 1)
int widthStart = pos - 1;
if (c > '9') {
throw ParseException.atPosition("invalid flag", message, widthStart);
}
int width = c - '0';
while (true) {
if (pos == end) {
return new FormatOptions(flags, width, UNSET);
}
c = message.charAt(pos++);
if (c == '.') {
return new FormatOptions(flags, width, parsePrecision(message, pos, end));
}
int n = (char) (c - '0');
if (n >= 10) {
throw ParseException.atPosition("invalid width character", message, pos - 1);
}
width = (width * 10) + n;
if (width > MAX_ALLOWED_WIDTH) {
throw ParseException.withBounds("width too large", message, widthStart, end);
}
}
}
|
[
"public",
"static",
"FormatOptions",
"parse",
"(",
"String",
"message",
",",
"int",
"pos",
",",
"int",
"end",
",",
"boolean",
"isUpperCase",
")",
"throws",
"ParseException",
"{",
"// It is vital that we shortcut parsing and return the default instance here (rather than just",
"// creating a new instance with default values) because we check for it using '==' later).",
"// Also, it saves us thousands of otherwise unnecessary allocations.",
"if",
"(",
"pos",
"==",
"end",
"&&",
"!",
"isUpperCase",
")",
"{",
"return",
"DEFAULT",
";",
"}",
"// STEP 1: Parse flag bits.",
"int",
"flags",
"=",
"isUpperCase",
"?",
"FLAG_UPPER_CASE",
":",
"0",
";",
"char",
"c",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"pos",
"==",
"end",
")",
"{",
"return",
"new",
"FormatOptions",
"(",
"flags",
",",
"UNSET",
",",
"UNSET",
")",
";",
"}",
"c",
"=",
"message",
".",
"charAt",
"(",
"pos",
"++",
")",
";",
"if",
"(",
"c",
"<",
"MIN_FLAG_VALUE",
"||",
"c",
">",
"MAX_FLAG_VALUE",
")",
"{",
"break",
";",
"}",
"int",
"flagIdx",
"=",
"indexOfFlagCharacter",
"(",
"c",
")",
";",
"if",
"(",
"flagIdx",
"<",
"0",
")",
"{",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"// Edge case of something like \"%.2f\" (precision but no width).",
"return",
"new",
"FormatOptions",
"(",
"flags",
",",
"UNSET",
",",
"parsePrecision",
"(",
"message",
",",
"pos",
",",
"end",
")",
")",
";",
"}",
"throw",
"ParseException",
".",
"atPosition",
"(",
"\"invalid flag\"",
",",
"message",
",",
"pos",
"-",
"1",
")",
";",
"}",
"int",
"flagBit",
"=",
"1",
"<<",
"flagIdx",
";",
"if",
"(",
"(",
"flags",
"&",
"flagBit",
")",
"!=",
"0",
")",
"{",
"throw",
"ParseException",
".",
"atPosition",
"(",
"\"repeated flag\"",
",",
"message",
",",
"pos",
"-",
"1",
")",
";",
"}",
"flags",
"|=",
"flagBit",
";",
"}",
"// STEP 2: Parse width (which must start with [1-9]).",
"// We know that c > MAX_FLAG_VALUE, which is really just '0', so (c >= 1)",
"int",
"widthStart",
"=",
"pos",
"-",
"1",
";",
"if",
"(",
"c",
">",
"'",
"'",
")",
"{",
"throw",
"ParseException",
".",
"atPosition",
"(",
"\"invalid flag\"",
",",
"message",
",",
"widthStart",
")",
";",
"}",
"int",
"width",
"=",
"c",
"-",
"'",
"'",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"pos",
"==",
"end",
")",
"{",
"return",
"new",
"FormatOptions",
"(",
"flags",
",",
"width",
",",
"UNSET",
")",
";",
"}",
"c",
"=",
"message",
".",
"charAt",
"(",
"pos",
"++",
")",
";",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"new",
"FormatOptions",
"(",
"flags",
",",
"width",
",",
"parsePrecision",
"(",
"message",
",",
"pos",
",",
"end",
")",
")",
";",
"}",
"int",
"n",
"=",
"(",
"char",
")",
"(",
"c",
"-",
"'",
"'",
")",
";",
"if",
"(",
"n",
">=",
"10",
")",
"{",
"throw",
"ParseException",
".",
"atPosition",
"(",
"\"invalid width character\"",
",",
"message",
",",
"pos",
"-",
"1",
")",
";",
"}",
"width",
"=",
"(",
"width",
"*",
"10",
")",
"+",
"n",
";",
"if",
"(",
"width",
">",
"MAX_ALLOWED_WIDTH",
")",
"{",
"throw",
"ParseException",
".",
"withBounds",
"(",
"\"width too large\"",
",",
"message",
",",
"widthStart",
",",
"end",
")",
";",
"}",
"}",
"}"
] |
Parses a sub-sequence of a log message to extract and return its options. Note that callers
cannot rely on this method producing new instances each time it is called as caching of common
option values may occur.
@param message the original log message in which the formatting options have been identified.
@param pos the index of the first character to parse.
@param end the index after the last character to be parsed.
@return the parsed options instance.
@throws ParseException if the specified sub-sequence of the string could not be parsed.
|
[
"Parses",
"a",
"sub",
"-",
"sequence",
"of",
"a",
"log",
"message",
"to",
"extract",
"and",
"return",
"its",
"options",
".",
"Note",
"that",
"callers",
"cannot",
"rely",
"on",
"this",
"method",
"producing",
"new",
"instances",
"each",
"time",
"it",
"is",
"called",
"as",
"caching",
"of",
"common",
"option",
"values",
"may",
"occur",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/FormatOptions.java#L161-L220
|
19,453
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/FormatOptions.java
|
FormatOptions.parseValidFlags
|
static int parseValidFlags(String flagChars, boolean hasUpperVariant) {
int flags = hasUpperVariant ? FLAG_UPPER_CASE : 0;
for (int i = 0; i < flagChars.length(); i++) {
int flagIdx = indexOfFlagCharacter(flagChars.charAt(i));
if (flagIdx < 0) {
throw new IllegalArgumentException("invalid flags: " + flagChars);
}
flags |= 1 << flagIdx;
}
return flags;
}
|
java
|
static int parseValidFlags(String flagChars, boolean hasUpperVariant) {
int flags = hasUpperVariant ? FLAG_UPPER_CASE : 0;
for (int i = 0; i < flagChars.length(); i++) {
int flagIdx = indexOfFlagCharacter(flagChars.charAt(i));
if (flagIdx < 0) {
throw new IllegalArgumentException("invalid flags: " + flagChars);
}
flags |= 1 << flagIdx;
}
return flags;
}
|
[
"static",
"int",
"parseValidFlags",
"(",
"String",
"flagChars",
",",
"boolean",
"hasUpperVariant",
")",
"{",
"int",
"flags",
"=",
"hasUpperVariant",
"?",
"FLAG_UPPER_CASE",
":",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"flagChars",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"int",
"flagIdx",
"=",
"indexOfFlagCharacter",
"(",
"flagChars",
".",
"charAt",
"(",
"i",
")",
")",
";",
"if",
"(",
"flagIdx",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid flags: \"",
"+",
"flagChars",
")",
";",
"}",
"flags",
"|=",
"1",
"<<",
"flagIdx",
";",
"}",
"return",
"flags",
";",
"}"
] |
Internal helper method for creating a bit-mask from a string of valid flag characters.
|
[
"Internal",
"helper",
"method",
"for",
"creating",
"a",
"bit",
"-",
"mask",
"from",
"a",
"string",
"of",
"valid",
"flag",
"characters",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/FormatOptions.java#L245-L255
|
19,454
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/FormatOptions.java
|
FormatOptions.filter
|
public FormatOptions filter(int allowedFlags, boolean allowWidth, boolean allowPrecision) {
if (isDefault()) {
return this;
}
int newFlags = allowedFlags & flags;
int newWidth = allowWidth ? width : UNSET;
int newPrecision = allowPrecision ? precision : UNSET;
// Remember that we must never create a non-canonical default instance.
if (newFlags == 0 && newWidth == UNSET && newPrecision == UNSET) {
return DEFAULT;
}
// This check would be faster if we encoded the entire state into a long value. It's also
// entirely possible we should just allocate a new instance and be damned (especially as
// having anything other than the default instance is rare).
// TODO(dbeaumont): Measure performance and see about removing this code, almost certainly fine.
if (newFlags == flags && newWidth == width && newPrecision == precision) {
return this;
}
return new FormatOptions(newFlags, newWidth, newPrecision);
}
|
java
|
public FormatOptions filter(int allowedFlags, boolean allowWidth, boolean allowPrecision) {
if (isDefault()) {
return this;
}
int newFlags = allowedFlags & flags;
int newWidth = allowWidth ? width : UNSET;
int newPrecision = allowPrecision ? precision : UNSET;
// Remember that we must never create a non-canonical default instance.
if (newFlags == 0 && newWidth == UNSET && newPrecision == UNSET) {
return DEFAULT;
}
// This check would be faster if we encoded the entire state into a long value. It's also
// entirely possible we should just allocate a new instance and be damned (especially as
// having anything other than the default instance is rare).
// TODO(dbeaumont): Measure performance and see about removing this code, almost certainly fine.
if (newFlags == flags && newWidth == width && newPrecision == precision) {
return this;
}
return new FormatOptions(newFlags, newWidth, newPrecision);
}
|
[
"public",
"FormatOptions",
"filter",
"(",
"int",
"allowedFlags",
",",
"boolean",
"allowWidth",
",",
"boolean",
"allowPrecision",
")",
"{",
"if",
"(",
"isDefault",
"(",
")",
")",
"{",
"return",
"this",
";",
"}",
"int",
"newFlags",
"=",
"allowedFlags",
"&",
"flags",
";",
"int",
"newWidth",
"=",
"allowWidth",
"?",
"width",
":",
"UNSET",
";",
"int",
"newPrecision",
"=",
"allowPrecision",
"?",
"precision",
":",
"UNSET",
";",
"// Remember that we must never create a non-canonical default instance.",
"if",
"(",
"newFlags",
"==",
"0",
"&&",
"newWidth",
"==",
"UNSET",
"&&",
"newPrecision",
"==",
"UNSET",
")",
"{",
"return",
"DEFAULT",
";",
"}",
"// This check would be faster if we encoded the entire state into a long value. It's also",
"// entirely possible we should just allocate a new instance and be damned (especially as",
"// having anything other than the default instance is rare).",
"// TODO(dbeaumont): Measure performance and see about removing this code, almost certainly fine.",
"if",
"(",
"newFlags",
"==",
"flags",
"&&",
"newWidth",
"==",
"width",
"&&",
"newPrecision",
"==",
"precision",
")",
"{",
"return",
"this",
";",
"}",
"return",
"new",
"FormatOptions",
"(",
"newFlags",
",",
"newWidth",
",",
"newPrecision",
")",
";",
"}"
] |
Returns a possibly new FormatOptions instance possibly containing a subset of the formatting
information. This is useful if a backend implementation wishes to create formatting options
that ignore some of the specified formatting information.
@param allowedFlags A mask of flag values to be retained in the returned instance. Use
{@link #ALL_FLAGS} to retain all flag values, or {@code 0} to suppress all flags.
@param allowWidth specifies whether to include width in the returned instance.
@param allowPrecision specifies whether to include precision in the returned instance.
|
[
"Returns",
"a",
"possibly",
"new",
"FormatOptions",
"instance",
"possibly",
"containing",
"a",
"subset",
"of",
"the",
"formatting",
"information",
".",
"This",
"is",
"useful",
"if",
"a",
"backend",
"implementation",
"wishes",
"to",
"create",
"formatting",
"options",
"that",
"ignore",
"some",
"of",
"the",
"specified",
"formatting",
"information",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/FormatOptions.java#L278-L297
|
19,455
|
google/flogger
|
api/src/main/java/com/google/common/flogger/backend/FormatOptions.java
|
FormatOptions.checkFlagConsistency
|
static boolean checkFlagConsistency(int flags, boolean hasWidth) {
// Check that we specify at most one of 'prefix plus' and 'prefix space'.
if ((flags & (FLAG_PREFIX_PLUS_FOR_POSITIVE_VALUES | FLAG_PREFIX_SPACE_FOR_POSITIVE_VALUES))
== (FLAG_PREFIX_PLUS_FOR_POSITIVE_VALUES | FLAG_PREFIX_SPACE_FOR_POSITIVE_VALUES)) {
return false;
}
// Check that we specify at most one of 'left align' and 'leading zeros'.
if ((flags & (FLAG_LEFT_ALIGN | FLAG_SHOW_LEADING_ZEROS))
== (FLAG_LEFT_ALIGN | FLAG_SHOW_LEADING_ZEROS)) {
return false;
}
// Check that if 'left align' or 'leading zeros' is specified, we also have a width value.
if ((flags & (FLAG_LEFT_ALIGN | FLAG_SHOW_LEADING_ZEROS)) != 0 && !hasWidth) {
return false;
}
return true;
}
|
java
|
static boolean checkFlagConsistency(int flags, boolean hasWidth) {
// Check that we specify at most one of 'prefix plus' and 'prefix space'.
if ((flags & (FLAG_PREFIX_PLUS_FOR_POSITIVE_VALUES | FLAG_PREFIX_SPACE_FOR_POSITIVE_VALUES))
== (FLAG_PREFIX_PLUS_FOR_POSITIVE_VALUES | FLAG_PREFIX_SPACE_FOR_POSITIVE_VALUES)) {
return false;
}
// Check that we specify at most one of 'left align' and 'leading zeros'.
if ((flags & (FLAG_LEFT_ALIGN | FLAG_SHOW_LEADING_ZEROS))
== (FLAG_LEFT_ALIGN | FLAG_SHOW_LEADING_ZEROS)) {
return false;
}
// Check that if 'left align' or 'leading zeros' is specified, we also have a width value.
if ((flags & (FLAG_LEFT_ALIGN | FLAG_SHOW_LEADING_ZEROS)) != 0 && !hasWidth) {
return false;
}
return true;
}
|
[
"static",
"boolean",
"checkFlagConsistency",
"(",
"int",
"flags",
",",
"boolean",
"hasWidth",
")",
"{",
"// Check that we specify at most one of 'prefix plus' and 'prefix space'.",
"if",
"(",
"(",
"flags",
"&",
"(",
"FLAG_PREFIX_PLUS_FOR_POSITIVE_VALUES",
"|",
"FLAG_PREFIX_SPACE_FOR_POSITIVE_VALUES",
")",
")",
"==",
"(",
"FLAG_PREFIX_PLUS_FOR_POSITIVE_VALUES",
"|",
"FLAG_PREFIX_SPACE_FOR_POSITIVE_VALUES",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check that we specify at most one of 'left align' and 'leading zeros'.",
"if",
"(",
"(",
"flags",
"&",
"(",
"FLAG_LEFT_ALIGN",
"|",
"FLAG_SHOW_LEADING_ZEROS",
")",
")",
"==",
"(",
"FLAG_LEFT_ALIGN",
"|",
"FLAG_SHOW_LEADING_ZEROS",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check that if 'left align' or 'leading zeros' is specified, we also have a width value.",
"if",
"(",
"(",
"flags",
"&",
"(",
"FLAG_LEFT_ALIGN",
"|",
"FLAG_SHOW_LEADING_ZEROS",
")",
")",
"!=",
"0",
"&&",
"!",
"hasWidth",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Helper to check for legal combinations of flags.
|
[
"Helper",
"to",
"check",
"for",
"legal",
"combinations",
"of",
"flags",
"."
] |
a164967a93a9f4ce92f34319fc0cc7c91a57321c
|
https://github.com/google/flogger/blob/a164967a93a9f4ce92f34319fc0cc7c91a57321c/api/src/main/java/com/google/common/flogger/backend/FormatOptions.java#L353-L369
|
19,456
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/Generics.java
|
Generics.resolveTypeVariable
|
public Class resolveTypeVariable (TypeVariable typeVariable) {
for (int i = argumentsSize - 2; i >= 0; i -= 2)
if (arguments[i] == typeVariable) return (Class)arguments[i + 1];
return null;
}
|
java
|
public Class resolveTypeVariable (TypeVariable typeVariable) {
for (int i = argumentsSize - 2; i >= 0; i -= 2)
if (arguments[i] == typeVariable) return (Class)arguments[i + 1];
return null;
}
|
[
"public",
"Class",
"resolveTypeVariable",
"(",
"TypeVariable",
"typeVariable",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"argumentsSize",
"-",
"2",
";",
"i",
">=",
"0",
";",
"i",
"-=",
"2",
")",
"if",
"(",
"arguments",
"[",
"i",
"]",
"==",
"typeVariable",
")",
"return",
"(",
"Class",
")",
"arguments",
"[",
"i",
"+",
"1",
"]",
";",
"return",
"null",
";",
"}"
] |
Returns the class for the specified type variable, or null if it is not known.
@return May be null.
|
[
"Returns",
"the",
"class",
"for",
"the",
"specified",
"type",
"variable",
"or",
"null",
"if",
"it",
"is",
"not",
"known",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/Generics.java#L163-L167
|
19,457
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/GenericsUtil.java
|
GenericsUtil.resolveType
|
static public Type resolveType (Class fromClass, Class toClass, Type type) {
// Explicit type, eg String.
if (type instanceof Class) return (Class)type;
// Type variable, eg T.
if (type instanceof TypeVariable) return resolveTypeVariable(fromClass, toClass, type, true);
// Type which has a type parameter, eg ArrayList<T> or ArrayList<ArrayList<T>>.
if (type instanceof ParameterizedType) return (Class)((ParameterizedType)type).getRawType();
// Array which has a type variable, eg T[] or T[][], and also arrays with a type parameter, eg ArrayList<T>[].
if (type instanceof GenericArrayType) {
int dimensions = 1;
while (true) {
type = ((GenericArrayType)type).getGenericComponentType();
if (!(type instanceof GenericArrayType)) break;
dimensions++;
}
Type componentType = resolveType(fromClass, toClass, type);
if (!(componentType instanceof Class)) return type;
if (dimensions == 1) return Array.newInstance((Class)componentType, 0).getClass();
return Array.newInstance((Class)componentType, new int[dimensions]).getClass();
}
// Type which has a wildcard, eg ArrayList<?>, ArrayList<? extends Number>, or ArrayList<? super Integer>.
if (type instanceof WildcardType) {
// Check upper bound first, it is more likely. There is always an upper bound.
Type upperBound = ((WildcardType)type).getUpperBounds()[0];
if (upperBound != Object.class) return resolveType(fromClass, toClass, upperBound);
Type[] lowerBounds = ((WildcardType)type).getLowerBounds();
if (lowerBounds.length != 0) return resolveType(fromClass, toClass, lowerBounds[0]);
return Object.class;
}
// If this happens, there is a case we need to handle.
throw new KryoException("Unable to resolve type: " + type);
}
|
java
|
static public Type resolveType (Class fromClass, Class toClass, Type type) {
// Explicit type, eg String.
if (type instanceof Class) return (Class)type;
// Type variable, eg T.
if (type instanceof TypeVariable) return resolveTypeVariable(fromClass, toClass, type, true);
// Type which has a type parameter, eg ArrayList<T> or ArrayList<ArrayList<T>>.
if (type instanceof ParameterizedType) return (Class)((ParameterizedType)type).getRawType();
// Array which has a type variable, eg T[] or T[][], and also arrays with a type parameter, eg ArrayList<T>[].
if (type instanceof GenericArrayType) {
int dimensions = 1;
while (true) {
type = ((GenericArrayType)type).getGenericComponentType();
if (!(type instanceof GenericArrayType)) break;
dimensions++;
}
Type componentType = resolveType(fromClass, toClass, type);
if (!(componentType instanceof Class)) return type;
if (dimensions == 1) return Array.newInstance((Class)componentType, 0).getClass();
return Array.newInstance((Class)componentType, new int[dimensions]).getClass();
}
// Type which has a wildcard, eg ArrayList<?>, ArrayList<? extends Number>, or ArrayList<? super Integer>.
if (type instanceof WildcardType) {
// Check upper bound first, it is more likely. There is always an upper bound.
Type upperBound = ((WildcardType)type).getUpperBounds()[0];
if (upperBound != Object.class) return resolveType(fromClass, toClass, upperBound);
Type[] lowerBounds = ((WildcardType)type).getLowerBounds();
if (lowerBounds.length != 0) return resolveType(fromClass, toClass, lowerBounds[0]);
return Object.class;
}
// If this happens, there is a case we need to handle.
throw new KryoException("Unable to resolve type: " + type);
}
|
[
"static",
"public",
"Type",
"resolveType",
"(",
"Class",
"fromClass",
",",
"Class",
"toClass",
",",
"Type",
"type",
")",
"{",
"// Explicit type, eg String.",
"if",
"(",
"type",
"instanceof",
"Class",
")",
"return",
"(",
"Class",
")",
"type",
";",
"// Type variable, eg T.",
"if",
"(",
"type",
"instanceof",
"TypeVariable",
")",
"return",
"resolveTypeVariable",
"(",
"fromClass",
",",
"toClass",
",",
"type",
",",
"true",
")",
";",
"// Type which has a type parameter, eg ArrayList<T> or ArrayList<ArrayList<T>>.",
"if",
"(",
"type",
"instanceof",
"ParameterizedType",
")",
"return",
"(",
"Class",
")",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getRawType",
"(",
")",
";",
"// Array which has a type variable, eg T[] or T[][], and also arrays with a type parameter, eg ArrayList<T>[].",
"if",
"(",
"type",
"instanceof",
"GenericArrayType",
")",
"{",
"int",
"dimensions",
"=",
"1",
";",
"while",
"(",
"true",
")",
"{",
"type",
"=",
"(",
"(",
"GenericArrayType",
")",
"type",
")",
".",
"getGenericComponentType",
"(",
")",
";",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"GenericArrayType",
")",
")",
"break",
";",
"dimensions",
"++",
";",
"}",
"Type",
"componentType",
"=",
"resolveType",
"(",
"fromClass",
",",
"toClass",
",",
"type",
")",
";",
"if",
"(",
"!",
"(",
"componentType",
"instanceof",
"Class",
")",
")",
"return",
"type",
";",
"if",
"(",
"dimensions",
"==",
"1",
")",
"return",
"Array",
".",
"newInstance",
"(",
"(",
"Class",
")",
"componentType",
",",
"0",
")",
".",
"getClass",
"(",
")",
";",
"return",
"Array",
".",
"newInstance",
"(",
"(",
"Class",
")",
"componentType",
",",
"new",
"int",
"[",
"dimensions",
"]",
")",
".",
"getClass",
"(",
")",
";",
"}",
"// Type which has a wildcard, eg ArrayList<?>, ArrayList<? extends Number>, or ArrayList<? super Integer>.",
"if",
"(",
"type",
"instanceof",
"WildcardType",
")",
"{",
"// Check upper bound first, it is more likely. There is always an upper bound.",
"Type",
"upperBound",
"=",
"(",
"(",
"WildcardType",
")",
"type",
")",
".",
"getUpperBounds",
"(",
")",
"[",
"0",
"]",
";",
"if",
"(",
"upperBound",
"!=",
"Object",
".",
"class",
")",
"return",
"resolveType",
"(",
"fromClass",
",",
"toClass",
",",
"upperBound",
")",
";",
"Type",
"[",
"]",
"lowerBounds",
"=",
"(",
"(",
"WildcardType",
")",
"type",
")",
".",
"getLowerBounds",
"(",
")",
";",
"if",
"(",
"lowerBounds",
".",
"length",
"!=",
"0",
")",
"return",
"resolveType",
"(",
"fromClass",
",",
"toClass",
",",
"lowerBounds",
"[",
"0",
"]",
")",
";",
"return",
"Object",
".",
"class",
";",
"}",
"// If this happens, there is a case we need to handle.",
"throw",
"new",
"KryoException",
"(",
"\"Unable to resolve type: \"",
"+",
"type",
")",
";",
"}"
] |
Returns the class for the specified type after replacing any type variables using the class hierarchy between the specified
classes.
@param toClass Must be a sub class of fromClass.
|
[
"Returns",
"the",
"class",
"for",
"the",
"specified",
"type",
"after",
"replacing",
"any",
"type",
"variables",
"using",
"the",
"class",
"hierarchy",
"between",
"the",
"specified",
"classes",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/GenericsUtil.java#L36-L72
|
19,458
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/GenericsUtil.java
|
GenericsUtil.resolveTypeVariable
|
static private Type resolveTypeVariable (Class fromClass, Class current, Type type, boolean first) {
Type genericSuper = current.getGenericSuperclass();
if (!(genericSuper instanceof ParameterizedType)) return type; // No type arguments passed to super class.
// Search fromClass to current inclusive, using the call stack to traverse the class hierarchy in super class first order.
Class superClass = current.getSuperclass();
if (superClass != fromClass) {
Type resolved = resolveTypeVariable(fromClass, superClass, type, false);
if (resolved instanceof Class) return (Class)resolved; // Resolved in a super class.
type = resolved;
}
// Match the type variable name to the super class parameter.
String name = type.toString(); // Java 8: getTypeName
TypeVariable[] params = superClass.getTypeParameters();
for (int i = 0, n = params.length; i < n; i++) {
TypeVariable param = params[i];
if (param.getName().equals(name)) {
// Use the super class' type variable index to find the actual class in the sub class declaration.
Type arg = ((ParameterizedType)genericSuper).getActualTypeArguments()[i];
// Success, the type variable was explicitly declared.
if (arg instanceof Class) return (Class)arg;
if (arg instanceof ParameterizedType) return resolveType(fromClass, current, arg);
if (arg instanceof TypeVariable) {
if (first) return type; // Failure, no more sub classes.
return arg; // Look for the new type variable in the next sub class.
}
}
}
// If this happens, there is a case we need to handle.
throw new KryoException("Unable to resolve type variable: " + type);
}
|
java
|
static private Type resolveTypeVariable (Class fromClass, Class current, Type type, boolean first) {
Type genericSuper = current.getGenericSuperclass();
if (!(genericSuper instanceof ParameterizedType)) return type; // No type arguments passed to super class.
// Search fromClass to current inclusive, using the call stack to traverse the class hierarchy in super class first order.
Class superClass = current.getSuperclass();
if (superClass != fromClass) {
Type resolved = resolveTypeVariable(fromClass, superClass, type, false);
if (resolved instanceof Class) return (Class)resolved; // Resolved in a super class.
type = resolved;
}
// Match the type variable name to the super class parameter.
String name = type.toString(); // Java 8: getTypeName
TypeVariable[] params = superClass.getTypeParameters();
for (int i = 0, n = params.length; i < n; i++) {
TypeVariable param = params[i];
if (param.getName().equals(name)) {
// Use the super class' type variable index to find the actual class in the sub class declaration.
Type arg = ((ParameterizedType)genericSuper).getActualTypeArguments()[i];
// Success, the type variable was explicitly declared.
if (arg instanceof Class) return (Class)arg;
if (arg instanceof ParameterizedType) return resolveType(fromClass, current, arg);
if (arg instanceof TypeVariable) {
if (first) return type; // Failure, no more sub classes.
return arg; // Look for the new type variable in the next sub class.
}
}
}
// If this happens, there is a case we need to handle.
throw new KryoException("Unable to resolve type variable: " + type);
}
|
[
"static",
"private",
"Type",
"resolveTypeVariable",
"(",
"Class",
"fromClass",
",",
"Class",
"current",
",",
"Type",
"type",
",",
"boolean",
"first",
")",
"{",
"Type",
"genericSuper",
"=",
"current",
".",
"getGenericSuperclass",
"(",
")",
";",
"if",
"(",
"!",
"(",
"genericSuper",
"instanceof",
"ParameterizedType",
")",
")",
"return",
"type",
";",
"// No type arguments passed to super class.",
"// Search fromClass to current inclusive, using the call stack to traverse the class hierarchy in super class first order.",
"Class",
"superClass",
"=",
"current",
".",
"getSuperclass",
"(",
")",
";",
"if",
"(",
"superClass",
"!=",
"fromClass",
")",
"{",
"Type",
"resolved",
"=",
"resolveTypeVariable",
"(",
"fromClass",
",",
"superClass",
",",
"type",
",",
"false",
")",
";",
"if",
"(",
"resolved",
"instanceof",
"Class",
")",
"return",
"(",
"Class",
")",
"resolved",
";",
"// Resolved in a super class.",
"type",
"=",
"resolved",
";",
"}",
"// Match the type variable name to the super class parameter.",
"String",
"name",
"=",
"type",
".",
"toString",
"(",
")",
";",
"// Java 8: getTypeName",
"TypeVariable",
"[",
"]",
"params",
"=",
"superClass",
".",
"getTypeParameters",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"n",
"=",
"params",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"TypeVariable",
"param",
"=",
"params",
"[",
"i",
"]",
";",
"if",
"(",
"param",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"// Use the super class' type variable index to find the actual class in the sub class declaration.",
"Type",
"arg",
"=",
"(",
"(",
"ParameterizedType",
")",
"genericSuper",
")",
".",
"getActualTypeArguments",
"(",
")",
"[",
"i",
"]",
";",
"// Success, the type variable was explicitly declared.",
"if",
"(",
"arg",
"instanceof",
"Class",
")",
"return",
"(",
"Class",
")",
"arg",
";",
"if",
"(",
"arg",
"instanceof",
"ParameterizedType",
")",
"return",
"resolveType",
"(",
"fromClass",
",",
"current",
",",
"arg",
")",
";",
"if",
"(",
"arg",
"instanceof",
"TypeVariable",
")",
"{",
"if",
"(",
"first",
")",
"return",
"type",
";",
"// Failure, no more sub classes.",
"return",
"arg",
";",
"// Look for the new type variable in the next sub class.",
"}",
"}",
"}",
"// If this happens, there is a case we need to handle.",
"throw",
"new",
"KryoException",
"(",
"\"Unable to resolve type variable: \"",
"+",
"type",
")",
";",
"}"
] |
Returns the class for the specified type variable by finding the first class in the hierarchy between the specified classes
which explicitly specifies the type variable's class.
@param current Must be a sub class of fromClass.
@return A Class if the type variable was resolved, else a TypeVariable to continue searching or if the type could not be
resolved.
|
[
"Returns",
"the",
"class",
"for",
"the",
"specified",
"type",
"variable",
"by",
"finding",
"the",
"first",
"class",
"in",
"the",
"hierarchy",
"between",
"the",
"specified",
"classes",
"which",
"explicitly",
"specifies",
"the",
"type",
"variable",
"s",
"class",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/GenericsUtil.java#L79-L113
|
19,459
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/GenericsUtil.java
|
GenericsUtil.resolveTypeParameters
|
static public Type[] resolveTypeParameters (Class fromClass, Class toClass, Type type) {
// Type which has a type parameter, eg ArrayList<T>.
if (type instanceof ParameterizedType) {
Type[] actualArgs = ((ParameterizedType)type).getActualTypeArguments();
int n = actualArgs.length;
Type[] generics = new Type[n];
for (int i = 0; i < n; i++)
generics[i] = resolveType(fromClass, toClass, actualArgs[i]);
return generics;
}
// Array which has a type parameter, eg "ArrayList<T>[]". Discard array types, resolve type parameter of the component type.
if (type instanceof GenericArrayType) {
while (true) {
type = ((GenericArrayType)type).getGenericComponentType();
if (!(type instanceof GenericArrayType)) break;
}
return resolveTypeParameters(fromClass, toClass, type);
}
return null; // No type parameters (is a class or type variable).
}
|
java
|
static public Type[] resolveTypeParameters (Class fromClass, Class toClass, Type type) {
// Type which has a type parameter, eg ArrayList<T>.
if (type instanceof ParameterizedType) {
Type[] actualArgs = ((ParameterizedType)type).getActualTypeArguments();
int n = actualArgs.length;
Type[] generics = new Type[n];
for (int i = 0; i < n; i++)
generics[i] = resolveType(fromClass, toClass, actualArgs[i]);
return generics;
}
// Array which has a type parameter, eg "ArrayList<T>[]". Discard array types, resolve type parameter of the component type.
if (type instanceof GenericArrayType) {
while (true) {
type = ((GenericArrayType)type).getGenericComponentType();
if (!(type instanceof GenericArrayType)) break;
}
return resolveTypeParameters(fromClass, toClass, type);
}
return null; // No type parameters (is a class or type variable).
}
|
[
"static",
"public",
"Type",
"[",
"]",
"resolveTypeParameters",
"(",
"Class",
"fromClass",
",",
"Class",
"toClass",
",",
"Type",
"type",
")",
"{",
"// Type which has a type parameter, eg ArrayList<T>.",
"if",
"(",
"type",
"instanceof",
"ParameterizedType",
")",
"{",
"Type",
"[",
"]",
"actualArgs",
"=",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getActualTypeArguments",
"(",
")",
";",
"int",
"n",
"=",
"actualArgs",
".",
"length",
";",
"Type",
"[",
"]",
"generics",
"=",
"new",
"Type",
"[",
"n",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"generics",
"[",
"i",
"]",
"=",
"resolveType",
"(",
"fromClass",
",",
"toClass",
",",
"actualArgs",
"[",
"i",
"]",
")",
";",
"return",
"generics",
";",
"}",
"// Array which has a type parameter, eg \"ArrayList<T>[]\". Discard array types, resolve type parameter of the component type.",
"if",
"(",
"type",
"instanceof",
"GenericArrayType",
")",
"{",
"while",
"(",
"true",
")",
"{",
"type",
"=",
"(",
"(",
"GenericArrayType",
")",
"type",
")",
".",
"getGenericComponentType",
"(",
")",
";",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"GenericArrayType",
")",
")",
"break",
";",
"}",
"return",
"resolveTypeParameters",
"(",
"fromClass",
",",
"toClass",
",",
"type",
")",
";",
"}",
"return",
"null",
";",
"// No type parameters (is a class or type variable).",
"}"
] |
Resolves type variables for the type parameters of the specified type by using the class hierarchy between the specified
classes.
@param toClass Must be a sub class of fromClass.
@return Null if the type has no type parameters, else contains Class entries for type parameters that were resolved and
TypeVariable entries for type parameters that couldn't be resolved.
|
[
"Resolves",
"type",
"variables",
"for",
"the",
"type",
"parameters",
"of",
"the",
"specified",
"type",
"by",
"using",
"the",
"class",
"hierarchy",
"between",
"the",
"specified",
"classes",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/GenericsUtil.java#L120-L141
|
19,460
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.require
|
protected int require (int required) throws KryoException {
int remaining = limit - position;
if (remaining >= required) return remaining;
if (required > capacity) throw new KryoException("Buffer too small: capacity: " + capacity + ", required: " + required);
int count;
// Try to fill the buffer.
if (remaining > 0) {
count = fill(buffer, limit, capacity - limit);
if (count == -1) throw new KryoException("Buffer underflow.");
remaining += count;
if (remaining >= required) {
limit += count;
return remaining;
}
}
// Was not enough, compact and try again.
System.arraycopy(buffer, position, buffer, 0, remaining);
total += position;
position = 0;
while (true) {
count = fill(buffer, remaining, capacity - remaining);
if (count == -1) {
if (remaining >= required) break;
throw new KryoException("Buffer underflow.");
}
remaining += count;
if (remaining >= required) break; // Enough has been read.
}
limit = remaining;
return remaining;
}
|
java
|
protected int require (int required) throws KryoException {
int remaining = limit - position;
if (remaining >= required) return remaining;
if (required > capacity) throw new KryoException("Buffer too small: capacity: " + capacity + ", required: " + required);
int count;
// Try to fill the buffer.
if (remaining > 0) {
count = fill(buffer, limit, capacity - limit);
if (count == -1) throw new KryoException("Buffer underflow.");
remaining += count;
if (remaining >= required) {
limit += count;
return remaining;
}
}
// Was not enough, compact and try again.
System.arraycopy(buffer, position, buffer, 0, remaining);
total += position;
position = 0;
while (true) {
count = fill(buffer, remaining, capacity - remaining);
if (count == -1) {
if (remaining >= required) break;
throw new KryoException("Buffer underflow.");
}
remaining += count;
if (remaining >= required) break; // Enough has been read.
}
limit = remaining;
return remaining;
}
|
[
"protected",
"int",
"require",
"(",
"int",
"required",
")",
"throws",
"KryoException",
"{",
"int",
"remaining",
"=",
"limit",
"-",
"position",
";",
"if",
"(",
"remaining",
">=",
"required",
")",
"return",
"remaining",
";",
"if",
"(",
"required",
">",
"capacity",
")",
"throw",
"new",
"KryoException",
"(",
"\"Buffer too small: capacity: \"",
"+",
"capacity",
"+",
"\", required: \"",
"+",
"required",
")",
";",
"int",
"count",
";",
"// Try to fill the buffer.\r",
"if",
"(",
"remaining",
">",
"0",
")",
"{",
"count",
"=",
"fill",
"(",
"buffer",
",",
"limit",
",",
"capacity",
"-",
"limit",
")",
";",
"if",
"(",
"count",
"==",
"-",
"1",
")",
"throw",
"new",
"KryoException",
"(",
"\"Buffer underflow.\"",
")",
";",
"remaining",
"+=",
"count",
";",
"if",
"(",
"remaining",
">=",
"required",
")",
"{",
"limit",
"+=",
"count",
";",
"return",
"remaining",
";",
"}",
"}",
"// Was not enough, compact and try again.\r",
"System",
".",
"arraycopy",
"(",
"buffer",
",",
"position",
",",
"buffer",
",",
"0",
",",
"remaining",
")",
";",
"total",
"+=",
"position",
";",
"position",
"=",
"0",
";",
"while",
"(",
"true",
")",
"{",
"count",
"=",
"fill",
"(",
"buffer",
",",
"remaining",
",",
"capacity",
"-",
"remaining",
")",
";",
"if",
"(",
"count",
"==",
"-",
"1",
")",
"{",
"if",
"(",
"remaining",
">=",
"required",
")",
"break",
";",
"throw",
"new",
"KryoException",
"(",
"\"Buffer underflow.\"",
")",
";",
"}",
"remaining",
"+=",
"count",
";",
"if",
"(",
"remaining",
">=",
"required",
")",
"break",
";",
"// Enough has been read.\r",
"}",
"limit",
"=",
"remaining",
";",
"return",
"remaining",
";",
"}"
] |
Fills the buffer with at least the number of bytes specified.
@param required Must be > 0.
@return The number of bytes remaining in the buffer, which will be at least <code>required</code> bytes.
@throws KryoException if {@link #fill(byte[], int, int)} is unable to provide more bytes (buffer underflow).
|
[
"Fills",
"the",
"buffer",
"with",
"at",
"least",
"the",
"number",
"of",
"bytes",
"specified",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L193-L227
|
19,461
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.optional
|
protected int optional (int optional) throws KryoException {
int remaining = limit - position;
if (remaining >= optional) return optional;
optional = Math.min(optional, capacity);
int count;
// Try to fill the buffer.
count = fill(buffer, limit, capacity - limit);
if (count == -1) return remaining == 0 ? -1 : Math.min(remaining, optional);
remaining += count;
if (remaining >= optional) {
limit += count;
return optional;
}
// Was not enough, compact and try again.
System.arraycopy(buffer, position, buffer, 0, remaining);
total += position;
position = 0;
while (true) {
count = fill(buffer, remaining, capacity - remaining);
if (count == -1) break;
remaining += count;
if (remaining >= optional) break; // Enough has been read.
}
limit = remaining;
return remaining == 0 ? -1 : Math.min(remaining, optional);
}
|
java
|
protected int optional (int optional) throws KryoException {
int remaining = limit - position;
if (remaining >= optional) return optional;
optional = Math.min(optional, capacity);
int count;
// Try to fill the buffer.
count = fill(buffer, limit, capacity - limit);
if (count == -1) return remaining == 0 ? -1 : Math.min(remaining, optional);
remaining += count;
if (remaining >= optional) {
limit += count;
return optional;
}
// Was not enough, compact and try again.
System.arraycopy(buffer, position, buffer, 0, remaining);
total += position;
position = 0;
while (true) {
count = fill(buffer, remaining, capacity - remaining);
if (count == -1) break;
remaining += count;
if (remaining >= optional) break; // Enough has been read.
}
limit = remaining;
return remaining == 0 ? -1 : Math.min(remaining, optional);
}
|
[
"protected",
"int",
"optional",
"(",
"int",
"optional",
")",
"throws",
"KryoException",
"{",
"int",
"remaining",
"=",
"limit",
"-",
"position",
";",
"if",
"(",
"remaining",
">=",
"optional",
")",
"return",
"optional",
";",
"optional",
"=",
"Math",
".",
"min",
"(",
"optional",
",",
"capacity",
")",
";",
"int",
"count",
";",
"// Try to fill the buffer.\r",
"count",
"=",
"fill",
"(",
"buffer",
",",
"limit",
",",
"capacity",
"-",
"limit",
")",
";",
"if",
"(",
"count",
"==",
"-",
"1",
")",
"return",
"remaining",
"==",
"0",
"?",
"-",
"1",
":",
"Math",
".",
"min",
"(",
"remaining",
",",
"optional",
")",
";",
"remaining",
"+=",
"count",
";",
"if",
"(",
"remaining",
">=",
"optional",
")",
"{",
"limit",
"+=",
"count",
";",
"return",
"optional",
";",
"}",
"// Was not enough, compact and try again.\r",
"System",
".",
"arraycopy",
"(",
"buffer",
",",
"position",
",",
"buffer",
",",
"0",
",",
"remaining",
")",
";",
"total",
"+=",
"position",
";",
"position",
"=",
"0",
";",
"while",
"(",
"true",
")",
"{",
"count",
"=",
"fill",
"(",
"buffer",
",",
"remaining",
",",
"capacity",
"-",
"remaining",
")",
";",
"if",
"(",
"count",
"==",
"-",
"1",
")",
"break",
";",
"remaining",
"+=",
"count",
";",
"if",
"(",
"remaining",
">=",
"optional",
")",
"break",
";",
"// Enough has been read.\r",
"}",
"limit",
"=",
"remaining",
";",
"return",
"remaining",
"==",
"0",
"?",
"-",
"1",
":",
"Math",
".",
"min",
"(",
"remaining",
",",
"optional",
")",
";",
"}"
] |
Fills the buffer with at least the number of bytes specified, if possible.
@param optional Must be > 0.
@return the number of bytes remaining, but not more than optional, or -1 if {@link #fill(byte[], int, int)} is unable to
provide more bytes.
|
[
"Fills",
"the",
"buffer",
"with",
"at",
"least",
"the",
"number",
"of",
"bytes",
"specified",
"if",
"possible",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L233-L263
|
19,462
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readInt
|
public int readInt () throws KryoException {
require(4);
byte[] buffer = this.buffer;
int p = this.position;
this.position = p + 4;
return buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24;
}
|
java
|
public int readInt () throws KryoException {
require(4);
byte[] buffer = this.buffer;
int p = this.position;
this.position = p + 4;
return buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24;
}
|
[
"public",
"int",
"readInt",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"4",
")",
";",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"this",
".",
"position",
"=",
"p",
"+",
"4",
";",
"return",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
";",
"}"
] |
Reads a 4 byte int.
|
[
"Reads",
"a",
"4",
"byte",
"int",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L377-L386
|
19,463
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readVarInt
|
public int readVarInt (boolean optimizePositive) throws KryoException {
if (require(1) < 5) return readVarInt_slow(optimizePositive);
int b = buffer[position++];
int result = b & 0x7F;
if ((b & 0x80) != 0) {
byte[] buffer = this.buffer;
int p = position;
b = buffer[p++];
result |= (b & 0x7F) << 7;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 14;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 21;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 28;
}
}
}
position = p;
}
return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
}
|
java
|
public int readVarInt (boolean optimizePositive) throws KryoException {
if (require(1) < 5) return readVarInt_slow(optimizePositive);
int b = buffer[position++];
int result = b & 0x7F;
if ((b & 0x80) != 0) {
byte[] buffer = this.buffer;
int p = position;
b = buffer[p++];
result |= (b & 0x7F) << 7;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 14;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 21;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 28;
}
}
}
position = p;
}
return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
}
|
[
"public",
"int",
"readVarInt",
"(",
"boolean",
"optimizePositive",
")",
"throws",
"KryoException",
"{",
"if",
"(",
"require",
"(",
"1",
")",
"<",
"5",
")",
"return",
"readVarInt_slow",
"(",
"optimizePositive",
")",
";",
"int",
"b",
"=",
"buffer",
"[",
"position",
"++",
"]",
";",
"int",
"result",
"=",
"b",
"&",
"0x7F",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"position",
";",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"7",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"14",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"21",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"28",
";",
"}",
"}",
"}",
"position",
"=",
"p",
";",
"}",
"return",
"optimizePositive",
"?",
"result",
":",
"(",
"(",
"result",
">>>",
"1",
")",
"^",
"-",
"(",
"result",
"&",
"1",
")",
")",
";",
"}"
] |
Reads a 1-5 byte int.
@see #canReadVarInt()
|
[
"Reads",
"a",
"1",
"-",
"5",
"byte",
"int",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L406-L430
|
19,464
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readLong
|
public long readLong () throws KryoException {
require(8);
byte[] buffer = this.buffer;
int p = position;
position = p + 8;
return buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56;
}
|
java
|
public long readLong () throws KryoException {
require(8);
byte[] buffer = this.buffer;
int p = position;
position = p + 8;
return buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56;
}
|
[
"public",
"long",
"readLong",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"8",
")",
";",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"position",
";",
"position",
"=",
"p",
"+",
"8",
";",
"return",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"4",
"]",
"&",
"0xFF",
")",
"<<",
"32",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"5",
"]",
"&",
"0xFF",
")",
"<<",
"40",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"6",
"]",
"&",
"0xFF",
")",
"<<",
"48",
"//\r",
"|",
"(",
"long",
")",
"buffer",
"[",
"p",
"+",
"7",
"]",
"<<",
"56",
";",
"}"
] |
Reads an 8 byte long.
|
[
"Reads",
"an",
"8",
"byte",
"long",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L543-L556
|
19,465
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readVarLong
|
public long readVarLong (boolean optimizePositive) throws KryoException {
if (require(1) < 9) return readVarLong_slow(optimizePositive);
int p = position;
int b = buffer[p++];
long result = b & 0x7F;
if ((b & 0x80) != 0) {
byte[] buffer = this.buffer;
b = buffer[p++];
result |= (b & 0x7F) << 7;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 14;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 21;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 28;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 35;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 42;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 49;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)b << 56;
}
}
}
}
}
}
}
}
position = p;
return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
}
|
java
|
public long readVarLong (boolean optimizePositive) throws KryoException {
if (require(1) < 9) return readVarLong_slow(optimizePositive);
int p = position;
int b = buffer[p++];
long result = b & 0x7F;
if ((b & 0x80) != 0) {
byte[] buffer = this.buffer;
b = buffer[p++];
result |= (b & 0x7F) << 7;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 14;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (b & 0x7F) << 21;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 28;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 35;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 42;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)(b & 0x7F) << 49;
if ((b & 0x80) != 0) {
b = buffer[p++];
result |= (long)b << 56;
}
}
}
}
}
}
}
}
position = p;
return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
}
|
[
"public",
"long",
"readVarLong",
"(",
"boolean",
"optimizePositive",
")",
"throws",
"KryoException",
"{",
"if",
"(",
"require",
"(",
"1",
")",
"<",
"9",
")",
"return",
"readVarLong_slow",
"(",
"optimizePositive",
")",
";",
"int",
"p",
"=",
"position",
";",
"int",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"long",
"result",
"=",
"b",
"&",
"0x7F",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"7",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"14",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"21",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"long",
")",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"28",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"long",
")",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"35",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"long",
")",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"42",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"long",
")",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"49",
";",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"b",
"=",
"buffer",
"[",
"p",
"++",
"]",
";",
"result",
"|=",
"(",
"long",
")",
"b",
"<<",
"56",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"position",
"=",
"p",
";",
"return",
"optimizePositive",
"?",
"result",
":",
"(",
"(",
"result",
">>>",
"1",
")",
"^",
"-",
"(",
"result",
"&",
"1",
")",
")",
";",
"}"
] |
Reads a 1-9 byte long.
@see #canReadLong()
|
[
"Reads",
"a",
"1",
"-",
"9",
"byte",
"long",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L569-L609
|
19,466
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readFloat
|
public float readFloat () throws KryoException {
require(4);
byte[] buffer = this.buffer;
int p = this.position;
this.position = p + 4;
return Float.intBitsToFloat(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24);
}
|
java
|
public float readFloat () throws KryoException {
require(4);
byte[] buffer = this.buffer;
int p = this.position;
this.position = p + 4;
return Float.intBitsToFloat(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24);
}
|
[
"public",
"float",
"readFloat",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"4",
")",
";",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"this",
".",
"position",
"=",
"p",
"+",
"4",
";",
"return",
"Float",
".",
"intBitsToFloat",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
")",
";",
"}"
] |
Reads a 4 byte float.
|
[
"Reads",
"a",
"4",
"byte",
"float",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L694-L703
|
19,467
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readDouble
|
public double readDouble () throws KryoException {
require(8);
byte[] buffer = this.buffer;
int p = position;
position = p + 8;
return Double.longBitsToDouble(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56);
}
|
java
|
public double readDouble () throws KryoException {
require(8);
byte[] buffer = this.buffer;
int p = position;
position = p + 8;
return Double.longBitsToDouble(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56);
}
|
[
"public",
"double",
"readDouble",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"8",
")",
";",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"position",
";",
"position",
"=",
"p",
"+",
"8",
";",
"return",
"Double",
".",
"longBitsToDouble",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"4",
"]",
"&",
"0xFF",
")",
"<<",
"32",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"5",
"]",
"&",
"0xFF",
")",
"<<",
"40",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"6",
"]",
"&",
"0xFF",
")",
"<<",
"48",
"//\r",
"|",
"(",
"long",
")",
"buffer",
"[",
"p",
"+",
"7",
"]",
"<<",
"56",
")",
";",
"}"
] |
Reads an 8 byte double.
|
[
"Reads",
"an",
"8",
"byte",
"double",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L713-L726
|
19,468
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readShort
|
public short readShort () throws KryoException {
require(2);
int p = position;
position = p + 2;
return (short)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
}
|
java
|
public short readShort () throws KryoException {
require(2);
int p = position;
position = p + 2;
return (short)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
}
|
[
"public",
"short",
"readShort",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"2",
")",
";",
"int",
"p",
"=",
"position",
";",
"position",
"=",
"p",
"+",
"2",
";",
"return",
"(",
"short",
")",
"(",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
")",
"|",
"(",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
")",
"<<",
"8",
")",
";",
"}"
] |
Reads a 2 byte short.
|
[
"Reads",
"a",
"2",
"byte",
"short",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L736-L741
|
19,469
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readShortUnsigned
|
public int readShortUnsigned () throws KryoException {
require(2);
int p = position;
position = p + 2;
return (buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8;
}
|
java
|
public int readShortUnsigned () throws KryoException {
require(2);
int p = position;
position = p + 2;
return (buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8;
}
|
[
"public",
"int",
"readShortUnsigned",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"2",
")",
";",
"int",
"p",
"=",
"position",
";",
"position",
"=",
"p",
"+",
"2",
";",
"return",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
")",
"|",
"(",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
")",
"<<",
"8",
";",
"}"
] |
Reads a 2 byte short as an int from 0 to 65535.
|
[
"Reads",
"a",
"2",
"byte",
"short",
"as",
"an",
"int",
"from",
"0",
"to",
"65535",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L744-L749
|
19,470
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readChar
|
public char readChar () throws KryoException {
require(2);
int p = position;
position = p + 2;
return (char)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
}
|
java
|
public char readChar () throws KryoException {
require(2);
int p = position;
position = p + 2;
return (char)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
}
|
[
"public",
"char",
"readChar",
"(",
")",
"throws",
"KryoException",
"{",
"require",
"(",
"2",
")",
";",
"int",
"p",
"=",
"position",
";",
"position",
"=",
"p",
"+",
"2",
";",
"return",
"(",
"char",
")",
"(",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
")",
"|",
"(",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
")",
"<<",
"8",
")",
";",
"}"
] |
Reads a 2 byte char.
|
[
"Reads",
"a",
"2",
"byte",
"char",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L754-L759
|
19,471
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readInts
|
public int[] readInts (int length) throws KryoException {
int[] array = new int[length];
if (optional(length << 2) == length << 2) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 4) {
array[i] = buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24;
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readInt();
}
return array;
}
|
java
|
public int[] readInts (int length) throws KryoException {
int[] array = new int[length];
if (optional(length << 2) == length << 2) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 4) {
array[i] = buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24;
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readInt();
}
return array;
}
|
[
"public",
"int",
"[",
"]",
"readInts",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"int",
"[",
"]",
"array",
"=",
"new",
"int",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
"<<",
"2",
")",
"==",
"length",
"<<",
"2",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"+=",
"4",
")",
"{",
"array",
"[",
"i",
"]",
"=",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
";",
"}",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readInt",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads an int array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"an",
"int",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L905-L922
|
19,472
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readLongs
|
public long[] readLongs (int length) throws KryoException {
long[] array = new long[length];
if (optional(length << 3) == length << 3) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 8) {
array[i] = buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56;
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readLong();
}
return array;
}
|
java
|
public long[] readLongs (int length) throws KryoException {
long[] array = new long[length];
if (optional(length << 3) == length << 3) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 8) {
array[i] = buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56;
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readLong();
}
return array;
}
|
[
"public",
"long",
"[",
"]",
"readLongs",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"long",
"[",
"]",
"array",
"=",
"new",
"long",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
"<<",
"3",
")",
"==",
"length",
"<<",
"3",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"+=",
"8",
")",
"{",
"array",
"[",
"i",
"]",
"=",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"4",
"]",
"&",
"0xFF",
")",
"<<",
"32",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"5",
"]",
"&",
"0xFF",
")",
"<<",
"40",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"6",
"]",
"&",
"0xFF",
")",
"<<",
"48",
"//\r",
"|",
"(",
"long",
")",
"buffer",
"[",
"p",
"+",
"7",
"]",
"<<",
"56",
";",
"}",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readLong",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads a long array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"a",
"long",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L937-L958
|
19,473
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readFloats
|
public float[] readFloats (int length) throws KryoException {
float[] array = new float[length];
if (optional(length << 2) == length << 2) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 4) {
array[i] = Float.intBitsToFloat(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24);
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readFloat();
}
return array;
}
|
java
|
public float[] readFloats (int length) throws KryoException {
float[] array = new float[length];
if (optional(length << 2) == length << 2) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 4) {
array[i] = Float.intBitsToFloat(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (buffer[p + 3] & 0xFF) << 24);
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readFloat();
}
return array;
}
|
[
"public",
"float",
"[",
"]",
"readFloats",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"float",
"[",
"]",
"array",
"=",
"new",
"float",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
"<<",
"2",
")",
"==",
"length",
"<<",
"2",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"+=",
"4",
")",
"{",
"array",
"[",
"i",
"]",
"=",
"Float",
".",
"intBitsToFloat",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
")",
";",
"}",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readFloat",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads a float array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"a",
"float",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L973-L990
|
19,474
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readDoubles
|
public double[] readDoubles (int length) throws KryoException {
double[] array = new double[length];
if (optional(length << 3) == length << 3) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 8) {
array[i] = Double.longBitsToDouble(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56);
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readDouble();
}
return array;
}
|
java
|
public double[] readDoubles (int length) throws KryoException {
double[] array = new double[length];
if (optional(length << 3) == length << 3) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 8) {
array[i] = Double.longBitsToDouble(buffer[p] & 0xFF //
| (buffer[p + 1] & 0xFF) << 8 //
| (buffer[p + 2] & 0xFF) << 16 //
| (long)(buffer[p + 3] & 0xFF) << 24 //
| (long)(buffer[p + 4] & 0xFF) << 32 //
| (long)(buffer[p + 5] & 0xFF) << 40 //
| (long)(buffer[p + 6] & 0xFF) << 48 //
| (long)buffer[p + 7] << 56);
}
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readDouble();
}
return array;
}
|
[
"public",
"double",
"[",
"]",
"readDoubles",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"double",
"[",
"]",
"array",
"=",
"new",
"double",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
"<<",
"3",
")",
"==",
"length",
"<<",
"3",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"+=",
"8",
")",
"{",
"array",
"[",
"i",
"]",
"=",
"Double",
".",
"longBitsToDouble",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"//\r",
"|",
"(",
"buffer",
"[",
"p",
"+",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"24",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"4",
"]",
"&",
"0xFF",
")",
"<<",
"32",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"5",
"]",
"&",
"0xFF",
")",
"<<",
"40",
"//\r",
"|",
"(",
"long",
")",
"(",
"buffer",
"[",
"p",
"+",
"6",
"]",
"&",
"0xFF",
")",
"<<",
"48",
"//\r",
"|",
"(",
"long",
")",
"buffer",
"[",
"p",
"+",
"7",
"]",
"<<",
"56",
")",
";",
"}",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readDouble",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads a double array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"a",
"double",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L993-L1014
|
19,475
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readShorts
|
public short[] readShorts (int length) throws KryoException {
short[] array = new short[length];
if (optional(length << 1) == length << 1) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 2)
array[i] = (short)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readShort();
}
return array;
}
|
java
|
public short[] readShorts (int length) throws KryoException {
short[] array = new short[length];
if (optional(length << 1) == length << 1) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 2)
array[i] = (short)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readShort();
}
return array;
}
|
[
"public",
"short",
"[",
"]",
"readShorts",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"short",
"[",
"]",
"array",
"=",
"new",
"short",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
"<<",
"1",
")",
"==",
"length",
"<<",
"1",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"+=",
"2",
")",
"array",
"[",
"i",
"]",
"=",
"(",
"short",
")",
"(",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
")",
"|",
"(",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
")",
"<<",
"8",
")",
";",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readShort",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads a short array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"a",
"short",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L1017-L1030
|
19,476
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readChars
|
public char[] readChars (int length) throws KryoException {
char[] array = new char[length];
if (optional(length << 1) == length << 1) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 2)
array[i] = (char)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readChar();
}
return array;
}
|
java
|
public char[] readChars (int length) throws KryoException {
char[] array = new char[length];
if (optional(length << 1) == length << 1) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p += 2)
array[i] = (char)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readChar();
}
return array;
}
|
[
"public",
"char",
"[",
"]",
"readChars",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"char",
"[",
"]",
"array",
"=",
"new",
"char",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
"<<",
"1",
")",
"==",
"length",
"<<",
"1",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"+=",
"2",
")",
"array",
"[",
"i",
"]",
"=",
"(",
"char",
")",
"(",
"(",
"buffer",
"[",
"p",
"]",
"&",
"0xFF",
")",
"|",
"(",
"(",
"buffer",
"[",
"p",
"+",
"1",
"]",
"&",
"0xFF",
")",
")",
"<<",
"8",
")",
";",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readChar",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads a char array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"a",
"char",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L1033-L1046
|
19,477
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/Input.java
|
Input.readBooleans
|
public boolean[] readBooleans (int length) throws KryoException {
boolean[] array = new boolean[length];
if (optional(length) == length) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p++)
array[i] = buffer[p] != 0;
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readBoolean();
}
return array;
}
|
java
|
public boolean[] readBooleans (int length) throws KryoException {
boolean[] array = new boolean[length];
if (optional(length) == length) {
byte[] buffer = this.buffer;
int p = this.position;
for (int i = 0; i < length; i++, p++)
array[i] = buffer[p] != 0;
position = p;
} else {
for (int i = 0; i < length; i++)
array[i] = readBoolean();
}
return array;
}
|
[
"public",
"boolean",
"[",
"]",
"readBooleans",
"(",
"int",
"length",
")",
"throws",
"KryoException",
"{",
"boolean",
"[",
"]",
"array",
"=",
"new",
"boolean",
"[",
"length",
"]",
";",
"if",
"(",
"optional",
"(",
"length",
")",
"==",
"length",
")",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"this",
".",
"buffer",
";",
"int",
"p",
"=",
"this",
".",
"position",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
",",
"p",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"buffer",
"[",
"p",
"]",
"!=",
"0",
";",
"position",
"=",
"p",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"readBoolean",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Reads a boolean array in bulk. This may be more efficient than reading them individually.
|
[
"Reads",
"a",
"boolean",
"array",
"in",
"bulk",
".",
"This",
"may",
"be",
"more",
"efficient",
"than",
"reading",
"them",
"individually",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/Input.java#L1049-L1062
|
19,478
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/serializers/FieldSerializer.java
|
FieldSerializer.getField
|
public CachedField getField (String fieldName) {
for (CachedField cachedField : cachedFields.fields)
if (cachedField.name.equals(fieldName)) return cachedField;
throw new IllegalArgumentException("Field \"" + fieldName + "\" not found on class: " + type.getName());
}
|
java
|
public CachedField getField (String fieldName) {
for (CachedField cachedField : cachedFields.fields)
if (cachedField.name.equals(fieldName)) return cachedField;
throw new IllegalArgumentException("Field \"" + fieldName + "\" not found on class: " + type.getName());
}
|
[
"public",
"CachedField",
"getField",
"(",
"String",
"fieldName",
")",
"{",
"for",
"(",
"CachedField",
"cachedField",
":",
"cachedFields",
".",
"fields",
")",
"if",
"(",
"cachedField",
".",
"name",
".",
"equals",
"(",
"fieldName",
")",
")",
"return",
"cachedField",
";",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Field \\\"\"",
"+",
"fieldName",
"+",
"\"\\\" not found on class: \"",
"+",
"type",
".",
"getName",
"(",
")",
")",
";",
"}"
] |
Returns the field with the specified name, allowing field specific settings to be configured.
|
[
"Returns",
"the",
"field",
"with",
"the",
"specified",
"name",
"allowing",
"field",
"specific",
"settings",
"to",
"be",
"configured",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/serializers/FieldSerializer.java#L170-L174
|
19,479
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/unsafe/UnsafeUtil.java
|
UnsafeUtil.newDirectBuffer
|
static public ByteBuffer newDirectBuffer (long address, int size) {
if (directByteBufferConstructor == null)
throw new UnsupportedOperationException("No direct ByteBuffer constructor is available.");
try {
return directByteBufferConstructor.newInstance(address, size, null);
} catch (Exception ex) {
throw new KryoException("Error creating a ByteBuffer at address: " + address, ex);
}
}
|
java
|
static public ByteBuffer newDirectBuffer (long address, int size) {
if (directByteBufferConstructor == null)
throw new UnsupportedOperationException("No direct ByteBuffer constructor is available.");
try {
return directByteBufferConstructor.newInstance(address, size, null);
} catch (Exception ex) {
throw new KryoException("Error creating a ByteBuffer at address: " + address, ex);
}
}
|
[
"static",
"public",
"ByteBuffer",
"newDirectBuffer",
"(",
"long",
"address",
",",
"int",
"size",
")",
"{",
"if",
"(",
"directByteBufferConstructor",
"==",
"null",
")",
"throw",
"new",
"UnsupportedOperationException",
"(",
"\"No direct ByteBuffer constructor is available.\"",
")",
";",
"try",
"{",
"return",
"directByteBufferConstructor",
".",
"newInstance",
"(",
"address",
",",
"size",
",",
"null",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"KryoException",
"(",
"\"Error creating a ByteBuffer at address: \"",
"+",
"address",
",",
"ex",
")",
";",
"}",
"}"
] |
Create a ByteBuffer that uses the specified off-heap memory address instead of allocating a new one.
@param address Address of the memory region to be used for a ByteBuffer.
@param size Size in bytes of the memory region.
@throws UnsupportedOperationException if creating a ByteBuffer this way is not available.
|
[
"Create",
"a",
"ByteBuffer",
"that",
"uses",
"the",
"specified",
"off",
"-",
"heap",
"memory",
"address",
"instead",
"of",
"allocating",
"a",
"new",
"one",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/unsafe/UnsafeUtil.java#L123-L131
|
19,480
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/unsafe/UnsafeUtil.java
|
UnsafeUtil.dispose
|
static public void dispose (ByteBuffer buffer) {
if (!(buffer instanceof DirectBuffer)) return;
if (cleanerMethod != null) {
try {
cleanMethod.invoke(cleanerMethod.invoke(buffer));
} catch (Throwable ignored) {
}
}
}
|
java
|
static public void dispose (ByteBuffer buffer) {
if (!(buffer instanceof DirectBuffer)) return;
if (cleanerMethod != null) {
try {
cleanMethod.invoke(cleanerMethod.invoke(buffer));
} catch (Throwable ignored) {
}
}
}
|
[
"static",
"public",
"void",
"dispose",
"(",
"ByteBuffer",
"buffer",
")",
"{",
"if",
"(",
"!",
"(",
"buffer",
"instanceof",
"DirectBuffer",
")",
")",
"return",
";",
"if",
"(",
"cleanerMethod",
"!=",
"null",
")",
"{",
"try",
"{",
"cleanMethod",
".",
"invoke",
"(",
"cleanerMethod",
".",
"invoke",
"(",
"buffer",
")",
")",
";",
"}",
"catch",
"(",
"Throwable",
"ignored",
")",
"{",
"}",
"}",
"}"
] |
Release a direct buffer immediately rather than waiting for GC.
|
[
"Release",
"a",
"direct",
"buffer",
"immediately",
"rather",
"than",
"waiting",
"for",
"GC",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/unsafe/UnsafeUtil.java#L139-L147
|
19,481
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/io/OutputChunked.java
|
OutputChunked.endChunk
|
public void endChunk () {
flush();
if (TRACE) trace("kryo", "End chunk.");
try {
getOutputStream().write(0); // Zero length chunk.
} catch (IOException ex) {
throw new KryoException(ex);
}
}
|
java
|
public void endChunk () {
flush();
if (TRACE) trace("kryo", "End chunk.");
try {
getOutputStream().write(0); // Zero length chunk.
} catch (IOException ex) {
throw new KryoException(ex);
}
}
|
[
"public",
"void",
"endChunk",
"(",
")",
"{",
"flush",
"(",
")",
";",
"if",
"(",
"TRACE",
")",
"trace",
"(",
"\"kryo\"",
",",
"\"End chunk.\"",
")",
";",
"try",
"{",
"getOutputStream",
"(",
")",
".",
"write",
"(",
"0",
")",
";",
"// Zero length chunk.\r",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"throw",
"new",
"KryoException",
"(",
"ex",
")",
";",
"}",
"}"
] |
Marks the curent written data as the end of a chunk. This chunk can then be skipped when reading.
|
[
"Marks",
"the",
"curent",
"written",
"data",
"as",
"the",
"end",
"of",
"a",
"chunk",
".",
"This",
"chunk",
"can",
"then",
"be",
"skipped",
"when",
"reading",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/io/OutputChunked.java#L97-L105
|
19,482
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/ObjectMap.java
|
ObjectMap.put
|
public V put (K key, V value) {
if (key == null) throw new IllegalArgumentException("key cannot be null.");
K[] keyTable = this.keyTable;
int mask = this.mask;
// Check for existing keys.
int hashCode = key.hashCode();
int index1 = hashCode & mask;
K key1 = keyTable[index1];
if (key.equals(key1)) {
V oldValue = valueTable[index1];
valueTable[index1] = value;
return oldValue;
}
int index2 = hash2(hashCode);
K key2 = keyTable[index2];
if (key.equals(key2)) {
V oldValue = valueTable[index2];
valueTable[index2] = value;
return oldValue;
}
int index3 = hash3(hashCode);
K key3 = keyTable[index3];
if (key.equals(key3)) {
V oldValue = valueTable[index3];
valueTable[index3] = value;
return oldValue;
}
int index4 = -1;
K key4 = null;
if (bigTable) {
index4 = hash4(hashCode);
key4 = keyTable[index4];
if (key.equals(key4)) {
V oldValue = valueTable[index4];
valueTable[index4] = value;
return oldValue;
}
}
// Update key in the stash.
for (int i = capacity, n = i + stashSize; i < n; i++) {
if (key.equals(keyTable[i])) {
V oldValue = valueTable[i];
valueTable[i] = value;
return oldValue;
}
}
// Check for empty buckets.
if (key1 == null) {
keyTable[index1] = key;
valueTable[index1] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (key2 == null) {
keyTable[index2] = key;
valueTable[index2] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (key3 == null) {
keyTable[index3] = key;
valueTable[index3] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (bigTable && key4 == null) {
keyTable[index4] = key;
valueTable[index4] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
push(key, value, index1, key1, index2, key2, index3, key3, index4, key4);
return null;
}
|
java
|
public V put (K key, V value) {
if (key == null) throw new IllegalArgumentException("key cannot be null.");
K[] keyTable = this.keyTable;
int mask = this.mask;
// Check for existing keys.
int hashCode = key.hashCode();
int index1 = hashCode & mask;
K key1 = keyTable[index1];
if (key.equals(key1)) {
V oldValue = valueTable[index1];
valueTable[index1] = value;
return oldValue;
}
int index2 = hash2(hashCode);
K key2 = keyTable[index2];
if (key.equals(key2)) {
V oldValue = valueTable[index2];
valueTable[index2] = value;
return oldValue;
}
int index3 = hash3(hashCode);
K key3 = keyTable[index3];
if (key.equals(key3)) {
V oldValue = valueTable[index3];
valueTable[index3] = value;
return oldValue;
}
int index4 = -1;
K key4 = null;
if (bigTable) {
index4 = hash4(hashCode);
key4 = keyTable[index4];
if (key.equals(key4)) {
V oldValue = valueTable[index4];
valueTable[index4] = value;
return oldValue;
}
}
// Update key in the stash.
for (int i = capacity, n = i + stashSize; i < n; i++) {
if (key.equals(keyTable[i])) {
V oldValue = valueTable[i];
valueTable[i] = value;
return oldValue;
}
}
// Check for empty buckets.
if (key1 == null) {
keyTable[index1] = key;
valueTable[index1] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (key2 == null) {
keyTable[index2] = key;
valueTable[index2] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (key3 == null) {
keyTable[index3] = key;
valueTable[index3] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (bigTable && key4 == null) {
keyTable[index4] = key;
valueTable[index4] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
push(key, value, index1, key1, index2, key2, index3, key3, index4, key4);
return null;
}
|
[
"public",
"V",
"put",
"(",
"K",
"key",
",",
"V",
"value",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"key cannot be null.\"",
")",
";",
"K",
"[",
"]",
"keyTable",
"=",
"this",
".",
"keyTable",
";",
"int",
"mask",
"=",
"this",
".",
"mask",
";",
"// Check for existing keys.\r",
"int",
"hashCode",
"=",
"key",
".",
"hashCode",
"(",
")",
";",
"int",
"index1",
"=",
"hashCode",
"&",
"mask",
";",
"K",
"key1",
"=",
"keyTable",
"[",
"index1",
"]",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"key1",
")",
")",
"{",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index1",
"]",
";",
"valueTable",
"[",
"index1",
"]",
"=",
"value",
";",
"return",
"oldValue",
";",
"}",
"int",
"index2",
"=",
"hash2",
"(",
"hashCode",
")",
";",
"K",
"key2",
"=",
"keyTable",
"[",
"index2",
"]",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"key2",
")",
")",
"{",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index2",
"]",
";",
"valueTable",
"[",
"index2",
"]",
"=",
"value",
";",
"return",
"oldValue",
";",
"}",
"int",
"index3",
"=",
"hash3",
"(",
"hashCode",
")",
";",
"K",
"key3",
"=",
"keyTable",
"[",
"index3",
"]",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"key3",
")",
")",
"{",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index3",
"]",
";",
"valueTable",
"[",
"index3",
"]",
"=",
"value",
";",
"return",
"oldValue",
";",
"}",
"int",
"index4",
"=",
"-",
"1",
";",
"K",
"key4",
"=",
"null",
";",
"if",
"(",
"bigTable",
")",
"{",
"index4",
"=",
"hash4",
"(",
"hashCode",
")",
";",
"key4",
"=",
"keyTable",
"[",
"index4",
"]",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"key4",
")",
")",
"{",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index4",
"]",
";",
"valueTable",
"[",
"index4",
"]",
"=",
"value",
";",
"return",
"oldValue",
";",
"}",
"}",
"// Update key in the stash.\r",
"for",
"(",
"int",
"i",
"=",
"capacity",
",",
"n",
"=",
"i",
"+",
"stashSize",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"if",
"(",
"key",
".",
"equals",
"(",
"keyTable",
"[",
"i",
"]",
")",
")",
"{",
"V",
"oldValue",
"=",
"valueTable",
"[",
"i",
"]",
";",
"valueTable",
"[",
"i",
"]",
"=",
"value",
";",
"return",
"oldValue",
";",
"}",
"}",
"// Check for empty buckets.\r",
"if",
"(",
"key1",
"==",
"null",
")",
"{",
"keyTable",
"[",
"index1",
"]",
"=",
"key",
";",
"valueTable",
"[",
"index1",
"]",
"=",
"value",
";",
"if",
"(",
"size",
"++",
">=",
"threshold",
")",
"resize",
"(",
"capacity",
"<<",
"1",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"key2",
"==",
"null",
")",
"{",
"keyTable",
"[",
"index2",
"]",
"=",
"key",
";",
"valueTable",
"[",
"index2",
"]",
"=",
"value",
";",
"if",
"(",
"size",
"++",
">=",
"threshold",
")",
"resize",
"(",
"capacity",
"<<",
"1",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"key3",
"==",
"null",
")",
"{",
"keyTable",
"[",
"index3",
"]",
"=",
"key",
";",
"valueTable",
"[",
"index3",
"]",
"=",
"value",
";",
"if",
"(",
"size",
"++",
">=",
"threshold",
")",
"resize",
"(",
"capacity",
"<<",
"1",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"bigTable",
"&&",
"key4",
"==",
"null",
")",
"{",
"keyTable",
"[",
"index4",
"]",
"=",
"key",
";",
"valueTable",
"[",
"index4",
"]",
"=",
"value",
";",
"if",
"(",
"size",
"++",
">=",
"threshold",
")",
"resize",
"(",
"capacity",
"<<",
"1",
")",
";",
"return",
"null",
";",
"}",
"push",
"(",
"key",
",",
"value",
",",
"index1",
",",
"key1",
",",
"index2",
",",
"key2",
",",
"index3",
",",
"key3",
",",
"index4",
",",
"key4",
")",
";",
"return",
"null",
";",
"}"
] |
Returns the old value associated with the specified key, or null.
|
[
"Returns",
"the",
"old",
"value",
"associated",
"with",
"the",
"specified",
"key",
"or",
"null",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/ObjectMap.java#L100-L183
|
19,483
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/ObjectMap.java
|
ObjectMap.remove
|
public V remove (K key) {
int hashCode = key.hashCode();
int index = hashCode & mask;
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
index = hash2(hashCode);
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
index = hash3(hashCode);
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
if (bigTable) {
index = hash4(hashCode);
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
}
return removeStash(key);
}
|
java
|
public V remove (K key) {
int hashCode = key.hashCode();
int index = hashCode & mask;
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
index = hash2(hashCode);
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
index = hash3(hashCode);
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
if (bigTable) {
index = hash4(hashCode);
if (key.equals(keyTable[index])) {
keyTable[index] = null;
V oldValue = valueTable[index];
valueTable[index] = null;
size--;
return oldValue;
}
}
return removeStash(key);
}
|
[
"public",
"V",
"remove",
"(",
"K",
"key",
")",
"{",
"int",
"hashCode",
"=",
"key",
".",
"hashCode",
"(",
")",
";",
"int",
"index",
"=",
"hashCode",
"&",
"mask",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"keyTable",
"[",
"index",
"]",
")",
")",
"{",
"keyTable",
"[",
"index",
"]",
"=",
"null",
";",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index",
"]",
";",
"valueTable",
"[",
"index",
"]",
"=",
"null",
";",
"size",
"--",
";",
"return",
"oldValue",
";",
"}",
"index",
"=",
"hash2",
"(",
"hashCode",
")",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"keyTable",
"[",
"index",
"]",
")",
")",
"{",
"keyTable",
"[",
"index",
"]",
"=",
"null",
";",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index",
"]",
";",
"valueTable",
"[",
"index",
"]",
"=",
"null",
";",
"size",
"--",
";",
"return",
"oldValue",
";",
"}",
"index",
"=",
"hash3",
"(",
"hashCode",
")",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"keyTable",
"[",
"index",
"]",
")",
")",
"{",
"keyTable",
"[",
"index",
"]",
"=",
"null",
";",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index",
"]",
";",
"valueTable",
"[",
"index",
"]",
"=",
"null",
";",
"size",
"--",
";",
"return",
"oldValue",
";",
"}",
"if",
"(",
"bigTable",
")",
"{",
"index",
"=",
"hash4",
"(",
"hashCode",
")",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"keyTable",
"[",
"index",
"]",
")",
")",
"{",
"keyTable",
"[",
"index",
"]",
"=",
"null",
";",
"V",
"oldValue",
"=",
"valueTable",
"[",
"index",
"]",
";",
"valueTable",
"[",
"index",
"]",
"=",
"null",
";",
"size",
"--",
";",
"return",
"oldValue",
";",
"}",
"}",
"return",
"removeStash",
"(",
"key",
")",
";",
"}"
] |
Returns the value associated with the key, or null.
|
[
"Returns",
"the",
"value",
"associated",
"with",
"the",
"key",
"or",
"null",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/ObjectMap.java#L399-L440
|
19,484
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/ObjectMap.java
|
ObjectMap.shrink
|
public void shrink (int maximumCapacity) {
if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
if (size > maximumCapacity) maximumCapacity = size;
if (capacity <= maximumCapacity) return;
maximumCapacity = nextPowerOfTwo(maximumCapacity);
resize(maximumCapacity);
}
|
java
|
public void shrink (int maximumCapacity) {
if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
if (size > maximumCapacity) maximumCapacity = size;
if (capacity <= maximumCapacity) return;
maximumCapacity = nextPowerOfTwo(maximumCapacity);
resize(maximumCapacity);
}
|
[
"public",
"void",
"shrink",
"(",
"int",
"maximumCapacity",
")",
"{",
"if",
"(",
"maximumCapacity",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"maximumCapacity must be >= 0: \"",
"+",
"maximumCapacity",
")",
";",
"if",
"(",
"size",
">",
"maximumCapacity",
")",
"maximumCapacity",
"=",
"size",
";",
"if",
"(",
"capacity",
"<=",
"maximumCapacity",
")",
"return",
";",
"maximumCapacity",
"=",
"nextPowerOfTwo",
"(",
"maximumCapacity",
")",
";",
"resize",
"(",
"maximumCapacity",
")",
";",
"}"
] |
Reduces the size of the backing arrays to be the specified capacity or less. If the capacity is already less, nothing is
done. If the map contains more items than the specified capacity, the next highest power of two capacity is used instead.
|
[
"Reduces",
"the",
"size",
"of",
"the",
"backing",
"arrays",
"to",
"be",
"the",
"specified",
"capacity",
"or",
"less",
".",
"If",
"the",
"capacity",
"is",
"already",
"less",
"nothing",
"is",
"done",
".",
"If",
"the",
"map",
"contains",
"more",
"items",
"than",
"the",
"specified",
"capacity",
"the",
"next",
"highest",
"power",
"of",
"two",
"capacity",
"is",
"used",
"instead",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/ObjectMap.java#L477-L483
|
19,485
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.getDefaultSerializer
|
public Serializer getDefaultSerializer (Class type) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
Serializer serializerForAnnotation = getDefaultSerializerForAnnotatedType(type);
if (serializerForAnnotation != null) return serializerForAnnotation;
for (int i = 0, n = defaultSerializers.size(); i < n; i++) {
DefaultSerializerEntry entry = defaultSerializers.get(i);
if (entry.type.isAssignableFrom(type) && entry.serializerFactory.isSupported(type))
return entry.serializerFactory.newSerializer(this, type);
}
return newDefaultSerializer(type);
}
|
java
|
public Serializer getDefaultSerializer (Class type) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
Serializer serializerForAnnotation = getDefaultSerializerForAnnotatedType(type);
if (serializerForAnnotation != null) return serializerForAnnotation;
for (int i = 0, n = defaultSerializers.size(); i < n; i++) {
DefaultSerializerEntry entry = defaultSerializers.get(i);
if (entry.type.isAssignableFrom(type) && entry.serializerFactory.isSupported(type))
return entry.serializerFactory.newSerializer(this, type);
}
return newDefaultSerializer(type);
}
|
[
"public",
"Serializer",
"getDefaultSerializer",
"(",
"Class",
"type",
")",
"{",
"if",
"(",
"type",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"type cannot be null.\"",
")",
";",
"Serializer",
"serializerForAnnotation",
"=",
"getDefaultSerializerForAnnotatedType",
"(",
"type",
")",
";",
"if",
"(",
"serializerForAnnotation",
"!=",
"null",
")",
"return",
"serializerForAnnotation",
";",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"n",
"=",
"defaultSerializers",
".",
"size",
"(",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"DefaultSerializerEntry",
"entry",
"=",
"defaultSerializers",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"entry",
".",
"type",
".",
"isAssignableFrom",
"(",
"type",
")",
"&&",
"entry",
".",
"serializerFactory",
".",
"isSupported",
"(",
"type",
")",
")",
"return",
"entry",
".",
"serializerFactory",
".",
"newSerializer",
"(",
"this",
",",
"type",
")",
";",
"}",
"return",
"newDefaultSerializer",
"(",
"type",
")",
";",
"}"
] |
Returns the best matching serializer for a class. This method can be overridden to implement custom logic to choose a
serializer.
|
[
"Returns",
"the",
"best",
"matching",
"serializer",
"for",
"a",
"class",
".",
"This",
"method",
"can",
"be",
"overridden",
"to",
"implement",
"custom",
"logic",
"to",
"choose",
"a",
"serializer",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L368-L381
|
19,486
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.writeClass
|
public Registration writeClass (Output output, Class type) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
try {
return classResolver.writeClass(output, type);
} finally {
if (depth == 0 && autoReset) reset();
}
}
|
java
|
public Registration writeClass (Output output, Class type) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
try {
return classResolver.writeClass(output, type);
} finally {
if (depth == 0 && autoReset) reset();
}
}
|
[
"public",
"Registration",
"writeClass",
"(",
"Output",
"output",
",",
"Class",
"type",
")",
"{",
"if",
"(",
"output",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"output cannot be null.\"",
")",
";",
"try",
"{",
"return",
"classResolver",
".",
"writeClass",
"(",
"output",
",",
"type",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Writes a class and returns its registration.
@param type May be null.
@return Will be null if type is null.
@see ClassResolver#writeClass(Output, Class)
|
[
"Writes",
"a",
"class",
"and",
"returns",
"its",
"registration",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L529-L536
|
19,487
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.writeObject
|
public void writeObject (Output output, Object object) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
if (object == null) throw new IllegalArgumentException("object cannot be null.");
beginObject();
try {
if (references && writeReferenceOrNull(output, object, false)) return;
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
getRegistration(object.getClass()).getSerializer().write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
java
|
public void writeObject (Output output, Object object) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
if (object == null) throw new IllegalArgumentException("object cannot be null.");
beginObject();
try {
if (references && writeReferenceOrNull(output, object, false)) return;
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
getRegistration(object.getClass()).getSerializer().write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
[
"public",
"void",
"writeObject",
"(",
"Output",
"output",
",",
"Object",
"object",
")",
"{",
"if",
"(",
"output",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"output cannot be null.\"",
")",
";",
"if",
"(",
"object",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"object cannot be null.\"",
")",
";",
"beginObject",
"(",
")",
";",
"try",
"{",
"if",
"(",
"references",
"&&",
"writeReferenceOrNull",
"(",
"output",
",",
"object",
",",
"false",
")",
")",
"return",
";",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Write\"",
",",
"object",
",",
"output",
".",
"position",
"(",
")",
")",
";",
"getRegistration",
"(",
"object",
".",
"getClass",
"(",
")",
")",
".",
"getSerializer",
"(",
")",
".",
"write",
"(",
"this",
",",
"output",
",",
"object",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"--",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Writes an object using the registered serializer.
|
[
"Writes",
"an",
"object",
"using",
"the",
"registered",
"serializer",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L539-L550
|
19,488
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.writeObject
|
public void writeObject (Output output, Object object, Serializer serializer) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
if (object == null) throw new IllegalArgumentException("object cannot be null.");
if (serializer == null) throw new IllegalArgumentException("serializer cannot be null.");
beginObject();
try {
if (references && writeReferenceOrNull(output, object, false)) return;
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
serializer.write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
java
|
public void writeObject (Output output, Object object, Serializer serializer) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
if (object == null) throw new IllegalArgumentException("object cannot be null.");
if (serializer == null) throw new IllegalArgumentException("serializer cannot be null.");
beginObject();
try {
if (references && writeReferenceOrNull(output, object, false)) return;
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
serializer.write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
[
"public",
"void",
"writeObject",
"(",
"Output",
"output",
",",
"Object",
"object",
",",
"Serializer",
"serializer",
")",
"{",
"if",
"(",
"output",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"output cannot be null.\"",
")",
";",
"if",
"(",
"object",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"object cannot be null.\"",
")",
";",
"if",
"(",
"serializer",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"serializer cannot be null.\"",
")",
";",
"beginObject",
"(",
")",
";",
"try",
"{",
"if",
"(",
"references",
"&&",
"writeReferenceOrNull",
"(",
"output",
",",
"object",
",",
"false",
")",
")",
"return",
";",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Write\"",
",",
"object",
",",
"output",
".",
"position",
"(",
")",
")",
";",
"serializer",
".",
"write",
"(",
"this",
",",
"output",
",",
"object",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"--",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Writes an object using the specified serializer. The registered serializer is ignored.
|
[
"Writes",
"an",
"object",
"using",
"the",
"specified",
"serializer",
".",
"The",
"registered",
"serializer",
"is",
"ignored",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L553-L565
|
19,489
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.writeObjectOrNull
|
public void writeObjectOrNull (Output output, Object object, Serializer serializer) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
if (serializer == null) throw new IllegalArgumentException("serializer cannot be null.");
beginObject();
try {
if (references) {
if (writeReferenceOrNull(output, object, true)) return;
} else if (!serializer.getAcceptsNull()) {
if (object == null) {
if (TRACE || (DEBUG && depth == 1)) log("Write", null, output.position());
output.writeByte(NULL);
return;
}
if (TRACE) trace("kryo", "Write: <not null>" + pos(output.position()));
output.writeByte(NOT_NULL);
}
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
serializer.write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
java
|
public void writeObjectOrNull (Output output, Object object, Serializer serializer) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
if (serializer == null) throw new IllegalArgumentException("serializer cannot be null.");
beginObject();
try {
if (references) {
if (writeReferenceOrNull(output, object, true)) return;
} else if (!serializer.getAcceptsNull()) {
if (object == null) {
if (TRACE || (DEBUG && depth == 1)) log("Write", null, output.position());
output.writeByte(NULL);
return;
}
if (TRACE) trace("kryo", "Write: <not null>" + pos(output.position()));
output.writeByte(NOT_NULL);
}
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
serializer.write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
[
"public",
"void",
"writeObjectOrNull",
"(",
"Output",
"output",
",",
"Object",
"object",
",",
"Serializer",
"serializer",
")",
"{",
"if",
"(",
"output",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"output cannot be null.\"",
")",
";",
"if",
"(",
"serializer",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"serializer cannot be null.\"",
")",
";",
"beginObject",
"(",
")",
";",
"try",
"{",
"if",
"(",
"references",
")",
"{",
"if",
"(",
"writeReferenceOrNull",
"(",
"output",
",",
"object",
",",
"true",
")",
")",
"return",
";",
"}",
"else",
"if",
"(",
"!",
"serializer",
".",
"getAcceptsNull",
"(",
")",
")",
"{",
"if",
"(",
"object",
"==",
"null",
")",
"{",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Write\"",
",",
"null",
",",
"output",
".",
"position",
"(",
")",
")",
";",
"output",
".",
"writeByte",
"(",
"NULL",
")",
";",
"return",
";",
"}",
"if",
"(",
"TRACE",
")",
"trace",
"(",
"\"kryo\"",
",",
"\"Write: <not null>\"",
"+",
"pos",
"(",
"output",
".",
"position",
"(",
")",
")",
")",
";",
"output",
".",
"writeByte",
"(",
"NOT_NULL",
")",
";",
"}",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Write\"",
",",
"object",
",",
"output",
".",
"position",
"(",
")",
")",
";",
"serializer",
".",
"write",
"(",
"this",
",",
"output",
",",
"object",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"--",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Writes an object or null using the specified serializer. The registered serializer is ignored.
@param object May be null.
|
[
"Writes",
"an",
"object",
"or",
"null",
"using",
"the",
"specified",
"serializer",
".",
"The",
"registered",
"serializer",
"is",
"ignored",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L594-L615
|
19,490
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.writeClassAndObject
|
public void writeClassAndObject (Output output, Object object) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
beginObject();
try {
if (object == null) {
writeClass(output, null);
return;
}
Registration registration = writeClass(output, object.getClass());
if (references && writeReferenceOrNull(output, object, false)) return;
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
registration.getSerializer().write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
java
|
public void writeClassAndObject (Output output, Object object) {
if (output == null) throw new IllegalArgumentException("output cannot be null.");
beginObject();
try {
if (object == null) {
writeClass(output, null);
return;
}
Registration registration = writeClass(output, object.getClass());
if (references && writeReferenceOrNull(output, object, false)) return;
if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
registration.getSerializer().write(this, output, object);
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
[
"public",
"void",
"writeClassAndObject",
"(",
"Output",
"output",
",",
"Object",
"object",
")",
"{",
"if",
"(",
"output",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"output cannot be null.\"",
")",
";",
"beginObject",
"(",
")",
";",
"try",
"{",
"if",
"(",
"object",
"==",
"null",
")",
"{",
"writeClass",
"(",
"output",
",",
"null",
")",
";",
"return",
";",
"}",
"Registration",
"registration",
"=",
"writeClass",
"(",
"output",
",",
"object",
".",
"getClass",
"(",
")",
")",
";",
"if",
"(",
"references",
"&&",
"writeReferenceOrNull",
"(",
"output",
",",
"object",
",",
"false",
")",
")",
"return",
";",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Write\"",
",",
"object",
",",
"output",
".",
"position",
"(",
")",
")",
";",
"registration",
".",
"getSerializer",
"(",
")",
".",
"write",
"(",
"this",
",",
"output",
",",
"object",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"--",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Writes the class and object or null using the registered serializer.
@param object May be null.
|
[
"Writes",
"the",
"class",
"and",
"object",
"or",
"null",
"using",
"the",
"registered",
"serializer",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L619-L634
|
19,491
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.readClass
|
public Registration readClass (Input input) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
try {
return classResolver.readClass(input);
} finally {
if (depth == 0 && autoReset) reset();
}
}
|
java
|
public Registration readClass (Input input) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
try {
return classResolver.readClass(input);
} finally {
if (depth == 0 && autoReset) reset();
}
}
|
[
"public",
"Registration",
"readClass",
"(",
"Input",
"input",
")",
"{",
"if",
"(",
"input",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"input cannot be null.\"",
")",
";",
"try",
"{",
"return",
"classResolver",
".",
"readClass",
"(",
"input",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Reads a class and returns its registration.
@return May be null.
@see ClassResolver#readClass(Input)
|
[
"Reads",
"a",
"class",
"and",
"returns",
"its",
"registration",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L674-L681
|
19,492
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.readObject
|
public <T> T readObject (Input input, Class<T> type) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
if (type == null) throw new IllegalArgumentException("type cannot be null.");
beginObject();
try {
T object;
if (references) {
int stackSize = readReferenceOrNull(input, type, false);
if (stackSize == REF) return (T)readObject;
object = (T)getRegistration(type).getSerializer().read(this, input, type);
if (stackSize == readReferenceIds.size) reference(object);
} else
object = (T)getRegistration(type).getSerializer().read(this, input, type);
if (TRACE || (DEBUG && depth == 1)) log("Read", object, input.position());
return object;
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
java
|
public <T> T readObject (Input input, Class<T> type) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
if (type == null) throw new IllegalArgumentException("type cannot be null.");
beginObject();
try {
T object;
if (references) {
int stackSize = readReferenceOrNull(input, type, false);
if (stackSize == REF) return (T)readObject;
object = (T)getRegistration(type).getSerializer().read(this, input, type);
if (stackSize == readReferenceIds.size) reference(object);
} else
object = (T)getRegistration(type).getSerializer().read(this, input, type);
if (TRACE || (DEBUG && depth == 1)) log("Read", object, input.position());
return object;
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
[
"public",
"<",
"T",
">",
"T",
"readObject",
"(",
"Input",
"input",
",",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"if",
"(",
"input",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"input cannot be null.\"",
")",
";",
"if",
"(",
"type",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"type cannot be null.\"",
")",
";",
"beginObject",
"(",
")",
";",
"try",
"{",
"T",
"object",
";",
"if",
"(",
"references",
")",
"{",
"int",
"stackSize",
"=",
"readReferenceOrNull",
"(",
"input",
",",
"type",
",",
"false",
")",
";",
"if",
"(",
"stackSize",
"==",
"REF",
")",
"return",
"(",
"T",
")",
"readObject",
";",
"object",
"=",
"(",
"T",
")",
"getRegistration",
"(",
"type",
")",
".",
"getSerializer",
"(",
")",
".",
"read",
"(",
"this",
",",
"input",
",",
"type",
")",
";",
"if",
"(",
"stackSize",
"==",
"readReferenceIds",
".",
"size",
")",
"reference",
"(",
"object",
")",
";",
"}",
"else",
"object",
"=",
"(",
"T",
")",
"getRegistration",
"(",
"type",
")",
".",
"getSerializer",
"(",
")",
".",
"read",
"(",
"this",
",",
"input",
",",
"type",
")",
";",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Read\"",
",",
"object",
",",
"input",
".",
"position",
"(",
")",
")",
";",
"return",
"object",
";",
"}",
"finally",
"{",
"if",
"(",
"--",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Reads an object using the registered serializer.
|
[
"Reads",
"an",
"object",
"using",
"the",
"registered",
"serializer",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L684-L702
|
19,493
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.readClassAndObject
|
public Object readClassAndObject (Input input) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
beginObject();
try {
Registration registration = readClass(input);
if (registration == null) return null;
Class type = registration.getType();
Object object;
if (references) {
int stackSize = readReferenceOrNull(input, type, false);
if (stackSize == REF) return readObject;
object = registration.getSerializer().read(this, input, type);
if (stackSize == readReferenceIds.size) reference(object);
} else
object = registration.getSerializer().read(this, input, type);
if (TRACE || (DEBUG && depth == 1)) log("Read", object, input.position());
return object;
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
java
|
public Object readClassAndObject (Input input) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
beginObject();
try {
Registration registration = readClass(input);
if (registration == null) return null;
Class type = registration.getType();
Object object;
if (references) {
int stackSize = readReferenceOrNull(input, type, false);
if (stackSize == REF) return readObject;
object = registration.getSerializer().read(this, input, type);
if (stackSize == readReferenceIds.size) reference(object);
} else
object = registration.getSerializer().read(this, input, type);
if (TRACE || (DEBUG && depth == 1)) log("Read", object, input.position());
return object;
} finally {
if (--depth == 0 && autoReset) reset();
}
}
|
[
"public",
"Object",
"readClassAndObject",
"(",
"Input",
"input",
")",
"{",
"if",
"(",
"input",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"input cannot be null.\"",
")",
";",
"beginObject",
"(",
")",
";",
"try",
"{",
"Registration",
"registration",
"=",
"readClass",
"(",
"input",
")",
";",
"if",
"(",
"registration",
"==",
"null",
")",
"return",
"null",
";",
"Class",
"type",
"=",
"registration",
".",
"getType",
"(",
")",
";",
"Object",
"object",
";",
"if",
"(",
"references",
")",
"{",
"int",
"stackSize",
"=",
"readReferenceOrNull",
"(",
"input",
",",
"type",
",",
"false",
")",
";",
"if",
"(",
"stackSize",
"==",
"REF",
")",
"return",
"readObject",
";",
"object",
"=",
"registration",
".",
"getSerializer",
"(",
")",
".",
"read",
"(",
"this",
",",
"input",
",",
"type",
")",
";",
"if",
"(",
"stackSize",
"==",
"readReferenceIds",
".",
"size",
")",
"reference",
"(",
"object",
")",
";",
"}",
"else",
"object",
"=",
"registration",
".",
"getSerializer",
"(",
")",
".",
"read",
"(",
"this",
",",
"input",
",",
"type",
")",
";",
"if",
"(",
"TRACE",
"||",
"(",
"DEBUG",
"&&",
"depth",
"==",
"1",
")",
")",
"log",
"(",
"\"Read\"",
",",
"object",
",",
"input",
".",
"position",
"(",
")",
")",
";",
"return",
"object",
";",
"}",
"finally",
"{",
"if",
"(",
"--",
"depth",
"==",
"0",
"&&",
"autoReset",
")",
"reset",
"(",
")",
";",
"}",
"}"
] |
Reads the class and object or null using the registered serializer.
@return May be null.
|
[
"Reads",
"the",
"class",
"and",
"object",
"or",
"null",
"using",
"the",
"registered",
"serializer",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L784-L805
|
19,494
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/Kryo.java
|
Kryo.setReferenceResolver
|
public void setReferenceResolver (ReferenceResolver referenceResolver) {
if (referenceResolver == null) throw new IllegalArgumentException("referenceResolver cannot be null.");
this.references = true;
this.referenceResolver = referenceResolver;
if (TRACE) trace("kryo", "Reference resolver: " + referenceResolver.getClass().getName());
}
|
java
|
public void setReferenceResolver (ReferenceResolver referenceResolver) {
if (referenceResolver == null) throw new IllegalArgumentException("referenceResolver cannot be null.");
this.references = true;
this.referenceResolver = referenceResolver;
if (TRACE) trace("kryo", "Reference resolver: " + referenceResolver.getClass().getName());
}
|
[
"public",
"void",
"setReferenceResolver",
"(",
"ReferenceResolver",
"referenceResolver",
")",
"{",
"if",
"(",
"referenceResolver",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"referenceResolver cannot be null.\"",
")",
";",
"this",
".",
"references",
"=",
"true",
";",
"this",
".",
"referenceResolver",
"=",
"referenceResolver",
";",
"if",
"(",
"TRACE",
")",
"trace",
"(",
"\"kryo\"",
",",
"\"Reference resolver: \"",
"+",
"referenceResolver",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}"
] |
Sets the reference resolver and enables references.
|
[
"Sets",
"the",
"reference",
"resolver",
"and",
"enables",
"references",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/Kryo.java#L1078-L1083
|
19,495
|
EsotericSoftware/kryo
|
src/com/esotericsoftware/kryo/util/IntMap.java
|
IntMap.clear
|
public void clear (int maximumCapacity) {
if (capacity <= maximumCapacity) {
clear();
return;
}
zeroValue = null;
hasZeroValue = false;
size = 0;
resize(maximumCapacity);
}
|
java
|
public void clear (int maximumCapacity) {
if (capacity <= maximumCapacity) {
clear();
return;
}
zeroValue = null;
hasZeroValue = false;
size = 0;
resize(maximumCapacity);
}
|
[
"public",
"void",
"clear",
"(",
"int",
"maximumCapacity",
")",
"{",
"if",
"(",
"capacity",
"<=",
"maximumCapacity",
")",
"{",
"clear",
"(",
")",
";",
"return",
";",
"}",
"zeroValue",
"=",
"null",
";",
"hasZeroValue",
"=",
"false",
";",
"size",
"=",
"0",
";",
"resize",
"(",
"maximumCapacity",
")",
";",
"}"
] |
Clears the map and reduces the size of the backing arrays to be the specified capacity if they are larger.
|
[
"Clears",
"the",
"map",
"and",
"reduces",
"the",
"size",
"of",
"the",
"backing",
"arrays",
"to",
"be",
"the",
"specified",
"capacity",
"if",
"they",
"are",
"larger",
"."
] |
a8be1ab26f347f299a3c3f7171d6447dd5390845
|
https://github.com/EsotericSoftware/kryo/blob/a8be1ab26f347f299a3c3f7171d6447dd5390845/src/com/esotericsoftware/kryo/util/IntMap.java#L496-L505
|
19,496
|
aws/aws-sdk-java
|
aws-java-sdk-guardduty/src/main/java/com/amazonaws/services/guardduty/model/PortProbeAction.java
|
PortProbeAction.setPortProbeDetails
|
public void setPortProbeDetails(java.util.Collection<PortProbeDetail> portProbeDetails) {
if (portProbeDetails == null) {
this.portProbeDetails = null;
return;
}
this.portProbeDetails = new java.util.ArrayList<PortProbeDetail>(portProbeDetails);
}
|
java
|
public void setPortProbeDetails(java.util.Collection<PortProbeDetail> portProbeDetails) {
if (portProbeDetails == null) {
this.portProbeDetails = null;
return;
}
this.portProbeDetails = new java.util.ArrayList<PortProbeDetail>(portProbeDetails);
}
|
[
"public",
"void",
"setPortProbeDetails",
"(",
"java",
".",
"util",
".",
"Collection",
"<",
"PortProbeDetail",
">",
"portProbeDetails",
")",
"{",
"if",
"(",
"portProbeDetails",
"==",
"null",
")",
"{",
"this",
".",
"portProbeDetails",
"=",
"null",
";",
"return",
";",
"}",
"this",
".",
"portProbeDetails",
"=",
"new",
"java",
".",
"util",
".",
"ArrayList",
"<",
"PortProbeDetail",
">",
"(",
"portProbeDetails",
")",
";",
"}"
] |
A list of port probe details objects.
@param portProbeDetails
A list of port probe details objects.
|
[
"A",
"list",
"of",
"port",
"probe",
"details",
"objects",
"."
] |
aa38502458969b2d13a1c3665a56aba600e4dbd0
|
https://github.com/aws/aws-sdk-java/blob/aa38502458969b2d13a1c3665a56aba600e4dbd0/aws-java-sdk-guardduty/src/main/java/com/amazonaws/services/guardduty/model/PortProbeAction.java#L95-L102
|
19,497
|
aws/aws-sdk-java
|
aws-java-sdk-emr/src/main/java/com/amazonaws/services/elasticmapreduce/spi/security/EncryptionContext.java
|
EncryptionContext.withContext
|
public EncryptionContext withContext(String key, String value) {
this.context.put(key, value);
return this;
}
|
java
|
public EncryptionContext withContext(String key, String value) {
this.context.put(key, value);
return this;
}
|
[
"public",
"EncryptionContext",
"withContext",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"this",
".",
"context",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] |
Fluent API to add encryption context.
|
[
"Fluent",
"API",
"to",
"add",
"encryption",
"context",
"."
] |
aa38502458969b2d13a1c3665a56aba600e4dbd0
|
https://github.com/aws/aws-sdk-java/blob/aa38502458969b2d13a1c3665a56aba600e4dbd0/aws-java-sdk-emr/src/main/java/com/amazonaws/services/elasticmapreduce/spi/security/EncryptionContext.java#L54-L57
|
19,498
|
aws/aws-sdk-java
|
aws-java-sdk-medialive/src/main/java/com/amazonaws/services/medialive/model/StopChannelResult.java
|
StopChannelResult.setEgressEndpoints
|
public void setEgressEndpoints(java.util.Collection<ChannelEgressEndpoint> egressEndpoints) {
if (egressEndpoints == null) {
this.egressEndpoints = null;
return;
}
this.egressEndpoints = new java.util.ArrayList<ChannelEgressEndpoint>(egressEndpoints);
}
|
java
|
public void setEgressEndpoints(java.util.Collection<ChannelEgressEndpoint> egressEndpoints) {
if (egressEndpoints == null) {
this.egressEndpoints = null;
return;
}
this.egressEndpoints = new java.util.ArrayList<ChannelEgressEndpoint>(egressEndpoints);
}
|
[
"public",
"void",
"setEgressEndpoints",
"(",
"java",
".",
"util",
".",
"Collection",
"<",
"ChannelEgressEndpoint",
">",
"egressEndpoints",
")",
"{",
"if",
"(",
"egressEndpoints",
"==",
"null",
")",
"{",
"this",
".",
"egressEndpoints",
"=",
"null",
";",
"return",
";",
"}",
"this",
".",
"egressEndpoints",
"=",
"new",
"java",
".",
"util",
".",
"ArrayList",
"<",
"ChannelEgressEndpoint",
">",
"(",
"egressEndpoints",
")",
";",
"}"
] |
The endpoints where outgoing connections initiate from
@param egressEndpoints
The endpoints where outgoing connections initiate from
|
[
"The",
"endpoints",
"where",
"outgoing",
"connections",
"initiate",
"from"
] |
aa38502458969b2d13a1c3665a56aba600e4dbd0
|
https://github.com/aws/aws-sdk-java/blob/aa38502458969b2d13a1c3665a56aba600e4dbd0/aws-java-sdk-medialive/src/main/java/com/amazonaws/services/medialive/model/StopChannelResult.java#L243-L250
|
19,499
|
aws/aws-sdk-java
|
aws-java-sdk-medialive/src/main/java/com/amazonaws/services/medialive/model/StopChannelResult.java
|
StopChannelResult.setInputAttachments
|
public void setInputAttachments(java.util.Collection<InputAttachment> inputAttachments) {
if (inputAttachments == null) {
this.inputAttachments = null;
return;
}
this.inputAttachments = new java.util.ArrayList<InputAttachment>(inputAttachments);
}
|
java
|
public void setInputAttachments(java.util.Collection<InputAttachment> inputAttachments) {
if (inputAttachments == null) {
this.inputAttachments = null;
return;
}
this.inputAttachments = new java.util.ArrayList<InputAttachment>(inputAttachments);
}
|
[
"public",
"void",
"setInputAttachments",
"(",
"java",
".",
"util",
".",
"Collection",
"<",
"InputAttachment",
">",
"inputAttachments",
")",
"{",
"if",
"(",
"inputAttachments",
"==",
"null",
")",
"{",
"this",
".",
"inputAttachments",
"=",
"null",
";",
"return",
";",
"}",
"this",
".",
"inputAttachments",
"=",
"new",
"java",
".",
"util",
".",
"ArrayList",
"<",
"InputAttachment",
">",
"(",
"inputAttachments",
")",
";",
"}"
] |
List of input attachments for channel.
@param inputAttachments
List of input attachments for channel.
|
[
"List",
"of",
"input",
"attachments",
"for",
"channel",
"."
] |
aa38502458969b2d13a1c3665a56aba600e4dbd0
|
https://github.com/aws/aws-sdk-java/blob/aa38502458969b2d13a1c3665a56aba600e4dbd0/aws-java-sdk-medialive/src/main/java/com/amazonaws/services/medialive/model/StopChannelResult.java#L365-L372
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.