├── .gitignore ├── LICENSE ├── README.md ├── build.xml ├── manifest.mf ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── licenseheader.txt ├── project.properties └── project.xml ├── src ├── com │ ├── codebrig │ │ └── beam │ │ │ ├── Beam.java │ │ │ ├── BeamClient.java │ │ │ ├── BeamServer.java │ │ │ ├── Communicator.java │ │ │ ├── CommunicatorException.java │ │ │ ├── ConnectionStateListener.java │ │ │ ├── ShutdownListener.java │ │ │ ├── SystemCommunicator.java │ │ │ ├── connection │ │ │ ├── ConnectionProtocol.java │ │ │ ├── ConnectionType.java │ │ │ ├── httptunnel │ │ │ │ └── TunnelPorts.java │ │ │ ├── raw │ │ │ │ ├── RawChannelHandler.java │ │ │ │ ├── RawChannelMessage.java │ │ │ │ ├── RawDataChannel.java │ │ │ │ ├── RawDataMessage.java │ │ │ │ └── RawOutputStream.java │ │ │ └── traversal │ │ │ │ ├── TraversalTechnique.java │ │ │ │ ├── punch │ │ │ │ └── udp │ │ │ │ │ ├── UDPPunchTraversalTechnique.java │ │ │ │ │ ├── client │ │ │ │ │ ├── UDPHoleClient.java │ │ │ │ │ └── UDPPunchClient.java │ │ │ │ │ ├── messages │ │ │ │ │ ├── UDPPunchMessage.java │ │ │ │ │ └── UDPPunchMessageType.java │ │ │ │ │ └── server │ │ │ │ │ ├── NATDevice.java │ │ │ │ │ ├── NATDeviceHolder.java │ │ │ │ │ ├── UDPPunchServer.java │ │ │ │ │ └── handlers │ │ │ │ │ ├── ConnectionHandler.java │ │ │ │ │ ├── HoleRequestHandler.java │ │ │ │ │ └── PunchRequestHandler.java │ │ │ │ └── upnp │ │ │ │ ├── UPNPControl.java │ │ │ │ ├── UPNPException.java │ │ │ │ └── UPNPTraversalTechnique.java │ │ │ ├── crypt │ │ │ ├── AES.java │ │ │ ├── AESException.java │ │ │ ├── CryptException.java │ │ │ ├── EncryptedBeamMessage.java │ │ │ ├── RSA.java │ │ │ ├── RSAConnection.java │ │ │ ├── RSAConnectionHolder.java │ │ │ ├── RSAException.java │ │ │ ├── handlers │ │ │ │ ├── AESBeamHandler.java │ │ │ │ ├── AESBeamLegacyHandler.java │ │ │ │ ├── RSABeamHandler.java │ │ │ │ ├── RSABeamLegacyHandler.java │ │ │ │ └── RSAHandshakeHandler.java │ │ │ └── messages │ │ │ │ ├── AESBeamMessage.java │ │ │ │ ├── RSABeamMessage.java │ │ │ │ └── RSAHandshakeMessage.java │ │ │ ├── handlers │ │ │ ├── BeamHandler.java │ │ │ ├── ClientHandler.java │ │ │ ├── LegacyHandler.java │ │ │ ├── SpecificBeamHandler.java │ │ │ └── SystemHandler.java │ │ │ ├── messages │ │ │ ├── BeamMessage.java │ │ │ ├── BeamMessageType.java │ │ │ ├── InvalidBeamMessage.java │ │ │ ├── LegacyMessage.java │ │ │ ├── ProtobufMessage.java │ │ │ ├── SystemLegacyMessage.java │ │ │ ├── SystemMessage.java │ │ │ └── SystemMessageType.java │ │ │ ├── pool │ │ │ ├── ClientPool.java │ │ │ ├── CommunicatorPool.java │ │ │ ├── DefaultClientPool.java │ │ │ └── DefaultCommunicatorPool.java │ │ │ ├── system │ │ │ ├── handlers │ │ │ │ ├── HandshakeHandler.java │ │ │ │ ├── TestConnectionHandler.java │ │ │ │ └── ping │ │ │ │ │ ├── ClientPingPongHandler.java │ │ │ │ │ └── ServerPingPongHandler.java │ │ │ └── messages │ │ │ │ ├── HandshakeMessage.java │ │ │ │ └── InvalidHandshakeException.java │ │ │ ├── transfer │ │ │ ├── FileBurstMessage.java │ │ │ ├── FileDataMessage.java │ │ │ ├── FileTransferChannel.java │ │ │ ├── FileTransferMessage.java │ │ │ ├── TransferException.java │ │ │ └── TransferTracker.java │ │ │ └── utils │ │ │ ├── Base64.java │ │ │ ├── ByteArrayQueue.java │ │ │ ├── ByteFIFO.java │ │ │ ├── CRC64.java │ │ │ ├── Checksum.java │ │ │ ├── Generator.java │ │ │ ├── LimitedQueue.java │ │ │ └── SystemPing.java │ ├── fasterxml │ │ └── jackson │ │ │ ├── core │ │ │ ├── Base64Variant.java │ │ │ ├── Base64Variants.java │ │ │ ├── FormatSchema.java │ │ │ ├── JsonEncoding.java │ │ │ ├── JsonFactory.java │ │ │ ├── JsonGenerationException.java │ │ │ ├── JsonGenerator.java │ │ │ ├── JsonLocation.java │ │ │ ├── JsonParseException.java │ │ │ ├── JsonParser.java │ │ │ ├── JsonPointer.java │ │ │ ├── JsonProcessingException.java │ │ │ ├── JsonStreamContext.java │ │ │ ├── JsonToken.java │ │ │ ├── JsonTokenId.java │ │ │ ├── ObjectCodec.java │ │ │ ├── PrettyPrinter.java │ │ │ ├── SerializableString.java │ │ │ ├── TreeCodec.java │ │ │ ├── TreeNode.java │ │ │ ├── Version.java │ │ │ ├── Versioned.java │ │ │ ├── base │ │ │ │ ├── GeneratorBase.java │ │ │ │ ├── ParserBase.java │ │ │ │ ├── ParserMinimalBase.java │ │ │ │ └── package-info.java │ │ │ ├── format │ │ │ │ ├── DataFormatDetector.java │ │ │ │ ├── DataFormatMatcher.java │ │ │ │ ├── InputAccessor.java │ │ │ │ ├── MatchStrength.java │ │ │ │ └── package-info.java │ │ │ ├── io │ │ │ │ ├── BaseReader.java │ │ │ │ ├── CharTypes.java │ │ │ │ ├── CharacterEscapes.java │ │ │ │ ├── IOContext.java │ │ │ │ ├── InputDecorator.java │ │ │ │ ├── JsonStringEncoder.java │ │ │ │ ├── MergedStream.java │ │ │ │ ├── NumberInput.java │ │ │ │ ├── NumberOutput.java │ │ │ │ ├── OutputDecorator.java │ │ │ │ ├── SegmentedStringWriter.java │ │ │ │ ├── SerializedString.java │ │ │ │ ├── UTF32Reader.java │ │ │ │ └── UTF8Writer.java │ │ │ ├── json │ │ │ │ ├── ByteSourceJsonBootstrapper.java │ │ │ │ ├── DupDetector.java │ │ │ │ ├── JsonGeneratorImpl.java │ │ │ │ ├── JsonReadContext.java │ │ │ │ ├── JsonWriteContext.java │ │ │ │ ├── PackageVersion.java │ │ │ │ ├── PackageVersion.java.in │ │ │ │ ├── ReaderBasedJsonParser.java │ │ │ │ ├── UTF8JsonGenerator.java │ │ │ │ ├── UTF8StreamJsonParser.java │ │ │ │ ├── WriterBasedJsonGenerator.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── sym │ │ │ │ ├── BytesToNameCanonicalizer.java │ │ │ │ ├── CharsToNameCanonicalizer.java │ │ │ │ ├── Name.java │ │ │ │ ├── Name1.java │ │ │ │ ├── Name2.java │ │ │ │ ├── Name3.java │ │ │ │ ├── NameN.java │ │ │ │ └── package-info.java │ │ │ ├── type │ │ │ │ ├── ResolvedType.java │ │ │ │ ├── TypeReference.java │ │ │ │ └── package-info.java │ │ │ └── util │ │ │ │ ├── ArraysCompat.java │ │ │ │ ├── BufferRecycler.java │ │ │ │ ├── ByteArrayBuilder.java │ │ │ │ ├── DefaultPrettyPrinter.java │ │ │ │ ├── Instantiatable.java │ │ │ │ ├── InternCache.java │ │ │ │ ├── JsonGeneratorDelegate.java │ │ │ │ ├── JsonParserDelegate.java │ │ │ │ ├── JsonParserSequence.java │ │ │ │ ├── MinimalPrettyPrinter.java │ │ │ │ ├── TextBuffer.java │ │ │ │ ├── VersionUtil.java │ │ │ │ └── package-info.java │ │ │ └── dataformat │ │ │ └── smile │ │ │ ├── PackageVersion.java │ │ │ ├── SmileBufferRecycler.java │ │ │ ├── SmileConstants.java │ │ │ ├── SmileFactory.java │ │ │ ├── SmileGenerator.java │ │ │ ├── SmileParser.java │ │ │ ├── SmileParserBootstrapper.java │ │ │ ├── SmileUtil.java │ │ │ ├── Tool.java │ │ │ ├── async │ │ │ ├── NonBlockingInputFeeder.java │ │ │ ├── NonBlockingParser.java │ │ │ ├── NonBlockingParserImpl.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ ├── google │ │ └── protobuf │ │ │ ├── AbstractMessage.java │ │ │ ├── AbstractMessageLite.java │ │ │ ├── AbstractParser.java │ │ │ ├── BlockingRpcChannel.java │ │ │ ├── BlockingService.java │ │ │ ├── BoundedByteString.java │ │ │ ├── ByteString.java │ │ │ ├── CodedInputStream.java │ │ │ ├── CodedOutputStream.java │ │ │ ├── DescriptorProtos.java │ │ │ ├── Descriptors.java │ │ │ ├── DynamicMessage.java │ │ │ ├── Extension.java │ │ │ ├── ExtensionRegistry.java │ │ │ ├── ExtensionRegistryLite.java │ │ │ ├── FieldSet.java │ │ │ ├── GeneratedMessage.java │ │ │ ├── GeneratedMessageLite.java │ │ │ ├── Internal.java │ │ │ ├── InvalidProtocolBufferException.java │ │ │ ├── LazyField.java │ │ │ ├── LazyFieldLite.java │ │ │ ├── LazyStringArrayList.java │ │ │ ├── LazyStringList.java │ │ │ ├── LiteralByteString.java │ │ │ ├── Message.java │ │ │ ├── MessageLite.java │ │ │ ├── MessageLiteOrBuilder.java │ │ │ ├── MessageOrBuilder.java │ │ │ ├── MessageReflection.java │ │ │ ├── Parser.java │ │ │ ├── ProtocolMessageEnum.java │ │ │ ├── ProtocolStringList.java │ │ │ ├── RepeatedFieldBuilder.java │ │ │ ├── RopeByteString.java │ │ │ ├── RpcCallback.java │ │ │ ├── RpcChannel.java │ │ │ ├── RpcController.java │ │ │ ├── RpcUtil.java │ │ │ ├── Service.java │ │ │ ├── ServiceException.java │ │ │ ├── SingleFieldBuilder.java │ │ │ ├── SmallSortedMap.java │ │ │ ├── TextFormat.java │ │ │ ├── UninitializedMessageException.java │ │ │ ├── UnknownFieldSet.java │ │ │ ├── UnmodifiableLazyStringList.java │ │ │ ├── Utf8.java │ │ │ └── WireFormat.java │ └── jcraft │ │ └── jhttptunnel │ │ ├── Bound.java │ │ ├── Client.java │ │ ├── Dispatch.java │ │ ├── HTTPSocket.java │ │ ├── InBound.java │ │ ├── InBoundURL.java │ │ ├── JHttpTunnel.java │ │ ├── JHttpTunnelClient.java │ │ ├── JHttpTunnelException.java │ │ ├── JHttpTunnelServer.java │ │ ├── OutBound.java │ │ └── OutBoundURL.java ├── io │ └── protostuff │ │ ├── B64Code.java │ │ ├── ByteArrayInput.java │ │ ├── ByteBufferInput.java │ │ ├── ByteString.java │ │ ├── CodedInput.java │ │ ├── CollectionSchema.java │ │ ├── CustomSchema.java │ │ ├── EnumLite.java │ │ ├── Exclude.java │ │ ├── FilterInput.java │ │ ├── FilterOutput.java │ │ ├── GraphByteArrayInput.java │ │ ├── GraphCodedInput.java │ │ ├── GraphIOUtil.java │ │ ├── GraphInput.java │ │ ├── GraphProtostuffOutput.java │ │ ├── IOUtil.java │ │ ├── Input.java │ │ ├── IntSerializer.java │ │ ├── JsonIOUtil.java │ │ ├── JsonInput.java │ │ ├── JsonInputException.java │ │ ├── JsonOutput.java │ │ ├── JsonXIOUtil.java │ │ ├── JsonXOutput.java │ │ ├── LimitedInputStream.java │ │ ├── LinkBuffer.java │ │ ├── LinkedBuffer.java │ │ ├── LowCopyProtobufOutput.java │ │ ├── LowCopyProtostuffOutput.java │ │ ├── MapSchema.java │ │ ├── Message.java │ │ ├── MessageCollectionSchema.java │ │ ├── MessageMapSchema.java │ │ ├── Morph.java │ │ ├── NumberParser.java │ │ ├── Output.java │ │ ├── Pipe.java │ │ ├── ProtobufException.java │ │ ├── ProtobufIOUtil.java │ │ ├── ProtobufOutput.java │ │ ├── ProtostuffException.java │ │ ├── ProtostuffIOUtil.java │ │ ├── ProtostuffOutput.java │ │ ├── Request.java │ │ ├── Response.java │ │ ├── Rpc.java │ │ ├── Schema.java │ │ ├── Service.java │ │ ├── SmileIOUtil.java │ │ ├── StatefulOutput.java │ │ ├── StreamedStringSerializer.java │ │ ├── StringMapSchema.java │ │ ├── StringSerializer.java │ │ ├── Tag.java │ │ ├── UninitializedMessageException.java │ │ ├── WireFormat.java │ │ ├── WriteSession.java │ │ ├── WriteSink.java │ │ ├── YamlIOUtil.java │ │ ├── YamlOutput.java │ │ └── runtime │ │ ├── ArrayFieldMap.java │ │ ├── ArraySchema.java │ │ ├── ArraySchemas.java │ │ ├── ClassSchema.java │ │ ├── DefaultIdStrategy.java │ │ ├── Delegate.java │ │ ├── DerivativeSchema.java │ │ ├── EnumIO.java │ │ ├── Field.java │ │ ├── FieldMap.java │ │ ├── HasDelegate.java │ │ ├── HasSchema.java │ │ ├── HashFieldMap.java │ │ ├── IdStrategy.java │ │ ├── NumberSchema.java │ │ ├── ObjectSchema.java │ │ ├── OnDemandSunReflectionFactory.java │ │ ├── PolymorphicCollectionSchema.java │ │ ├── PolymorphicEnumSchema.java │ │ ├── PolymorphicMapSchema.java │ │ ├── PolymorphicSchema.java │ │ ├── PolymorphicSchemaFactories.java │ │ ├── PolymorphicThrowableSchema.java │ │ ├── RuntimeCollectionField.java │ │ ├── RuntimeCollectionFieldFactory.java │ │ ├── RuntimeDerivativeField.java │ │ ├── RuntimeEnv.java │ │ ├── RuntimeFieldFactory.java │ │ ├── RuntimeMapField.java │ │ ├── RuntimeMapFieldFactory.java │ │ ├── RuntimeMessageField.java │ │ ├── RuntimeObjectField.java │ │ ├── RuntimePipeSchema.java │ │ ├── RuntimeReflectionFieldFactory.java │ │ ├── RuntimeRepeatedFieldFactory.java │ │ ├── RuntimeSchema.java │ │ └── RuntimeUnsafeFieldFactory.java └── net │ ├── jpountz │ ├── lz4 │ │ ├── LZ4BlockInputStream.java │ │ ├── LZ4BlockOutputStream.java │ │ ├── LZ4Compressor.java │ │ ├── LZ4Decompressor.java │ │ ├── LZ4Exception.java │ │ ├── LZ4Factory.java │ │ ├── LZ4HCJNICompressor.java │ │ ├── LZ4HCJavaSafeCompressor.java │ │ ├── LZ4HCJavaUnsafeCompressor.java │ │ ├── LZ4JNI.java │ │ ├── LZ4JNICompressor.java │ │ ├── LZ4JNIDecompressor.java │ │ ├── LZ4JNIUnknownSizeDecompressor.java │ │ ├── LZ4JavaSafeCompressor.java │ │ ├── LZ4JavaSafeDecompressor.java │ │ ├── LZ4JavaSafeUnknownSizeDecompressor.java │ │ ├── LZ4JavaUnsafeCompressor.java │ │ ├── LZ4JavaUnsafeDecompressor.java │ │ ├── LZ4JavaUnsafeUnknownSizeDecompressor.java │ │ ├── LZ4UnknownSizeDecompressor.java │ │ ├── LZ4UnsafeUtils.java │ │ └── LZ4Utils.java │ ├── util │ │ ├── Native.java │ │ ├── UnsafeUtils.java │ │ └── Utils.java │ └── xxhash │ │ ├── AbstractStreamingXXHash32Java.java │ │ ├── StreamingXXHash32.java │ │ ├── StreamingXXHash32Factory.java │ │ ├── StreamingXXHash32FactoryJNI.java │ │ ├── StreamingXXHash32FactoryJavaSafe.java │ │ ├── StreamingXXHash32FactoryJavaUnsafe.java │ │ ├── StreamingXXHash32JNI.java │ │ ├── StreamingXXHash32JavaSafe.java │ │ ├── StreamingXXHash32JavaUnsafe.java │ │ ├── XXHash32.java │ │ ├── XXHash32JNI.java │ │ ├── XXHash32JavaSafe.java │ │ ├── XXHash32JavaUnsafe.java │ │ ├── XXHashFactory.java │ │ ├── XXHashJNI.java │ │ └── XXHashUtils.java │ ├── rudp │ ├── ReliableServerSocket.java │ ├── ReliableSocket.java │ ├── ReliableSocketInputStream.java │ ├── ReliableSocketListener.java │ ├── ReliableSocketOutputStream.java │ ├── ReliableSocketProfile.java │ ├── ReliableSocketStateListener.java │ └── impl │ │ ├── ACKSegment.java │ │ ├── DATSegment.java │ │ ├── EAKSegment.java │ │ ├── FINSegment.java │ │ ├── NULSegment.java │ │ ├── RSTSegment.java │ │ ├── SYNSegment.java │ │ ├── Segment.java │ │ └── Timer.java │ └── sbbi │ └── upnp │ ├── Discovery.java │ ├── DiscoveryListener.java │ ├── DiscoveryResultsHandler.java │ ├── HttpResponse.java │ ├── XMLUtil.java │ ├── devices │ ├── Device.java │ └── RootDevice.java │ ├── impls │ └── InternetGatewayDevice.java │ ├── messages │ ├── ActionMessage.java │ ├── ActionMessageResponseParser.java │ ├── ActionResponse.java │ ├── StateVariableMessage.java │ ├── StateVariableResponse.java │ ├── StateVariableResponseParser.java │ ├── UPNPMessageFactory.java │ └── UPNPResponseException.java │ └── services │ ├── Action.java │ ├── Argument.java │ ├── ISO8601Date.java │ ├── Service.java │ ├── StateVariable.java │ └── StateVariableTypes.java └── test └── com └── codebrig └── beam ├── example └── chat │ ├── ExampleChatClient.java │ ├── ExampleChatMessage.java │ └── ExampleChatServer.java └── unit ├── TestClientBroadcastHandler.java ├── TestClientServer.java ├── TestServerHandler.java ├── connection ├── proxy │ └── Socks5ProxyTest.java ├── raw │ └── BeamRawTest.java └── traversal │ └── punch │ └── udp │ ├── TestUDPHoleClient.java │ ├── TestUDPPunchClient.java │ └── TestUDPPunchServer.java ├── crypt ├── AESTestHandler.java ├── BeamCryptTest.java └── RSATestHandler.java └── transfer └── TestFileTransfer.java /.gitignore: -------------------------------------------------------------------------------- 1 | /Beam/nbproject/private/ 2 | /nbproject/private/ 3 | /build/ 4 | /dist/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 CodeBrig 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=55aa8ab1 2 | build.xml.script.CRC32=d94e6b75 3 | build.xml.stylesheet.CRC32=8064a381@1.75.2.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=55aa8ab1 7 | nbproject/build-impl.xml.script.CRC32=7aef562d 8 | nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 9 | -------------------------------------------------------------------------------- /nbproject/licenseheader.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | Beam 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/Beam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class Beam 36 | { 37 | 38 | public static final String VERSION = "1.2.0 (alpha)"; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/CommunicatorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class CommunicatorException extends RuntimeException 36 | { 37 | 38 | public CommunicatorException (String message) { 39 | super (message); 40 | } 41 | 42 | public CommunicatorException (Throwable cause) { 43 | super (cause); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/ConnectionStateListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public abstract class ConnectionStateListener 36 | { 37 | 38 | public abstract void preConnection (Communicator comm); 39 | 40 | public abstract void postConnection (Communicator comm); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/ShutdownListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public abstract class ShutdownListener 36 | { 37 | 38 | public abstract void shutdownNotice (String message); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/SystemCommunicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public class SystemCommunicator 38 | { 39 | 40 | private final Communicator communicator; 41 | 42 | public SystemCommunicator (Communicator communicator) { 43 | this.communicator = communicator; 44 | } 45 | 46 | public Communicator getCommunicator () { 47 | return communicator; 48 | } 49 | 50 | public void handleMessage (BeamMessage message) { 51 | communicator.handleMessage (message); 52 | } 53 | 54 | public boolean isTestingConnection () { 55 | return communicator.isTestingConnection (); 56 | } 57 | 58 | public boolean isHandshakeComplete () { 59 | return communicator.isHandshakeComplete (); 60 | } 61 | 62 | public boolean isPerformingHandshake () { 63 | return communicator.isPerformingHandshake (); 64 | } 65 | 66 | public void captureHandshake (String version, long localTime, boolean tunnelConnection) { 67 | communicator.captureHandshake (version, localTime, tunnelConnection); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/ConnectionProtocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public enum ConnectionProtocol 36 | { 37 | 38 | TCP, 39 | UDP; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/httptunnel/TunnelPorts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.httptunnel; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public abstract class TunnelPorts 36 | { 37 | 38 | public abstract int getTunnelPort (int port); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/raw/RawChannelMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.raw; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | import com.codebrig.beam.messages.SystemMessage; 34 | import com.codebrig.beam.messages.SystemMessageType; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class RawChannelMessage extends SystemMessage 40 | { 41 | 42 | private long rawChannelId; 43 | 44 | public RawChannelMessage (long rawChannelId) { 45 | super (SystemMessageType.RAW_DATA_CONNECTION); 46 | 47 | this.rawChannelId = rawChannelId; 48 | } 49 | 50 | public RawChannelMessage (BeamMessage message) { 51 | super (message); 52 | } 53 | 54 | public RawChannelMessage setRawChannelId (long rawChannelId) { 55 | this.rawChannelId = rawChannelId; 56 | return this; 57 | } 58 | 59 | public long getRawChannelId () { 60 | return rawChannelId; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/traversal/TraversalTechnique.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.traversal; 31 | 32 | import java.net.Socket; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public interface TraversalTechnique 38 | { 39 | 40 | public boolean isUsableTechnique (); 41 | 42 | public abstract Socket connect (); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/traversal/punch/udp/UDPPunchTraversalTechnique.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.traversal.punch.udp; 31 | 32 | import com.codebrig.beam.connection.traversal.TraversalTechnique; 33 | import java.net.Socket; 34 | 35 | /** 36 | * @author Brandon Fergerson 37 | */ 38 | public class UDPPunchTraversalTechnique implements TraversalTechnique 39 | { 40 | 41 | public UDPPunchTraversalTechnique (boolean reliableUDP) { 42 | } 43 | 44 | public Socket connect () { 45 | throw new UnsupportedOperationException ("Not supported yet."); 46 | } 47 | 48 | public boolean isUsableTechnique () { 49 | throw new UnsupportedOperationException ("Not supported yet."); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/traversal/punch/udp/messages/UDPPunchMessageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.traversal.punch.udp.messages; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class UDPPunchMessageType 36 | { 37 | 38 | public static final int HOLE_REQUEST_MESSAGE = 1; 39 | public static final int PUNCH_REQUEST_MESSAGE = 2; 40 | public static final int CONNECTION_LISTEN_MESSAGE = 3; 41 | public static final int CONNECTION_CONNECT_MESSAGE = 4; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/traversal/punch/udp/server/NATDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.traversal.punch.udp.server; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import java.util.concurrent.ConcurrentHashMap; 34 | 35 | /** 36 | * @author Brandon Fergerson 37 | */ 38 | public class NATDevice 39 | { 40 | 41 | private final ConcurrentHashMap connections; 42 | private final Communicator comm; 43 | 44 | public NATDevice (Communicator comm) { 45 | this.connections = new ConcurrentHashMap (); 46 | this.comm = comm; 47 | } 48 | 49 | public void addConnection (String accessCode, int port) { 50 | connections.put (accessCode, port); 51 | } 52 | 53 | public boolean validAccessCode (String accessCode) { 54 | return connections.get (accessCode) != null; 55 | } 56 | 57 | public int getConnectionPort (String accessCode) { 58 | Integer connPort = connections.get (accessCode); 59 | 60 | if (connPort == null) { 61 | return -1; 62 | } 63 | return connPort; 64 | } 65 | 66 | public Communicator getCommunicator () { 67 | return comm; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/traversal/upnp/UPNPException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.traversal.upnp; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class UPNPException extends Exception 36 | { 37 | 38 | public UPNPException (String message) { 39 | super (message); 40 | } 41 | 42 | public UPNPException (String message, Throwable cause) { 43 | super (message, cause); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/connection/traversal/upnp/UPNPTraversalTechnique.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.connection.traversal.upnp; 31 | 32 | import com.codebrig.beam.connection.ConnectionProtocol; 33 | import com.codebrig.beam.connection.traversal.TraversalTechnique; 34 | import java.net.Socket; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class UPNPTraversalTechnique implements TraversalTechnique 40 | { 41 | 42 | private final ConnectionProtocol protocol; 43 | private final int timeout; 44 | 45 | public UPNPTraversalTechnique (ConnectionProtocol protocol, int timeout) { 46 | this.protocol = protocol; 47 | this.timeout = timeout; 48 | } 49 | 50 | public Socket connect () { 51 | throw new UnsupportedOperationException ("Not supported yet."); 52 | } 53 | 54 | public boolean isUsableTechnique () { 55 | try { 56 | new UPNPControl (protocol, timeout); 57 | } catch (Exception ex) { 58 | return false; 59 | } 60 | 61 | return true; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/crypt/AESException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.crypt; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class AESException extends CryptException 36 | { 37 | 38 | public AESException (String message) { 39 | super (message); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/crypt/CryptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.crypt; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class CryptException extends RuntimeException 36 | { 37 | 38 | public CryptException (String message) { 39 | super (message); 40 | } 41 | 42 | public CryptException (String message, Throwable cause) { 43 | super (message, cause); 44 | } 45 | 46 | public CryptException (Throwable cause) { 47 | super (cause); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/crypt/EncryptedBeamMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.crypt; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public interface EncryptedBeamMessage 38 | { 39 | 40 | public BeamMessage decryptBeamMessage (BeamMessage message) throws CryptException; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/crypt/RSAException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.crypt; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class RSAException extends CryptException 36 | { 37 | 38 | public RSAException (String message) { 39 | super (message); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/crypt/messages/AESBeamMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.crypt.messages; 31 | 32 | import com.codebrig.beam.crypt.AES; 33 | import com.codebrig.beam.crypt.EncryptedBeamMessage; 34 | import com.codebrig.beam.messages.BeamMessage; 35 | import com.codebrig.beam.messages.SystemMessage; 36 | 37 | /** 38 | * @author Brandon Fergerson 39 | */ 40 | public class AESBeamMessage extends BeamMessage implements EncryptedBeamMessage 41 | { 42 | 43 | private final AES aes; 44 | 45 | public AESBeamMessage (AES aes, int type) { 46 | super (type); 47 | this.aes = aes; 48 | } 49 | 50 | public AESBeamMessage (AES aes, BeamMessage message) { 51 | super (message); 52 | this.aes = aes; 53 | } 54 | 55 | @Override 56 | public byte[] getData () { 57 | return aes.encrypt (super.getData ()); 58 | } 59 | 60 | @Override 61 | public BeamMessage decryptBeamMessage (BeamMessage message) { 62 | byte[] decryptedData = aes.decrypt (message.getData ()); 63 | return new SystemMessage (message.getType (), decryptedData, message.isSystemMessage (), 64 | message.isRawData ()).toBeamMessage (decryptedData); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/crypt/messages/RSAHandshakeMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.crypt.messages; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | import com.codebrig.beam.messages.SystemMessage; 34 | import com.codebrig.beam.messages.SystemMessageType; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class RSAHandshakeMessage extends SystemMessage 40 | { 41 | 42 | private String connectionKey; 43 | private String session; 44 | 45 | public RSAHandshakeMessage () { 46 | super (SystemMessageType.RSA_CONNECTION_HANDSHAKE); 47 | } 48 | 49 | public RSAHandshakeMessage (BeamMessage message) { 50 | super (message); 51 | } 52 | 53 | public RSAHandshakeMessage setConnectionKey (String connectionKey) { 54 | this.connectionKey = connectionKey; 55 | return this; 56 | } 57 | 58 | public String getConnectionKey () { 59 | return connectionKey; 60 | } 61 | 62 | public RSAHandshakeMessage setSession (String session) { 63 | this.session = session; 64 | return this; 65 | } 66 | 67 | public String getSession () { 68 | return session; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/handlers/ClientHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.handlers; 31 | 32 | import com.codebrig.beam.BeamClient; 33 | import com.codebrig.beam.Communicator; 34 | 35 | /** 36 | * @author Brandon Fergerson 37 | */ 38 | public interface ClientHandler 39 | { 40 | 41 | public abstract ClientT getClient (Communicator comm); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/handlers/LegacyHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.handlers; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.messages.BeamMessage; 34 | import com.codebrig.beam.messages.LegacyMessage; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public abstract class LegacyHandler extends BeamHandler 40 | { 41 | 42 | public LegacyHandler (int... types) { 43 | super (types); 44 | } 45 | 46 | LegacyHandler (boolean systemHandler, int... types) { 47 | super (systemHandler, types); 48 | } 49 | 50 | @Override 51 | public BeamMessage messageReceived (Communicator comm, BeamMessage message) { 52 | return messageReceived (comm, convertMessage (convertMessage (message))); 53 | } 54 | 55 | @Override 56 | public LegacyMessage convertMessage (BeamMessage message) { 57 | return new LegacyMessage (message); 58 | } 59 | 60 | public MessageT convertMessage (LegacyMessage message) { 61 | return (MessageT) message; 62 | } 63 | 64 | public abstract MessageT messageReceived (Communicator comm, MessageT message); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/handlers/SpecificBeamHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.handlers; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | import io.protostuff.Schema; 34 | import io.protostuff.runtime.RuntimeSchema; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public abstract class SpecificBeamHandler extends BeamHandler 40 | { 41 | 42 | private final Class messageClazz; 43 | 44 | public SpecificBeamHandler (int messageType, Class messageClazz) { 45 | super (messageType); 46 | this.messageClazz = messageClazz; 47 | 48 | if (messageClazz == null) { 49 | throw new IllegalArgumentException ("Message clazz cannot be null!"); 50 | } 51 | } 52 | 53 | @Override 54 | public MessageT convertMessage (BeamMessage message) { 55 | Schema schema = (Schema) RuntimeSchema.getSchema (messageClazz); 56 | MessageT msg = schema.newMessage (); 57 | msg.copy (message); 58 | return msg; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/handlers/SystemHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.handlers; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.SystemCommunicator; 34 | import com.codebrig.beam.messages.BeamMessage; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public abstract class SystemHandler extends BeamHandler 40 | { 41 | 42 | public SystemHandler (int... types) { 43 | super (true, types); 44 | } 45 | 46 | public SystemHandler (boolean systemHandler, int... types) { 47 | super (systemHandler, types); 48 | } 49 | 50 | @Override 51 | public BeamMessage messageReceived (Communicator comm, BeamMessage message) { 52 | return messageReceived (new SystemCommunicator (comm), message); 53 | } 54 | 55 | public abstract BeamMessage messageReceived (final SystemCommunicator comm, final BeamMessage message); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/messages/BeamMessageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.messages; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public interface BeamMessageType 36 | { 37 | 38 | public String getName (int messageType); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/messages/InvalidBeamMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.messages; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class InvalidBeamMessage extends RuntimeException 36 | { 37 | 38 | public InvalidBeamMessage (String message) { 39 | super (message); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/messages/SystemLegacyMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.messages; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class SystemLegacyMessage extends LegacyMessage 36 | { 37 | 38 | public SystemLegacyMessage (int type) { 39 | super (type, true); 40 | } 41 | 42 | public SystemLegacyMessage (int type, byte[] data) { 43 | super (type, data, true); 44 | } 45 | 46 | public SystemLegacyMessage (boolean rawData, int type, byte[] data, boolean systemMessage) { 47 | super (type, data, systemMessage); 48 | } 49 | 50 | public SystemLegacyMessage (BeamMessage message) { 51 | super (message); 52 | } 53 | 54 | public LegacyMessage toBeamMessage () { 55 | //used to cast down SystemMessage instance 56 | return new LegacyMessage (this); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/messages/SystemMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.messages; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class SystemMessage extends BeamMessage 36 | { 37 | 38 | public SystemMessage (int type) { 39 | super (type, true); 40 | } 41 | 42 | public SystemMessage (int type, byte[] data) { 43 | super (type, data, true); 44 | } 45 | 46 | public SystemMessage (int type, byte[] data, boolean systemMessage, boolean rawData) { 47 | super (type, data, systemMessage, rawData); 48 | } 49 | 50 | public SystemMessage (BeamMessage message) { 51 | super (message); 52 | } 53 | 54 | public BeamMessage toBeamMessage () { 55 | //used to cast down SystemMessage instance 56 | return new BeamMessage (this); 57 | } 58 | 59 | public BeamMessage toBeamMessage (byte[] data) { 60 | //used to cast down SystemMessage instance 61 | BeamMessage msg = new BeamMessage (this); 62 | msg.data = data; 63 | return msg; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/pool/ClientPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.pool; 31 | 32 | import com.codebrig.beam.BeamClient; 33 | import com.codebrig.beam.messages.LegacyMessage; 34 | import java.util.Map; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public interface ClientPool 40 | { 41 | 42 | public abstract String getName (); 43 | 44 | public abstract void setName (String name); 45 | 46 | public abstract void addClient (ClientT client); 47 | 48 | public abstract ClientT removeClient (long clientUID); 49 | 50 | public abstract boolean sendDirectMessage (long clientUID, LegacyMessage message); 51 | 52 | public abstract int broadcastMessage (LegacyMessage message); 53 | 54 | public abstract void close (); 55 | 56 | public abstract boolean hasClient (long clientUID); 57 | 58 | public abstract ClientT getClient (long clientUID); 59 | 60 | public abstract int size (); 61 | 62 | public abstract Map getAllClients (); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/pool/CommunicatorPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.pool; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.messages.BeamMessage; 34 | import java.util.Map; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public interface CommunicatorPool 40 | { 41 | 42 | public abstract String getName (); 43 | 44 | public abstract void setName (String name); 45 | 46 | public abstract void addCommunicator (Communicator communicator); 47 | 48 | public abstract Communicator removeCommunicator (long commmunicatorUID); 49 | 50 | public abstract boolean sendDirectMessage (long communicatorUID, BeamMessage message); 51 | 52 | public abstract int broadcastMessage (BeamMessage message); 53 | 54 | public abstract void close (); 55 | 56 | public abstract boolean hasCommunicator (long commmunicatorUID); 57 | 58 | public abstract Communicator getCommunicator (long communicatorUID); 59 | 60 | public abstract int size (); 61 | 62 | public abstract Map getAllCommunicators (); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/system/handlers/TestConnectionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.system.handlers; 31 | 32 | import com.codebrig.beam.SystemCommunicator; 33 | import com.codebrig.beam.handlers.SystemHandler; 34 | import com.codebrig.beam.messages.BeamMessage; 35 | import com.codebrig.beam.messages.SystemMessage; 36 | import com.codebrig.beam.messages.SystemMessageType; 37 | 38 | /** 39 | * @author Brandon Fergerson 40 | */ 41 | public class TestConnectionHandler extends SystemHandler 42 | { 43 | 44 | public TestConnectionHandler () { 45 | super (SystemMessageType.TEST_CONNECTION); 46 | } 47 | 48 | @Override 49 | public BeamMessage messageReceived (SystemCommunicator comm, BeamMessage message) { 50 | if (comm.isTestingConnection ()) { 51 | //we are the one testing connection, handle response message 52 | comm.handleMessage (new SystemMessage (message).toBeamMessage ()); 53 | return null; 54 | } 55 | 56 | //got message. connection must be good 57 | return new SystemMessage (SystemMessageType.TEST_CONNECTION).toBeamMessage (); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/system/handlers/ping/ClientPingPongHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.system.handlers.ping; 31 | 32 | import com.codebrig.beam.SystemCommunicator; 33 | import com.codebrig.beam.handlers.SystemHandler; 34 | import com.codebrig.beam.messages.BeamMessage; 35 | import com.codebrig.beam.messages.SystemMessage; 36 | import com.codebrig.beam.messages.SystemMessageType; 37 | 38 | /** 39 | * @author Brandon Fergerson 40 | */ 41 | public class ClientPingPongHandler extends SystemHandler 42 | { 43 | 44 | private final BeamMessage pongMessage; 45 | 46 | public ClientPingPongHandler () { 47 | super (SystemMessageType.PING_PONG); 48 | 49 | this.pongMessage = new SystemMessage (SystemMessageType.PING_PONG); 50 | } 51 | 52 | @Override 53 | public BeamMessage messageReceived (SystemCommunicator comm, BeamMessage message) { 54 | //pong back 55 | return pongMessage; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/system/messages/HandshakeMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.system.messages; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | import com.codebrig.beam.messages.SystemMessage; 34 | import com.codebrig.beam.messages.SystemMessageType; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class HandshakeMessage extends SystemMessage 40 | { 41 | 42 | private String version; 43 | private long localTime; 44 | private boolean tunnelConnection; 45 | 46 | public HandshakeMessage (String version, long localTime, boolean tunnelConnection) { 47 | super (SystemMessageType.BEAM_HANDSHAKE); 48 | 49 | this.version = version; 50 | this.localTime = localTime; 51 | this.tunnelConnection = tunnelConnection; 52 | } 53 | 54 | public HandshakeMessage (BeamMessage beamMessage) { 55 | super (beamMessage); 56 | } 57 | 58 | public String getVersion () { 59 | return version; 60 | } 61 | 62 | public long getLocalTime () { 63 | return localTime; 64 | } 65 | 66 | public boolean isTunnelConnection () { 67 | return tunnelConnection; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/system/messages/InvalidHandshakeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.system.messages; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public class InvalidHandshakeException extends RuntimeException 36 | { 37 | 38 | public InvalidHandshakeException (String message) { 39 | super (message); 40 | } 41 | 42 | public InvalidHandshakeException (String message, Throwable cause) { 43 | super (message, cause); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/transfer/TransferException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.transfer; 31 | 32 | import java.io.IOException; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public class TransferException extends IOException 38 | { 39 | 40 | public TransferException (String message) { 41 | super (message); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/transfer/TransferTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.transfer; 31 | 32 | /** 33 | * @author Brandon Fergerson 34 | */ 35 | public interface TransferTracker 36 | { 37 | 38 | public void updateStats (long totalData, long totalDataSent, int dataSent, long cost); 39 | 40 | public void onFile (String onFileLocation, int onFile, int totalFiles); 41 | 42 | public void finished (); 43 | 44 | public void error (String errorMessage); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/codebrig/beam/utils/LimitedQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.utils; 31 | 32 | import java.util.LinkedList; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public class LimitedQueue extends LinkedList 38 | { 39 | 40 | private final int limit; 41 | 42 | public LimitedQueue (int limit) { 43 | this.limit = limit; 44 | } 45 | 46 | @Override 47 | public boolean add (E o) { 48 | boolean added = super.add (o); 49 | while (added && size () > limit) { 50 | super.remove (); 51 | } 52 | 53 | return added; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/FormatSchema.java: -------------------------------------------------------------------------------- 1 | /* Jackson JSON-processor. 2 | * 3 | * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi 4 | */ 5 | 6 | package com.fasterxml.jackson.core; 7 | 8 | /** 9 | * Simple tag interface used to mark schema objects that are used by some 10 | * {@link JsonParser} and {@link JsonGenerator} implementations to further 11 | * specify structure of expected format. 12 | * Basic JSON-based parsers and generators do not use schemas, but some data 13 | * formats (like many binary data formats like Thrift, protobuf) mandate 14 | * use of schemas. 15 | *

16 | * Since there is little commonality between schemas for different data formats, 17 | * this interface does not define much meaningful functionality for accessing 18 | * schema details; rather, specific parser and generator implementations need 19 | * to cast to schema implementations they use. This marker interface is mostly 20 | * used for tagging "some kind of schema" -- instead of passing opaque 21 | * {@link java.lang.Object} -- for documentation purposes. 22 | */ 23 | public interface FormatSchema 24 | { 25 | /** 26 | * Method that can be used to get an identifier that can be used for diagnostics 27 | * purposes, to indicate what kind of data format this schema is used for: typically 28 | * it is a short name of format itself, but it can also contain additional information 29 | * in cases where data format supports multiple types of schemas. 30 | */ 31 | String getSchemaType(); 32 | } 33 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/JsonEncoding.java: -------------------------------------------------------------------------------- 1 | /* Jackson JSON-processor. 2 | * 3 | * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi 4 | */ 5 | 6 | package com.fasterxml.jackson.core; 7 | 8 | /** 9 | * Enumeration that defines legal encodings that can be used 10 | * for JSON content, based on list of allowed encodings from 11 | * JSON specification. 12 | *

13 | * Note: if application want to explicitly disregard Encoding 14 | * limitations (to read in JSON encoded using an encoding not 15 | * listed as allowed), they can use {@link java.io.Reader} / 16 | * {@link java.io.Writer} instances as input 17 | */ 18 | public enum JsonEncoding { 19 | UTF8("UTF-8", false, 8), // N/A for big-endian, really 20 | UTF16_BE("UTF-16BE", true, 16), 21 | UTF16_LE("UTF-16LE", false, 16), 22 | UTF32_BE("UTF-32BE", true, 32), 23 | UTF32_LE("UTF-32LE", false, 32) 24 | ; 25 | 26 | protected final String _javaName; 27 | 28 | protected final boolean _bigEndian; 29 | 30 | protected final int _bits; 31 | 32 | JsonEncoding(String javaName, boolean bigEndian, int bits) 33 | { 34 | _javaName = javaName; 35 | _bigEndian = bigEndian; 36 | _bits = bits; 37 | } 38 | 39 | /** 40 | * Method for accessing encoding name that JDK will support. 41 | * 42 | * @return Matching encoding name that JDK will support. 43 | */ 44 | public String getJavaName() { return _javaName; } 45 | 46 | /** 47 | * Whether encoding is big-endian (if encoding supports such 48 | * notion). If no such distinction is made (as is the case for 49 | * {@link #UTF8}), return value is undefined. 50 | * 51 | * @return True for big-endian encodings; false for little-endian 52 | * (or if not applicable) 53 | */ 54 | public boolean isBigEndian() { return _bigEndian; } 55 | 56 | public int bits() { return _bits; } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/JsonGenerationException.java: -------------------------------------------------------------------------------- 1 | /* Jackson JSON-processor. 2 | * 3 | * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi 4 | */ 5 | 6 | package com.fasterxml.jackson.core; 7 | 8 | /** 9 | * Exception type for exceptions during JSON writing, such as trying 10 | * to output content in wrong context (non-matching end-array or end-object, 11 | * for example). 12 | */ 13 | public class JsonGenerationException 14 | extends JsonProcessingException 15 | { 16 | private final static long serialVersionUID = 123; // Stupid eclipse... 17 | 18 | public JsonGenerationException(Throwable rootCause) 19 | { 20 | super(rootCause); 21 | } 22 | 23 | public JsonGenerationException(String msg) 24 | { 25 | super(msg, (JsonLocation)null); 26 | } 27 | 28 | public JsonGenerationException(String msg, Throwable rootCause) 29 | { 30 | super(msg, (JsonLocation)null, rootCause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/JsonParseException.java: -------------------------------------------------------------------------------- 1 | /* Jackson JSON-processor. 2 | * 3 | * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi 4 | */ 5 | 6 | package com.fasterxml.jackson.core; 7 | 8 | /** 9 | * Exception type for parsing problems, used when non-well-formed content 10 | * (content that does not conform to JSON syntax as per specification) 11 | * is encountered. 12 | */ 13 | public class JsonParseException 14 | extends JsonProcessingException 15 | { 16 | private static final long serialVersionUID = 1L; 17 | 18 | public JsonParseException(String msg, JsonLocation loc) 19 | { 20 | super(msg, loc); 21 | } 22 | 23 | public JsonParseException(String msg, JsonLocation loc, Throwable root) 24 | { 25 | super(msg, loc, root); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/TreeCodec.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Interface that defines objects that can read and write 7 | * {@link TreeNode} instances using Streaming API. 8 | * 9 | * @since 2.3 10 | */ 11 | public abstract class TreeCodec 12 | { 13 | public abstract T readTree(JsonParser jp) 14 | throws IOException, JsonProcessingException; 15 | 16 | public abstract void writeTree(JsonGenerator jg, TreeNode tree) 17 | throws IOException, JsonProcessingException; 18 | 19 | public abstract TreeNode createArrayNode(); 20 | public abstract TreeNode createObjectNode(); 21 | 22 | public abstract JsonParser treeAsTokens(TreeNode node); 23 | } 24 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/Versioned.java: -------------------------------------------------------------------------------- 1 | /* Jackson JSON-processor. 2 | * 3 | * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi 4 | */ 5 | 6 | package com.fasterxml.jackson.core; 7 | 8 | /** 9 | * Interface that those Jackson components that are explicitly versioned will implement. 10 | * Intention is to allow both plug-in components (custom extensions) and applications and 11 | * frameworks that use Jackson to detect exact version of Jackson in use. 12 | * This may be useful for example for ensuring that proper Jackson version is deployed 13 | * (beyond mechanisms that deployment system may have), as well as for possible 14 | * workarounds. 15 | */ 16 | public interface Versioned { 17 | /** 18 | * Method called to detect version of the component that implements this interface; 19 | * returned version should never be null, but may return specific "not available" 20 | * instance (see {@link Version} for details). 21 | */ 22 | Version version(); 23 | } 24 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/base/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Base classes used by concrete Parser and Generator implementations; 3 | * contain functionality that is not specific to JSON or input 4 | * abstraction (byte vs char). 5 | * Most formats extend these types, although it is also possible to 6 | * directly extend {@link com.fasterxml.jackson.core.JsonParser} or 7 | * {@link com.fasterxml.jackson.core.JsonGenerator}. 8 | */ 9 | package com.fasterxml.jackson.core.base; 10 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/format/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Package that contains interfaces needed for dynamic, pluggable 3 | * format (auto)detection; as well as basic utility classes for 4 | * simple format detection functionality. 5 | */ 6 | package com.fasterxml.jackson.core.format; 7 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/io/OutputDecorator.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.io; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * Handler class that can be used to decorate output destinations. 7 | * Typical use is to use a filter abstraction (filtered output stream, 8 | * writer) around original output destination, and apply additional 9 | * processing during write operations. 10 | */ 11 | public abstract class OutputDecorator 12 | implements java.io.Serializable // since 2.1 13 | { 14 | private static final long serialVersionUID = 1L; 15 | 16 | /** 17 | * Method called by {@link com.fasterxml.jackson.core.JsonFactory} instance when 18 | * creating generator for given {@link OutputStream}, when this decorator 19 | * has been registered. 20 | * 21 | * @param ctxt IO context in use (provides access to declared encoding) 22 | * @param out Original output destination 23 | * 24 | * @return OutputStream to use; either passed in argument, or something that 25 | * calls it 26 | */ 27 | public abstract OutputStream decorate(IOContext ctxt, OutputStream out) 28 | throws IOException; 29 | 30 | /** 31 | * Method called by {@link com.fasterxml.jackson.core.JsonFactory} instance when 32 | * creating generator for given {@link Writer}, when this decorator 33 | * has been registered. 34 | * 35 | * @param ctxt IO context in use (provides access to declared encoding) 36 | * @param w Original output writer 37 | * 38 | * @return Writer to use; either passed in argument, or something that calls it 39 | */ 40 | public abstract Writer decorate(IOContext ctxt, Writer w) throws IOException; 41 | } 42 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/json/PackageVersion.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.json; 2 | 3 | import com.fasterxml.jackson.core.Version; 4 | import com.fasterxml.jackson.core.Versioned; 5 | import com.fasterxml.jackson.core.util.VersionUtil; 6 | 7 | /** 8 | * Automatically generated from PackageVersion.java.in during 9 | * packageVersion-generate execution of maven-replacer-plugin in 10 | * pom.xml. 11 | */ 12 | public final class PackageVersion implements Versioned { 13 | public final static Version VERSION = VersionUtil.parseVersion( 14 | "2.3.5", "com.fasterxml.jackson.core", "jackson-core"); 15 | 16 | @Override 17 | public Version version() { 18 | return VERSION; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/json/PackageVersion.java.in: -------------------------------------------------------------------------------- 1 | package @package@; 2 | 3 | import com.fasterxml.jackson.core.Version; 4 | import com.fasterxml.jackson.core.Versioned; 5 | import com.fasterxml.jackson.core.util.VersionUtil; 6 | 7 | /** 8 | * Automatically generated from PackageVersion.java.in during 9 | * packageVersion-generate execution of maven-replacer-plugin in 10 | * pom.xml. 11 | */ 12 | public final class PackageVersion implements Versioned { 13 | public final static Version VERSION = VersionUtil.parseVersion( 14 | "@projectversion@", "@projectgroupid@", "@projectartifactid@"); 15 | 16 | @Override 17 | public Version version() { 18 | return VERSION; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/json/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * JSON-specific parser and generator implementation classes that 3 | * Jackson defines and uses. 4 | * Application code should not (need to) use contents of this package; 5 | * nor are these implementations likely to be of use for sub-classing. 6 | */ 7 | package com.fasterxml.jackson.core.json; 8 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main public API classes of the core streaming JSON 3 | * processor: most importantly {@link com.fasterxml.jackson.core.JsonFactory} 4 | * used for constructing 5 | * JSON parser ({@link com.fasterxml.jackson.core.JsonParser}) 6 | * and generator 7 | * ({@link com.fasterxml.jackson.core.JsonParser}) 8 | * instances. 9 | *

10 | * Public API of the higher-level mapping interfaces ("Mapping API") 11 | * is found from the "jackson-databind" bundle, except for following 12 | * base interfaces that are defined here: 13 | *

    14 | *
  • {@link com.fasterxml.jackson.core.TreeNode} is included 15 | *within Streaming API to support integration of the Tree Model 16 | *(which is based on JsonNode) with the basic 17 | *parsers and generators (iff using mapping-supporting factory: which 18 | *is part of Mapping API, not core) 19 | *
  • 20 | *
  • {@link com.fasterxml.jackson.core.ObjectCodec} is included so that 21 | * reference to the object capable of serializing/deserializing 22 | * Objects to/from JSON (usually, com.fasterxml.jackson.databind.ObjectMapper) 23 | * can be exposed, without adding direct dependency to implementation. 24 | *
  • 25 | *
26 | */ 27 | 28 | package com.fasterxml.jackson.core; 29 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/sym/Name.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.sym; 2 | 3 | /** 4 | * Base class for tokenized names (key strings in objects) that have 5 | * been tokenized from byte-based input sources (like 6 | * {@link java.io.InputStream}. 7 | * 8 | * @author Tatu Saloranta 9 | */ 10 | public abstract class Name 11 | { 12 | protected final String _name; 13 | 14 | protected final int _hashCode; 15 | 16 | protected Name(String name, int hashCode) { 17 | _name = name; 18 | _hashCode = hashCode; 19 | } 20 | 21 | public String getName() { return _name; } 22 | 23 | /* 24 | /********************************************************** 25 | /* Methods for package/core parser 26 | /********************************************************** 27 | */ 28 | 29 | public abstract boolean equals(int quad1); 30 | 31 | public abstract boolean equals(int quad1, int quad2); 32 | 33 | public abstract boolean equals(int[] quads, int qlen); 34 | 35 | /* 36 | /********************************************************** 37 | /* Overridden standard methods 38 | /********************************************************** 39 | */ 40 | 41 | @Override public String toString() { return _name; } 42 | 43 | @Override public final int hashCode() { return _hashCode; } 44 | 45 | @Override public boolean equals(Object o) 46 | { 47 | // Canonical instances, can usually just do identity comparison 48 | return (o == this); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/sym/Name1.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.sym; 2 | 3 | /** 4 | * Specialized implementation of PName: can be used for short Strings 5 | * that consists of at most 4 bytes. Usually this means short 6 | * ascii-only names. 7 | *

8 | * The reason for such specialized classes is mostly space efficiency; 9 | * and to a lesser degree performance. Both are achieved for short 10 | * Strings by avoiding another level of indirection (via quad arrays) 11 | */ 12 | public final class Name1 13 | extends Name 14 | { 15 | final static Name1 sEmptyName = new Name1("", 0, 0); 16 | 17 | final int mQuad; 18 | 19 | Name1(String name, int hash, int quad) 20 | { 21 | super(name, hash); 22 | mQuad = quad; 23 | } 24 | 25 | static Name1 getEmptyName() { return sEmptyName; } 26 | 27 | @Override 28 | public boolean equals(int quad) 29 | { 30 | return (quad == mQuad); 31 | } 32 | 33 | @Override 34 | public boolean equals(int quad1, int quad2) 35 | { 36 | return (quad1 == mQuad) && (quad2 == 0); 37 | } 38 | 39 | @Override 40 | public boolean equals(int[] quads, int qlen) 41 | { 42 | return (qlen == 1 && quads[0] == mQuad); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/sym/Name2.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.sym; 2 | 3 | /** 4 | * Specialized implementation of PName: can be used for short Strings 5 | * that consists of 5 to 8 bytes. Usually this means relatively short 6 | * ascii-only names. 7 | *

8 | * The reason for such specialized classes is mostly space efficiency; 9 | * and to a lesser degree performance. Both are achieved for short 10 | * Strings by avoiding another level of indirection (via quad arrays) 11 | */ 12 | public final class Name2 13 | extends Name 14 | { 15 | final int mQuad1; 16 | 17 | final int mQuad2; 18 | 19 | Name2(String name, int hash, int quad1, int quad2) 20 | { 21 | super(name, hash); 22 | mQuad1 = quad1; 23 | mQuad2 = quad2; 24 | } 25 | 26 | @Override 27 | public boolean equals(int quad) { return false; } 28 | 29 | @Override 30 | public boolean equals(int quad1, int quad2) 31 | { 32 | return (quad1 == mQuad1) && (quad2 == mQuad2); 33 | } 34 | 35 | @Override 36 | public boolean equals(int[] quads, int qlen) 37 | { 38 | return (qlen == 2 && quads[0] == mQuad1 && quads[1] == mQuad2); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/sym/Name3.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.sym; 2 | 3 | /** 4 | * Specialized implementation of PName: can be used for short Strings 5 | * that consists of 9 to 12 bytes. It's the longest special purpose 6 | * implementaion; longer ones are expressed using {@link NameN}. 7 | */ 8 | public final class Name3 9 | extends Name 10 | { 11 | final int mQuad1; 12 | final int mQuad2; 13 | final int mQuad3; 14 | 15 | Name3(String name, int hash, int q1, int q2, int q3) 16 | { 17 | super(name, hash); 18 | mQuad1 = q1; 19 | mQuad2 = q2; 20 | mQuad3 = q3; 21 | } 22 | 23 | // Implies quad length == 1, never matches 24 | @Override 25 | public boolean equals(int quad) { return false; } 26 | 27 | // Implies quad length == 2, never matches 28 | @Override 29 | public boolean equals(int quad1, int quad2) { return false; } 30 | 31 | @Override 32 | public boolean equals(int[] quads, int qlen) 33 | { 34 | return (qlen == 3) 35 | && (quads[0] == mQuad1) 36 | && (quads[1] == mQuad2) 37 | && (quads[2] == mQuad3); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/sym/NameN.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.sym; 2 | 3 | /** 4 | * Generic implementation of PName used for "long" names, where long 5 | * means that its byte (UTF-8) representation is 13 bytes or more. 6 | */ 7 | public final class NameN 8 | extends Name 9 | { 10 | final int[] mQuads; 11 | final int mQuadLen; 12 | 13 | NameN(String name, int hash, int[] quads, int quadLen) 14 | { 15 | super(name, hash); 16 | /* We have specialized implementations for shorter 17 | * names, so let's not allow runt instances here 18 | */ 19 | if (quadLen < 3) { 20 | throw new IllegalArgumentException("Qlen must >= 3"); 21 | } 22 | mQuads = quads; 23 | mQuadLen = quadLen; 24 | } 25 | 26 | // Implies quad length == 1, never matches 27 | @Override 28 | public boolean equals(int quad) { return false; } 29 | 30 | // Implies quad length == 2, never matches 31 | @Override 32 | public boolean equals(int quad1, int quad2) { return false; } 33 | 34 | @Override 35 | public boolean equals(int[] quads, int qlen) 36 | { 37 | if (qlen != mQuadLen) { 38 | return false; 39 | } 40 | 41 | /* 26-Nov-2008, tatus: Strange, but it does look like 42 | * unrolling here is counter-productive, reducing 43 | * speed. Perhaps it prevents inlining by HotSpot or 44 | * something... 45 | */ 46 | // Will always have >= 3 quads, can unroll 47 | /* 48 | if (quads[0] == mQuads[0] 49 | && quads[1] == mQuads[1] 50 | && quads[2] == mQuads[2]) { 51 | for (int i = 3; i < qlen; ++i) { 52 | if (quads[i] != mQuads[i]) { 53 | return false; 54 | } 55 | } 56 | return true; 57 | } 58 | */ 59 | 60 | // or simpler way without unrolling: 61 | for (int i = 0; i < qlen; ++i) { 62 | if (quads[i] != mQuads[i]) { 63 | return false; 64 | } 65 | } 66 | return true; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/sym/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal implementation classes for efficient handling of 3 | * of symbols in JSON (field names in Objects) 4 | */ 5 | package com.fasterxml.jackson.core.sym; 6 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/type/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes needed for type introspection, mostly used by data binding 3 | * functionality. Most of this functionality is needed to properly handled 4 | * generic types, and to simplify and unify processing of things Jackson needs 5 | * to determine how contained types (of {@link java.util.Collection} and 6 | * {@link java.util.Map} classes) are to be handled. 7 | */ 8 | package com.fasterxml.jackson.core.type; 9 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/util/Instantiatable.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.core.util; 2 | 3 | /** 4 | * Add-on interface used to indicate things that may be "blueprint" objects 5 | * which can not be used as is, but are used for creating usable per-process 6 | * (serialization, deserialization) instances, using 7 | * {@link #createInstance} method. 8 | *

9 | * Note that some implementations may choose to implement {@link #createInstance} 10 | * by simply returning 'this': this is acceptable if instances are stateless. 11 | * 12 | * @see DefaultPrettyPrinter 13 | * 14 | * @since 2.1 15 | */ 16 | public interface Instantiatable 17 | { 18 | /** 19 | * Method called to ensure that we have a non-blueprint object to use; 20 | * it is either this object (if stateless), or a newly created object 21 | * with separate state. 22 | */ 23 | T createInstance(); 24 | } 25 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/core/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility classes used by Jackson Core functionality. 3 | */ 4 | package com.fasterxml.jackson.core.util; 5 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/PackageVersion.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.dataformat.smile; 2 | 3 | import com.fasterxml.jackson.core.Version; 4 | import com.fasterxml.jackson.core.Versioned; 5 | import com.fasterxml.jackson.core.util.VersionUtil; 6 | 7 | /** 8 | * Automatically generated from PackageVersion.java.in during 9 | * packageVersion-generate execution of maven-replacer-plugin in 10 | * pom.xml. 11 | */ 12 | public final class PackageVersion implements Versioned { 13 | public final static Version VERSION = VersionUtil.parseVersion( 14 | "2.3.5.1", "com.fasterxml.jackson.dataformat", "jackson-dataformat-smile"); 15 | 16 | @Override 17 | public Version version() { 18 | return VERSION; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/SmileBufferRecycler.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.dataformat.smile; 2 | 3 | /** 4 | * Simple helper class used for implementing simple reuse system for Smile-specific 5 | * buffers that are used. 6 | * 7 | * @param Type of name entries stored in arrays to recycle 8 | */ 9 | public class SmileBufferRecycler 10 | { 11 | public final static int DEFAULT_NAME_BUFFER_LENGTH = 64; 12 | 13 | public final static int DEFAULT_STRING_VALUE_BUFFER_LENGTH = 64; 14 | 15 | protected T[] _seenNamesBuffer; 16 | 17 | protected T[] _seenStringValuesBuffer; 18 | 19 | public SmileBufferRecycler() { } 20 | 21 | public T[] allocSeenNamesBuffer() 22 | { 23 | // 11-Feb-2011, tatu: Used to alloc here; but due to generics, can't easily any more 24 | T[] result = _seenNamesBuffer; 25 | if (result != null) { 26 | // let's ensure we don't retain it here, unless returned 27 | _seenNamesBuffer = null; 28 | // note: caller must have cleaned it up before returning 29 | } 30 | return result; 31 | } 32 | 33 | public T[] allocSeenStringValuesBuffer() 34 | { 35 | // 11-Feb-2011, tatu: Used to alloc here; but due to generics, can't easily any more 36 | T[] result = _seenStringValuesBuffer; 37 | if (result != null) { 38 | _seenStringValuesBuffer = null; 39 | // note: caller must have cleaned it up before returning 40 | } 41 | return result; 42 | } 43 | 44 | public void releaseSeenNamesBuffer(T[] buffer) { 45 | _seenNamesBuffer = buffer; 46 | } 47 | 48 | public void releaseSeenStringValuesBuffer(T[] buffer) { 49 | _seenStringValuesBuffer = buffer; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/SmileUtil.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.dataformat.smile; 2 | 3 | /** 4 | * Class for miscellaneous helper methods. 5 | */ 6 | public class SmileUtil 7 | { 8 | public static int zigzagEncode(int input) { 9 | // Canonical version: 10 | //return (input << 1) ^ (input >> 31); 11 | // but this is even better 12 | if (input < 0) { 13 | return (input << 1) ^ -1; 14 | } 15 | return (input << 1); 16 | } 17 | 18 | public static int zigzagDecode(int encoded) { 19 | // canonical: 20 | //return (encoded >>> 1) ^ (-(encoded & 1)); 21 | if ((encoded & 1) == 0) { // positive 22 | return (encoded >>> 1); 23 | } 24 | // negative 25 | return (encoded >>> 1) ^ -1; 26 | } 27 | 28 | public static long zigzagEncode(long input) { 29 | // Canonical version 30 | //return (input << 1) ^ (input >> 63); 31 | if (input < 0L) { 32 | return (input << 1) ^ -1L; 33 | } 34 | return (input << 1); 35 | } 36 | 37 | public static long zigzagDecode(long encoded) { 38 | // canonical: 39 | //return (encoded >>> 1) ^ (-(encoded & 1)); 40 | if ((encoded & 1) == 0) { // positive 41 | return (encoded >>> 1); 42 | } 43 | // negative 44 | return (encoded >>> 1) ^ -1L; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/async/NonBlockingInputFeeder.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.dataformat.smile.async; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Interface used by non-blocking {@link com.fasterxml.jackson.core.JsonParser} 7 | * to get more input to parse. 8 | * It is accessed by entity that feeds content to parse; at any given point 9 | * only one chunk of content can be processed so caller has to take care to 10 | * only feed more content when existing content has been parsed (which occurs 11 | * when parser's nextToken is called). Once application using 12 | * non-blocking parser has no more data to feed it should call 13 | * {@link #endOfInput} to indicate end of logical input stream. 14 | * 15 | * @author Tatu Saloranta 16 | */ 17 | public interface NonBlockingInputFeeder 18 | { 19 | /** 20 | * Method called to check whether it is ok to feed more data: parser returns true 21 | * if it has no more content to parse (and it is ok to feed more); otherwise false 22 | * (and no data should yet be fed). 23 | */ 24 | public boolean needMoreInput(); 25 | 26 | /** 27 | * Method that can be called to feed more data, if (and only if) 28 | * {@link #needMoreInput} returns true. 29 | * 30 | * @param data Byte array that contains data to feed: caller must ensure data remains 31 | * stable until it is fully processed (which is true when {@link #needMoreInput} 32 | * returns true) 33 | * @param offset Offset within array where input data to process starts 34 | * @param len Length of input data within array to process. 35 | * 36 | * @throws IOException if the state is such that this method should not be called 37 | * (has not yet consumed existing input data, or has been marked as closed) 38 | */ 39 | public void feedInput(byte[] data, int offset, int len) throws IOException; 40 | 41 | /** 42 | * Method that should be called after last chunk of data to parse has been fed 43 | * (with {@link #feedInput}); can be called regardless of what {@link #needMoreInput} 44 | * returns. After calling this method, no more data can be fed; and parser assumes 45 | * no more data will be available. 46 | */ 47 | public void endOfInput(); 48 | } 49 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParser.java: -------------------------------------------------------------------------------- 1 | package com.fasterxml.jackson.dataformat.smile.async; 2 | 3 | import java.io.IOException; 4 | 5 | import com.fasterxml.jackson.core.JsonParseException; 6 | import com.fasterxml.jackson.core.JsonToken; 7 | 8 | /** 9 | * Mix-in interface used with {@link com.fasterxml.jackson.core.JsonParser}, 10 | * extending it with features needed to process data in non-blocking 11 | * ("asynchronous") 12 | */ 13 | public interface NonBlockingParser 14 | extends NonBlockingInputFeeder 15 | { 16 | /** 17 | * Method that can be called when current token is not yet 18 | * available via {@link com.fasterxml.jackson.core.JsonParser#getCurrentToken}, 19 | * to try to figure out what kind of token will be eventually returned 20 | * once the whole token is decoded, if known. 21 | * Note that this may return {@link com.fasterxml.jackson.core.JsonToken#NOT_AVAILABLE}: 22 | * this occurs either if current token is known (and thus no more 23 | * parsing can be done yet), or if not enough content is available 24 | * to even determine next token type (typically we only need a single 25 | * byte, but in boundaries zero bytes is available). 26 | * 27 | * @return Token that will eventually be returned with 28 | * a call to {@link com.fasterxml.jackson.core.JsonParser#nextToken}, if known 29 | */ 30 | public JsonToken peekNextToken() throws IOException, JsonParseException; 31 | } 32 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/async/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Package that contains experimental non-blocking ("asynchronous") 3 | * implementation of reader-part of Jackson streaming API, 4 | * working on Smile format. 5 | */ 6 | package com.fasterxml.jackson.dataformat.smile.async; 7 | -------------------------------------------------------------------------------- /src/com/fasterxml/jackson/dataformat/smile/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Package that contains implementation of Jackson Streaming API that works 3 | * with Smile data format (see Smile format specification), 4 | * and can be used with standard Jackson data binding functionality to deal with 5 | * Smile encoded data. 6 | */ 7 | package com.fasterxml.jackson.dataformat.smile; 8 | -------------------------------------------------------------------------------- /src/com/google/protobuf/BlockingRpcChannel.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | package com.google.protobuf; 31 | 32 | /** 33 | *

34 | * Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel} is 35 | * the blocking equivalent to {@link RpcChannel}. 36 | * 37 | * @author kenton@google.com Kenton Varda 38 | * @author cpovirk@google.com Chris Povirk 39 | */ 40 | public interface BlockingRpcChannel 41 | { 42 | 43 | /** 44 | * Call the given method of the remote service and blocks until it returns. 45 | * {@code callBlockingMethod()} is the blocking equivalent to 46 | * {@link RpcChannel#callMethod}. 47 | */ 48 | Message callBlockingMethod ( 49 | Descriptors.MethodDescriptor method, 50 | RpcController controller, 51 | Message request, 52 | Message responsePrototype) throws ServiceException; 53 | } 54 | -------------------------------------------------------------------------------- /src/com/google/protobuf/ProtocolMessageEnum.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | package com.google.protobuf; 31 | 32 | import com.google.protobuf.Descriptors.EnumDescriptor; 33 | import com.google.protobuf.Descriptors.EnumValueDescriptor; 34 | 35 | /** 36 | * Interface of useful methods added to all enums generated by the protocol 37 | * compiler. 38 | */ 39 | public interface ProtocolMessageEnum extends Internal.EnumLite 40 | { 41 | 42 | /** 43 | * Return the value's numeric value as defined in the .proto file. 44 | */ 45 | int getNumber (); 46 | 47 | /** 48 | * Return the value's descriptor, which contains information such as value 49 | * name, number, and type. 50 | */ 51 | EnumValueDescriptor getValueDescriptor (); 52 | 53 | /** 54 | * Return the enum type's descriptor, which contains information about each 55 | * defined value, etc. 56 | */ 57 | EnumDescriptor getDescriptorForType (); 58 | } 59 | -------------------------------------------------------------------------------- /src/com/google/protobuf/ProtocolStringList.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | package com.google.protobuf; 31 | 32 | import java.util.List; 33 | 34 | /** 35 | * An interface extending {@code List} used for repeated string fields 36 | * to provide optional access to the data as a list of ByteStrings. The 37 | * underlying implementation stores values as either ByteStrings or Strings (see 38 | * {@link LazyStringArrayList}) depending on how the value was initialized or 39 | * last read, and it is often more efficient to deal with lists of ByteStrings 40 | * when handling protos that have been deserialized from bytes. 41 | */ 42 | public interface ProtocolStringList extends List 43 | { 44 | 45 | /** 46 | * Returns a view of the data as a list of ByteStrings. 47 | */ 48 | List asByteStringList (); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/google/protobuf/RpcCallback.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | package com.google.protobuf; 31 | 32 | /** 33 | * Interface for an RPC callback, normally called when an RPC completes. 34 | * {@code ParameterType} is normally the method's response message type. 35 | * 36 | *

37 | * Starting with version 2.3.0, RPC implementations should not try to build on 38 | * this, but should instead provide code generator plugins which generate code 39 | * specific to the particular RPC implementation. This way the generated code 40 | * can be more appropriate for the implementation in use and can avoid 41 | * unnecessary layers of indirection. 42 | * 43 | * @author kenton@google.com Kenton Varda 44 | */ 45 | public interface RpcCallback 46 | { 47 | 48 | void run (ParameterType parameter); 49 | } 50 | -------------------------------------------------------------------------------- /src/com/google/protobuf/ServiceException.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | package com.google.protobuf; 31 | 32 | /** 33 | * Thrown by blocking RPC methods when a failure occurs. 34 | * 35 | * @author cpovirk@google.com (Chris Povirk) 36 | */ 37 | public class ServiceException extends Exception 38 | { 39 | 40 | private static final long serialVersionUID = -1219262335729891920L; 41 | 42 | public ServiceException (final String message) { 43 | super (message); 44 | } 45 | 46 | public ServiceException (final Throwable cause) { 47 | super (cause); 48 | } 49 | 50 | public ServiceException (final String message, final Throwable cause) { 51 | super (message, cause); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/jcraft/jhttptunnel/Bound.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution. 13 | 14 | 3. The names of the authors may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 20 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 23 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.jcraft.jhttptunnel; 29 | 30 | import java.io.IOException; 31 | 32 | abstract class Bound 33 | { 34 | 35 | private String host = null; 36 | private int port = 80; 37 | protected int forwardPort; 38 | 39 | public Bound (int forwardPort) { 40 | this.forwardPort = forwardPort; 41 | } 42 | 43 | public void setHost (String host) { 44 | this.host = host; 45 | } 46 | 47 | public void setPort (int port) { 48 | this.port = port; 49 | } 50 | 51 | protected String getHost () { 52 | return host; 53 | } 54 | 55 | protected int getPort () { 56 | return port; 57 | } 58 | 59 | public int getForwardPort () { 60 | return forwardPort; 61 | } 62 | 63 | public void setForwardPort (int forwardPort) { 64 | this.forwardPort = forwardPort; 65 | } 66 | 67 | public abstract void connect () throws IOException; 68 | 69 | public abstract void close () throws IOException; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/com/jcraft/jhttptunnel/InBound.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution. 13 | 14 | 3. The names of the authors may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 20 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 23 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.jcraft.jhttptunnel; 29 | 30 | import java.io.IOException; 31 | 32 | public abstract class InBound extends Bound 33 | { 34 | 35 | public InBound (int forwardPort) { 36 | super (forwardPort); 37 | } 38 | 39 | public abstract int receiveData (byte[] buf, int s, int l) throws IOException; 40 | 41 | public abstract void resetBackoffTime (); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/jcraft/jhttptunnel/JHttpTunnel.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution. 13 | 14 | 3. The names of the authors may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 20 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 23 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.jcraft.jhttptunnel; 29 | 30 | public interface JHttpTunnel 31 | { 32 | 33 | public static final byte TUNNEL_OPEN = 1; 34 | public static final byte TUNNEL_DATA = 2; 35 | public static final byte TUNNEL_PADDING = 3; 36 | public static final byte TUNNEL_ERROR = 4; 37 | public static final byte TUNNEL_SIMPLE = 0x40; 38 | public static final byte TUNNEL_PAD1 = 5 | TUNNEL_SIMPLE; 39 | public static final byte TUNNEL_CLOSE = 6 | TUNNEL_SIMPLE; 40 | public static final byte TUNNEL_DISCONNECT = 7 | TUNNEL_SIMPLE; 41 | public static final byte TUNNEL_NEXT_READ = 10; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/jcraft/jhttptunnel/JHttpTunnelException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution. 13 | 14 | 3. The names of the authors may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 20 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 23 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.jcraft.jhttptunnel; 29 | 30 | import java.io.IOException; 31 | 32 | public class JHttpTunnelException extends IOException 33 | { 34 | 35 | public JHttpTunnelException () { 36 | } 37 | 38 | public JHttpTunnelException (String message) { 39 | super (message); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/jcraft/jhttptunnel/OutBound.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution. 13 | 14 | 3. The names of the authors may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 20 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 23 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.jcraft.jhttptunnel; 29 | 30 | import java.io.IOException; 31 | 32 | public abstract class OutBound extends Bound 33 | { 34 | 35 | private static final int CONTENT_LENGTH = 1024; 36 | private int content_length = CONTENT_LENGTH; 37 | protected int sendCount; 38 | 39 | public OutBound (int forwardPort) { 40 | super (forwardPort); 41 | } 42 | 43 | protected void setContentLength (int content_length) { 44 | this.content_length = content_length; 45 | } 46 | 47 | protected int getContentLength () { 48 | return content_length; 49 | } 50 | 51 | public abstract void sendData (byte[] foo, int s, int l, boolean flush) throws IOException; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/io/protostuff/CustomSchema.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2010 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff; 16 | 17 | import java.io.IOException; 18 | 19 | /** 20 | * A schema (helper class) that wraps another schema and allows its subclasses to override certain methods for more 21 | * customization. 22 | * 23 | * @author David Yu 24 | * @created May 28, 2010 25 | */ 26 | public abstract class CustomSchema implements Schema 27 | { 28 | 29 | protected final Schema schema; 30 | 31 | public CustomSchema(Schema schema) 32 | { 33 | this.schema = schema; 34 | } 35 | 36 | @Override 37 | public String getFieldName(int number) 38 | { 39 | return schema.getFieldName(number); 40 | } 41 | 42 | @Override 43 | public int getFieldNumber(String name) 44 | { 45 | return schema.getFieldNumber(name); 46 | } 47 | 48 | @Override 49 | public boolean isInitialized(T message) 50 | { 51 | return schema.isInitialized(message); 52 | } 53 | 54 | @Override 55 | public void mergeFrom(Input input, T message) throws IOException 56 | { 57 | schema.mergeFrom(input, message); 58 | } 59 | 60 | @Override 61 | public String messageFullName() 62 | { 63 | return schema.messageFullName(); 64 | } 65 | 66 | @Override 67 | public String messageName() 68 | { 69 | return schema.messageName(); 70 | } 71 | 72 | @Override 73 | public T newMessage() 74 | { 75 | return schema.newMessage(); 76 | } 77 | 78 | @Override 79 | public Class typeClass() 80 | { 81 | return schema.typeClass(); 82 | } 83 | 84 | @Override 85 | public void writeTo(Output output, T message) throws IOException 86 | { 87 | schema.writeTo(output, message); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/io/protostuff/Exclude.java: -------------------------------------------------------------------------------- 1 | //================================================================================ 2 | //Copyright (c) 2012, David Yu 3 | //All rights reserved. 4 | //-------------------------------------------------------------------------------- 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 3. Neither the name of protostuff nor the names of its contributors may be used 13 | // to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | //================================================================================ 28 | 29 | package io.protostuff; 30 | 31 | import java.lang.annotation.ElementType; 32 | import java.lang.annotation.Retention; 33 | import java.lang.annotation.RetentionPolicy; 34 | import java.lang.annotation.Target; 35 | 36 | /** 37 | * A field annotation to configure the field ignored. 38 | * 39 | * @author Johannes Elgh 40 | * @created Jul 30, 2014 41 | */ 42 | @Retention(RetentionPolicy.RUNTIME) 43 | @Target(ElementType.FIELD) 44 | public @interface Exclude 45 | { 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/io/protostuff/GraphInput.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2011 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff; 16 | 17 | /** 18 | * An input that is stateful and keeps track of the references. This is useful for updating the reference of the last 19 | * message (polymorphic) deserialized. 20 | * 21 | * @author David Yu 22 | * @created Jan 19, 2011 23 | */ 24 | public interface GraphInput extends Input 25 | { 26 | 27 | /** 28 | * Updates the last reference (the tip/end of the index) kept if the {@code lastMessage} was indeed the last 29 | * message. 30 | */ 31 | public void updateLast(Object morphedMessage, Object lastMessage); 32 | 33 | /** 34 | * Returns true if the last message was read as a reference. 35 | */ 36 | public boolean isCurrentMessageReference(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/io/protostuff/JsonInputException.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2010 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff; 16 | 17 | /** 18 | * Thrown when a json-encoded protobuf message being parsed is invalid in some way. 19 | * 20 | * @author David Yu 21 | * @created May 10, 2010 22 | */ 23 | public class JsonInputException extends ProtostuffException 24 | { 25 | 26 | private static final long serialVersionUID = 8137903301860116023L; 27 | 28 | public JsonInputException(String description) 29 | { 30 | super(description); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/io/protostuff/Message.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2009 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff; 16 | 17 | /** 18 | * The serializable object where its {@link Schema schema} handles its serialization and deserialization. 19 | * 20 | * @author David Yu 21 | * @created Nov 9, 2009 22 | */ 23 | public interface Message 24 | { 25 | 26 | /** 27 | * Gets the cached schema of this message. 28 | */ 29 | public Schema cachedSchema(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/io/protostuff/Morph.java: -------------------------------------------------------------------------------- 1 | //================================================================================ 2 | //Copyright (c) 2012, David Yu 3 | //All rights reserved. 4 | //-------------------------------------------------------------------------------- 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 3. Neither the name of protostuff nor the names of its contributors may be used 13 | // to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | //================================================================================ 28 | 29 | package io.protostuff; 30 | 31 | import java.lang.annotation.ElementType; 32 | import java.lang.annotation.Retention; 33 | import java.lang.annotation.RetentionPolicy; 34 | import java.lang.annotation.Target; 35 | 36 | /** 37 | * Used to configure non-final pojos, map interfaces and collection interfaces. 38 | * 39 | * @author David Yu 40 | * @created Apr 30, 2012 41 | */ 42 | @Retention(RetentionPolicy.RUNTIME) 43 | @Target(ElementType.FIELD) 44 | public @interface Morph 45 | { 46 | boolean value() default true; 47 | } 48 | -------------------------------------------------------------------------------- /src/io/protostuff/ProtostuffException.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2010 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff; 16 | 17 | import java.io.IOException; 18 | 19 | /** 20 | * The base io exception for all formats (protobuf/json/xml). 21 | * 22 | * @author David Yu 23 | * @created May 25, 2010 24 | */ 25 | public class ProtostuffException extends IOException 26 | { 27 | 28 | private static final long serialVersionUID = 3969366848110070516L; 29 | 30 | public ProtostuffException() 31 | { 32 | super(); 33 | } 34 | 35 | public ProtostuffException(String message) 36 | { 37 | super(message); 38 | } 39 | 40 | public ProtostuffException(String message, Throwable cause) 41 | { 42 | super(message, cause); 43 | } 44 | 45 | public ProtostuffException(Throwable cause) 46 | { 47 | super(cause); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/io/protostuff/Request.java: -------------------------------------------------------------------------------- 1 | package io.protostuff; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.METHOD; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | /** 11 | * Specify rpc request qualifier. 12 | * 13 | * @author Kostiantyn Shchepanovskyi 14 | */ 15 | @Documented 16 | @Target(METHOD) 17 | @Retention(RUNTIME) 18 | public @interface Request 19 | { 20 | String value(); 21 | } 22 | -------------------------------------------------------------------------------- /src/io/protostuff/Response.java: -------------------------------------------------------------------------------- 1 | package io.protostuff; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.METHOD; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | /** 11 | * Specify rpc response qualifier. 12 | * 13 | * @author Kostiantyn Shchepanovskyi 14 | */ 15 | @Documented 16 | @Target(METHOD) 17 | @Retention(RUNTIME) 18 | public @interface Response 19 | { 20 | String value(); 21 | } 22 | -------------------------------------------------------------------------------- /src/io/protostuff/Rpc.java: -------------------------------------------------------------------------------- 1 | package io.protostuff; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.METHOD; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Marker annotation, indicates that an annotated method is a rpc service method. 11 | * Other annotations can be used for request/response qualifiers customization - 12 | * {@link Request}, {@link Response}. 13 | * 14 | * @author Kostiantyn Shchepanovskyi 15 | */ 16 | @Retention(RUNTIME) 17 | @Target(METHOD) 18 | public @interface Rpc 19 | { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/io/protostuff/Service.java: -------------------------------------------------------------------------------- 1 | package io.protostuff; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.TYPE; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Rpc service annotation, specifies service namespace. 11 | * 12 | * https://github.com/protostuff/protostuff/wiki/Rpc-Services 13 | * 14 | *

15 | * Consider this service definition: 16 | *

17 |  *     package foo;
18 |  *     service Bar {
19 |  *         rpc DoWork(Request) returns(Response);
20 |  *     }
21 |  * 
22 | *

23 | * By default, service namespace is formed as a package + '.' + service name. 24 | * In the example above, service namespace is "foo.Bar". 25 | *

26 | * Request and response qualifiers are generated using rpc method name. 27 | * Request qualifier is formed as service namespace + '/' + method name + 'Request'. 28 | * Response qualifier is formed as service namespace + '/' + method name + 'Response'. 29 | * In the example above, request/response qualifiers are "foo.Bar/DoWorkRequest" and 30 | * "foo.Bar/DoWorkResponse". 31 | * 32 | * @author Kostiantyn Shchepanovskyi 33 | */ 34 | @Retention(RUNTIME) 35 | @Target(TYPE) 36 | public @interface Service 37 | { 38 | 39 | /** 40 | * Service namespace. 41 | */ 42 | String value(); 43 | } 44 | -------------------------------------------------------------------------------- /src/io/protostuff/StatefulOutput.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2011 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff; 16 | 17 | /** 18 | * An output that keeps the state of the schema being used. 19 | * 20 | * @author David Yu 21 | * @created Jan 24, 2011 22 | */ 23 | public interface StatefulOutput extends Output 24 | { 25 | 26 | /** 27 | * Updates the schema if {@code lastSchema} was indeed the last schema used. 28 | */ 29 | public void updateLast(Schema schema, Schema lastSchema); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/Field.java: -------------------------------------------------------------------------------- 1 | package io.protostuff.runtime; 2 | 3 | import java.io.IOException; 4 | 5 | import io.protostuff.Input; 6 | import io.protostuff.Output; 7 | import io.protostuff.Pipe; 8 | import io.protostuff.Tag; 9 | import io.protostuff.WireFormat; 10 | 11 | /** 12 | * Represents a field of a message/pojo. 13 | */ 14 | public abstract class Field 15 | { 16 | public final WireFormat.FieldType type; 17 | public final int number; 18 | public final String name; 19 | public final boolean repeated; 20 | public final int groupFilter; 21 | 22 | // public final Tag tag; 23 | 24 | public Field(WireFormat.FieldType type, int number, String name, boolean repeated, 25 | Tag tag) 26 | { 27 | this.type = type; 28 | this.number = number; 29 | this.name = name; 30 | this.repeated = repeated; 31 | this.groupFilter = tag == null ? 0 : tag.groupFilter(); 32 | // this.tag = tag; 33 | } 34 | 35 | public Field(WireFormat.FieldType type, int number, String name, Tag tag) 36 | { 37 | this(type, number, name, false, tag); 38 | } 39 | 40 | /** 41 | * Writes the value of a field to the {@code output}. 42 | */ 43 | protected abstract void writeTo(Output output, T message) 44 | throws IOException; 45 | 46 | /** 47 | * Reads the field value into the {@code message}. 48 | */ 49 | protected abstract void mergeFrom(Input input, T message) 50 | throws IOException; 51 | 52 | /** 53 | * Transfer the input field to the output field. 54 | */ 55 | protected abstract void transfer(Pipe pipe, Input input, Output output, 56 | boolean repeated) throws IOException; 57 | } 58 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/FieldMap.java: -------------------------------------------------------------------------------- 1 | package io.protostuff.runtime; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Interface for map of fields - defines how to you get field by name or number (tag). 7 | * 8 | * @author Kostiantyn Shchepanovskyi 9 | */ 10 | interface FieldMap 11 | { 12 | 13 | Field getFieldByNumber(int n); 14 | 15 | Field getFieldByName(String fieldName); 16 | 17 | int getFieldCount(); 18 | 19 | List> getFields(); 20 | } 21 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/HasDelegate.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2012 David Yu 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff.runtime; 16 | 17 | import io.protostuff.runtime.PolymorphicSchema.Handler; 18 | 19 | /** 20 | * Wraps a delegate. 21 | * 22 | * @author David Yu 23 | * @created Dec 5, 2012 24 | */ 25 | public class HasDelegate implements PolymorphicSchema.Factory 26 | { 27 | 28 | public final Delegate delegate; 29 | 30 | public final ArraySchemas.Base genericElementSchema; 31 | 32 | @SuppressWarnings("unchecked") 33 | public HasDelegate(Delegate delegate) 34 | { 35 | this.delegate = delegate; 36 | 37 | genericElementSchema = new ArraySchemas.DelegateArray(null, 38 | (Delegate) delegate); 39 | } 40 | 41 | /** 42 | * Returns the delegate. 43 | */ 44 | public final Delegate getDelegate() 45 | { 46 | return delegate; 47 | } 48 | 49 | @Override 50 | @SuppressWarnings("unchecked") 51 | public final PolymorphicSchema newSchema(Class typeClass, 52 | IdStrategy strategy, Handler handler) 53 | { 54 | return new ArraySchemas.DelegateArray(handler, 55 | (Delegate) delegate); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/OnDemandSunReflectionFactory.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2011 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | /** 16 | * 17 | */ 18 | package io.protostuff.runtime; 19 | 20 | import java.lang.reflect.Constructor; 21 | 22 | /** 23 | * This class is expected not to load unless {@link RuntimeEnv} made sure that sun.reflect.ReflectionFactory is in the 24 | * classpath. 25 | * 26 | * @author David Yu 27 | * @created Jul 8, 2011 28 | */ 29 | final class OnDemandSunReflectionFactory 30 | { 31 | 32 | private OnDemandSunReflectionFactory() 33 | { 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | static Constructor getConstructor(Class clazz, 38 | Constructor constructor) 39 | { 40 | return (Constructor) sun.reflect.ReflectionFactory 41 | .getReflectionFactory().newConstructorForSerialization(clazz, 42 | constructor); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/RuntimeMessageField.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2011 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff.runtime; 16 | 17 | import io.protostuff.Pipe; 18 | import io.protostuff.Schema; 19 | import io.protostuff.Tag; 20 | import io.protostuff.WireFormat.FieldType; 21 | 22 | /** 23 | * A runtime message field that lazily loads the schema to support cyclic dependencies. 24 | * 25 | * @author David Yu 26 | * @created Jan 19, 2011 27 | */ 28 | abstract class RuntimeMessageField extends Field 29 | { 30 | 31 | /** 32 | * The class of the message field. 33 | */ 34 | public final Class

typeClass; 35 | 36 | final HasSchema

hasSchema; 37 | 38 | public RuntimeMessageField(Class

typeClass, HasSchema

hasSchema, 39 | FieldType type, int number, String name, boolean repeated, Tag tag) 40 | { 41 | super(type, number, name, repeated, tag); 42 | this.typeClass = typeClass; 43 | this.hasSchema = hasSchema; 44 | } 45 | 46 | /** 47 | * Returns the schema. 48 | */ 49 | public Schema

getSchema() 50 | { 51 | return hasSchema.getSchema(); 52 | } 53 | 54 | /** 55 | * Returns the lazy initialized pipe schema. 56 | */ 57 | public Pipe.Schema

getPipeSchema() 58 | { 59 | return hasSchema.getPipeSchema(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/RuntimeObjectField.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2007-2011 David Yu dyuproject@gmail.com 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff.runtime; 16 | 17 | import io.protostuff.Tag; 18 | import io.protostuff.WireFormat.FieldType; 19 | 20 | /** 21 | * A runtime field whose field type is {@link Object} (dynamic). 22 | * 23 | * @author David Yu 24 | * @created Feb 1, 2011 25 | */ 26 | abstract class RuntimeObjectField extends Field implements 27 | PolymorphicSchema.Handler 28 | { 29 | 30 | /** 31 | * The polymorphic schema. 32 | */ 33 | public final PolymorphicSchema schema; 34 | 35 | public RuntimeObjectField(Class typeClass, FieldType type, int number, 36 | String name, boolean repeated, Tag tag, 37 | PolymorphicSchema.Factory factory, IdStrategy strategy) 38 | { 39 | super(type, number, name, repeated, tag); 40 | 41 | schema = factory.newSchema(typeClass, strategy, this); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/io/protostuff/runtime/RuntimePipeSchema.java: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | //Copyright 2012 David Yu 3 | //------------------------------------------------------------------------ 4 | //Licensed under the Apache License, Version 2.0 (the "License"); 5 | //you may not use this file except in compliance with the License. 6 | //You may obtain a copy of the License at 7 | //http://www.apache.org/licenses/LICENSE-2.0 8 | //Unless required by applicable law or agreed to in writing, software 9 | //distributed under the License is distributed on an "AS IS" BASIS, 10 | //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | //See the License for the specific language governing permissions and 12 | //limitations under the License. 13 | //======================================================================== 14 | 15 | package io.protostuff.runtime; 16 | 17 | import java.io.IOException; 18 | 19 | import io.protostuff.Input; 20 | import io.protostuff.Output; 21 | import io.protostuff.Pipe; 22 | import io.protostuff.Schema; 23 | 24 | /** 25 | * Runtime pipe schema. 26 | * 27 | * @author David Yu 28 | * @created Nov 9, 2012 29 | */ 30 | public final class RuntimePipeSchema extends Pipe.Schema 31 | { 32 | 33 | final FieldMap fieldsMap; 34 | 35 | public RuntimePipeSchema(Schema schema, FieldMap fieldMap) 36 | { 37 | super(schema); 38 | 39 | this.fieldsMap = fieldMap; 40 | } 41 | 42 | @Override 43 | protected void transfer(Pipe pipe, Input input, Output output) 44 | throws IOException 45 | { 46 | for (int number = input.readFieldNumber(wrappedSchema); number != 0; number = input 47 | .readFieldNumber(wrappedSchema)) 48 | { 49 | final Field field = fieldsMap.getFieldByNumber(number); 50 | if (field == null) 51 | input.handleUnknownField(number, wrappedSchema); 52 | else 53 | field.transfer(pipe, input, output, field.repeated); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4Compressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * LZ4 compressor. 18 | *

19 | * Instances of this class are thread-safe. 20 | */ 21 | public abstract class LZ4Compressor 22 | { 23 | 24 | /** 25 | * Return the maximum compressed length for an input of size 26 | * length. 27 | */ 28 | @SuppressWarnings("static-method") 29 | public final int maxCompressedLength (int length) { 30 | return LZ4Utils.maxCompressedLength (length); 31 | } 32 | 33 | /** 34 | * Compress src[srcOff:srcOff+srcLen] into 35 | * dest[destOff:destOff+destLen] and return the compressed 36 | * length. 37 | * 38 | * This method will throw a {@link LZ4Exception} if this compressor is 39 | * unable to compress the input into less than maxDestLen 40 | * bytes. To prevent this exception to be thrown, you should make sure that 41 | * maxDestLen >= maxCompressedLength(srcLen). 42 | * 43 | * @throws LZ4Exception if maxDestLen is too small 44 | * @return the compressed size 45 | */ 46 | public abstract int compress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen); 47 | 48 | /** 49 | * Convenience method. Equivalent to calling 50 | * {@link #compress(byte[], int, int, byte[], int, int)} with 51 | * destLen = dest.length - destOff. 52 | */ 53 | public final int compress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff) { 54 | return compress (src, srcOff, srcLen, dest, destOff, dest.length - destOff); 55 | } 56 | 57 | @Override 58 | public String toString () { 59 | return getClass ().getSimpleName (); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4Decompressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * LZ4 decompressor that requires the size of the original input to be known. 18 | * Use {@link LZ4UnknownSizeDecompressor} if you only know the size of the 19 | * compressed stream. 20 | *

21 | * Instances of this class are thread-safe. 22 | */ 23 | public abstract class LZ4Decompressor 24 | { 25 | 26 | /** 27 | * Uncompress src[srcOff:] into 28 | * dest[destOff:destOff+destLen] and return the number of bytes 29 | * read from src. destLen must be exactly the size 30 | * of the decompressed data. 31 | * 32 | * @param destLen the exact size of the original input 33 | * 34 | * @return the number of bytes read to restore the original input 35 | */ 36 | public abstract int decompress (byte[] src, int srcOff, byte[] dest, int destOff, int destLen); 37 | 38 | @Override 39 | public String toString () { 40 | return getClass ().getSimpleName (); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4Exception.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * LZ4 compression or decompression error. 18 | */ 19 | public class LZ4Exception extends RuntimeException 20 | { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public LZ4Exception (String msg, Throwable t) { 25 | super (msg, t); 26 | } 27 | 28 | public LZ4Exception (String msg) { 29 | super (msg); 30 | } 31 | 32 | public LZ4Exception () { 33 | super (); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4HCJNICompressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import static net.jpountz.util.Utils.checkRange; 17 | 18 | /** 19 | * High compression {@link LZ4Compressor}s implemented with JNI bindings to the 20 | * original C implementation of LZ4. 21 | */ 22 | final class LZ4HCJNICompressor extends LZ4Compressor 23 | { 24 | 25 | public static final LZ4Compressor INSTANCE = new LZ4HCJNICompressor (); 26 | 27 | @Override 28 | public int compress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { 29 | checkRange (src, srcOff, srcLen); 30 | checkRange (dest, destOff, maxDestLen); 31 | if (maxDestLen < maxCompressedLength (srcLen)) { 32 | throw new IllegalArgumentException ("This compressor does not support output buffers whose size is < maxCompressedLength(srcLen)"); 33 | } 34 | final int result = LZ4JNI.LZ4_compressHC (src, srcOff, srcLen, dest, destOff); 35 | if (result <= 0) { 36 | throw new LZ4Exception (); 37 | } 38 | return result; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4JNI.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import net.jpountz.util.Native; 17 | 18 | /** 19 | * JNI bindings to the original C implementation of LZ4. 20 | */ 21 | enum LZ4JNI 22 | { 23 | 24 | 25 | ; 26 | 27 | static { 28 | Native.load (); 29 | init (); 30 | } 31 | 32 | static native void init (); 33 | 34 | static native int LZ4_compress_limitedOutput (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen); 35 | 36 | static native int LZ4_compressHC (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff); 37 | 38 | static native int LZ4_decompress (byte[] src, int srcOff, byte[] dest, int destOff, int destLen); 39 | 40 | static native int LZ4_decompress_unknownOutputSize (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen); 41 | 42 | static native int LZ4_compressBound (int len); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4JNICompressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import static net.jpountz.util.Utils.checkRange; 17 | 18 | /** 19 | * Fast {@link LZ4Compressor}s implemented with JNI bindings to the original C 20 | * implementation of LZ4. 21 | */ 22 | final class LZ4JNICompressor extends LZ4Compressor 23 | { 24 | 25 | public static final LZ4Compressor INSTANCE = new LZ4JNICompressor (); 26 | 27 | @Override 28 | public int compress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { 29 | checkRange (src, srcOff, srcLen); 30 | checkRange (dest, destOff, maxDestLen); 31 | final int result = LZ4JNI.LZ4_compress_limitedOutput (src, srcOff, srcLen, dest, destOff, maxDestLen); 32 | if (result <= 0) { 33 | throw new LZ4Exception ("maxDestLen is too small"); 34 | } 35 | return result; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4JNIDecompressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import static net.jpountz.util.Utils.checkRange; 17 | 18 | /** 19 | * {@link LZ4Decompressor} implemented with JNI bindings to the original C 20 | * implementation of LZ4. 21 | */ 22 | final class LZ4JNIDecompressor extends LZ4Decompressor 23 | { 24 | 25 | public static final LZ4JNIDecompressor INSTANCE = new LZ4JNIDecompressor (); 26 | 27 | @Override 28 | public final int decompress (byte[] src, int srcOff, byte[] dest, int destOff, int destLen) { 29 | checkRange (src, srcOff); 30 | checkRange (dest, destOff, destLen); 31 | final int result = LZ4JNI.LZ4_decompress (src, srcOff, dest, destOff, destLen); 32 | if (result < 0) { 33 | throw new LZ4Exception ("Error decoding offset " + (srcOff - result) + " of input buffer"); 34 | } 35 | return result; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4JNIUnknownSizeDecompressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import static net.jpountz.util.Utils.checkRange; 17 | 18 | /** 19 | * {@link LZ4Decompressor} implemented with JNI bindings to the original C 20 | * implementation of LZ4. 21 | */ 22 | final class LZ4JNIUnknownSizeDecompressor extends LZ4UnknownSizeDecompressor 23 | { 24 | 25 | public static final LZ4UnknownSizeDecompressor INSTANCE = new LZ4JNIUnknownSizeDecompressor (); 26 | 27 | @Override 28 | public final int decompress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { 29 | checkRange (src, srcOff, srcLen); 30 | checkRange (dest, destOff, maxDestLen); 31 | final int result = LZ4JNI.LZ4_decompress_unknownOutputSize (src, srcOff, srcLen, dest, destOff, maxDestLen); 32 | if (result < 0) { 33 | throw new LZ4Exception ("Error decoding offset " + (srcOff - result) + " of input buffer"); 34 | } 35 | return result; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/net/jpountz/lz4/LZ4UnknownSizeDecompressor.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.lz4; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * LZ4 decompressor that requires the size of the compressed data to be known. 18 | *

19 | * Implementations of this class are usually a little slower than those of 20 | * {@link LZ4Decompressor} but do not require the size of the original data to 21 | * be known. 22 | */ 23 | public abstract class LZ4UnknownSizeDecompressor 24 | { 25 | 26 | /** 27 | * Uncompress src[srcOff:srcLen] into 28 | * dest[destOff:destOff+maxDestLen] and returns the number of 29 | * decompressed bytes written into dest. 30 | * 31 | * @param srcLen the exact size of the compressed stream 32 | * 33 | * @return the original input size 34 | * 35 | * @throws LZ4Exception if maxDestLen is too small 36 | */ 37 | public abstract int decompress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen); 38 | 39 | /** 40 | * Convenience method. Equivalent to calling 41 | * {@link #decompress(byte[], int, int, byte[], int, int)} with 42 | * maxDestLen = dest.length - destOff. 43 | */ 44 | public final int decompress (byte[] src, int srcOff, int srcLen, byte[] dest, int destOff) { 45 | return decompress (src, srcOff, srcLen, dest, destOff, dest.length - destOff); 46 | } 47 | 48 | @Override 49 | public String toString () { 50 | return getClass ().getSimpleName (); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/net/jpountz/util/Utils.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.util; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.nio.ByteOrder; 17 | 18 | public enum Utils 19 | { 20 | 21 | ; 22 | 23 | public static final ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder (); 24 | 25 | public static void checkRange (byte[] buf, int off) { 26 | if (off < 0 || off >= buf.length) { 27 | throw new ArrayIndexOutOfBoundsException (off); 28 | } 29 | } 30 | 31 | public static void checkRange (byte[] buf, int off, int len) { 32 | checkLength (len); 33 | if (len > 0) { 34 | checkRange (buf, off); 35 | checkRange (buf, off + len - 1); 36 | } 37 | } 38 | 39 | public static void checkLength (int len) { 40 | if (len < 0) { 41 | throw new IllegalArgumentException ("lengths must be >= 0"); 42 | } 43 | } 44 | 45 | public static int readIntBE (byte[] buf, int i) { 46 | return ((buf[i] & 0xFF) << 24) | ((buf[i + 1] & 0xFF) << 16) | ((buf[i + 2] & 0xFF) << 8) | (buf[i + 3] & 0xFF); 47 | } 48 | 49 | public static int readIntLE (byte[] buf, int i) { 50 | return (buf[i] & 0xFF) | ((buf[i + 1] & 0xFF) << 8) | ((buf[i + 2] & 0xFF) << 16) | ((buf[i + 3] & 0xFF) << 24); 51 | } 52 | 53 | public static int readInt (byte[] buf, int i) { 54 | if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) { 55 | return readIntBE (buf, i); 56 | } else { 57 | return readIntLE (buf, i); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/AbstractStreamingXXHash32Java.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import static net.jpountz.xxhash.XXHashUtils.PRIME1; 17 | import static net.jpountz.xxhash.XXHashUtils.PRIME2; 18 | 19 | abstract class AbstractStreamingXXHash32Java extends StreamingXXHash32 20 | { 21 | 22 | int v1, v2, v3, v4, memSize; 23 | long totalLen; 24 | final byte[] memory; 25 | 26 | AbstractStreamingXXHash32Java (int seed) { 27 | super (seed); 28 | memory = new byte[16]; 29 | reset (); 30 | } 31 | 32 | @Override 33 | public void reset () { 34 | v1 = seed + PRIME1 + PRIME2; 35 | v2 = seed + PRIME2; 36 | v3 = seed + 0; 37 | v4 = seed - PRIME1; 38 | totalLen = 0; 39 | memSize = 0; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/StreamingXXHash32Factory.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | interface StreamingXXHash32Factory 17 | { 18 | 19 | StreamingXXHash32 newStreamingHash (int seed); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/StreamingXXHash32FactoryJNI.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | final class StreamingXXHash32FactoryJNI implements StreamingXXHash32Factory 17 | { 18 | 19 | public static final StreamingXXHash32Factory INSTANCE = new StreamingXXHash32FactoryJNI (); 20 | 21 | @Override 22 | public StreamingXXHash32 newStreamingHash (int seed) { 23 | return new StreamingXXHash32JNI (seed); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/StreamingXXHash32FactoryJavaSafe.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | final class StreamingXXHash32FactoryJavaSafe implements StreamingXXHash32Factory 17 | { 18 | 19 | public static final StreamingXXHash32Factory INSTANCE = new StreamingXXHash32FactoryJavaSafe (); 20 | 21 | @Override 22 | public StreamingXXHash32 newStreamingHash (int seed) { 23 | return new StreamingXXHash32JavaSafe (seed); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/StreamingXXHash32FactoryJavaUnsafe.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | final class StreamingXXHash32FactoryJavaUnsafe implements StreamingXXHash32Factory 17 | { 18 | 19 | public static final StreamingXXHash32Factory INSTANCE = new StreamingXXHash32FactoryJavaUnsafe (); 20 | 21 | @Override 22 | public StreamingXXHash32 newStreamingHash (int seed) { 23 | return new StreamingXXHash32JavaUnsafe (seed); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/StreamingXXHash32JNI.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | final class StreamingXXHash32JNI extends StreamingXXHash32 17 | { 18 | 19 | private long state; 20 | 21 | StreamingXXHash32JNI (int seed) { 22 | super (seed); 23 | state = XXHashJNI.XXH32_init (seed); 24 | } 25 | 26 | private void checkState () { 27 | if (state == 0) { 28 | throw new AssertionError ("Already finalized"); 29 | } 30 | } 31 | 32 | @Override 33 | public void reset () { 34 | checkState (); 35 | XXHashJNI.XXH32_free (state); 36 | state = XXHashJNI.XXH32_init (seed); 37 | } 38 | 39 | @Override 40 | public int getValue () { 41 | checkState (); 42 | return XXHashJNI.XXH32_getIntermediateResult (state); 43 | } 44 | 45 | @Override 46 | public void update (byte[] bytes, int off, int len) { 47 | checkState (); 48 | XXHashJNI.XXH32_feed (state, bytes, off, len); 49 | } 50 | 51 | @Override 52 | protected void finalize () throws Throwable { 53 | super.finalize (); 54 | // free memory 55 | XXHashJNI.XXH32_free (state); 56 | state = 0; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/XXHash32.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * A 32-bits hash. 18 | *

19 | * Instances of this class are thread-safe. 20 | */ 21 | public abstract class XXHash32 22 | { 23 | 24 | /** 25 | * Compute the 32-bits hash of buf[off:off+len] using seed 26 | * seed. 27 | */ 28 | public abstract int hash (byte[] buf, int off, int len, int seed); 29 | 30 | @Override 31 | public String toString () { 32 | return getClass ().getSimpleName (); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/XXHash32JNI.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import static net.jpountz.util.Utils.checkRange; 17 | 18 | final class XXHash32JNI extends XXHash32 19 | { 20 | 21 | public static final XXHash32 INSTANCE = new XXHash32JNI (); 22 | 23 | @Override 24 | public int hash (byte[] buf, int off, int len, int seed) { 25 | checkRange (buf, off, len); 26 | return XXHashJNI.XXH32 (buf, off, len, seed); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/XXHashJNI.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import net.jpountz.util.Native; 17 | 18 | enum XXHashJNI 19 | { 20 | 21 | 22 | ; 23 | 24 | static { 25 | Native.load (); 26 | init (); 27 | } 28 | 29 | private static native void init (); 30 | 31 | static native int XXH32 (byte[] input, int offset, int len, int seed); 32 | 33 | static native long XXH32_init (int seed); 34 | 35 | static native void XXH32_feed (long state, byte[] input, int offset, int len); 36 | 37 | static native int XXH32_getIntermediateResult (long state); 38 | 39 | static native int XXH32_result (long state); 40 | 41 | static native void XXH32_free (long state); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/net/jpountz/xxhash/XXHashUtils.java: -------------------------------------------------------------------------------- 1 | package net.jpountz.xxhash; 2 | 3 | /* 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | enum XXHashUtils 17 | { 18 | 19 | ; 20 | 21 | static final int PRIME1 = -1640531535; 22 | static final int PRIME2 = -2048144777; 23 | static final int PRIME3 = -1028477379; 24 | static final int PRIME4 = 668265263; 25 | static final int PRIME5 = 374761393; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/net/rudp/ReliableSocketListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Reliable UDP (rudp) 3 | * Copyright (c) 2009, Adrian Granados (agranados@ihmc.us) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | package net.rudp; 31 | 32 | /** 33 | * The listener interface for receiving packet events. The class that is 34 | * interested in processing a packet event implements this interface. 35 | * 36 | * @author Adrian Granados 37 | * 38 | */ 39 | public interface ReliableSocketListener 40 | { 41 | 42 | /** 43 | * Invoked when a data packet is sent. 44 | */ 45 | public void packetSent (); 46 | 47 | /** 48 | * Invoked when a data packet is retransmitted. 49 | */ 50 | public void packetRetransmitted (); 51 | 52 | /** 53 | * Invoked when a data packet is received in-order. 54 | */ 55 | public void packetReceivedInOrder (); 56 | 57 | /** 58 | * Invoked when a out of sequence data packet is received. 59 | */ 60 | public void packetReceivedOutOfOrder (); 61 | } 62 | -------------------------------------------------------------------------------- /src/net/rudp/impl/ACKSegment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Reliable UDP (rudp) 3 | * Copyright (c) 2009, Adrian Granados (agranados@ihmc.us) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | package net.rudp.impl; 31 | 32 | /* 33 | * ACK Segment 34 | * 35 | * 0 1 2 3 4 5 6 7 8 15 36 | * +-+-+-+-+-+-+-+-+---------------+ 37 | * |0|1|0|0|0|0|0|0| 6 | 38 | * +-+-+-+-+-+-+-+-+---------------+ 39 | * | Sequence # | Ack Number | 40 | * +---------------+---------------+ 41 | * | Checksum | 42 | * +---------------+---------------+ 43 | * 44 | */ 45 | public class ACKSegment extends Segment 46 | { 47 | 48 | protected ACKSegment () { 49 | } 50 | 51 | public ACKSegment (int seqn, int ackn) { 52 | init (ACK_FLAG, seqn, RUDP_HEADER_LEN); 53 | setAck (ackn); 54 | } 55 | 56 | public String type () { 57 | return "ACK"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/net/rudp/impl/FINSegment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Reliable UDP (rudp) 3 | * Copyright (c) 2009, Adrian Granados (agranados@ihmc.us) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | package net.rudp.impl; 31 | 32 | /* 33 | * FIN Segment 34 | * 35 | * 0 1 2 3 4 5 6 7 8 15 36 | * +-+-+-+-+-+-+-+-+---------------+ 37 | * | |A| | | | | | | | 38 | * |0|C|0|0|0|0|1|0| 6 | 39 | * | |K| | | | | | | | 40 | * +-+-+-+-+-+-+-+-+---------------+ 41 | * | Sequence # | Ack Number | 42 | * +---------------+---------------+ 43 | * | Header Checksum | 44 | * +---------------+---------------+ 45 | * 46 | */ 47 | public class FINSegment extends Segment 48 | { 49 | 50 | protected FINSegment () { 51 | } 52 | 53 | public FINSegment (int seqn) { 54 | init (FIN_FLAG, seqn, RUDP_HEADER_LEN); 55 | } 56 | 57 | public String type () { 58 | return "FIN"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/net/rudp/impl/NULSegment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Reliable UDP (rudp) 3 | * Copyright (c) 2009, Adrian Granados (agranados@ihmc.us) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | package net.rudp.impl; 31 | 32 | /* 33 | * NUL Segment 34 | * 35 | * 0 1 2 3 4 5 6 7 8 15 36 | * +-+-+-+-+-+-+-+-+---------------+ 37 | * |0|1|0|0|1|0|0|0| 6 | 38 | * +-+-+-+-+-+-+-+-+---------------+ 39 | * | Sequence # | Ack Number | 40 | * +---------------+---------------+ 41 | * | Checksum | 42 | * +---------------+---------------+ 43 | * 44 | */ 45 | public class NULSegment extends Segment 46 | { 47 | 48 | protected NULSegment () { 49 | } 50 | 51 | public NULSegment (int seqn) { 52 | init (NUL_FLAG, seqn, RUDP_HEADER_LEN); 53 | } 54 | 55 | public String type () { 56 | return "NUL"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/net/rudp/impl/RSTSegment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Reliable UDP (rudp) 3 | * Copyright (c) 2009, Adrian Granados (agranados@ihmc.us) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | package net.rudp.impl; 31 | 32 | /* 33 | * RST Segment 34 | * 35 | * 0 1 2 3 4 5 6 7 8 15 36 | * +-+-+-+-+-+-+-+-+---------------+ 37 | * | |A| | | | | | | | 38 | * |0|C|0|1|0|0|0|0| 6 | 39 | * | |K| | | | | | | | 40 | * +-+-+-+-+-+-+-+-+---------------+ 41 | * | Sequence # | Ack Number | 42 | * +---------------+---------------+ 43 | * | Header Checksum | 44 | * +---------------+---------------+ 45 | * 46 | */ 47 | public class RSTSegment extends Segment 48 | { 49 | 50 | protected RSTSegment () { 51 | } 52 | 53 | public RSTSegment (int seqn) { 54 | init (RST_FLAG, seqn, RUDP_HEADER_LEN); 55 | } 56 | 57 | public String type () { 58 | return "RST"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/com/codebrig/beam/example/chat/ExampleChatMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.example.chat; 31 | 32 | import com.codebrig.beam.messages.BeamMessage; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public class ExampleChatMessage extends BeamMessage 38 | { 39 | 40 | public static final int CHAT_MESSAGE_ID = 1000; 41 | 42 | private String username; 43 | private String message; 44 | 45 | public ExampleChatMessage () { 46 | super (CHAT_MESSAGE_ID); 47 | } 48 | 49 | public ExampleChatMessage (BeamMessage message) { 50 | super (message); 51 | } 52 | 53 | public ExampleChatMessage setUsername (String username) { 54 | this.username = username; 55 | return this; 56 | } 57 | 58 | public String getUsername () { 59 | return username; 60 | } 61 | 62 | public ExampleChatMessage setMessage (String message) { 63 | this.message = message; 64 | return this; 65 | } 66 | 67 | public String getMessage () { 68 | return message; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /test/com/codebrig/beam/unit/TestClientBroadcastHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.unit; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.handlers.LegacyHandler; 34 | import com.codebrig.beam.messages.LegacyMessage; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class TestClientBroadcastHandler extends LegacyHandler 40 | { 41 | 42 | public TestClientBroadcastHandler () { 43 | super (TestClientServer.TEST_MESSAGE); 44 | } 45 | 46 | @Override 47 | public LegacyMessage messageReceived (Communicator comm, LegacyMessage message) { 48 | System.out.println (String.format ("%s received broadcast message: %s", 49 | comm.getName (), message.getString ("broadcast_message"))); 50 | 51 | //don't respond 52 | return null; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /test/com/codebrig/beam/unit/TestServerHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.unit; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.handlers.LegacyHandler; 34 | import com.codebrig.beam.messages.LegacyMessage; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class TestServerHandler extends LegacyHandler 40 | { 41 | 42 | public TestServerHandler () { 43 | super (TestClientServer.TEST_MESSAGE); 44 | } 45 | 46 | @Override 47 | public LegacyMessage messageReceived (Communicator comm, LegacyMessage message) { 48 | System.out.println ("Client sent message: " + message.getString ("client_message")); 49 | 50 | //don't respond 51 | return null; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /test/com/codebrig/beam/unit/connection/traversal/punch/udp/TestUDPPunchServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.unit.connection.traversal.punch.udp; 31 | 32 | import com.codebrig.beam.connection.traversal.punch.udp.server.UDPPunchServer; 33 | 34 | /** 35 | * @author Brandon Fergerson 36 | */ 37 | public class TestUDPPunchServer 38 | { 39 | 40 | public static final int TEST_PUNCH_SERVER_PORT = 33333; 41 | 42 | public static final String TEST_PUNCH_PEER_IDENTIFIER = "TEST_IDENT"; 43 | public static final String TEST_PUNCH_PEER_ACCESS_CODE = "SECRET"; 44 | public static final int TEST_PUNCH_MESSAGE_TYPE = 1; 45 | 46 | public static void main (String[] args) { 47 | UDPPunchServer punchServer = new UDPPunchServer ("Test Punch Server", TEST_PUNCH_SERVER_PORT); 48 | punchServer.start (); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /test/com/codebrig/beam/unit/crypt/AESTestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.unit.crypt; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.crypt.handlers.AESBeamLegacyHandler; 34 | import com.codebrig.beam.messages.LegacyMessage; 35 | 36 | public class AESTestHandler extends AESBeamLegacyHandler 37 | { 38 | 39 | public AESTestHandler () { 40 | super (BeamCryptTest.aes, BeamCryptTest.AES_CRYPT_TEST_MESSAGE); 41 | } 42 | 43 | @Override 44 | public LegacyMessage messageReceived (Communicator comm, LegacyMessage message) { 45 | assert (message.get ("aes_test_variable").equals ("aes_test_value")); 46 | System.out.println ("AES sent message valid!"); 47 | 48 | LegacyMessage responseMessage = new LegacyMessage (BeamCryptTest.AES_CRYPT_TEST_MESSAGE); 49 | responseMessage.setString ("aes_response_variable", "aes_response_value"); 50 | 51 | return responseMessage; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /test/com/codebrig/beam/unit/crypt/RSATestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014-2015 CodeBrig, LLC. 3 | * http://www.codebrig.com/ 4 | * 5 | * Beam - Client/Server & P2P Networking Library 6 | * 7 | * ==== 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ==== 29 | */ 30 | package com.codebrig.beam.unit.crypt; 31 | 32 | import com.codebrig.beam.Communicator; 33 | import com.codebrig.beam.crypt.handlers.RSABeamLegacyHandler; 34 | import com.codebrig.beam.messages.LegacyMessage; 35 | 36 | /** 37 | * @author Brandon Fergerson 38 | */ 39 | public class RSATestHandler extends RSABeamLegacyHandler 40 | { 41 | 42 | public RSATestHandler () { 43 | super (BeamCryptTest.RSA_CRYPT_TEST_MESSAGE); 44 | } 45 | 46 | @Override 47 | public LegacyMessage messageReceived (Communicator comm, LegacyMessage message) { 48 | assert (message.get ("rsa_test_variable").equals ("rsa_test_value")); 49 | System.out.println ("RSA sent message valid!"); 50 | 51 | LegacyMessage responseMessage = new LegacyMessage (BeamCryptTest.RSA_CRYPT_TEST_MESSAGE); 52 | responseMessage.setString ("rsa_response_variable", "rsa_response_value"); 53 | 54 | return responseMessage; 55 | } 56 | 57 | } 58 | --------------------------------------------------------------------------------