Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
veblush committed Jun 3, 2021
1 parent 87f281c commit 479c04e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public T parse(InputStream stream) {
try {
if (stream instanceof KnownLength) {
int size = stream.available();
if (stream instanceof Detachable
&& stream instanceof HasByteBuffer
if (stream instanceof Detachable && stream instanceof HasByteBuffer
&& ((HasByteBuffer) stream).byteBufferSupported()) {
// Stream is now detached here and should be closed later.
stream = ((Detachable) stream).detach();
Expand All @@ -102,15 +101,14 @@ public T parse(InputStream stream) {
try {
message = parseFrom(cis);
} catch (InvalidProtocolBufferException ipbe) {
throw Status.INTERNAL.withDescription("Invalid protobuf byte sequence")
.withCause(ipbe).asRuntimeException();
throw Status.INTERNAL.withDescription("Invalid protobuf byte sequence").withCause(ipbe).asRuntimeException();
}
unclosedStreams.put(message, stream);
return message;
return message;
} else {
// slow path
return baseMarshaller.parse(stream);
}
}
}

private T parseFrom(CodedInputStream stream) throws InvalidProtocolBufferException {
Expand All @@ -128,5 +126,5 @@ private T parseFrom(CodedInputStream stream) throws InvalidProtocolBufferExcepti
// call stream.close() function to return it to the pool.
public InputStream popStream(T message) {
return unclosedStreams.remove(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@
import java.security.Provider;

public class ZeroCopyReadinessChecker {
private static final boolean isZeroCopyReady;
private static final boolean isZeroCopyReady;

static {
// Check whether io.grpc.Detachable exists?
boolean detachableClassExists = false;
try {
// Try to load Detachable interface in the package where KnownLength is in.
// This can be done directly by looking up io.grpc.Detachable but rather
// done indirectly to handle the case where gRPC is being shaded in a
// different package.
String knownLengthClassName = KnownLength.class.getName();
String detachableClassName = knownLengthClassName.substring(0, knownLengthClassName.lastIndexOf('.') + 1)
+ "Detachable";
Class<?> detachableClass = Class.forName(detachableClassName);
detachableClassExists = (detachableClass != null);
} catch (ClassNotFoundException ex) {
}
// Check whether com.google.protobuf.UnsafeByteOperations exists?
boolean unsafeByteOperationsClassExists = false;
try {
// Same above
String messageLiteClassName = MessageLite.class.getName();
String unsafeByteOperationsClassName = messageLiteClassName.substring(0, messageLiteClassName.lastIndexOf('.') + 1)
+ "UnsafeByteOperations";
Class<?> unsafeByteOperationsClass = Class.forName(unsafeByteOperationsClassName);
unsafeByteOperationsClassExists = (unsafeByteOperationsClass != null);
} catch (ClassNotFoundException ex) {
}
isZeroCopyReady = detachableClassExists && unsafeByteOperationsClassExists;
static {
// Check whether io.grpc.Detachable exists?
boolean detachableClassExists = false;
try {
// Try to load Detachable interface in the package where KnownLength is in.
// This can be done directly by looking up io.grpc.Detachable but rather
// done indirectly to handle the case where gRPC is being shaded in a
// different package.
String knownLengthClassName = KnownLength.class.getName();
String detachableClassName = knownLengthClassName.substring(0, knownLengthClassName.lastIndexOf('.') + 1)
+ "Detachable";
Class<?> detachableClass = Class.forName(detachableClassName);
detachableClassExists = (detachableClass != null);
} catch (ClassNotFoundException ex) {
}

public static boolean isReady() {
return isZeroCopyReady;
// Check whether com.google.protobuf.UnsafeByteOperations exists?
boolean unsafeByteOperationsClassExists = false;
try {
// Same above
String messageLiteClassName = MessageLite.class.getName();
String unsafeByteOperationsClassName = messageLiteClassName.substring(0,
messageLiteClassName.lastIndexOf('.') + 1) + "UnsafeByteOperations";
Class<?> unsafeByteOperationsClass = Class.forName(unsafeByteOperationsClassName);
unsafeByteOperationsClassExists = (unsafeByteOperationsClass != null);
} catch (ClassNotFoundException ex) {
}
isZeroCopyReady = detachableClassExists && unsafeByteOperationsClassExists;
}

public static boolean isReady() {
return isZeroCopyReady;
}
}

0 comments on commit 479c04e

Please sign in to comment.