diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2016-01-29 13:51:05 -0800 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2016-01-29 13:51:05 -0800 |
commit | 5221dcbe479ed765d8103ed7601c69b6d8d6ca4f (patch) | |
tree | d48fed101cf2fc21e07d3034cc4e01c81f00bac2 /java | |
parent | cb3f428810456dbb31211ed421401b90fb3b6586 (diff) |
Integrate from google internal.
Java files are moved to un-do the hack in the prevous commit, which
moved the java files to the original position for integration.
Diffstat (limited to 'java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/AbstractMessage.java (renamed from java/src/main/java/com/google/protobuf/AbstractMessage.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java (renamed from java/src/main/java/com/google/protobuf/AbstractMessageLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/AbstractParser.java (renamed from java/src/main/java/com/google/protobuf/AbstractParser.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java (renamed from java/src/main/java/com/google/protobuf/AbstractProtobufList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java (renamed from java/src/main/java/com/google/protobuf/BlockingRpcChannel.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/BlockingService.java (renamed from java/src/main/java/com/google/protobuf/BlockingService.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/BooleanArrayList.java (renamed from java/src/main/java/com/google/protobuf/BooleanArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ByteString.java (renamed from java/src/main/java/com/google/protobuf/ByteString.java) | 364 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/CodedInputStream.java (renamed from java/src/main/java/com/google/protobuf/CodedInputStream.java) | 52 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/CodedOutputStream.java (renamed from java/src/main/java/com/google/protobuf/CodedOutputStream.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Descriptors.java (renamed from java/src/main/java/com/google/protobuf/Descriptors.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/DoubleArrayList.java (renamed from java/src/main/java/com/google/protobuf/DoubleArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/DynamicMessage.java (renamed from java/src/main/java/com/google/protobuf/DynamicMessage.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ExperimentalApi.java | 36 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Extension.java (renamed from java/src/main/java/com/google/protobuf/Extension.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ExtensionLite.java (renamed from java/src/main/java/com/google/protobuf/ExtensionLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java (renamed from java/src/main/java/com/google/protobuf/ExtensionRegistry.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java (renamed from java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/FieldSet.java (renamed from java/src/main/java/com/google/protobuf/FieldSet.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/FloatArrayList.java (renamed from java/src/main/java/com/google/protobuf/FloatArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/GeneratedMessage.java (renamed from java/src/main/java/com/google/protobuf/GeneratedMessage.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java (renamed from java/src/main/java/com/google/protobuf/GeneratedMessageLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/IntArrayList.java (renamed from java/src/main/java/com/google/protobuf/IntArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Internal.java (renamed from java/src/main/java/com/google/protobuf/Internal.java) | 60 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java (renamed from java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/LazyField.java (renamed from java/src/main/java/com/google/protobuf/LazyField.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/LazyFieldLite.java (renamed from java/src/main/java/com/google/protobuf/LazyFieldLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java (renamed from java/src/main/java/com/google/protobuf/LazyStringArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/LazyStringList.java (renamed from java/src/main/java/com/google/protobuf/LazyStringList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/LongArrayList.java (renamed from java/src/main/java/com/google/protobuf/LongArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MapEntry.java (renamed from java/src/main/java/com/google/protobuf/MapEntry.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MapEntryLite.java (renamed from java/src/main/java/com/google/protobuf/MapEntryLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MapField.java (renamed from java/src/main/java/com/google/protobuf/MapField.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MapFieldLite.java (renamed from java/src/main/java/com/google/protobuf/MapFieldLite.java) | 2 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Message.java (renamed from java/src/main/java/com/google/protobuf/Message.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MessageLite.java (renamed from java/src/main/java/com/google/protobuf/MessageLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java (renamed from java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MessageLiteToString.java (renamed from java/src/main/java/com/google/protobuf/MessageLiteToString.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java (renamed from java/src/main/java/com/google/protobuf/MessageOrBuilder.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MessageReflection.java (renamed from java/src/main/java/com/google/protobuf/MessageReflection.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/MutabilityOracle.java (renamed from java/src/main/java/com/google/protobuf/MutabilityOracle.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/NioByteString.java (renamed from java/src/main/java/com/google/protobuf/NioByteString.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Parser.java (renamed from java/src/main/java/com/google/protobuf/Parser.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java (renamed from java/src/main/java/com/google/protobuf/ProtobufArrayList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java (renamed from java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ProtocolStringList.java (renamed from java/src/main/java/com/google/protobuf/ProtocolStringList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java (renamed from java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/RopeByteString.java (renamed from java/src/main/java/com/google/protobuf/RopeByteString.java) | 6 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/RpcCallback.java (renamed from java/src/main/java/com/google/protobuf/RpcCallback.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/RpcChannel.java (renamed from java/src/main/java/com/google/protobuf/RpcChannel.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/RpcController.java (renamed from java/src/main/java/com/google/protobuf/RpcController.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/RpcUtil.java (renamed from java/src/main/java/com/google/protobuf/RpcUtil.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Service.java (renamed from java/src/main/java/com/google/protobuf/Service.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ServiceException.java (renamed from java/src/main/java/com/google/protobuf/ServiceException.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java (renamed from java/src/main/java/com/google/protobuf/SingleFieldBuilder.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/SmallSortedMap.java (renamed from java/src/main/java/com/google/protobuf/SmallSortedMap.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/TextFormat.java (renamed from java/src/main/java/com/google/protobuf/TextFormat.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java (renamed from java/src/main/java/com/google/protobuf/TextFormatEscaper.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java (renamed from java/src/main/java/com/google/protobuf/UninitializedMessageException.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java (renamed from java/src/main/java/com/google/protobuf/UnknownFieldSet.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java (renamed from java/src/main/java/com/google/protobuf/UnknownFieldSetLite.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java (renamed from java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java (renamed from java/src/main/java/com/google/protobuf/UnsafeByteStrings.java) | 16 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/Utf8.java (renamed from java/src/main/java/com/google/protobuf/Utf8.java) | 0 | ||||
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/WireFormat.java (renamed from java/src/main/java/com/google/protobuf/WireFormat.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java (renamed from java/src/test/java/com/google/protobuf/AbstractMessageTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/AnyTest.java (renamed from java/src/test/java/com/google/protobuf/AnyTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/BooleanArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java (renamed from java/src/test/java/com/google/protobuf/BoundedByteStringTest.java) | 4 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/ByteStringTest.java (renamed from java/src/test/java/com/google/protobuf/ByteStringTest.java) | 8 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java (renamed from java/src/test/java/com/google/protobuf/CheckUtf8Test.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java (renamed from java/src/test/java/com/google/protobuf/CodedInputStreamTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java (renamed from java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java (renamed from java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/DescriptorsTest.java (renamed from java/src/test/java/com/google/protobuf/DescriptorsTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/DoubleArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java (renamed from java/src/test/java/com/google/protobuf/DynamicMessageTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java (renamed from java/src/test/java/com/google/protobuf/FieldPresenceTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/FloatArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java (renamed from java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java (renamed from java/src/test/java/com/google/protobuf/GeneratedMessageTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/IntArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/IntArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java (renamed from java/src/test/java/com/google/protobuf/IsValidUtf8Test.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java (renamed from java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java (renamed from java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LazyFieldTest.java (renamed from java/src/test/java/com/google/protobuf/LazyFieldTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java (renamed from java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java (renamed from java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java (renamed from java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LiteTest.java (renamed from java/src/test/java/com/google/protobuf/LiteTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java (renamed from java/src/test/java/com/google/protobuf/LiteralByteStringTest.java) | 18 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LongArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/LongArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java (renamed from java/src/test/java/com/google/protobuf/MapForProto2LiteTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/MapForProto2Test.java (renamed from java/src/test/java/com/google/protobuf/MapForProto2Test.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/MapTest.java (renamed from java/src/test/java/com/google/protobuf/MapTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/MessageTest.java (renamed from java/src/test/java/com/google/protobuf/MessageTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java (renamed from java/src/test/java/com/google/protobuf/NestedBuildersTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/NioByteStringTest.java (renamed from java/src/test/java/com/google/protobuf/NioByteStringTest.java) | 17 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java | 212 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/ParserTest.java (renamed from java/src/test/java/com/google/protobuf/ParserTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java (renamed from java/src/test/java/com/google/protobuf/ProtobufArrayListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java (renamed from java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java (renamed from java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java (renamed from java/src/test/java/com/google/protobuf/RopeByteStringTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/ServiceTest.java (renamed from java/src/test/java/com/google/protobuf/ServiceTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java (renamed from java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java (renamed from java/src/test/java/com/google/protobuf/SmallSortedMapTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java (renamed from java/src/test/java/com/google/protobuf/TestBadIdentifiers.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/TestUtil.java (renamed from java/src/test/java/com/google/protobuf/TestUtil.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/TextFormatTest.java (renamed from java/src/test/java/com/google/protobuf/TextFormatTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java (renamed from java/src/test/java/com/google/protobuf/UnknownEnumValueTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java (renamed from java/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java (renamed from java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java (renamed from java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java (renamed from java/src/test/java/com/google/protobuf/WellKnownTypesTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/WireFormatTest.java (renamed from java/src/test/java/com/google/protobuf/WireFormatTest.java) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/any_test.proto (renamed from java/src/test/java/com/google/protobuf/any_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/field_presence_test.proto (renamed from java/src/test/java/com/google/protobuf/field_presence_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto (renamed from java/src/test/java/com/google/protobuf/lazy_fields_lite.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto (renamed from java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto (renamed from java/src/test/java/com/google/protobuf/map_for_proto2_lite_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto (renamed from java/src/test/java/com/google/protobuf/map_for_proto2_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto (renamed from java/src/test/java/com/google/protobuf/map_initialization_order_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/map_test.proto (renamed from java/src/test/java/com/google/protobuf/map_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto (renamed from java/src/test/java/com/google/protobuf/multiple_files_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto (renamed from java/src/test/java/com/google/protobuf/nested_builders_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/nested_extension.proto (renamed from java/src/test/java/com/google/protobuf/nested_extension.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto (renamed from java/src/test/java/com/google/protobuf/nested_extension_lite.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto (renamed from java/src/test/java/com/google/protobuf/non_nested_extension.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto (renamed from java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto (renamed from java/src/test/java/com/google/protobuf/outer_class_name_test.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto (renamed from java/src/test/java/com/google/protobuf/outer_class_name_test2.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto (renamed from java/src/test/java/com/google/protobuf/outer_class_name_test3.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto (renamed from java/src/test/java/com/google/protobuf/test_bad_identifiers.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto (renamed from java/src/test/java/com/google/protobuf/test_check_utf8.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto (renamed from java/src/test/java/com/google/protobuf/test_check_utf8_size.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/test_custom_options.proto (renamed from java/src/test/java/com/google/protobuf/test_custom_options.proto) | 0 | ||||
-rw-r--r-- | java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto (renamed from java/src/test/java/com/google/protobuf/test_extra_interfaces.proto) | 0 | ||||
-rw-r--r-- | java/lite/pom.xml | 4 | ||||
-rw-r--r-- | java/src/main/java/com/google/protobuf/BoundedByteString.java | 124 | ||||
-rw-r--r-- | java/src/main/java/com/google/protobuf/LiteralByteString.java | 267 | ||||
-rw-r--r-- | java/src/test/java/com/google/protobuf/ParseExceptionsTest.java | 211 | ||||
-rw-r--r-- | java/util/src/test/proto/com/google/protobuf/util/json_test.proto (renamed from java/util/src/test/java/com/google/protobuf/util/json_test.proto) | 0 |
144 files changed, 660 insertions, 741 deletions
diff --git a/java/src/main/java/com/google/protobuf/AbstractMessage.java b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index 9f418f2b..9f418f2b 100644 --- a/java/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java diff --git a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java b/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java index 12384983..12384983 100644 --- a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java diff --git a/java/src/main/java/com/google/protobuf/AbstractParser.java b/java/core/src/main/java/com/google/protobuf/AbstractParser.java index 1a4c6311..1a4c6311 100644 --- a/java/src/main/java/com/google/protobuf/AbstractParser.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractParser.java diff --git a/java/src/main/java/com/google/protobuf/AbstractProtobufList.java b/java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java index bb6446b2..bb6446b2 100644 --- a/java/src/main/java/com/google/protobuf/AbstractProtobufList.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java diff --git a/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java b/java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java index d535efb9..d535efb9 100644 --- a/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java +++ b/java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java diff --git a/java/src/main/java/com/google/protobuf/BlockingService.java b/java/core/src/main/java/com/google/protobuf/BlockingService.java index d01f0b8f..d01f0b8f 100644 --- a/java/src/main/java/com/google/protobuf/BlockingService.java +++ b/java/core/src/main/java/com/google/protobuf/BlockingService.java diff --git a/java/src/main/java/com/google/protobuf/BooleanArrayList.java b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java index 70e042f5..70e042f5 100644 --- a/java/src/main/java/com/google/protobuf/BooleanArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java diff --git a/java/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 68f20d51..305236f3 100644 --- a/java/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -1,38 +1,13 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Copyright 2007 Google Inc. All rights reserved. package com.google.protobuf; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; import java.io.OutputStream; import java.io.Serializable; import java.io.UnsupportedEncodingException; @@ -41,6 +16,7 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; @@ -81,7 +57,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { /** * Empty {@code ByteString}. */ - public static final ByteString EMPTY = new LiteralByteString(new byte[0]); + public static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY); /** * Cached hash value. Intentionally accessed via a data race, which @@ -258,6 +234,24 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { public static ByteString copyFrom(byte[] bytes) { return copyFrom(bytes, 0, bytes.length); } + + /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal only + * usage to force a classload of ByteString before LiteralByteString. + */ + static ByteString wrap(byte[] bytes) { + // TODO(dweis): Return EMPTY when bytes are empty to reduce allocations? + return new LiteralByteString(bytes); + } + + /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal only + * usage to force a classload of ByteString before BoundedByteString and + * LiteralByteString. + */ + static ByteString wrap(byte[] bytes, int offset, int length) { + return new BoundedByteString(bytes, offset, length); + } /** * Copies the next {@code size} bytes from a {@code java.nio.ByteBuffer} into @@ -1149,4 +1143,314 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { return String.format("<ByteString@%s size=%d>", Integer.toHexString(System.identityHashCode(this)), size()); } + + /** + * This class implements a {@link com.google.protobuf.ByteString} backed by a + * single array of bytes, contiguous in memory. It supports substring by + * pointing to only a sub-range of the underlying byte array, meaning that a + * substring will reference the full byte-array of the string it's made from, + * exactly as with {@link String}. + * + * @author carlanton@google.com (Carl Haverl) + */ + // Keep this class private to avoid deadlocks in classloading across threads as ByteString's + // static initializer loads LiteralByteString and another thread loads LiteralByteString. + private static class LiteralByteString extends ByteString.LeafByteString { + private static final long serialVersionUID = 1L; + + protected final byte[] bytes; + + /** + * Creates a {@code LiteralByteString} backed by the given array, without + * copying. + * + * @param bytes array to wrap + */ + LiteralByteString(byte[] bytes) { + this.bytes = bytes; + } + + @Override + public byte byteAt(int index) { + // Unlike most methods in this class, this one is a direct implementation + // ignoring the potential offset because we need to do range-checking in the + // substring case anyway. + return bytes[index]; + } + + @Override + public int size() { + return bytes.length; + } + + // ================================================================= + // ByteString -> substring + + @Override + public final ByteString substring(int beginIndex, int endIndex) { + final int length = checkRange(beginIndex, endIndex, size()); + + if (length == 0) { + return ByteString.EMPTY; + } + + return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length); + } + + // ================================================================= + // ByteString -> byte[] + + @Override + protected void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + // Optimized form, not for subclasses, since we don't call + // getOffsetIntoBytes() or check the 'numberToCopy' parameter. + // TODO(nathanmittler): Is not calling getOffsetIntoBytes really saving that much? + System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy); + } + + @Override + public final void copyTo(ByteBuffer target) { + target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes + } + + @Override + public final ByteBuffer asReadOnlyByteBuffer() { + return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer(); + } + + @Override + public final List<ByteBuffer> asReadOnlyByteBufferList() { + return Collections.singletonList(asReadOnlyByteBuffer()); + } + + @Override + public final void writeTo(OutputStream outputStream) throws IOException { + outputStream.write(toByteArray()); + } + + @Override + final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite) + throws IOException { + outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite); + } + + @Override + protected final String toStringInternal(Charset charset) { + return new String(bytes, getOffsetIntoBytes(), size(), charset); + } + + // ================================================================= + // UTF-8 decoding + + @Override + public final boolean isValidUtf8() { + int offset = getOffsetIntoBytes(); + return Utf8.isValidUtf8(bytes, offset, offset + size()); + } + + @Override + protected final int partialIsValidUtf8(int state, int offset, int length) { + int index = getOffsetIntoBytes() + offset; + return Utf8.partialIsValidUtf8(state, bytes, index, index + length); + } + + // ================================================================= + // equals() and hashCode() + + @Override + public final boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof ByteString)) { + return false; + } + + if (size() != ((ByteString) other).size()) { + return false; + } + if (size() == 0) { + return true; + } + + if (other instanceof LiteralByteString) { + LiteralByteString otherAsLiteral = (LiteralByteString) other; + // If we know the hash codes and they are not equal, we know the byte + // strings are not equal. + int thisHash = peekCachedHashCode(); + int thatHash = otherAsLiteral.peekCachedHashCode(); + if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) { + return false; + } + + return equalsRange((LiteralByteString) other, 0, size()); + } else { + // RopeByteString and NioByteString. + return other.equals(this); + } + } + + /** + * Check equality of the substring of given length of this object starting at + * zero with another {@code LiteralByteString} substring starting at offset. + * + * @param other what to compare a substring in + * @param offset offset into other + * @param length number of bytes to compare + * @return true for equality of substrings, else false. + */ + @Override + final boolean equalsRange(ByteString other, int offset, int length) { + if (length > other.size()) { + throw new IllegalArgumentException("Length too large: " + length + size()); + } + if (offset + length > other.size()) { + throw new IllegalArgumentException( + "Ran off end of other: " + offset + ", " + length + ", " + other.size()); + } + + if (other instanceof LiteralByteString) { + LiteralByteString lbsOther = (LiteralByteString) other; + byte[] thisBytes = bytes; + byte[] otherBytes = lbsOther.bytes; + int thisLimit = getOffsetIntoBytes() + length; + for ( + int thisIndex = getOffsetIntoBytes(), + otherIndex = lbsOther.getOffsetIntoBytes() + offset; + (thisIndex < thisLimit); ++thisIndex, ++otherIndex) { + if (thisBytes[thisIndex] != otherBytes[otherIndex]) { + return false; + } + } + return true; + } + + return other.substring(offset, offset + length).equals(substring(0, length)); + } + + @Override + protected final int partialHash(int h, int offset, int length) { + return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); + } + + // ================================================================= + // Input stream + + @Override + public final InputStream newInput() { + return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy + } + + @Override + public final CodedInputStream newCodedInput() { + // We trust CodedInputStream not to modify the bytes, or to give anyone + // else access to them. + return CodedInputStream.newInstance( + bytes, getOffsetIntoBytes(), size(), true /* bufferIsImmutable */); + } + + // ================================================================= + // Internal methods + + /** + * Offset into {@code bytes[]} to use, non-zero for substrings. + * + * @return always 0 for this class + */ + protected int getOffsetIntoBytes() { + return 0; + } + } + + /** + * This class is used to represent the substring of a {@link ByteString} over a + * single byte array. In terms of the public API of {@link ByteString}, you end + * up here by calling {@link ByteString#copyFrom(byte[])} followed by {@link + * ByteString#substring(int, int)}. + * + * <p>This class contains most of the overhead involved in creating a substring + * from a {@link LiteralByteString}. The overhead involves some range-checking + * and two extra fields. + * + * @author carlanton@google.com (Carl Haverl) + */ + // Keep this class private to avoid deadlocks in classloading across threads as ByteString's + // static initializer loads LiteralByteString and another thread loads BoundedByteString. + private static final class BoundedByteString extends LiteralByteString { + + private final int bytesOffset; + private final int bytesLength; + + /** + * Creates a {@code BoundedByteString} backed by the sub-range of given array, + * without copying. + * + * @param bytes array to wrap + * @param offset index to first byte to use in bytes + * @param length number of bytes to use from bytes + * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0}, + * or if {@code offset + length > + * bytes.length}. + */ + BoundedByteString(byte[] bytes, int offset, int length) { + super(bytes); + checkRange(offset, offset + length, bytes.length); + + this.bytesOffset = offset; + this.bytesLength = length; + } + + /** + * Gets the byte at the given index. + * Throws {@link ArrayIndexOutOfBoundsException} + * for backwards-compatibility reasons although it would more properly be + * {@link IndexOutOfBoundsException}. + * + * @param index index of byte + * @return the value + * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size + */ + @Override + public byte byteAt(int index) { + // We must check the index ourselves as we cannot rely on Java array index + // checking for substrings. + checkIndex(index, size()); + return bytes[bytesOffset + index]; + } + + @Override + public int size() { + return bytesLength; + } + + @Override + protected int getOffsetIntoBytes() { + return bytesOffset; + } + + // ================================================================= + // ByteString -> byte[] + + @Override + protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset, + int numberToCopy) { + System.arraycopy(bytes, getOffsetIntoBytes() + sourceOffset, target, + targetOffset, numberToCopy); + } + + // ================================================================= + // Serializable + + private static final long serialVersionUID = 1L; + + Object writeReplace() { + return ByteString.wrap(toByteArray()); + } + + private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { + throw new InvalidObjectException( + "BoundedByteStream instances are not to be serialized directly"); + } + } } diff --git a/java/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index adc91536..b3118ee0 100644 --- a/java/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -70,7 +70,15 @@ public final class CodedInputStream { */ public static CodedInputStream newInstance(final byte[] buf, final int off, final int len) { - CodedInputStream result = new CodedInputStream(buf, off, len); + return newInstance(buf, off, len, false); + } + + /** + * Create a new CodedInputStream wrapping the given byte array slice. + */ + public static CodedInputStream newInstance(final byte[] buf, final int off, + final int len, boolean bufferIsImmutable) { + CodedInputStream result = new CodedInputStream(buf, off, len, bufferIsImmutable); try { // Some uses of CodedInputStream can be more efficient if they know // exactly how many bytes are available. By pushing the end point of the @@ -113,31 +121,6 @@ public final class CodedInputStream { } } - /** - * Create a new CodedInputStream wrapping a LiteralByteString. - */ - static CodedInputStream newInstance(LiteralByteString byteString) { - CodedInputStream result = new CodedInputStream(byteString); - try { - // Some uses of CodedInputStream can be more efficient if they know - // exactly how many bytes are available. By pushing the end point of the - // buffer as a limit, we allow them to get this information via - // getBytesUntilLimit(). Pushing a limit that we know is at the end of - // the stream can never hurt, since we can never past that point anyway. - result.pushLimit(byteString.size()); - } catch (InvalidProtocolBufferException ex) { - // The only reason pushLimit() might throw an exception here is if len - // is negative. Normally pushLimit()'s parameter comes directly off the - // wire, so it's important to catch exceptions in case of corrupt or - // malicious data. However, in this case, we expect that len is not a - // user-supplied value, so we can assume that it being negative indicates - // a programming error. Therefore, throwing an unchecked exception is - // appropriate. - throw new IllegalArgumentException(ex); - } - return result; - } - // ----------------------------------------------------------------- /** @@ -506,7 +489,7 @@ public final class CodedInputStream { // Fast path: We already have the bytes in a contiguous buffer, so // just copy directly from it. final ByteString result = bufferIsImmutable && enableAliasing - ? new BoundedByteString(buffer, bufferPos, size) + ? ByteString.wrap(buffer, bufferPos, size) : ByteString.copyFrom(buffer, bufferPos, size); bufferPos += size; return result; @@ -514,7 +497,7 @@ public final class CodedInputStream { return ByteString.EMPTY; } else { // Slow path: Build a byte array first then copy it. - return new LiteralByteString(readRawBytesSlowPath(size)); + return ByteString.wrap(readRawBytesSlowPath(size)); } } @@ -886,13 +869,13 @@ public final class CodedInputStream { private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB private static final int BUFFER_SIZE = 4096; - private CodedInputStream(final byte[] buffer, final int off, final int len) { + private CodedInputStream(final byte[] buffer, final int off, final int len, boolean bufferIsImmutable) { this.buffer = buffer; bufferSize = off + len; bufferPos = off; totalBytesRetired = -off; input = null; - bufferIsImmutable = false; + this.bufferIsImmutable = bufferIsImmutable; } private CodedInputStream(final InputStream input) { @@ -904,15 +887,6 @@ public final class CodedInputStream { bufferIsImmutable = false; } - private CodedInputStream(final LiteralByteString byteString) { - buffer = byteString.bytes; - bufferPos = byteString.getOffsetIntoBytes(); - bufferSize = bufferPos + byteString.size(); - totalBytesRetired = -bufferPos; - input = null; - bufferIsImmutable = true; - } - public void enableAliasing(boolean enabled) { this.enableAliasing = enabled; } diff --git a/java/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index d8ebad21..d8ebad21 100644 --- a/java/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java diff --git a/java/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index 5e15cfbe..5e15cfbe 100644 --- a/java/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java diff --git a/java/src/main/java/com/google/protobuf/DoubleArrayList.java b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java index bcc9d6ee..bcc9d6ee 100644 --- a/java/src/main/java/com/google/protobuf/DoubleArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java diff --git a/java/src/main/java/com/google/protobuf/DynamicMessage.java b/java/core/src/main/java/com/google/protobuf/DynamicMessage.java index 3ea1b688..3ea1b688 100644 --- a/java/src/main/java/com/google/protobuf/DynamicMessage.java +++ b/java/core/src/main/java/com/google/protobuf/DynamicMessage.java diff --git a/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java b/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java new file mode 100644 index 00000000..6f41fb81 --- /dev/null +++ b/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java @@ -0,0 +1,36 @@ +package com.google.protobuf; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates a public API that can change at any time, and has no guarantee of API stability and + * backward-compatibility. + * + * <p>Usage guidelines: + * <ol> + * <li>This annotation is used only on public API. Internal interfaces should not use it.</li> + * <li>This annotation should only be added to new APIs. Adding it to an existing API is + * considered API-breaking.</li> + * <li>Removing this annotation from an API gives it stable status.</li> + * </ol> + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE}) +@Documented +public @interface ExperimentalApi { + /** + * Context information such as links to discussion thread, tracking issue etc. + */ + String value() default ""; +} + diff --git a/java/src/main/java/com/google/protobuf/Extension.java b/java/core/src/main/java/com/google/protobuf/Extension.java index 68d29f33..68d29f33 100644 --- a/java/src/main/java/com/google/protobuf/Extension.java +++ b/java/core/src/main/java/com/google/protobuf/Extension.java diff --git a/java/src/main/java/com/google/protobuf/ExtensionLite.java b/java/core/src/main/java/com/google/protobuf/ExtensionLite.java index f8f5bd2c..f8f5bd2c 100644 --- a/java/src/main/java/com/google/protobuf/ExtensionLite.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionLite.java diff --git a/java/src/main/java/com/google/protobuf/ExtensionRegistry.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java index 0067392f..0067392f 100644 --- a/java/src/main/java/com/google/protobuf/ExtensionRegistry.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java diff --git a/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 65cf7385..65cf7385 100644 --- a/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java diff --git a/java/src/main/java/com/google/protobuf/FieldSet.java b/java/core/src/main/java/com/google/protobuf/FieldSet.java index 47924b65..47924b65 100644 --- a/java/src/main/java/com/google/protobuf/FieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/FieldSet.java diff --git a/java/src/main/java/com/google/protobuf/FloatArrayList.java b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java index 033b5eed..033b5eed 100644 --- a/java/src/main/java/com/google/protobuf/FloatArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java diff --git a/java/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java index ceb97a4e..ceb97a4e 100644 --- a/java/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java diff --git a/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index 81e1862c..81e1862c 100644 --- a/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java diff --git a/java/src/main/java/com/google/protobuf/IntArrayList.java b/java/core/src/main/java/com/google/protobuf/IntArrayList.java index f4e68ed8..f4e68ed8 100644 --- a/java/src/main/java/com/google/protobuf/IntArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/IntArrayList.java diff --git a/java/src/main/java/com/google/protobuf/Internal.java b/java/core/src/main/java/com/google/protobuf/Internal.java index 11901998..dca5f23b 100644 --- a/java/src/main/java/com/google/protobuf/Internal.java +++ b/java/core/src/main/java/com/google/protobuf/Internal.java @@ -1,32 +1,4 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Copyright 2007 Google Inc. All rights reserved. package com.google.protobuf; @@ -283,10 +255,32 @@ public class Internal { // ByteString with the same content. This is to ensure that the generated // hashCode() method will return the same value as the pure reflection // based hashCode() method. - return LiteralByteString.hashCode(bytes); + return Internal.hashCode(bytes, 0, bytes.length); + } + + /** + * Helper method for implementing {@link LiteralByteString#hashCode()}. + */ + static int hashCode(byte[] bytes, int offset, int length) { + // The hash code for a byte array should be the same as the hash code for a + // ByteString with the same content. This is to ensure that the generated + // hashCode() method will return the same value as the pure reflection + // based hashCode() method. + int h = Internal.partialHash(length, bytes, offset, length); + return h == 0 ? 1 : h; } /** + * Helper method for continuously hashing bytes. + */ + static int partialHash(int h, byte[] bytes, int offset, int length) { + for (int i = offset; i < offset + length; i++) { + h = h * 31 + bytes[i]; + } + return h; + } + + /** * Helper method for implementing {@link Message#equals(Object)} for bytes * field. */ @@ -337,8 +331,7 @@ public class Internal { public static int hashCodeByteBuffer(ByteBuffer bytes) { if (bytes.hasArray()) { // Fast path. - int h = LiteralByteString.hashCode(bytes.capacity(), bytes.array(), - bytes.arrayOffset(), bytes.capacity()); + int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity()); return h == 0 ? 1 : h; } else { // Read the data into a temporary byte array before calculating the @@ -353,7 +346,7 @@ public class Internal { final int length = duplicated.remaining() <= bufferSize ? duplicated.remaining() : bufferSize; duplicated.get(buffer, 0, length); - h = LiteralByteString.hashCode(h, buffer, 0, length); + h = partialHash(h, buffer, 0, length); } return h == 0 ? 1 : h; } @@ -385,7 +378,6 @@ public class Internal { public static final CodedInputStream EMPTY_CODED_INPUT_STREAM = CodedInputStream.newInstance(EMPTY_BYTE_ARRAY); - /** * Provides an immutable view of {@code List<T>} around a {@code List<F>}. * diff --git a/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index 85ce7b24..85ce7b24 100644 --- a/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java diff --git a/java/src/main/java/com/google/protobuf/LazyField.java b/java/core/src/main/java/com/google/protobuf/LazyField.java index 5e0a485c..5e0a485c 100644 --- a/java/src/main/java/com/google/protobuf/LazyField.java +++ b/java/core/src/main/java/com/google/protobuf/LazyField.java diff --git a/java/src/main/java/com/google/protobuf/LazyFieldLite.java b/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java index eea1fe3c..eea1fe3c 100644 --- a/java/src/main/java/com/google/protobuf/LazyFieldLite.java +++ b/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java diff --git a/java/src/main/java/com/google/protobuf/LazyStringArrayList.java b/java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java index c3be3cca..c3be3cca 100644 --- a/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java diff --git a/java/src/main/java/com/google/protobuf/LazyStringList.java b/java/core/src/main/java/com/google/protobuf/LazyStringList.java index 3eeedca1..3eeedca1 100644 --- a/java/src/main/java/com/google/protobuf/LazyStringList.java +++ b/java/core/src/main/java/com/google/protobuf/LazyStringList.java diff --git a/java/src/main/java/com/google/protobuf/LongArrayList.java b/java/core/src/main/java/com/google/protobuf/LongArrayList.java index ebe62029..ebe62029 100644 --- a/java/src/main/java/com/google/protobuf/LongArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/LongArrayList.java diff --git a/java/src/main/java/com/google/protobuf/MapEntry.java b/java/core/src/main/java/com/google/protobuf/MapEntry.java index 31414bb4..31414bb4 100644 --- a/java/src/main/java/com/google/protobuf/MapEntry.java +++ b/java/core/src/main/java/com/google/protobuf/MapEntry.java diff --git a/java/src/main/java/com/google/protobuf/MapEntryLite.java b/java/core/src/main/java/com/google/protobuf/MapEntryLite.java index bcffa946..bcffa946 100644 --- a/java/src/main/java/com/google/protobuf/MapEntryLite.java +++ b/java/core/src/main/java/com/google/protobuf/MapEntryLite.java diff --git a/java/src/main/java/com/google/protobuf/MapField.java b/java/core/src/main/java/com/google/protobuf/MapField.java index b290993c..b290993c 100644 --- a/java/src/main/java/com/google/protobuf/MapField.java +++ b/java/core/src/main/java/com/google/protobuf/MapField.java diff --git a/java/src/main/java/com/google/protobuf/MapFieldLite.java b/java/core/src/main/java/com/google/protobuf/MapFieldLite.java index 16d3e6d2..960b6339 100644 --- a/java/src/main/java/com/google/protobuf/MapFieldLite.java +++ b/java/core/src/main/java/com/google/protobuf/MapFieldLite.java @@ -136,7 +136,7 @@ public final class MapFieldLite<K, V> implements MutabilityOracle { private static int calculateHashCodeForObject(Object a) { if (a instanceof byte[]) { - return LiteralByteString.hashCode((byte[]) a); + return Internal.hashCode((byte[]) a); } // Enums should be stored as integers internally. if (a instanceof EnumLite) { diff --git a/java/src/main/java/com/google/protobuf/Message.java b/java/core/src/main/java/com/google/protobuf/Message.java index 9516d71f..9516d71f 100644 --- a/java/src/main/java/com/google/protobuf/Message.java +++ b/java/core/src/main/java/com/google/protobuf/Message.java diff --git a/java/src/main/java/com/google/protobuf/MessageLite.java b/java/core/src/main/java/com/google/protobuf/MessageLite.java index 798b7943..798b7943 100644 --- a/java/src/main/java/com/google/protobuf/MessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/MessageLite.java diff --git a/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java b/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java index 818386ce..818386ce 100644 --- a/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java diff --git a/java/src/main/java/com/google/protobuf/MessageLiteToString.java b/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java index e69de29b..e69de29b 100644 --- a/java/src/main/java/com/google/protobuf/MessageLiteToString.java +++ b/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java diff --git a/java/src/main/java/com/google/protobuf/MessageOrBuilder.java b/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java index f0fc4859..f0fc4859 100644 --- a/java/src/main/java/com/google/protobuf/MessageOrBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java diff --git a/java/src/main/java/com/google/protobuf/MessageReflection.java b/java/core/src/main/java/com/google/protobuf/MessageReflection.java index de4bfd3e..de4bfd3e 100644 --- a/java/src/main/java/com/google/protobuf/MessageReflection.java +++ b/java/core/src/main/java/com/google/protobuf/MessageReflection.java diff --git a/java/src/main/java/com/google/protobuf/MutabilityOracle.java b/java/core/src/main/java/com/google/protobuf/MutabilityOracle.java index 82b723c9..82b723c9 100644 --- a/java/src/main/java/com/google/protobuf/MutabilityOracle.java +++ b/java/core/src/main/java/com/google/protobuf/MutabilityOracle.java diff --git a/java/src/main/java/com/google/protobuf/NioByteString.java b/java/core/src/main/java/com/google/protobuf/NioByteString.java index f71e41b2..f71e41b2 100644 --- a/java/src/main/java/com/google/protobuf/NioByteString.java +++ b/java/core/src/main/java/com/google/protobuf/NioByteString.java diff --git a/java/src/main/java/com/google/protobuf/Parser.java b/java/core/src/main/java/com/google/protobuf/Parser.java index 3fa11c3b..3fa11c3b 100644 --- a/java/src/main/java/com/google/protobuf/Parser.java +++ b/java/core/src/main/java/com/google/protobuf/Parser.java diff --git a/java/src/main/java/com/google/protobuf/ProtobufArrayList.java b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java index d2f82ac5..d2f82ac5 100644 --- a/java/src/main/java/com/google/protobuf/ProtobufArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java diff --git a/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java b/java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java index 0c8df989..0c8df989 100644 --- a/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java +++ b/java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java diff --git a/java/src/main/java/com/google/protobuf/ProtocolStringList.java b/java/core/src/main/java/com/google/protobuf/ProtocolStringList.java index d553b41e..d553b41e 100644 --- a/java/src/main/java/com/google/protobuf/ProtocolStringList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtocolStringList.java diff --git a/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java index f91cdbce..f91cdbce 100644 --- a/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java diff --git a/java/src/main/java/com/google/protobuf/RopeByteString.java b/java/core/src/main/java/com/google/protobuf/RopeByteString.java index 6e8eb724..469c90c2 100644 --- a/java/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/core/src/main/java/com/google/protobuf/RopeByteString.java @@ -213,14 +213,14 @@ final class RopeByteString extends ByteString { * @param right string on the right * @return string formed by copying data bytes */ - private static LiteralByteString concatenateBytes(ByteString left, + private static ByteString concatenateBytes(ByteString left, ByteString right) { int leftSize = left.size(); int rightSize = right.size(); byte[] bytes = new byte[leftSize + rightSize]; left.copyTo(bytes, 0, 0, leftSize); right.copyTo(bytes, 0, leftSize, rightSize); - return new LiteralByteString(bytes); // Constructor wraps bytes + return ByteString.wrap(bytes); // Constructor wraps bytes } /** @@ -735,7 +735,7 @@ final class RopeByteString extends ByteString { private static final long serialVersionUID = 1L; Object writeReplace() { - return new LiteralByteString(toByteArray()); + return ByteString.wrap(toByteArray()); } private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { diff --git a/java/src/main/java/com/google/protobuf/RpcCallback.java b/java/core/src/main/java/com/google/protobuf/RpcCallback.java index 10752968..10752968 100644 --- a/java/src/main/java/com/google/protobuf/RpcCallback.java +++ b/java/core/src/main/java/com/google/protobuf/RpcCallback.java diff --git a/java/src/main/java/com/google/protobuf/RpcChannel.java b/java/core/src/main/java/com/google/protobuf/RpcChannel.java index f272f4ad..f272f4ad 100644 --- a/java/src/main/java/com/google/protobuf/RpcChannel.java +++ b/java/core/src/main/java/com/google/protobuf/RpcChannel.java diff --git a/java/src/main/java/com/google/protobuf/RpcController.java b/java/core/src/main/java/com/google/protobuf/RpcController.java index a92dd7be..a92dd7be 100644 --- a/java/src/main/java/com/google/protobuf/RpcController.java +++ b/java/core/src/main/java/com/google/protobuf/RpcController.java diff --git a/java/src/main/java/com/google/protobuf/RpcUtil.java b/java/core/src/main/java/com/google/protobuf/RpcUtil.java index 694b8d13..694b8d13 100644 --- a/java/src/main/java/com/google/protobuf/RpcUtil.java +++ b/java/core/src/main/java/com/google/protobuf/RpcUtil.java diff --git a/java/src/main/java/com/google/protobuf/Service.java b/java/core/src/main/java/com/google/protobuf/Service.java index ba7b033e..ba7b033e 100644 --- a/java/src/main/java/com/google/protobuf/Service.java +++ b/java/core/src/main/java/com/google/protobuf/Service.java diff --git a/java/src/main/java/com/google/protobuf/ServiceException.java b/java/core/src/main/java/com/google/protobuf/ServiceException.java index 00d57075..00d57075 100644 --- a/java/src/main/java/com/google/protobuf/ServiceException.java +++ b/java/core/src/main/java/com/google/protobuf/ServiceException.java diff --git a/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java b/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java index aba65e32..aba65e32 100644 --- a/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java diff --git a/java/src/main/java/com/google/protobuf/SmallSortedMap.java b/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java index 0674d2e2..0674d2e2 100644 --- a/java/src/main/java/com/google/protobuf/SmallSortedMap.java +++ b/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java diff --git a/java/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index c99b5285..c99b5285 100644 --- a/java/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java diff --git a/java/src/main/java/com/google/protobuf/TextFormatEscaper.java b/java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java index e69de29b..e69de29b 100644 --- a/java/src/main/java/com/google/protobuf/TextFormatEscaper.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java diff --git a/java/src/main/java/com/google/protobuf/UninitializedMessageException.java b/java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java index 5714c063..5714c063 100644 --- a/java/src/main/java/com/google/protobuf/UninitializedMessageException.java +++ b/java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java diff --git a/java/src/main/java/com/google/protobuf/UnknownFieldSet.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java index 7cd2250e..7cd2250e 100644 --- a/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java diff --git a/java/src/main/java/com/google/protobuf/UnknownFieldSetLite.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java index 435ad4d4..435ad4d4 100644 --- a/java/src/main/java/com/google/protobuf/UnknownFieldSetLite.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java diff --git a/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java b/java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java index 5257c5a2..5257c5a2 100644 --- a/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +++ b/java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java diff --git a/java/src/main/java/com/google/protobuf/UnsafeByteStrings.java b/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java index c1997515..8806395c 100644 --- a/java/src/main/java/com/google/protobuf/UnsafeByteStrings.java +++ b/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java @@ -33,15 +33,18 @@ package com.google.protobuf; import java.nio.ByteBuffer; /** - * Provides unsafe factory methods for {@link ByteString} instances. + * Provides a number of unsafe byte operations to be used by advanced applications with high + * performance requirements. These methods are referred to as "unsafe" due to the fact that they + * potentially expose the backing buffer of a {@link ByteString} to the application. * * <p><strong>DISCLAIMER:</strong> The methods in this class should only be called if it is * guaranteed that the the buffer backing the {@link ByteString} will never change! Mutation of a * {@link ByteString} can lead to unexpected and undesirable consequences in your application, * and will likely be difficult to debug. Proceed with caution! */ -public final class UnsafeByteStrings { - private UnsafeByteStrings() {} +@ExperimentalApi +public final class UnsafeByteOperations { + private UnsafeByteOperations() {} /** * An unsafe operation that returns a {@link ByteString} that is backed by the provided buffer. @@ -50,6 +53,11 @@ public final class UnsafeByteStrings { * @return a {@link ByteString} backed by the provided buffer. */ public static ByteString unsafeWrap(ByteBuffer buffer) { - return new NioByteString(buffer); + if (buffer.hasArray()) { + final int offset = buffer.arrayOffset(); + return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); + } else { + return new NioByteString(buffer); + } } } diff --git a/java/src/main/java/com/google/protobuf/Utf8.java b/java/core/src/main/java/com/google/protobuf/Utf8.java index 48c7e9e6..48c7e9e6 100644 --- a/java/src/main/java/com/google/protobuf/Utf8.java +++ b/java/core/src/main/java/com/google/protobuf/Utf8.java diff --git a/java/src/main/java/com/google/protobuf/WireFormat.java b/java/core/src/main/java/com/google/protobuf/WireFormat.java index 8dbe1ae3..8dbe1ae3 100644 --- a/java/src/main/java/com/google/protobuf/WireFormat.java +++ b/java/core/src/main/java/com/google/protobuf/WireFormat.java diff --git a/java/src/test/java/com/google/protobuf/AbstractMessageTest.java b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java index d964ef59..d964ef59 100644 --- a/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java diff --git a/java/src/test/java/com/google/protobuf/AnyTest.java b/java/core/src/test/java/com/google/protobuf/AnyTest.java index e169f69d..e169f69d 100644 --- a/java/src/test/java/com/google/protobuf/AnyTest.java +++ b/java/core/src/test/java/com/google/protobuf/AnyTest.java diff --git a/java/src/test/java/com/google/protobuf/BooleanArrayListTest.java b/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java index b8ad1fe4..b8ad1fe4 100644 --- a/java/src/test/java/com/google/protobuf/BooleanArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java b/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java index 2dfae2e6..7a8a0a5e 100644 --- a/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java @@ -62,7 +62,7 @@ public class BoundedByteStringTest extends LiteralByteStringTest { @Override public void testToString() throws UnsupportedEncodingException { String testString = "I love unicode \u1234\u5678 characters"; - LiteralByteString unicode = new LiteralByteString(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); ByteString chopped = unicode.substring(2, unicode.size() - 6); assertEquals(classUnderTest + ".substring() must have the expected type", classUnderTest, getActualClassName(chopped)); @@ -75,7 +75,7 @@ public class BoundedByteStringTest extends LiteralByteStringTest { @Override public void testCharsetToString() { String testString = "I love unicode \u1234\u5678 characters"; - LiteralByteString unicode = new LiteralByteString(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); ByteString chopped = unicode.substring(2, unicode.size() - 6); assertEquals(classUnderTest + ".substring() must have the expected type", classUnderTest, getActualClassName(chopped)); diff --git a/java/src/test/java/com/google/protobuf/ByteStringTest.java b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java index 36f64251..5267c160 100644 --- a/java/src/test/java/com/google/protobuf/ByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java @@ -655,11 +655,11 @@ public class ByteStringTest extends TestCase { // trees of empty leaves, to make a string that will fail this test. for (int i = 1; i < duo.size(); ++i) { assertTrue("Substrings of size() < 2 must not be RopeByteStrings", - duo.substring(i - 1, i) instanceof LiteralByteString); + duo.substring(i - 1, i) instanceof ByteString.LeafByteString); } for (int i = 1; i < quintet.size(); ++i) { assertTrue("Substrings of size() < 2 must not be RopeByteStrings", - quintet.substring(i - 1, i) instanceof LiteralByteString); + quintet.substring(i - 1, i) instanceof ByteString.LeafByteString); } } @@ -724,7 +724,7 @@ public class ByteStringTest extends TestCase { } data1[1] = (byte) 11; // Test LiteralByteString.writeTo(OutputStream,int,int) - LiteralByteString left = new LiteralByteString(data1); + ByteString left = ByteString.wrap(data1); byte[] result = substringUsingWriteTo(left, 1, 1); assertEquals(1, result.length); assertEquals((byte) 11, result[0]); @@ -733,7 +733,7 @@ public class ByteStringTest extends TestCase { for (int i = 0; i < data1.length; i++) { data2[i] = (byte) 2; } - LiteralByteString right = new LiteralByteString(data2); + ByteString right = ByteString.wrap(data2); // Concatenate two ByteStrings to create a RopeByteString. ByteString root = left.concat(right); // Make sure we are actually testing a RopeByteString with a simple tree diff --git a/java/src/test/java/com/google/protobuf/CheckUtf8Test.java b/java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java index 3d6381c9..3d6381c9 100644 --- a/java/src/test/java/com/google/protobuf/CheckUtf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java diff --git a/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java index 18d8142c..18d8142c 100644 --- a/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java diff --git a/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 6018ea55..6018ea55 100644 --- a/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java diff --git a/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java b/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java index e7905f79..e7905f79 100644 --- a/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +++ b/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java diff --git a/java/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index 82ff34af..82ff34af 100644 --- a/java/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java diff --git a/java/src/test/java/com/google/protobuf/DoubleArrayListTest.java b/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java index d3deaa07..d3deaa07 100644 --- a/java/src/test/java/com/google/protobuf/DoubleArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/DynamicMessageTest.java b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java index 55144e7c..55144e7c 100644 --- a/java/src/test/java/com/google/protobuf/DynamicMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java diff --git a/java/src/test/java/com/google/protobuf/FieldPresenceTest.java b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java index eaeec0b8..eaeec0b8 100644 --- a/java/src/test/java/com/google/protobuf/FieldPresenceTest.java +++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java diff --git a/java/src/test/java/com/google/protobuf/FloatArrayListTest.java b/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java index a5e65424..a5e65424 100644 --- a/java/src/test/java/com/google/protobuf/FloatArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java b/java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java index a92ba374..a92ba374 100644 --- a/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +++ b/java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java diff --git a/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 70812b95..70812b95 100644 --- a/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java diff --git a/java/src/test/java/com/google/protobuf/IntArrayListTest.java b/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java index 3733eb30..3733eb30 100644 --- a/java/src/test/java/com/google/protobuf/IntArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java b/java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java index 8751baae..8751baae 100644 --- a/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java diff --git a/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java b/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java index 321669f3..321669f3 100644 --- a/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java diff --git a/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java b/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java index 211b5697..211b5697 100644 --- a/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java diff --git a/java/src/test/java/com/google/protobuf/LazyFieldTest.java b/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java index 2b900065..2b900065 100644 --- a/java/src/test/java/com/google/protobuf/LazyFieldTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java diff --git a/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java b/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java index afe0fffd..afe0fffd 100644 --- a/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java diff --git a/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java b/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java index 0f42ac50..0f42ac50 100644 --- a/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java b/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java index 0ef414aa..0ef414aa 100644 --- a/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java diff --git a/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java b/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java index 035917c8..035917c8 100644 --- a/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java diff --git a/java/src/test/java/com/google/protobuf/LiteTest.java b/java/core/src/test/java/com/google/protobuf/LiteTest.java index b1f298ff..b1f298ff 100644 --- a/java/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteTest.java diff --git a/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java index c8495633..68b55ceb 100644 --- a/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java @@ -75,9 +75,7 @@ public class LiteralByteStringTest extends TestCase { } protected String getActualClassName(Object object) { - String actualClassName = object.getClass().getName(); - actualClassName = actualClassName.substring(actualClassName.lastIndexOf('.') + 1); - return actualClassName; + return object.getClass().getSimpleName(); } public void testByteAt() { @@ -350,14 +348,14 @@ public class LiteralByteStringTest extends TestCase { public void testToString() throws UnsupportedEncodingException { String testString = "I love unicode \u1234\u5678 characters"; - LiteralByteString unicode = new LiteralByteString(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); String roundTripString = unicode.toString(UTF_8); assertEquals(classUnderTest + " unicode must match", testString, roundTripString); } public void testCharsetToString() { String testString = "I love unicode \u1234\u5678 characters"; - LiteralByteString unicode = new LiteralByteString(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); String roundTripString = unicode.toString(Internal.UTF_8); assertEquals(classUnderTest + " unicode must match", testString, roundTripString); } @@ -365,7 +363,7 @@ public class LiteralByteStringTest extends TestCase { public void testToString_returnsCanonicalEmptyString() { assertSame(classUnderTest + " must be the same string references", ByteString.EMPTY.toString(Internal.UTF_8), - new LiteralByteString(new byte[]{}).toString(Internal.UTF_8)); + ByteString.wrap(new byte[]{}).toString(Internal.UTF_8)); } public void testToString_raisesException() { @@ -377,7 +375,7 @@ public class LiteralByteStringTest extends TestCase { } try { - new LiteralByteString(referenceBytes).toString("invalid"); + ByteString.wrap(referenceBytes).toString("invalid"); fail("Should have thrown an exception."); } catch (UnsupportedEncodingException expected) { // This is success @@ -390,15 +388,15 @@ public class LiteralByteStringTest extends TestCase { assertFalse(classUnderTest + " must not equal the empty string", stringUnderTest.equals(ByteString.EMPTY)); assertEquals(classUnderTest + " empty strings must be equal", - new LiteralByteString(new byte[]{}), stringUnderTest.substring(55, 55)); + ByteString.wrap(new byte[]{}), stringUnderTest.substring(55, 55)); assertEquals(classUnderTest + " must equal another string with the same value", - stringUnderTest, new LiteralByteString(referenceBytes)); + stringUnderTest, ByteString.wrap(referenceBytes)); byte[] mungedBytes = new byte[referenceBytes.length]; System.arraycopy(referenceBytes, 0, mungedBytes, 0, referenceBytes.length); mungedBytes[mungedBytes.length - 5] = (byte) (mungedBytes[mungedBytes.length - 5] ^ 0xFF); assertFalse(classUnderTest + " must not equal every string with the same length", - stringUnderTest.equals(new LiteralByteString(mungedBytes))); + stringUnderTest.equals(ByteString.wrap(mungedBytes))); } public void testHashCode() { diff --git a/java/src/test/java/com/google/protobuf/LongArrayListTest.java b/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java index 1bd094f7..1bd094f7 100644 --- a/java/src/test/java/com/google/protobuf/LongArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/MapForProto2LiteTest.java b/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java index 3d8c9bc4..3d8c9bc4 100644 --- a/java/src/test/java/com/google/protobuf/MapForProto2LiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java diff --git a/java/src/test/java/com/google/protobuf/MapForProto2Test.java b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index 1fa3cbdb..1fa3cbdb 100644 --- a/java/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java diff --git a/java/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java index 0e5c1284..0e5c1284 100644 --- a/java/src/test/java/com/google/protobuf/MapTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapTest.java diff --git a/java/src/test/java/com/google/protobuf/MessageTest.java b/java/core/src/test/java/com/google/protobuf/MessageTest.java index abcd3a1d..abcd3a1d 100644 --- a/java/src/test/java/com/google/protobuf/MessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/MessageTest.java diff --git a/java/src/test/java/com/google/protobuf/NestedBuildersTest.java b/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java index 23653126..23653126 100644 --- a/java/src/test/java/com/google/protobuf/NestedBuildersTest.java +++ b/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java diff --git a/java/src/test/java/com/google/protobuf/NioByteStringTest.java b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java index 0679937f..e40a3662 100644 --- a/java/src/test/java/com/google/protobuf/NioByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java @@ -52,13 +52,12 @@ import java.util.NoSuchElementException; * Tests for {@link NioByteString}. */ public class NioByteStringTest extends TestCase { - private static final ByteString EMPTY = UnsafeByteStrings.unsafeWrap( - ByteBuffer.wrap(new byte[0])); + private static final ByteString EMPTY = new NioByteString(ByteBuffer.wrap(new byte[0])); private static final String CLASSNAME = NioByteString.class.getSimpleName(); private static final byte[] BYTES = ByteStringTest.getTestBytes(1234, 11337766L); - private static final int EXPECTED_HASH = new LiteralByteString(BYTES).hashCode(); + private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode(); private static final ByteBuffer BUFFER = ByteBuffer.wrap(BYTES.clone()); - private static final ByteString TEST_STRING = UnsafeByteStrings.unsafeWrap(BUFFER); + private static final ByteString TEST_STRING = new NioByteString(BUFFER); public void testExpectedType() { String actualClassName = getActualClassName(TEST_STRING); @@ -362,7 +361,7 @@ public class NioByteStringTest extends TestCase { public void testToString_returnsCanonicalEmptyString() { assertSame(CLASSNAME + " must be the same string references", EMPTY.toString(UTF_8), - UnsafeByteStrings.unsafeWrap(ByteBuffer.wrap(new byte[0])).toString(UTF_8)); + new NioByteString(ByteBuffer.wrap(new byte[0])).toString(UTF_8)); } public void testToString_raisesException() { @@ -389,11 +388,11 @@ public class NioByteStringTest extends TestCase { assertEquals(CLASSNAME + " empty strings must be equal", EMPTY, TEST_STRING.substring(55, 55)); assertEquals(CLASSNAME + " must equal another string with the same value", - TEST_STRING, UnsafeByteStrings.unsafeWrap(BUFFER)); + TEST_STRING, new NioByteString(BUFFER)); byte[] mungedBytes = mungedBytes(); assertFalse(CLASSNAME + " must not equal every string with the same length", - TEST_STRING.equals(UnsafeByteStrings.unsafeWrap(ByteBuffer.wrap(mungedBytes)))); + TEST_STRING.equals(new NioByteString(ByteBuffer.wrap(mungedBytes)))); } public void testEqualsLiteralByteString() { @@ -451,7 +450,7 @@ public class NioByteStringTest extends TestCase { } public void testPeekCachedHashCode() { - ByteString newString = UnsafeByteStrings.unsafeWrap(BUFFER); + ByteString newString = new NioByteString(BUFFER); assertEquals(CLASSNAME + ".peekCachedHashCode() should return zero at first", 0, newString.peekCachedHashCode()); newString.hashCode(); @@ -541,6 +540,6 @@ public class NioByteStringTest extends TestCase { } private static ByteString forString(String str) { - return UnsafeByteStrings.unsafeWrap(ByteBuffer.wrap(str.getBytes(UTF_8))); + return new NioByteString(ByteBuffer.wrap(str.getBytes(UTF_8))); } } diff --git a/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java b/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java new file mode 100644 index 00000000..03593413 --- /dev/null +++ b/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java @@ -0,0 +1,212 @@ +package com.google.protobuf; + +import com.google.protobuf.DescriptorProtos.DescriptorProto; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests the exceptions thrown when parsing from a stream. The methods on the {@link Parser} + * interface are specified to only throw {@link InvalidProtocolBufferException}. But we really want + * to distinguish between invalid protos vs. actual I/O errors (like failures reading from a + * socket, etc.). So, when we're not using the parser directly, an {@link IOException} should be + * thrown where appropriate, instead of always an {@link InvalidProtocolBufferException}. + * + * @author jh@squareup.com (Joshua Humphries) + */ +public class ParseExceptionsTest { + +// disable for now for update the maven local repo. +// private interface ParseTester { +// DescriptorProto parse(InputStream in) throws IOException; +// } +// +// private byte serializedProto[]; +// +// private void setup() { +// serializedProto = DescriptorProto.getDescriptor().toProto().toByteArray(); +// } +// +// private void setupDelimited() { +// ByteArrayOutputStream bos = new ByteArrayOutputStream(); +// try { +// DescriptorProto.getDescriptor().toProto().writeDelimitedTo(bos); +// } catch (IOException e) { +// fail("Exception not expected: " + e); +// } +// serializedProto = bos.toByteArray(); +// } +// +// @Test public void message_parseFrom_InputStream() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.parseFrom(in); +// } +// }); +// } +// +// @Test public void message_parseFrom_InputStreamAndExtensionRegistry() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.parseFrom(in, ExtensionRegistry.newInstance()); +// } +// }); +// } +// +// @Test public void message_parseFrom_CodedInputStream() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.parseFrom(CodedInputStream.newInstance(in)); +// } +// }); +// } +// +// @Test public void message_parseFrom_CodedInputStreamAndExtensionRegistry() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.parseFrom(CodedInputStream.newInstance(in), +// ExtensionRegistry.newInstance()); +// } +// }); +// } +// +// @Test public void message_parseDelimitedFrom_InputStream() { +// setupDelimited(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.parseDelimitedFrom(in); +// } +// }); +// } +// +// @Test public void message_parseDelimitedFrom_InputStreamAndExtensionRegistry() { +// setupDelimited(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.parseDelimitedFrom(in, ExtensionRegistry.newInstance()); +// } +// }); +// } +// +// @Test public void messageBuilder_mergeFrom_InputStream() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.newBuilder().mergeFrom(in).build(); +// } +// }); +// } +// +// @Test public void messageBuilder_mergeFrom_InputStreamAndExtensionRegistry() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.newBuilder().mergeFrom(in, ExtensionRegistry.newInstance()).build(); +// } +// }); +// } +// +// @Test public void messageBuilder_mergeFrom_CodedInputStream() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.newBuilder().mergeFrom(CodedInputStream.newInstance(in)).build(); +// } +// }); +// } +// +// @Test public void messageBuilder_mergeFrom_CodedInputStreamAndExtensionRegistry() { +// setup(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// return DescriptorProto.newBuilder() +// .mergeFrom(CodedInputStream.newInstance(in), ExtensionRegistry.newInstance()).build(); +// } +// }); +// } +// +// @Test public void messageBuilder_mergeDelimitedFrom_InputStream() { +// setupDelimited(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// DescriptorProto.Builder builder = DescriptorProto.newBuilder(); +// builder.mergeDelimitedFrom(in); +// return builder.build(); +// } +// }); +// } +// +// @Test public void messageBuilder_mergeDelimitedFrom_InputStreamAndExtensionRegistry() { +// setupDelimited(); +// verifyExceptions(new ParseTester() { +// public DescriptorProto parse(InputStream in) throws IOException { +// DescriptorProto.Builder builder = DescriptorProto.newBuilder(); +// builder.mergeDelimitedFrom(in, ExtensionRegistry.newInstance()); +// return builder.build(); +// } +// }); +// } +// +// private void verifyExceptions(ParseTester parseTester) { +// // No exception +// try { +// assertEquals(DescriptorProto.getDescriptor().toProto(), +// parseTester.parse(new ByteArrayInputStream(serializedProto))); +// } catch (IOException e) { +// fail("No exception expected: " + e); +// } +// +// // IOException +// try { +// // using a "broken" stream that will throw part-way through reading the message +// parseTester.parse(broken(new ByteArrayInputStream(serializedProto))); +// fail("IOException expected but not thrown"); +// } catch (IOException e) { +// assertFalse(e instanceof InvalidProtocolBufferException); +// } +// +// // InvalidProtocolBufferException +// try { +// // make the serialized proto invalid +// for (int i = 0; i < 50; i++) { +// serializedProto[i] = -1; +// } +// parseTester.parse(new ByteArrayInputStream(serializedProto)); +// fail("InvalidProtocolBufferException expected but not thrown"); +// } catch (IOException e) { +// assertTrue(e instanceof InvalidProtocolBufferException); +// } +// } +// +// private InputStream broken(InputStream i) { +// return new FilterInputStream(i) { +// int count = 0; +// +// @Override public int read() throws IOException { +// if (count++ >= 50) { +// throw new IOException("I'm broken!"); +// } +// return super.read(); +// } +// +// @Override public int read(byte b[], int off, int len) throws IOException { +// if ((count += len) >= 50) { +// throw new IOException("I'm broken!"); +// } +// return super.read(b, off, len); +// } +// }; +// } +} diff --git a/java/src/test/java/com/google/protobuf/ParserTest.java b/java/core/src/test/java/com/google/protobuf/ParserTest.java index 5a92bacf..5a92bacf 100644 --- a/java/src/test/java/com/google/protobuf/ParserTest.java +++ b/java/core/src/test/java/com/google/protobuf/ParserTest.java diff --git a/java/src/test/java/com/google/protobuf/ProtobufArrayListTest.java b/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java index 245c3dee..245c3dee 100644 --- a/java/src/test/java/com/google/protobuf/ProtobufArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java diff --git a/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java b/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java index 49d52321..49d52321 100644 --- a/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java +++ b/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java diff --git a/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java index dc56f2e9..dc56f2e9 100644 --- a/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java diff --git a/java/src/test/java/com/google/protobuf/RopeByteStringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java index 4ec3a409..4ec3a409 100644 --- a/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java diff --git a/java/src/test/java/com/google/protobuf/ServiceTest.java b/java/core/src/test/java/com/google/protobuf/ServiceTest.java index ff980d66..ff980d66 100644 --- a/java/src/test/java/com/google/protobuf/ServiceTest.java +++ b/java/core/src/test/java/com/google/protobuf/ServiceTest.java diff --git a/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java b/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java index 58b80007..58b80007 100644 --- a/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java +++ b/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java diff --git a/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java b/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java index 366086d3..366086d3 100644 --- a/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +++ b/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java diff --git a/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java index 2c60fe0e..2c60fe0e 100644 --- a/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java diff --git a/java/src/test/java/com/google/protobuf/TestUtil.java b/java/core/src/test/java/com/google/protobuf/TestUtil.java index 01acb884..01acb884 100644 --- a/java/src/test/java/com/google/protobuf/TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/TestUtil.java diff --git a/java/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 1df4fad7..1df4fad7 100644 --- a/java/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java diff --git a/java/src/test/java/com/google/protobuf/UnknownEnumValueTest.java b/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java index 8f45976f..8f45976f 100644 --- a/java/src/test/java/com/google/protobuf/UnknownEnumValueTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java diff --git a/java/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java index dc987379..dc987379 100644 --- a/java/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java diff --git a/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java index 8c9dcafe..8c9dcafe 100644 --- a/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java diff --git a/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java b/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java index b1c75fc3..b1c75fc3 100644 --- a/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java diff --git a/java/src/test/java/com/google/protobuf/WellKnownTypesTest.java b/java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java index 982e200f..982e200f 100644 --- a/java/src/test/java/com/google/protobuf/WellKnownTypesTest.java +++ b/java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java diff --git a/java/src/test/java/com/google/protobuf/WireFormatTest.java b/java/core/src/test/java/com/google/protobuf/WireFormatTest.java index 0175005d..0175005d 100644 --- a/java/src/test/java/com/google/protobuf/WireFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/WireFormatTest.java diff --git a/java/src/test/java/com/google/protobuf/any_test.proto b/java/core/src/test/proto/com/google/protobuf/any_test.proto index 80173d8a..80173d8a 100644 --- a/java/src/test/java/com/google/protobuf/any_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/any_test.proto diff --git a/java/src/test/java/com/google/protobuf/field_presence_test.proto b/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto index 8f3ca8c6..8f3ca8c6 100644 --- a/java/src/test/java/com/google/protobuf/field_presence_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto diff --git a/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto b/java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto index 5580f72d..5580f72d 100644 --- a/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto +++ b/java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto diff --git a/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto b/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto index 86837250..86837250 100644 --- a/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto +++ b/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto diff --git a/java/src/test/java/com/google/protobuf/map_for_proto2_lite_test.proto b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto index d5418f28..d5418f28 100644 --- a/java/src/test/java/com/google/protobuf/map_for_proto2_lite_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto diff --git a/java/src/test/java/com/google/protobuf/map_for_proto2_test.proto b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto index a9be5166..a9be5166 100644 --- a/java/src/test/java/com/google/protobuf/map_for_proto2_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto diff --git a/java/src/test/java/com/google/protobuf/map_initialization_order_test.proto b/java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto index b02ac599..b02ac599 100644 --- a/java/src/test/java/com/google/protobuf/map_initialization_order_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto diff --git a/java/src/test/java/com/google/protobuf/map_test.proto b/java/core/src/test/proto/com/google/protobuf/map_test.proto index 2280ac03..2280ac03 100644 --- a/java/src/test/java/com/google/protobuf/map_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_test.proto diff --git a/java/src/test/java/com/google/protobuf/multiple_files_test.proto b/java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto index 92790506..92790506 100644 --- a/java/src/test/java/com/google/protobuf/multiple_files_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto diff --git a/java/src/test/java/com/google/protobuf/nested_builders_test.proto b/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto index a5dd66d8..a5dd66d8 100644 --- a/java/src/test/java/com/google/protobuf/nested_builders_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto diff --git a/java/src/test/java/com/google/protobuf/nested_extension.proto b/java/core/src/test/proto/com/google/protobuf/nested_extension.proto index 704e649e..704e649e 100644 --- a/java/src/test/java/com/google/protobuf/nested_extension.proto +++ b/java/core/src/test/proto/com/google/protobuf/nested_extension.proto diff --git a/java/src/test/java/com/google/protobuf/nested_extension_lite.proto b/java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto index a95c38b2..a95c38b2 100644 --- a/java/src/test/java/com/google/protobuf/nested_extension_lite.proto +++ b/java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto diff --git a/java/src/test/java/com/google/protobuf/non_nested_extension.proto b/java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto index 31fac552..31fac552 100644 --- a/java/src/test/java/com/google/protobuf/non_nested_extension.proto +++ b/java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto diff --git a/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto b/java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto index 37c369ed..37c369ed 100644 --- a/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto +++ b/java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto diff --git a/java/src/test/java/com/google/protobuf/outer_class_name_test.proto b/java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto index 42083681..42083681 100644 --- a/java/src/test/java/com/google/protobuf/outer_class_name_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto diff --git a/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto b/java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto index 3e5956b0..3e5956b0 100644 --- a/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto +++ b/java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto diff --git a/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto b/java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto index 74a8ba3c..74a8ba3c 100644 --- a/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto +++ b/java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto diff --git a/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto index 2b1f65e4..2b1f65e4 100644 --- a/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto diff --git a/java/src/test/java/com/google/protobuf/test_check_utf8.proto b/java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto index 119c1dcb..119c1dcb 100644 --- a/java/src/test/java/com/google/protobuf/test_check_utf8.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto diff --git a/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto b/java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto index f06d76d6..f06d76d6 100644 --- a/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto diff --git a/java/src/test/java/com/google/protobuf/test_custom_options.proto b/java/core/src/test/proto/com/google/protobuf/test_custom_options.proto index f8efd455..f8efd455 100644 --- a/java/src/test/java/com/google/protobuf/test_custom_options.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_custom_options.proto diff --git a/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto b/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto index 645f57b4..645f57b4 100644 --- a/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 29d8c8c4..70c7d047 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -84,7 +84,6 @@ <include>**/AbstractMessageLite.java</include> <include>**/AbstractParser.java</include> <include>**/AbstractProtobufList.java</include> - <include>**/BoundedByteString.java</include> <include>**/BooleanArrayList.java</include> <include>**/ByteString.java</include> <include>**/CodedInputStream.java</include> @@ -101,7 +100,6 @@ <include>**/LazyFieldLite.java</include> <include>**/LazyStringArrayList.java</include> <include>**/LazyStringList.java</include> - <include>**/LiteralByteString.java</include> <include>**/LongArrayList.java</include> <include>**/MapEntryLite.java</include> <include>**/MapFieldLite.java</include> @@ -119,7 +117,7 @@ <include>**/UninitializedMessageException.java</include> <include>**/UnknownFieldSetLite.java</include> <include>**/UnmodifiableLazyStringList.java</include> - <include>**/UnsafeByteStrings.java</include> + <include>**/UnsafeByteOperations.java</include> <include>**/Utf8.java</include> <include>**/WireFormat.java</include> </includes> diff --git a/java/src/main/java/com/google/protobuf/BoundedByteString.java b/java/src/main/java/com/google/protobuf/BoundedByteString.java deleted file mode 100644 index 934c9030..00000000 --- a/java/src/main/java/com/google/protobuf/BoundedByteString.java +++ /dev/null @@ -1,124 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; - -/** - * This class is used to represent the substring of a {@link ByteString} over a - * single byte array. In terms of the public API of {@link ByteString}, you end - * up here by calling {@link ByteString#copyFrom(byte[])} followed by {@link - * ByteString#substring(int, int)}. - * - * <p>This class contains most of the overhead involved in creating a substring - * from a {@link LiteralByteString}. The overhead involves some range-checking - * and two extra fields. - * - * @author carlanton@google.com (Carl Haverl) - */ -final class BoundedByteString extends LiteralByteString { - - private final int bytesOffset; - private final int bytesLength; - - /** - * Creates a {@code BoundedByteString} backed by the sub-range of given array, - * without copying. - * - * @param bytes array to wrap - * @param offset index to first byte to use in bytes - * @param length number of bytes to use from bytes - * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0}, - * or if {@code offset + length > - * bytes.length}. - */ - BoundedByteString(byte[] bytes, int offset, int length) { - super(bytes); - checkRange(offset, offset + length, bytes.length); - - this.bytesOffset = offset; - this.bytesLength = length; - } - - /** - * Gets the byte at the given index. - * Throws {@link ArrayIndexOutOfBoundsException} - * for backwards-compatibility reasons although it would more properly be - * {@link IndexOutOfBoundsException}. - * - * @param index index of byte - * @return the value - * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size - */ - @Override - public byte byteAt(int index) { - // We must check the index ourselves as we cannot rely on Java array index - // checking for substrings. - checkIndex(index, size()); - return bytes[bytesOffset + index]; - } - - @Override - public int size() { - return bytesLength; - } - - @Override - protected int getOffsetIntoBytes() { - return bytesOffset; - } - - // ================================================================= - // ByteString -> byte[] - - @Override - protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset, - int numberToCopy) { - System.arraycopy(bytes, getOffsetIntoBytes() + sourceOffset, target, - targetOffset, numberToCopy); - } - - // ================================================================= - // Serializable - - private static final long serialVersionUID = 1L; - - Object writeReplace() { - return new LiteralByteString(toByteArray()); - } - - private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { - throw new InvalidObjectException( - "BoundedByteStream instances are not to be serialized directly"); - } -} diff --git a/java/src/main/java/com/google/protobuf/LiteralByteString.java b/java/src/main/java/com/google/protobuf/LiteralByteString.java deleted file mode 100644 index a18c2792..00000000 --- a/java/src/main/java/com/google/protobuf/LiteralByteString.java +++ /dev/null @@ -1,267 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.List; - -/** - * This class implements a {@link com.google.protobuf.ByteString} backed by a - * single array of bytes, contiguous in memory. It supports substring by - * pointing to only a sub-range of the underlying byte array, meaning that a - * substring will reference the full byte-array of the string it's made from, - * exactly as with {@link String}. - * - * @author carlanton@google.com (Carl Haverl) - */ -class LiteralByteString extends ByteString.LeafByteString { - private static final long serialVersionUID = 1L; - - protected final byte[] bytes; - - /** - * Creates a {@code LiteralByteString} backed by the given array, without - * copying. - * - * @param bytes array to wrap - */ - LiteralByteString(byte[] bytes) { - this.bytes = bytes; - } - - @Override - public byte byteAt(int index) { - // Unlike most methods in this class, this one is a direct implementation - // ignoring the potential offset because we need to do range-checking in the - // substring case anyway. - return bytes[index]; - } - - @Override - public int size() { - return bytes.length; - } - - // ================================================================= - // ByteString -> substring - - @Override - public final ByteString substring(int beginIndex, int endIndex) { - final int length = checkRange(beginIndex, endIndex, size()); - - if (length == 0) { - return ByteString.EMPTY; - } - - return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length); - } - - // ================================================================= - // ByteString -> byte[] - - @Override - protected void copyToInternal( - byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { - // Optimized form, not for subclasses, since we don't call - // getOffsetIntoBytes() or check the 'numberToCopy' parameter. - // TODO(nathanmittler): Is not calling getOffsetIntoBytes really saving that much? - System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy); - } - - @Override - public final void copyTo(ByteBuffer target) { - target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes - } - - @Override - public final ByteBuffer asReadOnlyByteBuffer() { - return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer(); - } - - @Override - public final List<ByteBuffer> asReadOnlyByteBufferList() { - return Collections.singletonList(asReadOnlyByteBuffer()); - } - - @Override - public final void writeTo(OutputStream outputStream) throws IOException { - outputStream.write(toByteArray()); - } - - @Override - final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite) - throws IOException { - outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite); - } - - @Override - protected final String toStringInternal(Charset charset) { - return new String(bytes, getOffsetIntoBytes(), size(), charset); - } - - // ================================================================= - // UTF-8 decoding - - @Override - public final boolean isValidUtf8() { - int offset = getOffsetIntoBytes(); - return Utf8.isValidUtf8(bytes, offset, offset + size()); - } - - @Override - protected final int partialIsValidUtf8(int state, int offset, int length) { - int index = getOffsetIntoBytes() + offset; - return Utf8.partialIsValidUtf8(state, bytes, index, index + length); - } - - // ================================================================= - // equals() and hashCode() - - @Override - public final boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof ByteString)) { - return false; - } - - if (size() != ((ByteString) other).size()) { - return false; - } - if (size() == 0) { - return true; - } - - if (other instanceof LiteralByteString) { - LiteralByteString otherAsLiteral = (LiteralByteString) other; - // If we know the hash codes and they are not equal, we know the byte - // strings are not equal. - int thisHash = peekCachedHashCode(); - int thatHash = otherAsLiteral.peekCachedHashCode(); - if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) { - return false; - } - - return equalsRange((LiteralByteString) other, 0, size()); - } else { - // RopeByteString and NioByteString. - return other.equals(this); - } - } - - /** - * Check equality of the substring of given length of this object starting at - * zero with another {@code LiteralByteString} substring starting at offset. - * - * @param other what to compare a substring in - * @param offset offset into other - * @param length number of bytes to compare - * @return true for equality of substrings, else false. - */ - @Override - final boolean equalsRange(ByteString other, int offset, int length) { - if (length > other.size()) { - throw new IllegalArgumentException("Length too large: " + length + size()); - } - if (offset + length > other.size()) { - throw new IllegalArgumentException( - "Ran off end of other: " + offset + ", " + length + ", " + other.size()); - } - - if (other instanceof LiteralByteString) { - LiteralByteString lbsOther = (LiteralByteString) other; - byte[] thisBytes = bytes; - byte[] otherBytes = lbsOther.bytes; - int thisLimit = getOffsetIntoBytes() + length; - for ( - int thisIndex = getOffsetIntoBytes(), otherIndex = lbsOther.getOffsetIntoBytes() + offset; - (thisIndex < thisLimit); ++thisIndex, ++otherIndex) { - if (thisBytes[thisIndex] != otherBytes[otherIndex]) { - return false; - } - } - return true; - } - - return other.substring(offset, offset + length).equals(substring(0, length)); - } - - @Override - protected final int partialHash(int h, int offset, int length) { - return hashCode(h, bytes, getOffsetIntoBytes() + offset, length); - } - - static int hashCode(int h, byte[] bytes, int offset, int length) { - for (int i = offset; i < offset + length; i++) { - h = h * 31 + bytes[i]; - } - return h; - } - - static int hashCode(byte[] bytes) { - int h = hashCode(bytes.length, bytes, 0, bytes.length); - return h == 0 ? 1 : h; - } - - // ================================================================= - // Input stream - - @Override - public final InputStream newInput() { - return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy - } - - @Override - public final CodedInputStream newCodedInput() { - // We trust CodedInputStream not to modify the bytes, or to give anyone - // else access to them. - return CodedInputStream.newInstance(this); - } - - // ================================================================= - // Internal methods - - /** - * Offset into {@code bytes[]} to use, non-zero for substrings. - * - * @return always 0 for this class - */ - protected int getOffsetIntoBytes() { - return 0; - } -} diff --git a/java/src/test/java/com/google/protobuf/ParseExceptionsTest.java b/java/src/test/java/com/google/protobuf/ParseExceptionsTest.java deleted file mode 100644 index 37fa242d..00000000 --- a/java/src/test/java/com/google/protobuf/ParseExceptionsTest.java +++ /dev/null @@ -1,211 +0,0 @@ -package com.google.protobuf; - -import com.google.protobuf.DescriptorProtos.DescriptorProto; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Tests the exceptions thrown when parsing from a stream. The methods on the {@link Parser} - * interface are specified to only throw {@link InvalidProtocolBufferException}. But we really want - * to distinguish between invalid protos vs. actual I/O errors (like failures reading from a - * socket, etc.). So, when we're not using the parser directly, an {@link IOException} should be - * thrown where appropriate, instead of always an {@link InvalidProtocolBufferException}. - * - * @author jh@squareup.com (Joshua Humphries) - */ -public class ParseExceptionsTest { - - private interface ParseTester { - DescriptorProto parse(InputStream in) throws IOException; - } - - private byte serializedProto[]; - - private void setup() { - serializedProto = DescriptorProto.getDescriptor().toProto().toByteArray(); - } - - private void setupDelimited() { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try { - DescriptorProto.getDescriptor().toProto().writeDelimitedTo(bos); - } catch (IOException e) { - fail("Exception not expected: " + e); - } - serializedProto = bos.toByteArray(); - } - - @Test public void message_parseFrom_InputStream() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.parseFrom(in); - } - }); - } - - @Test public void message_parseFrom_InputStreamAndExtensionRegistry() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.parseFrom(in, ExtensionRegistry.newInstance()); - } - }); - } - - @Test public void message_parseFrom_CodedInputStream() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.parseFrom(CodedInputStream.newInstance(in)); - } - }); - } - - @Test public void message_parseFrom_CodedInputStreamAndExtensionRegistry() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.parseFrom(CodedInputStream.newInstance(in), - ExtensionRegistry.newInstance()); - } - }); - } - - @Test public void message_parseDelimitedFrom_InputStream() { - setupDelimited(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.parseDelimitedFrom(in); - } - }); - } - - @Test public void message_parseDelimitedFrom_InputStreamAndExtensionRegistry() { - setupDelimited(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.parseDelimitedFrom(in, ExtensionRegistry.newInstance()); - } - }); - } - - @Test public void messageBuilder_mergeFrom_InputStream() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.newBuilder().mergeFrom(in).build(); - } - }); - } - - @Test public void messageBuilder_mergeFrom_InputStreamAndExtensionRegistry() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.newBuilder().mergeFrom(in, ExtensionRegistry.newInstance()).build(); - } - }); - } - - @Test public void messageBuilder_mergeFrom_CodedInputStream() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.newBuilder().mergeFrom(CodedInputStream.newInstance(in)).build(); - } - }); - } - - @Test public void messageBuilder_mergeFrom_CodedInputStreamAndExtensionRegistry() { - setup(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - return DescriptorProto.newBuilder() - .mergeFrom(CodedInputStream.newInstance(in), ExtensionRegistry.newInstance()).build(); - } - }); - } - - @Test public void messageBuilder_mergeDelimitedFrom_InputStream() { - setupDelimited(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - DescriptorProto.Builder builder = DescriptorProto.newBuilder(); - builder.mergeDelimitedFrom(in); - return builder.build(); - } - }); - } - - @Test public void messageBuilder_mergeDelimitedFrom_InputStreamAndExtensionRegistry() { - setupDelimited(); - verifyExceptions(new ParseTester() { - public DescriptorProto parse(InputStream in) throws IOException { - DescriptorProto.Builder builder = DescriptorProto.newBuilder(); - builder.mergeDelimitedFrom(in, ExtensionRegistry.newInstance()); - return builder.build(); - } - }); - } - - private void verifyExceptions(ParseTester parseTester) { - // No exception - try { - assertEquals(DescriptorProto.getDescriptor().toProto(), - parseTester.parse(new ByteArrayInputStream(serializedProto))); - } catch (IOException e) { - fail("No exception expected: " + e); - } - - // IOException - try { - // using a "broken" stream that will throw part-way through reading the message - parseTester.parse(broken(new ByteArrayInputStream(serializedProto))); - fail("IOException expected but not thrown"); - } catch (IOException e) { - assertFalse(e instanceof InvalidProtocolBufferException); - } - - // InvalidProtocolBufferException - try { - // make the serialized proto invalid - for (int i = 0; i < 50; i++) { - serializedProto[i] = -1; - } - parseTester.parse(new ByteArrayInputStream(serializedProto)); - fail("InvalidProtocolBufferException expected but not thrown"); - } catch (IOException e) { - assertTrue(e instanceof InvalidProtocolBufferException); - } - } - - private InputStream broken(InputStream i) { - return new FilterInputStream(i) { - int count = 0; - - @Override public int read() throws IOException { - if (count++ >= 50) { - throw new IOException("I'm broken!"); - } - return super.read(); - } - - @Override public int read(byte b[], int off, int len) throws IOException { - if ((count += len) >= 50) { - throw new IOException("I'm broken!"); - } - return super.read(b, off, len); - } - }; - } -} diff --git a/java/util/src/test/java/com/google/protobuf/util/json_test.proto b/java/util/src/test/proto/com/google/protobuf/util/json_test.proto index 509c1d69..509c1d69 100644 --- a/java/util/src/test/java/com/google/protobuf/util/json_test.proto +++ b/java/util/src/test/proto/com/google/protobuf/util/json_test.proto |