diff options
author | 2015-10-20 16:24:48 -0400 | |
---|---|---|
committer | 2016-01-15 21:51:19 -0500 | |
commit | f3c75580e4e7b18c372e1f83e4283701c01bcaca (patch) | |
tree | 7fc56ae23162f1e90c1dd15cda04f7d4b4f9fe7b /java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java | |
parent | 9a5d892e2a2708335a3223d10e268ea932245e15 (diff) |
throw IOException instead of InvalidProtocolBufferException when appropriate
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index 0a761052..85ce7b24 100644 --- a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java @@ -46,6 +46,10 @@ public class InvalidProtocolBufferException extends IOException { super(description); } + public InvalidProtocolBufferException(IOException e) { + super(e.getMessage(), e); + } + /** * Attaches an unfinished message to the exception to support best-effort * parsing in {@code Parser} interface. @@ -66,6 +70,14 @@ public class InvalidProtocolBufferException extends IOException { return unfinishedMessage; } + /** + * Unwraps the underlying {@link IOException} if this exception was caused by an I/O + * problem. Otherwise, returns {@code this}. + */ + public IOException unwrapIOException() { + return getCause() instanceof IOException ? (IOException) getCause() : this; + } + static InvalidProtocolBufferException truncatedMessage() { return new InvalidProtocolBufferException( "While parsing a protocol message, the input ended unexpectedly " + |