├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── SECURITY.md ├── api ├── build-test-java11 ├── build-test-java17 ├── build-test-java21 ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── marshalling │ │ │ ├── AbstractClassResolver.java │ │ │ ├── AbstractMarshaller.java │ │ │ ├── AbstractMarshallerFactory.java │ │ │ ├── AbstractObjectInput.java │ │ │ ├── AbstractObjectOutput.java │ │ │ ├── AbstractUnmarshaller.java │ │ │ ├── AnnotationClassExternalizerFactory.java │ │ │ ├── ByteBufferInput.java │ │ │ ├── ByteBufferOutput.java │ │ │ ├── ByteInput.java │ │ │ ├── ByteInputStream.java │ │ │ ├── ByteOutput.java │ │ │ ├── ByteOutputStream.java │ │ │ ├── BytePipe.java │ │ │ ├── ByteWriter.java │ │ │ ├── ChainedUnmarshallingObjectInputFilter.java │ │ │ ├── ChainingClassExternalizerFactory.java │ │ │ ├── ChainingClassTable.java │ │ │ ├── ChainingObjectResolver.java │ │ │ ├── ChainingObjectTable.java │ │ │ ├── ClassExternalizerFactory.java │ │ │ ├── ClassNameTransformer.java │ │ │ ├── ClassResolver.java │ │ │ ├── ClassTable.java │ │ │ ├── ContextClassResolver.java │ │ │ ├── Creator.java │ │ │ ├── ExceptionListener.java │ │ │ ├── Externalize.java │ │ │ ├── Externalizer.java │ │ │ ├── FieldSetter.java │ │ │ ├── FilterInfoAdapter.java │ │ │ ├── InputStreamByteInput.java │ │ │ ├── JavaEE2JakartaEEClassNameTransformer.java │ │ │ ├── LimitedByteInput.java │ │ │ ├── LimitedByteOutput.java │ │ │ ├── MappingClassExternalizerFactory.java │ │ │ ├── Marshaller.java │ │ │ ├── MarshallerFactory.java │ │ │ ├── MarshallerObjectInput.java │ │ │ ├── MarshallerObjectInputStream.java │ │ │ ├── MarshallerObjectOutput.java │ │ │ ├── MarshallerObjectOutputStream.java │ │ │ ├── Marshalling.java │ │ │ ├── MarshallingConfiguration.java │ │ │ ├── MarshallingObjectOutputStream.java │ │ │ ├── ModularClassResolver.java │ │ │ ├── ModularClassTable.java │ │ │ ├── ObjectInputFilterAdapter.java │ │ │ ├── ObjectInputStreamUnmarshaller.java │ │ │ ├── ObjectOutputStreamMarshaller.java │ │ │ ├── ObjectResolver.java │ │ │ ├── ObjectTable.java │ │ │ ├── OutputStreamByteOutput.java │ │ │ ├── Pair.java │ │ │ ├── ProviderDescriptor.java │ │ │ ├── SerializabilityChecker.java │ │ │ ├── SimpleByteInput.java │ │ │ ├── SimpleByteOutput.java │ │ │ ├── SimpleClassResolver.java │ │ │ ├── SimpleDataInput.java │ │ │ ├── SimpleDataOutput.java │ │ │ ├── StreamHeader.java │ │ │ ├── TraceInformation.java │ │ │ ├── TransformingClassResolver.java │ │ │ ├── UTFUtils.java │ │ │ ├── Unmarshaller.java │ │ │ ├── UnmarshallingFilterInfoAdapter.java │ │ │ ├── UnmarshallingObjectInputFilter.java │ │ │ ├── UnmarshallingObjectInputFilterAdapter.java │ │ │ ├── UnmarshallingObjectInputFilterImpl.java │ │ │ ├── UnmarshallingObjectInputStream.java │ │ │ ├── Version.java │ │ │ ├── Version.properties │ │ │ ├── _private │ │ │ ├── GetDeclaredConstructorAction.java │ │ │ ├── GetDeclaredFieldAction.java │ │ │ ├── GetDeclaredFieldsAction.java │ │ │ ├── GetReflectionFactoryAction.java │ │ │ ├── GetUnsafeAction.java │ │ │ └── SetAccessibleAction.java │ │ │ ├── cloner │ │ │ ├── ClassCloner.java │ │ │ ├── ClassLoaderClassCloner.java │ │ │ ├── CloneTable.java │ │ │ ├── CloneableCloner.java │ │ │ ├── ClonerConfiguration.java │ │ │ ├── ObjectCloner.java │ │ │ ├── ObjectClonerFactory.java │ │ │ ├── ObjectClonerSource.java │ │ │ ├── ObjectCloners.java │ │ │ └── SerializingCloner.java │ │ │ ├── package-info.java │ │ │ ├── reflect │ │ │ ├── JDKSpecific.java │ │ │ ├── PublicReflectiveCreator.java │ │ │ ├── ReflectiveCreator.java │ │ │ ├── SerMethods.java │ │ │ ├── SerializableClass.java │ │ │ ├── SerializableClassRegistry.java │ │ │ ├── SerializableField.java │ │ │ ├── SunReflectiveCreator.java │ │ │ └── package-info.java │ │ │ └── util │ │ │ ├── BooleanFieldPutter.java │ │ │ ├── BooleanReadField.java │ │ │ ├── ByteFieldPutter.java │ │ │ ├── ByteReadField.java │ │ │ ├── CharFieldPutter.java │ │ │ ├── CharReadField.java │ │ │ ├── DoubleFieldPutter.java │ │ │ ├── DoubleReadField.java │ │ │ ├── FieldPutter.java │ │ │ ├── FlatNavigableMap.java │ │ │ ├── FlatNavigableSet.java │ │ │ ├── FloatFieldPutter.java │ │ │ ├── FloatReadField.java │ │ │ ├── IdentityIntMap.java │ │ │ ├── IdentityIntSet.java │ │ │ ├── IntFieldPutter.java │ │ │ ├── IntKeyMap.java │ │ │ ├── IntMap.java │ │ │ ├── IntReadField.java │ │ │ ├── IntSet.java │ │ │ ├── Kind.java │ │ │ ├── LongFieldPutter.java │ │ │ ├── LongReadField.java │ │ │ ├── ObjectFieldPutter.java │ │ │ ├── ObjectReadField.java │ │ │ ├── ReadField.java │ │ │ ├── ShortFieldPutter.java │ │ │ └── ShortReadField.java │ └── java16 │ │ └── org │ │ └── jboss │ │ └── marshalling │ │ └── reflect │ │ └── JDKSpecific.java │ └── test │ └── java │ └── org │ └── jboss │ └── marshalling │ ├── ByteBufferInputTestCase.java │ ├── Javaee2JakartaeeMappingTestCase.java │ ├── UnmarshallingObjectInputFilterTestCase.java │ └── cloner │ ├── ClassLoaderClassClonerTestCase.java │ ├── DateFieldType.java │ └── SerializingClonerTestCase.java ├── pom.xml ├── river ├── build-test-java11 ├── build-test-java17 ├── build-test-java21 ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── marshalling │ │ │ └── river │ │ │ ├── BasicSerializableClassDescriptor.java │ │ │ ├── BlockMarshaller.java │ │ │ ├── BlockUnmarshaller.java │ │ │ ├── ClassDescriptor.java │ │ │ ├── ClassDescriptors.java │ │ │ ├── ExternalizerClassDescriptor.java │ │ │ ├── FutureSerializableClassDescriptor.java │ │ │ ├── Protocol.java │ │ │ ├── RiverMarshaller.java │ │ │ ├── RiverMarshallerFactory.java │ │ │ ├── RiverObjectInputStream.java │ │ │ ├── RiverObjectOutputStream.java │ │ │ ├── RiverProviderDescriptor.java │ │ │ ├── RiverPutField.java │ │ │ ├── RiverUnmarshaller.java │ │ │ ├── SerializableClassDescriptor.java │ │ │ ├── SerializableGapClassDescriptor.java │ │ │ ├── SimpleClassDescriptor.java │ │ │ ├── Validator.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.jboss.marshalling.ProviderDescriptor │ └── test │ └── java │ └── org │ └── jboss │ └── marshalling │ └── river │ └── ReadWriteTest.java ├── serial ├── build-test-java11 ├── build-test-java17 ├── build-test-java21 ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── jboss │ │ └── marshalling │ │ └── serial │ │ ├── BlockMarshaller.java │ │ ├── BlockUnmarshaller.java │ │ ├── Descriptor.java │ │ ├── ExtendedObjectStreamConstants.java │ │ ├── ExternalizedObject.java │ │ ├── NoDataDescriptor.java │ │ ├── PlainDescriptor.java │ │ ├── ProxyDescriptor.java │ │ ├── Serial.java │ │ ├── SerialMarshaller.java │ │ ├── SerialMarshallerFactory.java │ │ ├── SerialObjectInputStream.java │ │ ├── SerialObjectOutputStream.java │ │ ├── SerialProviderDescriptor.java │ │ ├── SerialUnmarshaller.java │ │ └── UnknownDescriptor.java │ └── resources │ └── META-INF │ └── services │ └── org.jboss.marshalling.ProviderDescriptor └── tests ├── build-test-java11 ├── build-test-java17 ├── build-test-java21 ├── pom.xml └── src ├── main └── resources │ └── testing.policy └── test └── java └── org └── jboss ├── marshalling └── FilterTests.java └── test └── marshalling ├── EqualableArrayDeque.java ├── LRUMap.java ├── MarshallerFactoryTestMarshallerProvider.java ├── MarshallerFactoryTestUnmarshallerProvider.java ├── ObjectInputStreamTestUnmarshallerProvider.java ├── ObjectOutputStreamTestMarshallerProvider.java ├── OtherMarshallerTests.java ├── ReadWriteTest.java ├── RecordTestFactory.java ├── RecordTests.java ├── RiverVersionZeroMarshallerFactoryTestMarshallerProviderImpl.java ├── SerialFilterMarshallerTests.java ├── SimpleMarshallerTestFactory.java ├── SimpleMarshallerTests.java ├── SingleObjectMarshallerTestFactory.java ├── SingleObjectMarshallerTests.java ├── TestArrayList.java ├── TestBase.java ├── TestCollectionHolder.java ├── TestComplexExternalizableObject.java ├── TestComplexObject.java ├── TestMarshallerProvider.java └── TestUnmarshallerProvider.java /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | open-pull-requests-limit: 10 13 | - package-ecosystem: "github-actions" 14 | directory: "/" 15 | schedule: 16 | interval: "daily" 17 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: JBoss Marshalling CI 5 | 6 | on: 7 | pull_request: 8 | types: [opened, synchronize, reopened, ready_for_review] 9 | 10 | jobs: 11 | build-test-matrix: 12 | name: ${{ matrix.jdk-distribution }}-${{ matrix.os }} 13 | runs-on: ${{ matrix.os }} 14 | timeout-minutes: 10 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ubuntu-latest, macos-latest, windows-latest] 19 | jdk-distribution: [temurin, semeru] 20 | steps: 21 | - name: Configure runner - Linux 22 | if: contains(matrix.os, 'ubuntu') 23 | run: | 24 | sudo bash -c "echo '127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4' > /etc/hosts" 25 | sudo bash -c "echo '::1 localhost localhost.localdomain localhost6 localhost6.localdomain6' >> /etc/hosts" 26 | - name: Configure Runner - Windows 27 | if: contains(matrix.os, 'windows') 28 | run: | 29 | echo '127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4' > %SystemRoot%\System32\drivers\etc\hosts 30 | echo '::1 localhost localhost.localdomain localhost6 localhost6.localdomain6' >> %SystemRoot%\System32\drivers\etc\hosts 31 | shell: cmd 32 | - uses: actions/checkout@v4 33 | - name: Set up JDKs 34 | uses: actions/setup-java@v4 35 | with: 36 | distribution: ${{ matrix.jdk-distribution }} 37 | java-version: | 38 | 11 39 | 17 40 | 21 41 | 23 42 | - name: Run Tests 43 | run: mvn -ntp -U -B -fae clean install -Pjava21-test-classpath "-Djava11.home=${{env.JAVA_HOME_11_X64}}${{env.JAVA_HOME_11_ARM64}}" "-Djava17.home=${{env.JAVA_HOME_17_X64}}${{env.JAVA_HOME_17_ARM64}}" "-Djava21.home=${{env.JAVA_HOME_21_X64}}${{env.JAVA_HOME_21_ARM64}}" 44 | - uses: actions/upload-artifact@v4 45 | if: failure() 46 | with: 47 | name: surefire-${{ matrix.jdk-distribution }}-${{ matrix.os }} 48 | path: '**/surefire-reports/*.txt' 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | dependency-reduced-pom.xml 3 | *.iws 4 | *.ipr 5 | *.iml 6 | /.idea 7 | pom.xml.versionsBackup 8 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | @ropalka @dmlloyd 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## JBoss Marshalling Community Code of Conduct v1.0 2 | 3 | ### Contributor Code of Conduct 4 | 5 | As contributors and maintainers of this project, and in the interest of fostering 6 | an open and welcoming community, we pledge to respect all people who contribute 7 | through reporting issues, posting feature requests, updating documentation, 8 | submitting pull requests or patches, and other activities. 9 | 10 | We are committed to making participation in this project a harassment-free experience for 11 | everyone, regardless of level of experience, gender, gender identity and expression, 12 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, 13 | religion, or nationality. 14 | 15 | Examples of unacceptable behavior by participants include: 16 | 17 | * The use of sexualized language or imagery 18 | * Personal attacks 19 | * Trolling or insulting/derogatory comments 20 | * Public or private harassment 21 | * Publishing other's private information, such as physical or electronic addresses, without explicit permission 22 | * Other unethical or unprofessional conduct. 23 | 24 | Project maintainers have the right and responsibility to remove, edit, or reject 25 | comments, commits, code, wiki edits, issues, and other contributions that are not 26 | aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers 27 | commit themselves to fairly and consistently applying these principles to every aspect 28 | of managing this project. Project maintainers who do not follow or enforce the Code of 29 | Conduct may be permanently removed from the project team. 30 | 31 | This code of conduct applies both within project spaces and in public spaces 32 | when an individual is representing the project or its community. 33 | 34 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 35 | contacting a JBoss Marshalling project lead, David Lloyd . 36 | 37 | 38 | This Code of Conduct is adapted from the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md) which is 39 | adapted from the Contributor Covenant 40 | (http://contributor-covenant.org), version 1.2.0, available at 41 | http://contributor-covenant.org/version/1/2/0/ 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## JBoss Marshalling 2 | 3 | JBoss Marshalling is an alternative serialization API used by [WildFly](https://github.com/wildfly/wildfly) project 4 | addressing many problems of JDK serialization API while remaining fully compatible with "java.io.Serializable". 5 | 6 | ## Building 7 | 8 | Prerequisites: 9 | 10 | * JDK 11 or newer - check `java -version` 11 | * Maven 3.6.0 or newer - check `mvn -v` 12 | 13 | To build with your own Maven installation: 14 | 15 | mvn install 16 | 17 | ## Documentation 18 | 19 | All documentation lives at https://jbossmarshalling.jboss.org/ 20 | 21 | ## Issue tracker 22 | 23 | All issues can be reported at https://github.com/jboss-remoting/jboss-marshalling/issues 24 | 25 | ## Code 26 | 27 | All code can be found at https://github.com/jboss-remoting/jboss-marshalling 28 | 29 | ## License 30 | 31 | All code distributed under [ASL 2.0](LICENSE.txt). 32 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Security Contacts and Procedures 4 | 5 | JBoss Marshalling community takes security very seriously, and we aim to take immediate action to address serious security-related problems that involve our products or services. 6 | 7 | Please report any suspected security vulnerability in this project to Red Hat Product Security at secalert@redhat.com. You can use our GPG key to communicate with us securely. 8 | 9 | To report an issue in any Red Hat branded website or online service, please contact Red Hat Information Security at site-security@redhat.com. 10 | https://access.redhat.com/security/team/contact 11 | 12 | -------------------------------------------------------------------------------- /api/build-test-java11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/api/build-test-java11 -------------------------------------------------------------------------------- /api/build-test-java17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/api/build-test-java17 -------------------------------------------------------------------------------- /api/build-test-java21: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/api/build-test-java21 -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/AbstractObjectOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.ObjectOutput; 23 | 24 | /** 25 | * An abstract object output implementation. 26 | */ 27 | public abstract class AbstractObjectOutput extends SimpleDataOutput implements ObjectOutput { 28 | 29 | /** 30 | * Construct a new instance. 31 | * 32 | * @param bufferSize the buffer size 33 | */ 34 | protected AbstractObjectOutput(final int bufferSize) { 35 | super(bufferSize); 36 | } 37 | 38 | /** 39 | * Implementation of the actual object-writing method. 40 | * 41 | * @param obj the object to write 42 | * @param unshared {@code true} if the instance is unshared, {@code false} if it is shared 43 | * @throws IOException if an I/O error occurs 44 | */ 45 | protected abstract void doWriteObject(Object obj, boolean unshared) throws IOException; 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | public void writeObjectUnshared(Object obj) throws IOException { 51 | doWriteObject(obj, true); 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | public void writeObject(Object obj) throws IOException { 58 | doWriteObject(obj, false); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/AnnotationClassExternalizerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * An externalizer factory which looks for the presence of the {@link org.jboss.marshalling.Externalize Externalize} annotation. 23 | */ 24 | public class AnnotationClassExternalizerFactory implements ClassExternalizerFactory { 25 | 26 | /** 27 | * Construct a new instance. 28 | */ 29 | public AnnotationClassExternalizerFactory() { 30 | } 31 | 32 | /** {@inheritDoc} */ 33 | public Externalizer getExternalizer(final Class type) { 34 | final Externalize ann = type.getAnnotation(Externalize.class); 35 | if (ann == null) { 36 | return null; 37 | } else { 38 | try { 39 | return ann.value().newInstance(); 40 | } catch (Exception e) { 41 | throw new IllegalArgumentException("Cannot instantiate externalizer for " + type, e); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ByteInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | /** 25 | * An {@code InputStream} which implements {@code ByteInput} and reads bytes from another {@code ByteInput}. 26 | * Usually the {@link Marshalling#createByteInput(InputStream)} method should be used to create instances because 27 | * it can detect when the target already implements {@code ByteInput}. 28 | */ 29 | public class ByteInputStream extends SimpleByteInput { 30 | 31 | protected volatile ByteInput byteInput; 32 | 33 | /** 34 | * Create a new instance. 35 | * 36 | * @param byteInput the byte input to read from 37 | */ 38 | public ByteInputStream(final ByteInput byteInput) { 39 | this.byteInput = byteInput; 40 | } 41 | 42 | /** {@inheritDoc} */ 43 | public int read() throws IOException { 44 | return byteInput.read(); 45 | } 46 | 47 | /** {@inheritDoc} */ 48 | public int read(final byte[] b) throws IOException { 49 | return byteInput.read(b); 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public int read(final byte[] b, final int off, final int len) throws IOException { 54 | return byteInput.read(b, off, len); 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public long skip(final long n) throws IOException { 59 | return byteInput.skip(n); 60 | } 61 | 62 | /** {@inheritDoc} */ 63 | public int available() throws IOException { 64 | return byteInput.available(); 65 | } 66 | 67 | /** {@inheritDoc} */ 68 | public void close() throws IOException { 69 | byteInput.close(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ByteOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.Closeable; 22 | import java.io.Flushable; 23 | import java.io.IOException; 24 | 25 | /** 26 | * An output stream of bytes. 27 | */ 28 | public interface ByteOutput extends Closeable, Flushable { 29 | /** 30 | * Writes to the output stream the eight low-order bits of the argument {@code b}. The 24 high-order bits of 31 | * {@code b} are ignored. 32 | * 33 | * @param b the byte to write 34 | * @throws IOException if an error occurs 35 | */ 36 | void write(int b) throws IOException; 37 | 38 | /** 39 | * Write all the bytes from the given array to the stream. 40 | * 41 | * @param b the byte array 42 | * @throws IOException if an error occurs 43 | */ 44 | void write(byte[] b) throws IOException; 45 | 46 | /** 47 | * Write some of the bytes from the given array to the stream. 48 | * 49 | * @param b the byte array 50 | * @param off the index to start writing from 51 | * @param len the number of bytes to write 52 | * @throws IOException if an error occurs 53 | */ 54 | void write(byte[] b, int off, int len) throws IOException; 55 | } 56 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ByteOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.OutputStream; 23 | 24 | /** 25 | * An {@code OutputStream} which implements {@code ByteOutput} and writes bytes to another {@code ByteOutput}. 26 | * Usually the {@link Marshalling#createByteOutput(OutputStream)} method should be used to create instances because 27 | * it can detect when the target already implements {@code ByteOutput}. 28 | */ 29 | public class ByteOutputStream extends SimpleByteOutput { 30 | 31 | protected volatile ByteOutput byteOutput; 32 | 33 | /** 34 | * Construct a new instance. 35 | * 36 | * @param byteOutput the byte output to write to 37 | */ 38 | public ByteOutputStream(final ByteOutput byteOutput) { 39 | this.byteOutput = byteOutput; 40 | } 41 | 42 | /** {@inheritDoc} */ 43 | public void write(final int b) throws IOException { 44 | byteOutput.write(b); 45 | } 46 | 47 | /** {@inheritDoc} */ 48 | public void write(final byte[] b) throws IOException { 49 | byteOutput.write(b); 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public void write(final byte[] b, final int off, final int len) throws IOException { 54 | byteOutput.write(b, off, len); 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public void flush() throws IOException { 59 | byteOutput.flush(); 60 | } 61 | 62 | /** {@inheritDoc} */ 63 | public void close() throws IOException { 64 | byteOutput.close(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/BytePipe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.PipedInputStream; 23 | import java.io.PipedOutputStream; 24 | 25 | /** 26 | * A paired {@link ByteInput} and {@link ByteOutput}. Each end must be used from a different thread, otherwise a deadlock 27 | * condition will occur. 28 | */ 29 | public final class BytePipe { 30 | private final ByteInput input; 31 | private final ByteOutput output; 32 | 33 | /** 34 | * Construct a new instance. 35 | */ 36 | public BytePipe() { 37 | final PipedOutputStream output = new PipedOutputStream(); 38 | final PipedInputStream input; 39 | try { 40 | input = new PipedInputStream(output); 41 | } catch (IOException e) { 42 | throw new IllegalStateException(e); 43 | } 44 | this.input = Marshalling.createByteInput(input); 45 | this.output = Marshalling.createByteOutput(output); 46 | } 47 | 48 | /** 49 | * Get the input side of this pipe. 50 | * 51 | * @return the input side 52 | */ 53 | public ByteInput getInput() { 54 | return input; 55 | } 56 | 57 | /** 58 | * Get the output side of this pipe. 59 | * 60 | * @return the output side 61 | */ 62 | public ByteOutput getOutput() { 63 | return output; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ByteWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * A writer for class or object tables which simply writes a flat sequence of bytes. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public final class ByteWriter implements ObjectTable.Writer, ClassTable.Writer { 29 | private final byte[] bytes; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param bytes the bytes to write 35 | */ 36 | public ByteWriter(final byte... bytes) { 37 | this.bytes = bytes; 38 | } 39 | 40 | public void writeObject(final Marshaller marshaller, final Object object) throws IOException { 41 | marshaller.write(bytes); 42 | } 43 | 44 | public void writeClass(final Marshaller marshaller, final Class clazz) throws IOException { 45 | marshaller.write(bytes); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ChainedUnmarshallingObjectInputFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2023 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * {@link UnmarshallingObjectInputFilter} implementation that is chaining multiple {@link UnmarshallingObjectInputFilter}s. 23 | * 24 | * @author Brian Stansberry 25 | * @author Richard Opalka 26 | */ 27 | final class ChainedUnmarshallingObjectInputFilter implements UnmarshallingObjectInputFilter { 28 | 29 | private final UnmarshallingObjectInputFilter[] chain; 30 | 31 | ChainedUnmarshallingObjectInputFilter(final UnmarshallingObjectInputFilter... chain) { 32 | this.chain = chain; 33 | } 34 | 35 | @Override 36 | public Status checkInput(final FilterInfo filterInfo) { 37 | for (UnmarshallingObjectInputFilter filter : chain) { 38 | Status status = filter.checkInput(filterInfo); 39 | if (status != Status.UNDECIDED) { 40 | return status; 41 | } 42 | } 43 | return Status.UNDECIDED; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ClassExternalizerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * A factory for locating custom externalizers. 23 | */ 24 | public interface ClassExternalizerFactory { 25 | /** 26 | * Look up a custom externalizer for a given object class. If no such externalizer exists, returns {@code null}. 27 | * 28 | * @param type the type to be externalized 29 | * @return the externalizer, or {@code null} if there is none 30 | */ 31 | Externalizer getExternalizer(Class type); 32 | } 33 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ClassNameTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2022 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * A class name transformer. Allows to remap one java type name to another java type name. 23 | * 24 | * @author Richard Opalka 25 | */ 26 | public interface ClassNameTransformer { 27 | 28 | /** 29 | * Transforms unmarshaller input stream java type names. 30 | * @param className candidate to be translated 31 | * @return either original or new class name 32 | */ 33 | String transformInput(String className); 34 | 35 | /** 36 | * Transforms marshaller output stream java type names. 37 | * @param className candidate to be translated 38 | * @return either original or new class name 39 | */ 40 | String transformOutput(String className); 41 | 42 | /** 43 | * Translates all incoming Java EE 8- types to Jakarta EE 9+ types and all outgoing Jakarta EE 9+ types to Java EE 8- types. 44 | */ 45 | ClassNameTransformer JAVAEE_TO_JAKARTAEE = new JavaEE2JakartaEEClassNameTransformer(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ClassTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * A lookup mechanism for predefined classes. Some marshallers can use this to 25 | * avoid sending lengthy class descriptor information. 26 | */ 27 | public interface ClassTable { 28 | /** 29 | * Determine whether the given class reference is a valid predefined reference. 30 | * 31 | * @param clazz the candidate class 32 | * @return the class writer, or {@code null} to use the default mechanism 33 | * @throws IOException if an I/O error occurs 34 | */ 35 | Writer getClassWriter(Class clazz) throws IOException; 36 | 37 | /** 38 | * Read a class from the stream. The class will have been written by the 39 | * {@link #getClassWriter(Class)} method's {@code Writer} instance, as defined above. 40 | * 41 | * @param unmarshaller the unmarshaller to read from 42 | * @return the class 43 | * @throws IOException if an I/O error occurs 44 | * @throws ClassNotFoundException if a class could not be found 45 | */ 46 | Class readClass(Unmarshaller unmarshaller) throws IOException, ClassNotFoundException; 47 | 48 | /** 49 | * The class writer for a specific class. 50 | * @apiviz.exclude 51 | */ 52 | interface Writer { 53 | /** 54 | * Write the predefined class reference to the stream. 55 | * 56 | * @param marshaller the marshaller to write to 57 | * @param clazz the class reference to write 58 | * @throws IOException if an I/O error occurs 59 | */ 60 | void writeClass(Marshaller marshaller, Class clazz) throws IOException; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ContextClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import static java.lang.System.getSecurityManager; 22 | import static java.security.AccessController.doPrivileged; 23 | 24 | import java.security.PrivilegedAction; 25 | 26 | /** 27 | * A class resolver which uses the context classloader to resolve classes. 28 | */ 29 | public class ContextClassResolver extends AbstractClassResolver { 30 | 31 | private static final PrivilegedAction GET_TCCL_ACTION = new PrivilegedAction() { 32 | public ClassLoader run() { 33 | return Thread.currentThread().getContextClassLoader(); 34 | } 35 | }; 36 | 37 | /** 38 | * Construct a new instance. 39 | */ 40 | public ContextClassResolver() { 41 | } 42 | 43 | /** 44 | * Construct a new instance. 45 | * 46 | * @param enforceSerialVersionUid {@code true} if an exception should be thrown on an incorrect serialVersionUID 47 | */ 48 | public ContextClassResolver(final boolean enforceSerialVersionUid) { 49 | super(enforceSerialVersionUid); 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | protected ClassLoader getClassLoader() { 54 | if (getSecurityManager() == null) { 55 | return Thread.currentThread().getContextClassLoader(); 56 | } else { 57 | return doPrivileged(GET_TCCL_ACTION); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/Creator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.InvalidClassException; 22 | 23 | /** 24 | * An instance creator. Creates an uninitialized instance of a class. 25 | * 26 | * @deprecated This API is deprecated and will be removed in a future version. 27 | */ 28 | @Deprecated 29 | public interface Creator { 30 | /** 31 | * Create an object instance. 32 | * 33 | * @param clazz the type of object to create 34 | * @return the object instance 35 | * @throws InvalidClassException if an instance of the class could not be instantiated for some reason 36 | */ 37 | T create(Class clazz) throws InvalidClassException; 38 | } 39 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ExceptionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * A listener for exceptions which occur during marshalling or unmarshalling. Not all protocols will support all 23 | * methods. These methods are intended for the purpose of interjecting additional debug information into the stack 24 | * trace by way of the {@link TraceInformation} class. The appropriate callback will be called in the event of an exception, 25 | * at every level of recursion into the marshalling or unmarshalling process. 26 | * @apiviz.exclude 27 | */ 28 | public interface ExceptionListener { 29 | 30 | /** 31 | * Handle a problem marshalling the given object. 32 | * 33 | * @param problem the problem 34 | * @param subject the object being marshalled 35 | */ 36 | void handleMarshallingException(Throwable problem, Object subject); 37 | 38 | /** 39 | * Handle a problem unmarshalling an object of the given class. 40 | * 41 | * @param problem the problem 42 | * @param subjectClass the class being marshalled 43 | */ 44 | void handleUnmarshallingException(Throwable problem, Class subjectClass); 45 | 46 | /** 47 | * Handle a problem unmarshalling an object whose class cannot be determined. 48 | * 49 | * @param problem the problem 50 | */ 51 | void handleUnmarshallingException(Throwable problem); 52 | 53 | /** 54 | * An exception listener which does nothing. 55 | */ 56 | ExceptionListener NO_OP = new ExceptionListener() { 57 | public void handleMarshallingException(final Throwable problem, final Object subject) { 58 | } 59 | 60 | public void handleUnmarshallingException(final Throwable problem, final Class subjectClass) { 61 | } 62 | 63 | public void handleUnmarshallingException(final Throwable problem) { 64 | } 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/Externalize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Inherited; 26 | import java.lang.annotation.Documented; 27 | 28 | /** 29 | * Indicate that this class should be externalized by an instance of the given externalizer class. Any externalizer 30 | * provided by a {@link org.jboss.marshalling.ClassExternalizerFactory ClassExternalizerFactory} will typically take 31 | * precedence over the externalizer specified by this annotation. 32 | * 33 | * @apiviz.exclude 34 | */ 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Target(ElementType.TYPE) 37 | @Inherited 38 | @Documented 39 | public @interface Externalize { 40 | 41 | /** 42 | * Specify the externalizer class to be used by the annotated class. 43 | * 44 | * @return the externalizer type 45 | */ 46 | Class value(); 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/Externalizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.ObjectOutput; 23 | import java.io.ObjectInput; 24 | import java.io.Serializable; 25 | 26 | /** 27 | * A replacement serializer for an object class. 28 | */ 29 | public interface Externalizer extends Serializable { 30 | /** 31 | * Write the external representation of an object. The object's class and the externalizer's class will 32 | * already have been written. 33 | * 34 | * @param subject the object to externalize 35 | * @param output the output 36 | * @throws IOException if an error occurs 37 | */ 38 | void writeExternal(Object subject, ObjectOutput output) throws IOException; 39 | 40 | /** 41 | * Create an instance of a type. The object may then be initialized from {@code input}, or that may be deferred 42 | * to the {@code readExternal()} method. Instances may simply delegate the task to the given {@code Creator}. 43 | * Note that this method is called only on the leaf class, so externalizers for non-final classes that initialize 44 | * the instance from the stream need to be aware of this. 45 | * 46 | * @param subjectType the type of object to create 47 | * @param input the input 48 | * @return the new instance 49 | * @throws IOException if an error occurs 50 | * @throws ClassNotFoundException if a class could not be found during read 51 | */ 52 | Object createExternal(Class subjectType, ObjectInput input) throws IOException, ClassNotFoundException; 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/FilterInfoAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2023 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.ObjectInputFilter; 22 | 23 | /** 24 | * An adapter that allows to use an UnmarshallingObjectInputFilter.FilterInfo in place of an ObjectInputFilter.FilterInfo. 25 | * 26 | * @author Brian Stansberry 27 | * @author Richard Opalka 28 | */ 29 | final class FilterInfoAdapter implements ObjectInputFilter.FilterInfo { 30 | 31 | private final UnmarshallingObjectInputFilter.FilterInfo adaptee; 32 | 33 | FilterInfoAdapter(final UnmarshallingObjectInputFilter.FilterInfo adaptee) { 34 | this.adaptee = adaptee; 35 | } 36 | 37 | @Override 38 | public Class serialClass() { 39 | return adaptee.getUnmarshalledClass(); 40 | } 41 | 42 | @Override 43 | public long arrayLength() { 44 | return adaptee.getArrayLength(); 45 | } 46 | 47 | @Override 48 | public long depth() { 49 | return adaptee.getDepth(); 50 | } 51 | 52 | @Override 53 | public long references() { 54 | return adaptee.getReferences(); 55 | } 56 | 57 | @Override 58 | public long streamBytes() { 59 | return adaptee.getStreamBytes(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/InputStreamByteInput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.FilterInputStream; 22 | import java.io.InputStream; 23 | 24 | /** 25 | * An {@code InputStream} implementing {@code ByteInput} which reads input from another {@code InputStream}. 26 | * Usually the {@link Marshalling#createInputStream(ByteInput)} method should be used to create instances because 27 | * it can detect when the target already extends {@code InputStream}. 28 | */ 29 | public class InputStreamByteInput extends FilterInputStream implements ByteInput { 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param inputStream the input stream to read from 35 | */ 36 | public InputStreamByteInput(final InputStream inputStream) { 37 | super(inputStream); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/LimitedByteOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.InterruptedIOException; 23 | 24 | /** 25 | * A limited byte output stream. Throws an exception if too many bytes are written. 26 | */ 27 | public class LimitedByteOutput extends ByteOutputStream { 28 | 29 | private final long limit; 30 | private long count; 31 | 32 | /** 33 | * Construct a new instance. 34 | * 35 | * @param byteOutput the byte output to write to 36 | * @param limit the byte limit 37 | */ 38 | public LimitedByteOutput(final ByteOutput byteOutput, final long limit) { 39 | super(byteOutput); 40 | this.limit = limit; 41 | } 42 | 43 | /** {@inheritDoc} */ 44 | public void write(final int b) throws IOException { 45 | final long count = this.count; 46 | if (count < limit) { 47 | super.write(b); 48 | this.count = count + 1; 49 | } else { 50 | throw new IOException("Limit exceeded"); 51 | } 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | public void write(final byte[] b, final int off, final int len) throws IOException { 56 | final long count = this.count; 57 | if (count + len > limit) { 58 | throw new IOException("Limit exceeded"); 59 | } 60 | try { 61 | super.write(b, off, len); 62 | } catch (InterruptedIOException e) { 63 | this.count = count + e.bytesTransferred; 64 | throw e; 65 | } 66 | this.count = count + len; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/MappingClassExternalizerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.util.Map; 22 | import java.util.HashMap; 23 | import java.util.Collections; 24 | 25 | /** 26 | * An externalizer factory which uses a fixed mapping from class to externalizer. 27 | */ 28 | public class MappingClassExternalizerFactory implements ClassExternalizerFactory { 29 | 30 | private final Map, Externalizer> externalizerMap; 31 | 32 | /** 33 | * Construct a new instance. A copy is made of the given map. 34 | * 35 | * @param map the mapping 36 | */ 37 | public MappingClassExternalizerFactory(final Map, Externalizer> map) { 38 | externalizerMap = Collections.unmodifiableMap(new HashMap, Externalizer>(map)); 39 | } 40 | 41 | /** {@inheritDoc} This implementation uses the fixed mapping that was specified in the constructor. */ 42 | public Externalizer getExternalizer(final Class type) { 43 | return externalizerMap.get(type); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/Marshaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.ObjectOutput; 22 | import java.io.IOException; 23 | 24 | /** 25 | * An object marshaller for writing objects to byte streams. 26 | */ 27 | public interface Marshaller extends ObjectOutput, ByteOutput { 28 | /** 29 | * Write an object to the underlying storage or stream as a new instance. The class that implements this interface 30 | * defines how the object is written. 31 | * 32 | * @param obj the object to be written 33 | * @throws IOException if an error occurs 34 | */ 35 | void writeObjectUnshared(Object obj) throws IOException; 36 | 37 | /** 38 | * Begin marshalling to a stream. 39 | * 40 | * @param newOutput the new stream 41 | * @throws IOException if an error occurs during setup, such as an error writing the header 42 | */ 43 | void start(ByteOutput newOutput) throws IOException; 44 | 45 | /** 46 | * Discard the instance cache. May also discard the class cache in implementations that do not support separated 47 | * class and instance caches. 48 | * 49 | * @throws IOException if an error occurs 50 | */ 51 | void clearInstanceCache() throws IOException; 52 | 53 | /** 54 | * Discard the class cache. Implicitly also discards the instance cache. 55 | * 56 | * @throws IOException if an error occurs 57 | */ 58 | void clearClassCache() throws IOException; 59 | 60 | /** 61 | * Finish marshalling to a stream. Any transient class or instance cache is discarded. The stream is released. 62 | * No further marshalling may be done until the {@link #start(ByteOutput)} method is again invoked. 63 | * 64 | * @throws IOException if an error occurs 65 | */ 66 | void finish() throws IOException; 67 | } 68 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/MarshallerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * The main marshaller factory. 25 | * @apiviz.landmark 26 | */ 27 | public interface MarshallerFactory { 28 | /** 29 | * Create an unmarshaller from this configuration. 30 | * 31 | * @return an unmarshaller 32 | * @param configuration the marshalling configuration to use 33 | * @throws IOException if an error occurs 34 | */ 35 | Unmarshaller createUnmarshaller(MarshallingConfiguration configuration) throws IOException; 36 | 37 | /** 38 | * Create a marshaller from this configuration. 39 | * 40 | * @return a marshaller 41 | * @param configuration the marshalling configuration to use 42 | * @throws IOException if an error occurs 43 | */ 44 | Marshaller createMarshaller(MarshallingConfiguration configuration) throws IOException; 45 | } 46 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ObjectInputFilterAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2023 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.ObjectInputFilter; 22 | 23 | /** 24 | * An adapter that allows to use an UnmarshallingObjectInputFilter in place of an ObjectInputFilter. 25 | * 26 | * @author Brian Stansberry 27 | * @author Richard Opalka 28 | */ 29 | final class ObjectInputFilterAdapter implements ObjectInputFilter { 30 | 31 | private final UnmarshallingObjectInputFilter adaptee; 32 | 33 | ObjectInputFilterAdapter(UnmarshallingObjectInputFilter adaptee) { 34 | this.adaptee = adaptee; 35 | } 36 | 37 | @Override 38 | public Status checkInput(final FilterInfo filterInfo) { 39 | UnmarshallingObjectInputFilter.Status status = adaptee.checkInput(new UnmarshallingFilterInfoAdapter(filterInfo)); 40 | 41 | switch (status) { 42 | case ALLOWED: 43 | return ObjectInputFilter.Status.ALLOWED; 44 | case REJECTED: 45 | return ObjectInputFilter.Status.REJECTED; 46 | case UNDECIDED: 47 | return ObjectInputFilter.Status.UNDECIDED; 48 | } 49 | throw new IllegalStateException("Unexpected filtering decision: " + status); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ObjectResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * Resolver for substituting objects in a stream. The resolver is invoked on write before any serialization 23 | * takes place. 24 | */ 25 | public interface ObjectResolver { 26 | /** 27 | * Get the original object for a replacement object read from a stream. 28 | * 29 | * @param replacement the replacement object 30 | * @return the original 31 | */ 32 | Object readResolve(Object replacement); 33 | 34 | /** 35 | * Get a replacement for an object being written to a stream. 36 | * 37 | * @param original the original object 38 | * @return the replacement 39 | */ 40 | Object writeReplace(Object original); 41 | } 42 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ObjectTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * A lookup mechanism for predefined object references. Some marshallers can use this to 25 | * correlate to known object instances. 26 | */ 27 | public interface ObjectTable { 28 | /** 29 | * Determine whether the given object reference is a valid predefined reference. 30 | * 31 | * @param object the candidate object 32 | * @return the object writer, or {@code null} to use the default mechanism 33 | * @throws IOException if an I/O error occurs 34 | */ 35 | Writer getObjectWriter(Object object) throws IOException; 36 | 37 | /** 38 | * Read an instance from the stream. The instance will have been written by the 39 | * {@link #getObjectWriter(Object)} method's {@code Writer} instance, as defined above. 40 | * 41 | * @param unmarshaller the unmarshaller to read from 42 | * @return the object instance 43 | * @throws IOException if an I/O error occurs 44 | * @throws ClassNotFoundException if a class could not be found 45 | */ 46 | Object readObject(Unmarshaller unmarshaller) throws IOException, ClassNotFoundException; 47 | 48 | /** 49 | * The object writer for a specific object. 50 | * @apiviz.exclude 51 | */ 52 | interface Writer { 53 | /** 54 | * Write the predefined object reference to the stream. 55 | * 56 | * @param marshaller the marshaller to write to 57 | * @param object the object reference to write 58 | * @throws IOException if an I/O error occurs 59 | */ 60 | void writeObject(Marshaller marshaller, Object object) throws IOException; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/OutputStreamByteOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.FilterOutputStream; 22 | import java.io.IOException; 23 | import java.io.OutputStream; 24 | 25 | /** 26 | * An {@code OutputStream} which implements {@code ByteInput} and reads data from another {@code OutputStream}. 27 | * Usually the {@link Marshalling#createByteOutput(java.nio.ByteBuffer)} method should be used to create instances because 28 | * it can detect when the target already extends {@code OutputStream}. 29 | */ 30 | public class OutputStreamByteOutput extends FilterOutputStream implements ByteOutput { 31 | 32 | /** 33 | * Construct a new instance. 34 | * 35 | * @param outputStream the output stream to write to 36 | */ 37 | public OutputStreamByteOutput(final OutputStream outputStream) { 38 | super(outputStream); 39 | } 40 | 41 | /** 42 | * Writes {@code len} bytes from the specified {@code byte} array starting at offset {@code off} to this 43 | * output stream. 44 | * 45 | * @param b the data 46 | * @param off the start offset in the data 47 | * @param len the number of bytes to write 48 | * 49 | * @throws IOException if an I/O error occurs 50 | */ 51 | public void write(final byte[] b, final int off, final int len) throws IOException { 52 | out.write(b, off, len); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/ProviderDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * A provider descriptor for automatically-discovered marshalling factory types. Since instances of this interface are 23 | * constructed automatically, implementing classes should have a no-arg constructor. 24 | *

25 | * To add an automatically-discovered marshaller, create a file called {@code "META-INF/services/org.jboss.marshalling.ProviderDescriptor"} 26 | * and populate it with the names of classes that implement this interface. 27 | * 28 | * @see java.util.ServiceLoader 29 | * @apiviz.landmark 30 | */ 31 | public interface ProviderDescriptor { 32 | 33 | /** 34 | * Get the name of this provider. 35 | * 36 | * @return the provider name 37 | */ 38 | String getName(); 39 | 40 | /** 41 | * Get the supported wire protocol versions for this provider, in descending order. 42 | * 43 | * @return the supported versions in descending order 44 | */ 45 | int[] getSupportedVersions(); 46 | 47 | /** 48 | * Get the marshaller factory instance for this provider. 49 | * 50 | * @return the marshaller factory 51 | */ 52 | MarshallerFactory getMarshallerFactory(); 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/SerializabilityChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * A checker to determine whether an object class should be treated as serializable. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public interface SerializabilityChecker { 29 | 30 | /** 31 | * Determine whether an object class is serializable. 32 | * 33 | * @param clazz the object class to test 34 | * @return {@code true} if the object class is serializable, {@code false} otherwise 35 | */ 36 | boolean isSerializable(final Class clazz); 37 | 38 | /** 39 | * The default serializability checker. Returns {@code true} for any class which implements {@link Serializable}. 40 | */ 41 | SerializabilityChecker DEFAULT = new SerializabilityChecker() { 42 | public boolean isSerializable(final Class clazz) { 43 | return Serializable.class.isAssignableFrom(clazz); 44 | } 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/SimpleByteInput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.InputStream; 22 | 23 | /** 24 | * A simple byte input which extends {@code InputStream}. 25 | */ 26 | public abstract class SimpleByteInput extends InputStream implements ByteInput { 27 | } 28 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/SimpleByteOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.OutputStream; 22 | 23 | /** 24 | * A simple byte output which extends {@code OutputStream}. 25 | */ 26 | public abstract class SimpleByteOutput extends OutputStream implements ByteOutput { 27 | } 28 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/SimpleClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | /** 22 | * A class resolver which uses a predefined classloader. 23 | */ 24 | public class SimpleClassResolver extends AbstractClassResolver { 25 | private final ClassLoader classLoader; 26 | 27 | /** 28 | * Construct a new instance, specifying a classloader. 29 | * 30 | * @param classLoader the classloader to use 31 | */ 32 | public SimpleClassResolver(final ClassLoader classLoader) { 33 | this(false, classLoader); 34 | } 35 | 36 | /** 37 | * Construct a new instance, specifying a classloader and a flag which determines whether {@code serialVersionUID} 38 | * matching will be enforced. 39 | * 40 | * @param enforceSerialVersionUid {@code true} to throw an exception on unmatched {@code serialVersionUID} 41 | * @param classLoader the classloader to use 42 | */ 43 | public SimpleClassResolver(final boolean enforceSerialVersionUid, final ClassLoader classLoader) { 44 | super(enforceSerialVersionUid); 45 | this.classLoader = classLoader; 46 | } 47 | 48 | /** {@inheritDoc} */ 49 | protected ClassLoader getClassLoader() { 50 | return classLoader; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/StreamHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * A producer of stream headers. 25 | */ 26 | public interface StreamHeader { 27 | /** 28 | * Read the stream header from the stream. 29 | * 30 | * @param input the stream header 31 | * @throws IOException if the header is invalid or an error occurs 32 | */ 33 | void readHeader(ByteInput input) throws IOException; 34 | 35 | /** 36 | * Write the stream header to the stream. 37 | * 38 | * @param output the stream header 39 | * @throws IOException if an error occurs 40 | */ 41 | void writeHeader(ByteOutput output) throws IOException; 42 | } 43 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/UnmarshallingFilterInfoAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2023 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.ObjectInputFilter; 22 | 23 | /** 24 | * An adapter that allows to use an ObjectInputFilter.FilterInfo in place of an UnmarshallingObjectInputFilter.FilterInfo. 25 | * 26 | * @author Brian Stansberry 27 | * @author Richard Opalka 28 | */ 29 | final class UnmarshallingFilterInfoAdapter implements UnmarshallingObjectInputFilter.FilterInfo { 30 | 31 | private final ObjectInputFilter.FilterInfo adaptee; 32 | 33 | UnmarshallingFilterInfoAdapter(final ObjectInputFilter.FilterInfo adaptee) { 34 | this.adaptee = adaptee; 35 | } 36 | 37 | @Override 38 | public Class getUnmarshalledClass() { 39 | return adaptee.serialClass(); 40 | } 41 | 42 | @Override 43 | public long getArrayLength() { 44 | return adaptee.arrayLength(); 45 | } 46 | 47 | @Override 48 | public long getDepth() { 49 | return adaptee.depth(); 50 | } 51 | 52 | @Override 53 | public long getReferences() { 54 | return adaptee.references(); 55 | } 56 | 57 | @Override 58 | public long getStreamBytes() { 59 | return adaptee.streamBytes(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/UnmarshallingObjectInputFilterAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2023 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.ObjectInputFilter; 22 | 23 | /** 24 | * An adapter that allows to use an ObjectInputFilter in place of an UnmarshallingObjectInputFilter. 25 | * 26 | * @author Brian Stansberry 27 | * @author Richard Opalka 28 | */ 29 | final class UnmarshallingObjectInputFilterAdapter implements UnmarshallingObjectInputFilter { 30 | 31 | private final ObjectInputFilter adaptee; 32 | 33 | UnmarshallingObjectInputFilterAdapter(ObjectInputFilter adaptee) { 34 | this.adaptee = adaptee; 35 | } 36 | 37 | @Override 38 | public Status checkInput(final FilterInfo input) { 39 | ObjectInputFilter.Status status = adaptee.checkInput(new FilterInfoAdapter(input)); 40 | 41 | switch (status) { 42 | case ALLOWED: 43 | return Status.ALLOWED; 44 | case REJECTED: 45 | return Status.REJECTED; 46 | case UNDECIDED: 47 | return Status.UNDECIDED; 48 | } 49 | throw new IllegalStateException("Unexpected filtering decision: " + status); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.InputStreamReader; 24 | import java.nio.charset.StandardCharsets; 25 | import java.util.Properties; 26 | 27 | /** 28 | * The version of the Marshalling API. 29 | * @apiviz.exclude 30 | */ 31 | public final class Version { 32 | 33 | static { 34 | String jarName = "(unknown)"; 35 | String versionString = "(unknown)"; 36 | try (final InputStream stream = Version.class.getResourceAsStream("Version.properties")) { 37 | if (stream != null) try (final InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { 38 | Properties versionProps = new Properties(); 39 | versionProps.load(reader); 40 | jarName = versionProps.getProperty("jarName", jarName); 41 | versionString = versionProps.getProperty("version", versionString); 42 | } 43 | } catch (IOException ignored) { 44 | } 45 | JAR_NAME = jarName; 46 | VERSION = versionString; 47 | } 48 | 49 | private Version() { 50 | } 51 | 52 | static final String JAR_NAME; 53 | 54 | /** 55 | * The version. 56 | */ 57 | public static final String VERSION; 58 | 59 | /** 60 | * Get the version string. 61 | * 62 | * @return the version string 63 | */ 64 | public static String getVersionString() { 65 | return VERSION; 66 | } 67 | 68 | /** 69 | * Get the JAR file name. 70 | * 71 | * @return the JAR file name 72 | */ 73 | public static String getJarName() { 74 | return JAR_NAME; 75 | } 76 | 77 | /** 78 | * Print the version to {@code System.out}. 79 | * 80 | * @param args ignored 81 | */ 82 | public static void main(String[] args) { 83 | System.out.printf("JBoss Marshalling version %s\n", VERSION); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/Version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # JBoss, Home of Professional Open Source. 3 | # Copyright 2016 Red Hat, Inc., and individual contributors 4 | # as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | version=${project.version} 20 | jarName=${project.artifactId} 21 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/_private/GetDeclaredConstructorAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2018 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling._private; 20 | 21 | import java.lang.reflect.Constructor; 22 | import java.security.PrivilegedAction; 23 | 24 | /** 25 | */ 26 | public class GetDeclaredConstructorAction implements PrivilegedAction> { 27 | private final Class clazz; 28 | private final Class[] paramTypes; 29 | 30 | public GetDeclaredConstructorAction(final Class clazz, final Class... paramTypes) { 31 | this.clazz = clazz; 32 | this.paramTypes = paramTypes; 33 | } 34 | 35 | public Constructor run() { 36 | try { 37 | return clazz.getDeclaredConstructor(paramTypes); 38 | } catch (NoSuchMethodException e) { 39 | throw new NoSuchMethodError(e.getMessage()); 40 | } 41 | } 42 | 43 | public static GetDeclaredConstructorAction create(Class clazz, Class... paramTypes) { 44 | return new GetDeclaredConstructorAction<>(clazz, paramTypes); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/_private/GetDeclaredFieldAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2018 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling._private; 20 | 21 | import java.lang.reflect.Field; 22 | import java.security.PrivilegedAction; 23 | 24 | /** 25 | */ 26 | public class GetDeclaredFieldAction implements PrivilegedAction { 27 | private final Class clazz; 28 | private final String name; 29 | 30 | public GetDeclaredFieldAction(final Class clazz, final String name) { 31 | this.clazz = clazz; 32 | this.name = name; 33 | } 34 | 35 | public Field run() { 36 | try { 37 | return clazz.getDeclaredField(name); 38 | } catch (NoSuchFieldException e) { 39 | throw new NoSuchFieldError(e.getMessage()); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/_private/GetDeclaredFieldsAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2018 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling._private; 20 | 21 | import java.lang.reflect.Field; 22 | import java.security.PrivilegedAction; 23 | 24 | /** 25 | */ 26 | public class GetDeclaredFieldsAction implements PrivilegedAction { 27 | private final Class clazz; 28 | 29 | public GetDeclaredFieldsAction(final Class clazz) { 30 | this.clazz = clazz; 31 | } 32 | 33 | public Field[] run() { 34 | return clazz.getDeclaredFields(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/_private/GetReflectionFactoryAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2018 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling._private; 20 | 21 | import java.security.PrivilegedAction; 22 | 23 | import sun.reflect.ReflectionFactory; 24 | 25 | /** 26 | */ 27 | public class GetReflectionFactoryAction implements PrivilegedAction { 28 | public static final GetReflectionFactoryAction INSTANCE = new GetReflectionFactoryAction(); 29 | 30 | private GetReflectionFactoryAction() { 31 | } 32 | 33 | public ReflectionFactory run() { 34 | return ReflectionFactory.getReflectionFactory(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/_private/GetUnsafeAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2018 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling._private; 20 | 21 | import java.lang.reflect.Field; 22 | import java.security.PrivilegedAction; 23 | 24 | import sun.misc.Unsafe; 25 | 26 | /** 27 | */ 28 | public class GetUnsafeAction implements PrivilegedAction { 29 | public static final GetUnsafeAction INSTANCE = new GetUnsafeAction(); 30 | 31 | private GetUnsafeAction() { 32 | } 33 | 34 | public Unsafe run() { 35 | try { 36 | Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); 37 | unsafeField.setAccessible(true); 38 | return (Unsafe) unsafeField.get(null); 39 | } catch (IllegalAccessException | NoSuchFieldException e) { 40 | throw new Error(e); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/_private/SetAccessibleAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2018 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling._private; 20 | 21 | import java.lang.reflect.AccessibleObject; 22 | import java.security.PrivilegedAction; 23 | 24 | /** 25 | */ 26 | public class SetAccessibleAction implements PrivilegedAction { 27 | private final AccessibleObject obj; 28 | 29 | public SetAccessibleAction(final AccessibleObject obj) { 30 | this.obj = obj; 31 | } 32 | 33 | public Void run() { 34 | obj.setAccessible(true); 35 | return null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/ClassCloner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * A cloner for class types. Used (for example) to load an equivalent class from an alternate classloader. 25 | */ 26 | public interface ClassCloner { 27 | 28 | /** 29 | * Clone the given class. 30 | * 31 | * @param original the class to clone 32 | * @return the cloned class 33 | * @throws IOException if cloning fails due to a serialization problem 34 | * @throws ClassNotFoundException if cloning fails due to an unavailable class 35 | */ 36 | Class clone(Class original) throws IOException, ClassNotFoundException; 37 | 38 | /** 39 | * Clone the given reflection proxy class. 40 | * 41 | * @param proxyClass the proxy class to clone 42 | * @return the cloned proxy class 43 | * @throws IOException if cloning fails due to a serialization problem 44 | * @throws ClassNotFoundException if cloning fails due to an unavailable class 45 | */ 46 | Class cloneProxy(Class proxyClass) throws IOException, ClassNotFoundException; 47 | 48 | /** 49 | * A class cloner which just returns the class it is given. This cloner can be used in cases where an object 50 | * must be deep-cloned within the same class loader. 51 | */ 52 | ClassCloner IDENTITY = new ClassCloner() { 53 | public Class clone(final Class original) { 54 | return original; 55 | } 56 | 57 | public Class cloneProxy(final Class proxyClass) { 58 | return proxyClass; 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/ClassLoaderClassCloner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | import java.io.IOException; 22 | import java.lang.reflect.Proxy; 23 | 24 | /** 25 | * A class cloner which uses the given class loader to resolve classes. 26 | */ 27 | public class ClassLoaderClassCloner implements ClassCloner { 28 | 29 | private final ClassLoader destClassLoader; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param destClassLoader the class loader to use 35 | */ 36 | public ClassLoaderClassCloner(final ClassLoader destClassLoader) { 37 | this.destClassLoader = destClassLoader; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public Class clone(final Class original) throws IOException, ClassNotFoundException { 42 | if (original.isPrimitive()) { 43 | return original; 44 | } 45 | final String name = original.getName(); 46 | if (name.startsWith("java.")) { 47 | return original; 48 | } else if (original.getClassLoader() == destClassLoader) { 49 | return original; 50 | } else { 51 | return Class.forName(name, true, destClassLoader); 52 | } 53 | } 54 | 55 | /** {@inheritDoc} */ 56 | public Class cloneProxy(final Class proxyClass) throws IOException, ClassNotFoundException { 57 | final Class[] origInterfaces = proxyClass.getInterfaces(); 58 | final Class[] interfaces = new Class[origInterfaces.length]; 59 | for (int i = 0, origInterfacesLength = origInterfaces.length; i < origInterfacesLength; i++) { 60 | interfaces[i] = clone(origInterfaces[i]); 61 | } 62 | return Proxy.getProxyClass(destClassLoader, interfaces); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/CloneTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * An interface which allows extending a cloner to types that it would not otherwise support. 25 | */ 26 | public interface CloneTable { 27 | 28 | /** 29 | * Attempt to clone the given object. If no clone can be made or acquired from this table, return {@code null}. 30 | * 31 | * @param original the original 32 | * @param objectCloner the object cloner 33 | * @param classCloner the class cloner 34 | * @return the clone or {@code null} if none can be acquired 35 | * @throws IOException if an I/O error occurs 36 | * @throws ClassNotFoundException if a class is not found 37 | */ 38 | Object clone(Object original, ObjectCloner objectCloner, ClassCloner classCloner) throws IOException, ClassNotFoundException; 39 | 40 | /** 41 | * A null clone table. 42 | */ 43 | CloneTable NULL = new CloneTable() { 44 | public Object clone(final Object original, final ObjectCloner objectCloner, final ClassCloner classCloner) throws IOException, ClassNotFoundException { 45 | return null; 46 | } 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/ObjectCloner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * An object cloner. Creates a (possibly deep) clone of an object. Unlike Marshallers and Unmarshallers, ObjectCloners 25 | * are thread-safe and can be used to clone object graphs concurrently. 26 | */ 27 | public interface ObjectCloner { 28 | 29 | /** 30 | * Clear the cloner state and any caches. 31 | */ 32 | void reset(); 33 | 34 | /** 35 | * Create a deep clone of the given object. 36 | * 37 | * @param orig the original object 38 | * @return the deep clone 39 | * @throws IOException if a serialization error occurs 40 | * @throws ClassNotFoundException if a class cannot be loaded during the cloning process 41 | */ 42 | Object clone(Object orig) throws IOException, ClassNotFoundException; 43 | 44 | /** 45 | * The identity object cloner. Always returns the same object it is given. 46 | */ 47 | ObjectCloner IDENTITY = new ObjectCloner() { 48 | public void reset() { 49 | } 50 | 51 | public Object clone(final Object orig) { 52 | return orig; 53 | } 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/ObjectClonerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | /** 22 | * An object cloner factory. 23 | */ 24 | public interface ObjectClonerFactory { 25 | 26 | /** 27 | * Create a new cloner with the given configuration. 28 | * 29 | * @param configuration the configuration to use 30 | * @return the new cloner 31 | */ 32 | ObjectCloner createCloner(ClonerConfiguration configuration); 33 | 34 | /** 35 | * An object cloner factory which produces identity object cloners. 36 | * 37 | * @see ObjectCloner#IDENTITY 38 | */ 39 | ObjectClonerFactory IDENTITY = new ObjectClonerFactory() { 40 | public ObjectCloner createCloner(final ClonerConfiguration configuration) { 41 | return ObjectCloner.IDENTITY; 42 | } 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/ObjectClonerSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | /** 22 | * A source for object cloners. Use in applications where the configuration of cloners must be abstracted 23 | * away from their creation. 24 | */ 25 | public interface ObjectClonerSource { 26 | 27 | /** 28 | * Create a new object cloner. 29 | * 30 | * @return a new object cloner 31 | */ 32 | ObjectCloner createNew(); 33 | 34 | /** 35 | * An object cloner which returns the identity cloner. 36 | * 37 | * @see ObjectCloner#IDENTITY 38 | */ 39 | ObjectClonerSource IDENTITY = new ObjectClonerSource() { 40 | public ObjectCloner createNew() { 41 | return ObjectCloner.IDENTITY; 42 | } 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/cloner/ObjectCloners.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | /** 22 | * A class which may be used to got cloner factory instances. 23 | */ 24 | public final class ObjectCloners { 25 | 26 | private static final ObjectClonerFactory CLONEABLE = new ObjectClonerFactory() { 27 | public ObjectCloner createCloner(final ClonerConfiguration configuration) { 28 | return new CloneableCloner(configuration); 29 | } 30 | }; 31 | 32 | private static final ObjectClonerFactory SERIALIZING = new ObjectClonerFactory() { 33 | public ObjectCloner createCloner(final ClonerConfiguration configuration) { 34 | return new SerializingCloner(configuration); 35 | } 36 | }; 37 | 38 | private ObjectCloners() { 39 | } 40 | 41 | /** 42 | * Get the cloneable object cloner factory. 43 | * 44 | * @return the cloneable object cloner factory 45 | */ 46 | public static ObjectClonerFactory getCloneableObjectClonerFactory() { 47 | return CLONEABLE; 48 | } 49 | 50 | /** 51 | * Get the serializing object cloner factory. 52 | * 53 | * @return the serializing object cloner factory 54 | */ 55 | public static ObjectClonerFactory getSerializingObjectClonerFactory() { 56 | return SERIALIZING; 57 | } 58 | 59 | /** 60 | * Get an object cloner source which creates cloners with a static configuration. 61 | * 62 | * @param factory the cloner factory to use 63 | * @param configuration the configuration to use for all cloners 64 | * @return the cloner source 65 | */ 66 | public static ObjectClonerSource createObjectClonerSource(final ObjectClonerFactory factory, final ClonerConfiguration configuration) { 67 | final ClonerConfiguration finalConfig = configuration.clone(); 68 | return new ObjectClonerSource() { 69 | public ObjectCloner createNew() { 70 | return factory.createCloner(finalConfig); 71 | } 72 | }; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * The marshalling API. Marshalling is done by use of {@link org.jboss.marshalling.Marshaller Marshaller} and {@link org.jboss.marshalling.Unmarshaller Unmarshaller} instances. These 21 | * instances are acquired from a {@link org.jboss.marshalling.MarshallerFactory MarshallerFactory} using a {@link MarshallingConfiguration Configuration} to configure them. The 22 | * default implementation is the River protocol, usable by way of the {@link org.jboss.marshalling.river} package. 23 | */ 24 | package org.jboss.marshalling; 25 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/reflect/PublicReflectiveCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.reflect; 20 | 21 | import java.io.InvalidClassException; 22 | import org.jboss.marshalling.Creator; 23 | 24 | /** 25 | * A creator that simply uses reflection to locate and invoke a public, zero-argument constructor. 26 | * 27 | * @deprecated this class simply delegates to {@link ReflectiveCreator}. 28 | */ 29 | @Deprecated 30 | public class PublicReflectiveCreator implements Creator { 31 | private final ReflectiveCreator reflectiveCreator = new ReflectiveCreator(); 32 | 33 | /** {@inheritDoc} */ 34 | public T create(final Class clazz) throws InvalidClassException { 35 | return reflectiveCreator.create(clazz); 36 | } 37 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/reflect/SunReflectiveCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.reflect; 20 | 21 | import java.lang.reflect.Constructor; 22 | 23 | /** 24 | * An object creator that uses methods only found in certain JVMs to create a new constructor if needed. 25 | * 26 | * @deprecated This creator is no longer used and will be removed in a future version. 27 | */ 28 | @Deprecated 29 | public class SunReflectiveCreator extends ReflectiveCreator { 30 | 31 | private static SerializableClassRegistry registry = SerializableClassRegistry.getInstanceUnchecked(); 32 | 33 | /** 34 | * {@inheritDoc} This implementation will attempt to create a new constructor if one is not available. 35 | */ 36 | protected Constructor getNewConstructor(final Class clazz) { 37 | return registry.lookup(clazz).getNoInitConstructor(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/reflect/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * Reflection utilities for marshalling users and implementations. 21 | */ 22 | package org.jboss.marshalling.reflect; 23 | 24 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/BooleanFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import java.io.IOException; 22 | import org.jboss.marshalling.Marshaller; 23 | 24 | /** 25 | * A field putter for boolean-type fields. 26 | */ 27 | public class BooleanFieldPutter extends FieldPutter { 28 | private boolean value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeBoolean(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.BOOLEAN; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public void setBoolean(boolean value) { 42 | this.value = value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public boolean getBoolean() { 47 | return value; 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/BooleanReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a boolean type. 26 | */ 27 | public class BooleanReadField extends ReadField { 28 | 29 | private final boolean value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public BooleanReadField(final SerializableField field, final boolean value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public BooleanReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = false; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.BOOLEAN; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public boolean getBoolean() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/ByteFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for byte-type fields. 26 | */ 27 | public class ByteFieldPutter extends FieldPutter { 28 | private byte value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeByte(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.BYTE; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public byte getByte() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setByte(final byte value) { 47 | this.value = value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/ByteReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a byte type. 26 | */ 27 | public class ByteReadField extends ReadField { 28 | 29 | private final byte value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public ByteReadField(final SerializableField field, final byte value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public ByteReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.BYTE; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public byte getByte() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/CharFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for char-type fields. 26 | */ 27 | public class CharFieldPutter extends FieldPutter { 28 | private char value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeChar(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.CHAR; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public char getChar() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setChar(final char value) { 47 | this.value = value; 48 | } 49 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/CharReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a character type. 26 | */ 27 | public class CharReadField extends ReadField { 28 | 29 | private final char value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public CharReadField(final SerializableField field, final char value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public CharReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.CHAR; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public char getChar() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/DoubleFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for double-type fields. 26 | */ 27 | public class DoubleFieldPutter extends FieldPutter { 28 | private double value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeDouble(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.DOUBLE; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public double getDouble() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setDouble(final double value) { 47 | this.value = value; 48 | } 49 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/DoubleReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a double type. 26 | */ 27 | public class DoubleReadField extends ReadField { 28 | 29 | private final double value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public DoubleReadField(final SerializableField field, final double value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public DoubleReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.DOUBLE; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public double getDouble() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/FloatFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for float-type fields. 26 | */ 27 | public class FloatFieldPutter extends FieldPutter { 28 | private float value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeFloat(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.FLOAT; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public float getFloat() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setFloat(final float value) { 47 | this.value = value; 48 | } 49 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/FloatReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a float type. 26 | */ 27 | public class FloatReadField extends ReadField { 28 | 29 | private final float value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public FloatReadField(final SerializableField field, final float value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public FloatReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.FLOAT; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public float getFloat() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/IntFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for int-type fields. 26 | */ 27 | public class IntFieldPutter extends FieldPutter { 28 | private int value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeInt(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.INT; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public int getInt() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setInt(final int value) { 47 | this.value = value; 48 | } 49 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/IntReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is an int type. 26 | */ 27 | public class IntReadField extends ReadField { 28 | 29 | private final int value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public IntReadField(final SerializableField field, final int value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public IntReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.INT; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public int getInt() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/Kind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | /** 22 | * The kind of field. 23 | */ 24 | public enum Kind { 25 | /** 26 | * Field of type {@code boolean}. 27 | */ 28 | BOOLEAN, 29 | /** 30 | * Field of type {@code byte}. 31 | */ 32 | BYTE, 33 | /** 34 | * Field of type {@code char}. 35 | */ 36 | CHAR, 37 | /** 38 | * Field of type {@code double}. 39 | */ 40 | DOUBLE, 41 | /** 42 | * Field of type {@code float}. 43 | */ 44 | FLOAT, 45 | /** 46 | * Field of type {@code int}. 47 | */ 48 | INT, 49 | /** 50 | * Field of type {@code long}. 51 | */ 52 | LONG, 53 | /** 54 | * Field of object type. 55 | */ 56 | OBJECT, 57 | /** 58 | * Field of type {@code short}. 59 | */ 60 | SHORT, 61 | ; 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/LongFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for long-type fields. 26 | */ 27 | public class LongFieldPutter extends FieldPutter { 28 | private long value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeLong(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.LONG; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public long getLong() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setLong(final long value) { 47 | this.value = value; 48 | } 49 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/LongReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a long type. 26 | */ 27 | public class LongReadField extends ReadField { 28 | 29 | private final long value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public LongReadField(final SerializableField field, final long value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public LongReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.LONG; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public long getLong() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/ObjectFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for object-type fields. 26 | */ 27 | public class ObjectFieldPutter extends FieldPutter { 28 | private Object value; 29 | private final boolean unshared; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param unshared {@code true} if this object should be recorded as "unshared", {@code false} otherwise 35 | */ 36 | public ObjectFieldPutter(final boolean unshared) { 37 | this.unshared = unshared; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public void write(final Marshaller marshaller) throws IOException { 42 | if (unshared) { 43 | marshaller.writeObjectUnshared(value); 44 | } else { 45 | marshaller.writeObject(value); 46 | } 47 | } 48 | 49 | /** {@inheritDoc} */ 50 | public Kind getKind() { 51 | return Kind.OBJECT; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | public Object getObject() { 56 | return value; 57 | } 58 | 59 | /** {@inheritDoc} */ 60 | public void setObject(final Object value) { 61 | this.value = value; 62 | } 63 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/ObjectReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is an object type. 26 | */ 27 | public class ObjectReadField extends ReadField { 28 | 29 | private final Object value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public ObjectReadField(final SerializableField field, final Object value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public ObjectReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = null; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.OBJECT; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public Object getObject() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/ShortFieldPutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A field putter for short-type fields. 26 | */ 27 | public class ShortFieldPutter extends FieldPutter { 28 | private short value; 29 | 30 | /** {@inheritDoc} */ 31 | public void write(final Marshaller marshaller) throws IOException { 32 | marshaller.writeShort(value); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | public Kind getKind() { 37 | return Kind.SHORT; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | public short getShort() { 42 | return value; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public void setShort(final short value) { 47 | this.value = value; 48 | } 49 | } -------------------------------------------------------------------------------- /api/src/main/java/org/jboss/marshalling/util/ShortReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.util; 20 | 21 | import org.jboss.marshalling.reflect.SerializableField; 22 | import java.io.IOException; 23 | 24 | /** 25 | * A read field whose value is a boolean type. 26 | */ 27 | public class ShortReadField extends ReadField { 28 | 29 | private final short value; 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param field the serializable field 35 | * @param value the value 36 | */ 37 | public ShortReadField(final SerializableField field, final short value) { 38 | super(field.getName(), false); 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Construct a new instance with the default value. 44 | * 45 | * @param field the serializable field 46 | */ 47 | public ShortReadField(final SerializableField field) { 48 | super(field.getName(), true); 49 | value = 0; 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | public Kind getKind() { 54 | return Kind.SHORT; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | public short getShort() throws IOException { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/test/java/org/jboss/marshalling/ByteBufferInputTestCase.java: -------------------------------------------------------------------------------- 1 | package org.jboss.marshalling; 2 | 3 | import java.io.IOException; 4 | import java.nio.ByteBuffer; 5 | 6 | import org.testng.Assert; 7 | import org.testng.annotations.Test; 8 | 9 | /** 10 | * Test case for {@link ByteBufferInput}. 11 | * 12 | * @author Ariel Kuechler 13 | */ 14 | public final class ByteBufferInputTestCase { 15 | 16 | /** 17 | * Test case to test {@link ByteBufferInput#read(byte[], int, int)} with offset in target array. 18 | * 19 | * @throws IOException 20 | * error during reading 21 | */ 22 | @Test 23 | public final void testReadArrayWithOffset() throws IOException { 24 | final byte[] testBytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 25 | final ByteBuffer byteBuffer = ByteBuffer.wrap(testBytes); 26 | final ByteBufferInput byteBufferInput = new ByteBufferInput(byteBuffer); 27 | 28 | final byte[] result = new byte[4]; 29 | int read; 30 | 31 | // read first four bytes without offset in target array 32 | read = byteBufferInput.read(result); 33 | Assert.assertEquals(4, read); 34 | Assert.assertEquals(new byte[] { 0, 1, 2, 3 }, result); 35 | 36 | // read next three bytes with 0 offset in target array 37 | read = byteBufferInput.read(result, 0, 3); 38 | Assert.assertEquals(3, read); 39 | Assert.assertEquals(new byte[] { 4, 5, 6, 3 }, result); 40 | 41 | // read next four bytes with an offset of two in target array 42 | read = byteBufferInput.read(result, 2, 2); 43 | Assert.assertEquals(2, read); 44 | Assert.assertEquals(new byte[] { 4, 5, 7, 8 }, result); 45 | 46 | byteBufferInput.close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/src/test/java/org/jboss/marshalling/Javaee2JakartaeeMappingTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2022 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import static org.jboss.marshalling.ClassNameTransformer.JAVAEE_TO_JAKARTAEE; 22 | import static org.testng.Assert.assertEquals; 23 | 24 | import org.testng.annotations.Test; 25 | 26 | /** 27 | * Test case for {@link org.jboss.marshalling.ClassNameTransformer#JAVAEE_TO_JAKARTAEE} default translator. 28 | * 29 | * @author Richard Opalka 30 | */ 31 | public final class Javaee2JakartaeeMappingTestCase { 32 | @Test 33 | public void testTransformInput() { 34 | assertEquals(JAVAEE_TO_JAKARTAEE.transformInput("javax.servlet.ServletRequest"), "jakarta.servlet.ServletRequest"); 35 | assertEquals(JAVAEE_TO_JAKARTAEE.transformInput("javax.servleta.ServletRequest"), "javax.servleta.ServletRequest"); 36 | assertEquals(JAVAEE_TO_JAKARTAEE.transformInput("javax.security.auth.message.Principal"), "jakarta.security.auth.message.Principal"); 37 | assertEquals(JAVAEE_TO_JAKARTAEE.transformInput("javax.Bar"), "javax.Bar"); 38 | } 39 | 40 | @Test 41 | public void testTransformOutput() { 42 | assertEquals(JAVAEE_TO_JAKARTAEE.transformOutput("jakarta.el.ELContextListener"), "javax.el.ELContextListener"); 43 | assertEquals(JAVAEE_TO_JAKARTAEE.transformOutput("jakarta.xml.bind.Element"), "javax.xml.bind.Element"); 44 | assertEquals(JAVAEE_TO_JAKARTAEE.transformOutput("jakarta.xml.binda.Element"), "jakarta.xml.binda.Element"); 45 | assertEquals(JAVAEE_TO_JAKARTAEE.transformOutput("jakarta.Foo"), "jakarta.Foo"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /api/src/test/java/org/jboss/marshalling/cloner/ClassLoaderClassClonerTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | import org.testng.Assert; 22 | import org.testng.annotations.Test; 23 | 24 | /** 25 | * @author Jaikiran Pai 26 | */ 27 | public class ClassLoaderClassClonerTestCase { 28 | 29 | /** 30 | * Tests that cloning of primitive types via {@link ClassLoaderClassCloner#clone(Class)} doesn't run into 31 | * issues 32 | * 33 | * @throws Exception 34 | */ 35 | @Test 36 | public void testPrimitiveCloning() throws Exception { 37 | final ClassLoaderClassCloner cloner = new ClassLoaderClassCloner(this.getClass().getClassLoader()); 38 | 39 | Assert.assertEquals(cloner.clone(Double.TYPE), Double.TYPE, "Unexpected cloned type for " + Double.TYPE); 40 | Assert.assertEquals(cloner.clone(Boolean.TYPE), Boolean.TYPE, "Unexpected cloned type for " + Boolean.TYPE); 41 | Assert.assertEquals(cloner.clone(Character.TYPE), Character.TYPE, "Unexpected cloned type for " + Character.TYPE); 42 | Assert.assertEquals(cloner.clone(Void.TYPE), Void.TYPE, "Unexpected cloned type for " + Void.TYPE); 43 | Assert.assertEquals(cloner.clone(Short.TYPE), Short.TYPE, "Unexpected cloned type for " + Short.TYPE); 44 | Assert.assertEquals(cloner.clone(Long.TYPE), Long.TYPE, "Unexpected cloned type for " + Long.TYPE); 45 | Assert.assertEquals(cloner.clone(Float.TYPE), Float.TYPE, "Unexpected cloned type for " + Float.TYPE); 46 | Assert.assertEquals(cloner.clone(Integer.TYPE), Integer.TYPE, "Unexpected cloned type for " + Integer.TYPE); 47 | Assert.assertEquals(cloner.clone(Byte.TYPE), Byte.TYPE, "Unexpected cloned type for " + Byte.TYPE); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/test/java/org/jboss/marshalling/cloner/DateFieldType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.cloner; 20 | 21 | import java.io.IOException; 22 | import java.io.ObjectInputStream; 23 | import java.io.ObjectOutputStream; 24 | import java.io.Serializable; 25 | import java.util.Date; 26 | 27 | /** 28 | * @author David M. Lloyd 29 | */ 30 | public final class DateFieldType implements Serializable { 31 | 32 | private static final long serialVersionUID = -884445687188992945L; 33 | 34 | private final Date date; 35 | private transient boolean foo; 36 | 37 | public DateFieldType(final Date date) { 38 | this.date = date; 39 | } 40 | 41 | public DateFieldType(final Date date, final boolean foo) { 42 | this.date = date; 43 | this.foo = foo; 44 | } 45 | 46 | public Date getDate() { 47 | return date; 48 | } 49 | 50 | public boolean equals(Object other) { 51 | return other instanceof DateFieldType && equals((DateFieldType)other); 52 | } 53 | 54 | public boolean equals(DateFieldType other) { 55 | return this == other || other != null && date.equals(other.date) && foo == other.foo; 56 | } 57 | 58 | public int hashCode() { 59 | return date.hashCode() ^ Boolean.valueOf(foo).hashCode(); 60 | } 61 | 62 | private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { 63 | ois.defaultReadObject(); 64 | foo = ois.readBoolean(); 65 | } 66 | 67 | private void writeObject(ObjectOutputStream oos) throws IOException { 68 | oos.defaultWriteObject(); 69 | oos.writeBoolean(foo); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /river/build-test-java11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/river/build-test-java11 -------------------------------------------------------------------------------- /river/build-test-java17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/river/build-test-java17 -------------------------------------------------------------------------------- /river/build-test-java21: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/river/build-test-java21 -------------------------------------------------------------------------------- /river/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 22 | 23 | 4.0.0 24 | 25 | JBoss Marshalling River 26 | JBoss Marshalling River Implementation 27 | jboss-marshalling-river 28 | jar 29 | 30 | 31 | org.jboss.marshalling 32 | jboss-marshalling-parent 33 | 2.3.0.Final-SNAPSHOT 34 | 35 | 36 | 37 | 38 | org.jboss.marshalling 39 | jboss-marshalling 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-jar-plugin 48 | 49 | 50 | 51 | org.jboss.marshalling.river 52 | 53 | 54 | 55 | 56 | 57 | org.jacoco 58 | jacoco-maven-plugin 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/BasicSerializableClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.reflect.SerializableClass; 22 | import org.jboss.marshalling.reflect.SerializableField; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | final class BasicSerializableClassDescriptor extends SerializableClassDescriptor { 28 | private final Class type; 29 | private final int typeID; 30 | private final SerializableClass serializableClass; 31 | private final ClassDescriptor superClassDescriptor; 32 | private final SerializableField[] fields; 33 | 34 | protected BasicSerializableClassDescriptor(final SerializableClass serializableClass, final ClassDescriptor superClassDescriptor, final SerializableField[] fields, final int classType) throws ClassNotFoundException { 35 | type = serializableClass == null ? null : serializableClass.getSubjectClass(); 36 | typeID = classType; 37 | this.serializableClass = serializableClass; 38 | this.superClassDescriptor = superClassDescriptor; 39 | this.fields = fields; 40 | } 41 | 42 | public Class getType() { 43 | return type; 44 | } 45 | 46 | public int getTypeID() { 47 | return typeID; 48 | } 49 | 50 | public SerializableClass getSerializableClass() { 51 | return serializableClass; 52 | } 53 | 54 | public ClassDescriptor getSuperClassDescriptor() { 55 | return superClassDescriptor; 56 | } 57 | 58 | public SerializableField[] getFields() { 59 | return fields; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/ClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | /** 22 | * @author David M. Lloyd 23 | */ 24 | abstract class ClassDescriptor { 25 | 26 | public abstract Class getType(); 27 | 28 | public abstract int getTypeID(); 29 | 30 | public Class getNearestType() { 31 | return getType(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/ExternalizerClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.Externalizer; 22 | 23 | /** 24 | * 25 | */ 26 | final class ExternalizerClassDescriptor extends SimpleClassDescriptor { 27 | private final Externalizer externalizer; 28 | 29 | public ExternalizerClassDescriptor(final Class clazz, final Externalizer externalizer) { 30 | super(clazz, Protocol.ID_EXTERNALIZER_CLASS); 31 | this.externalizer = externalizer; 32 | } 33 | 34 | public Externalizer getExternalizer() { 35 | return externalizer; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/FutureSerializableClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.reflect.SerializableClass; 22 | import org.jboss.marshalling.reflect.SerializableField; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | final class FutureSerializableClassDescriptor extends SerializableClassDescriptor { 28 | private final Class type; 29 | private final int typeID; 30 | 31 | private SerializableClassDescriptor result; 32 | 33 | public FutureSerializableClassDescriptor(final Class type, final int typeID) { 34 | this.type = type; 35 | this.typeID = typeID; 36 | } 37 | 38 | public Class getType() { 39 | return type; 40 | } 41 | 42 | public int getTypeID() { 43 | return typeID; 44 | } 45 | 46 | public ClassDescriptor getSuperClassDescriptor() { 47 | return check(result).getSuperClassDescriptor(); 48 | } 49 | 50 | public SerializableField[] getFields() { 51 | return check(result).getFields(); 52 | } 53 | 54 | public SerializableClass getSerializableClass() { 55 | return check(result).getSerializableClass(); 56 | } 57 | 58 | public void setResult(final SerializableClassDescriptor result) { 59 | this.result = result; 60 | } 61 | 62 | private SerializableClassDescriptor check(final SerializableClassDescriptor result) { 63 | if (result == null) { 64 | throw new IllegalStateException("Serializable class not resolved"); 65 | } 66 | return result; 67 | } 68 | 69 | public String toString() { 70 | return "future " + result; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/RiverMarshallerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import static java.lang.System.getSecurityManager; 22 | import static java.security.AccessController.doPrivileged; 23 | 24 | import org.jboss.marshalling.AbstractMarshallerFactory; 25 | import org.jboss.marshalling.Unmarshaller; 26 | import org.jboss.marshalling.Marshaller; 27 | import org.jboss.marshalling.reflect.SerializableClassRegistry; 28 | import org.jboss.marshalling.MarshallingConfiguration; 29 | import java.io.IOException; 30 | import java.security.PrivilegedAction; 31 | 32 | /** 33 | * The River marshaller factory implementation. 34 | */ 35 | public class RiverMarshallerFactory extends AbstractMarshallerFactory { 36 | private final SerializableClassRegistry registry; 37 | 38 | /** 39 | * Construct a new instance of a River marshaller factory. 40 | */ 41 | public RiverMarshallerFactory() { 42 | if (getSecurityManager() == null) { 43 | registry = SerializableClassRegistry.getInstance(); 44 | } else { 45 | registry = doPrivileged(new PrivilegedAction() { 46 | public SerializableClassRegistry run() { 47 | return SerializableClassRegistry.getInstance(); 48 | } 49 | }); 50 | } 51 | } 52 | 53 | /** {@inheritDoc} */ 54 | public Unmarshaller createUnmarshaller(final MarshallingConfiguration configuration) throws IOException { 55 | return new RiverUnmarshaller(this, registry, configuration); 56 | } 57 | 58 | /** {@inheritDoc} */ 59 | public Marshaller createMarshaller(final MarshallingConfiguration configuration) throws IOException { 60 | return new RiverMarshaller(this, registry, configuration); 61 | } 62 | 63 | protected int getDefaultVersion() { 64 | return 4; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/RiverProviderDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.ProviderDescriptor; 22 | import org.jboss.marshalling.MarshallerFactory; 23 | 24 | /** 25 | * The River implementation of the provider descriptor interface. 26 | * 27 | * @apiviz.exclude 28 | */ 29 | public final class RiverProviderDescriptor implements ProviderDescriptor { 30 | 31 | private static final MarshallerFactory MARSHALLER_FACTORY = new RiverMarshallerFactory(); 32 | private static final int[] VERSIONS; 33 | 34 | static { 35 | final int range = Protocol.MAX_VERSION - Protocol.MIN_VERSION + 1; 36 | final int[] versions = new int[range]; 37 | for (int i = 0; i < range; i ++) { 38 | versions[i] = Protocol.MAX_VERSION - i; 39 | } 40 | VERSIONS = versions; 41 | } 42 | 43 | /** {@inheritDoc} */ 44 | public String getName() { 45 | return "river"; 46 | } 47 | 48 | /** {@inheritDoc} */ 49 | public int[] getSupportedVersions() { 50 | return VERSIONS.clone(); 51 | } 52 | 53 | /** {@inheritDoc} */ 54 | public MarshallerFactory getMarshallerFactory() { 55 | return MARSHALLER_FACTORY; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/SerializableClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.SerializabilityChecker; 22 | import org.jboss.marshalling.reflect.SerializableField; 23 | import org.jboss.marshalling.reflect.SerializableClass; 24 | 25 | /** 26 | * 27 | */ 28 | abstract class SerializableClassDescriptor extends ClassDescriptor { 29 | 30 | protected SerializableClassDescriptor() {} 31 | 32 | public abstract Class getType(); 33 | 34 | public abstract int getTypeID(); 35 | 36 | public Class getNearestType() { 37 | Class type = getType(); 38 | return type == null ? getSuperClassDescriptor().getNearestType() : type; 39 | } 40 | 41 | public abstract ClassDescriptor getSuperClassDescriptor(); 42 | 43 | public abstract SerializableField[] getFields(); 44 | 45 | public abstract SerializableClass getSerializableClass(); 46 | 47 | public String toString() { 48 | final ClassDescriptor superClassDescriptor = getSuperClassDescriptor(); 49 | if (superClassDescriptor == null) { 50 | return String.format("%s for %s (id %x02)", getClass().getSimpleName(), getType(), Integer.valueOf(getTypeID())); 51 | } else { 52 | return String.format("%s for %s (id %x02) extends %s", getClass().getSimpleName(), getType(), Integer.valueOf(getTypeID()), superClassDescriptor); 53 | } 54 | } 55 | 56 | public Class getNonSerializableSuperclass(SerializabilityChecker checker) { 57 | Class nearestType = getNearestType(); 58 | if (nearestType == null) return Object.class; 59 | while (checker.isSerializable(nearestType)) { 60 | nearestType = nearestType.getSuperclass(); 61 | } 62 | return nearestType; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/SerializableGapClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.reflect.SerializableClass; 22 | import org.jboss.marshalling.reflect.SerializableField; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | final class SerializableGapClassDescriptor extends SerializableClassDescriptor { 28 | 29 | private final Class type; 30 | private final SerializableClass serializableClass; 31 | private final ClassDescriptor superDescriptor; 32 | 33 | public SerializableGapClassDescriptor(final SerializableClass serializableClass, final ClassDescriptor superDescriptor) throws ClassNotFoundException { 34 | type = serializableClass.getSubjectClass(); 35 | this.serializableClass = serializableClass; 36 | this.superDescriptor = superDescriptor; 37 | } 38 | 39 | public Class getType() { 40 | return type; 41 | } 42 | 43 | public int getTypeID() { 44 | return Protocol.ID_SERIALIZABLE_CLASS; 45 | } 46 | 47 | public ClassDescriptor getSuperClassDescriptor() { 48 | return superDescriptor; 49 | } 50 | 51 | public SerializableField[] getFields() { 52 | return SerializableClass.NOFIELDS; 53 | } 54 | 55 | public SerializableClass getSerializableClass() { 56 | return serializableClass; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/SimpleClassDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | /** 22 | * 23 | */ 24 | class SimpleClassDescriptor extends ClassDescriptor { 25 | private final Class type; 26 | private int typeID; 27 | // non-public (due to security) 28 | 29 | public SimpleClassDescriptor(final Class type, final int typeID) { 30 | this.type = type; 31 | this.typeID = typeID; 32 | } 33 | 34 | public Class getType() { 35 | return type; 36 | } 37 | 38 | public int getTypeID() { 39 | return typeID; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/Validator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import java.io.ObjectInputValidation; 22 | 23 | final class Validator implements Comparable { 24 | private final int priority; 25 | private final int seq; 26 | private final ObjectInputValidation validation; 27 | 28 | public Validator(final int priority, final int seq, final ObjectInputValidation validation) { 29 | this.priority = priority; 30 | this.seq = seq; 31 | this.validation = validation; 32 | } 33 | 34 | public int compareTo(final Validator o) { 35 | return priority == o.priority ? seq - o.seq : o.priority - priority; 36 | } 37 | 38 | public ObjectInputValidation getValidation() { 39 | return validation; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /river/src/main/java/org/jboss/marshalling/river/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * The River protocol implementation package. Construct an instance of the {@link org.jboss.marshalling.river.RiverMarshallerFactory RiverMarshallerFactory} 21 | * class to use the River marshalling protocol. 22 | */ 23 | package org.jboss.marshalling.river; 24 | -------------------------------------------------------------------------------- /river/src/main/resources/META-INF/services/org.jboss.marshalling.ProviderDescriptor: -------------------------------------------------------------------------------- 1 | # 2 | # JBoss, Home of Professional Open Source. 3 | # Copyright 2014 Red Hat, Inc., and individual contributors 4 | # as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | # 20 | # River protocol provider 21 | # 22 | org.jboss.marshalling.river.RiverProviderDescriptor 23 | -------------------------------------------------------------------------------- /river/src/test/java/org/jboss/marshalling/river/ReadWriteTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.river; 20 | 21 | import org.jboss.marshalling.MarshallerFactory; 22 | import org.jboss.marshalling.Marshaller; 23 | import org.jboss.marshalling.Marshalling; 24 | import org.jboss.marshalling.Unmarshaller; 25 | import org.jboss.marshalling.MarshallingConfiguration; 26 | import java.io.ByteArrayOutputStream; 27 | import java.io.ByteArrayInputStream; 28 | 29 | /** 30 | * 31 | */ 32 | public abstract class ReadWriteTest { 33 | public void run() throws Throwable { 34 | final MarshallerFactory factory = new RiverMarshallerFactory(); 35 | final MarshallingConfiguration configuration = new MarshallingConfiguration(); 36 | configure(configuration); 37 | final Marshaller marshaller = factory.createMarshaller(configuration); 38 | final ByteArrayOutputStream baos = new ByteArrayOutputStream(10240); 39 | marshaller.start(Marshalling.createByteOutput(baos)); 40 | runWrite(marshaller); 41 | marshaller.finish(); 42 | final byte[] bytes = baos.toByteArray(); 43 | final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration); 44 | unmarshaller.start(Marshalling.createByteInput(new ByteArrayInputStream(bytes))); 45 | runRead(unmarshaller); 46 | unmarshaller.finish(); 47 | } 48 | 49 | public void configure(MarshallingConfiguration configuration) throws Throwable {} 50 | 51 | public void runWrite(Marshaller marshaller) throws Throwable {}; 52 | 53 | public void runRead(Unmarshaller unmarshaller) throws Throwable {}; 54 | } 55 | -------------------------------------------------------------------------------- /serial/build-test-java11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/serial/build-test-java11 -------------------------------------------------------------------------------- /serial/build-test-java17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/serial/build-test-java17 -------------------------------------------------------------------------------- /serial/build-test-java21: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/serial/build-test-java21 -------------------------------------------------------------------------------- /serial/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 22 | 23 | 4.0.0 24 | 25 | JBoss Marshalling Serial 26 | JBoss Marshalling Serial Implementation 27 | jboss-marshalling-serial 28 | jar 29 | 30 | 31 | org.jboss.marshalling 32 | jboss-marshalling-parent 33 | 2.3.0.Final-SNAPSHOT 34 | 35 | 36 | 37 | 38 | org.jboss.marshalling 39 | jboss-marshalling 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-jar-plugin 48 | 49 | 50 | 51 | org.jboss.marshalling.serial 52 | 53 | 54 | 55 | 56 | 57 | org.jacoco 58 | jacoco-maven-plugin 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /serial/src/main/java/org/jboss/marshalling/serial/Descriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.serial; 20 | 21 | import org.jboss.marshalling.reflect.SerializableClass; 22 | import org.jboss.marshalling.reflect.SerializableField; 23 | import java.io.IOException; 24 | 25 | /** 26 | * 27 | */ 28 | abstract class Descriptor implements ExtendedObjectStreamConstants { 29 | private final Descriptor parent; 30 | private final Class type; 31 | 32 | protected Descriptor(final Descriptor parent, final Class type) { 33 | this.parent = parent; 34 | this.type = type; 35 | } 36 | 37 | protected Descriptor getParent() { 38 | return parent; 39 | } 40 | 41 | protected Class getType() { 42 | return type; 43 | } 44 | 45 | protected Class getNearestType() { 46 | return type != null ? type : parent != null ? parent.getNearestType() : Object.class; 47 | } 48 | 49 | protected abstract void readSerial(SerialUnmarshaller serialUnmarshaller, SerializableClass sc, Object subject) throws IOException, ClassNotFoundException; 50 | 51 | public int getFlags() { 52 | return 0; 53 | } 54 | 55 | public SerializableField[] getFields() { 56 | return SerializableClass.NOFIELDS; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /serial/src/main/java/org/jboss/marshalling/serial/ExtendedObjectStreamConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.serial; 20 | 21 | import java.io.ObjectStreamConstants; 22 | 23 | /** 24 | * Protocol extensions used locally for JBoss Marshalling extensions to Class/Object Resolvers. 25 | */ 26 | interface ExtendedObjectStreamConstants extends ObjectStreamConstants { 27 | int TC_CLASSTABLEDESC = 0xF0; 28 | int TC_OBJECTTABLE = 0xF1; 29 | } 30 | -------------------------------------------------------------------------------- /serial/src/main/java/org/jboss/marshalling/serial/NoDataDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.serial; 20 | 21 | import org.jboss.marshalling.reflect.SerializableClass; 22 | import java.io.IOException; 23 | 24 | /** 25 | * 26 | */ 27 | class NoDataDescriptor extends Descriptor { 28 | 29 | NoDataDescriptor(final Class type, final Descriptor parent) { 30 | super(parent, type); 31 | } 32 | 33 | protected void readSerial(final SerialUnmarshaller serialUnmarshaller, final SerializableClass sc, final Object subject) throws IOException, ClassNotFoundException { 34 | if (sc.hasReadObjectNoData()) { 35 | sc.callReadObjectNoData(subject); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /serial/src/main/java/org/jboss/marshalling/serial/ProxyDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.serial; 20 | 21 | import java.io.ObjectStreamConstants; 22 | 23 | /** 24 | * 25 | */ 26 | class ProxyDescriptor extends NoDataDescriptor { 27 | private final String[] interfaces; 28 | 29 | ProxyDescriptor(final Class type, final Descriptor parent, final String[] interfaces) { 30 | super(type, parent); 31 | this.interfaces = interfaces; 32 | } 33 | 34 | public String[] getInterfaces() { 35 | return interfaces; 36 | } 37 | 38 | public int getFlags() { 39 | return ObjectStreamConstants.SC_SERIALIZABLE; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /serial/src/main/java/org/jboss/marshalling/serial/SerialProviderDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling.serial; 20 | 21 | import org.jboss.marshalling.ProviderDescriptor; 22 | import org.jboss.marshalling.MarshallerFactory; 23 | 24 | /** 25 | * The Serial implementation of the provider descriptor interface. 26 | * 27 | * @apiviz.exclude 28 | */ 29 | public final class SerialProviderDescriptor implements ProviderDescriptor { 30 | 31 | private static final MarshallerFactory MARSHALLER_FACTORY = new SerialMarshallerFactory(); 32 | private static final int[] VERSIONS = new int[] { 5 }; 33 | 34 | /** {@inheritDoc} */ 35 | public String getName() { 36 | return "serial"; 37 | } 38 | 39 | /** {@inheritDoc} */ 40 | public int[] getSupportedVersions() { 41 | return VERSIONS.clone(); 42 | } 43 | 44 | /** {@inheritDoc} */ 45 | public MarshallerFactory getMarshallerFactory() { 46 | return MARSHALLER_FACTORY; 47 | } 48 | } -------------------------------------------------------------------------------- /serial/src/main/resources/META-INF/services/org.jboss.marshalling.ProviderDescriptor: -------------------------------------------------------------------------------- 1 | # 2 | # JBoss, Home of Professional Open Source. 3 | # Copyright 2014 Red Hat, Inc., and individual contributors 4 | # as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | # 20 | # Serial protocol provider 21 | # 22 | org.jboss.marshalling.serial.SerialProviderDescriptor 23 | -------------------------------------------------------------------------------- /tests/build-test-java11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/tests/build-test-java11 -------------------------------------------------------------------------------- /tests/build-test-java17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/tests/build-test-java17 -------------------------------------------------------------------------------- /tests/build-test-java21: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboss-remoting/jboss-marshalling/c1e93b3ca8be439efc954d0252eb7da781fbdfb2/tests/build-test-java21 -------------------------------------------------------------------------------- /tests/src/main/resources/testing.policy: -------------------------------------------------------------------------------- 1 | 2 | // Permissions for the tests 3 | 4 | grant codeBase "file:${build.home}/tests/target/main/classes/-" 5 | { 6 | permission java.io.SerializablePermission "allowSerializationReflection"; 7 | permission java.io.SerializablePermission "enableSubclassImplementation"; 8 | permission java.io.SerializablePermission "enableSubstitution"; 9 | permission java.io.SerializablePermission "creator"; 10 | }; 11 | 12 | // Permissions for the core 13 | 14 | grant codeBase "file:${build.home}/api/target/main/classes/-" 15 | { 16 | permission java.io.SerializablePermission "allowSerializationReflection"; 17 | permission java.io.SerializablePermission "enableSubclassImplementation"; 18 | permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect"; 19 | permission java.lang.RuntimePermission "reflectionFactoryAccess"; 20 | permission java.lang.RuntimePermission "accessDeclaredMembers"; 21 | permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; 22 | permission java.io.SerializablePermission "creator"; 23 | 24 | }; 25 | 26 | grant codeBase "file:${build.home}/river/target/main/classes/-" 27 | { 28 | permission java.io.SerializablePermission "allowSerializationReflection"; 29 | permission java.io.SerializablePermission "enableSubclassImplementation"; 30 | permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; 31 | }; 32 | 33 | grant codeBase "file:${build.home}/serialization-java/target/main/classes/-" 34 | { 35 | permission java.io.SerializablePermission "allowSerializationReflection"; 36 | permission java.io.SerializablePermission "enableSubclassImplementation"; 37 | permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; 38 | permission java.io.SerializablePermission "enableSubstitution"; 39 | }; 40 | 41 | grant codeBase "file:${build.home}/serial/target/main/classes/-" 42 | { 43 | permission java.io.SerializablePermission "allowSerializationReflection"; 44 | permission java.io.SerializablePermission "enableSubclassImplementation"; 45 | permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; 46 | }; 47 | 48 | // Support classes 49 | 50 | grant codeBase "file:${build.home}/testing-support/target/main/classes/-" 51 | { 52 | permission java.security.AllPermission; 53 | }; 54 | 55 | grant codeBase "file:${idea.home}/-" 56 | { 57 | permission java.security.AllPermission; 58 | }; 59 | 60 | grant codeBase "file:${lib.testng.local}" 61 | { 62 | permission java.security.AllPermission; 63 | }; 64 | 65 | grant codeBase "file:${ant.library.dir}/-" 66 | { 67 | permission java.security.AllPermission; 68 | }; 69 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/marshalling/FilterTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2023 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.marshalling; 20 | 21 | import org.testng.Assert; 22 | import org.testng.annotations.Test; 23 | 24 | import java.io.InvalidClassException; 25 | import java.io.ObjectInputStream; 26 | import java.io.ObjectOutputStream; 27 | import java.nio.ByteBuffer; 28 | 29 | public class FilterTests { 30 | 31 | @Test 32 | public void jdkSpecific_setObjectInputStreamFilter() throws Exception { 33 | try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInput(createPayload()))) { 34 | AbstractUnmarshaller.setObjectInputStreamFilter(ois, UnmarshallingObjectInputFilter.ACCEPTING); 35 | ois.readObject(); 36 | } catch (InvalidClassException e) { 37 | Assert.fail("Deserialization was expected to succeed."); 38 | } 39 | 40 | try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInput(createPayload()))) { 41 | AbstractUnmarshaller.setObjectInputStreamFilter(ois, UnmarshallingObjectInputFilter.REJECTING); 42 | ois.readObject(); 43 | Assert.fail("Deserialization was expected to fail."); 44 | } catch (InvalidClassException expected) { 45 | } 46 | } 47 | 48 | private static ByteBuffer createPayload() throws Exception { 49 | ByteBuffer buffer = ByteBuffer.allocate(1000); 50 | try (ObjectOutputStream oos = new ObjectOutputStream(new ByteBufferOutput(buffer))) { 51 | oos.writeObject(new Integer[] {1, 2, 3}); 52 | } 53 | //noinspection RedundantCast 54 | ((ByteBuffer) buffer).flip(); // JDK 9+ to JDK 8 cross-compilation issue 55 | return buffer; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/EqualableArrayDeque.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import java.util.ArrayDeque; 22 | import java.util.Iterator; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | public final class EqualableArrayDeque extends ArrayDeque { 28 | 29 | private static final long serialVersionUID = 5029699446105430182L; 30 | 31 | public boolean equals(final Object obj) { 32 | return obj instanceof EqualableArrayDeque && equals((EqualableArrayDeque)obj); 33 | } 34 | 35 | public boolean equals(final EqualableArrayDeque obj) { 36 | Iterator i1 = iterator(); 37 | Iterator i2 = obj.iterator(); 38 | while (i1.hasNext() && i2.hasNext()) { 39 | X o1 = i1.next(); 40 | Object o2 = i2.next(); 41 | if (o1 == null ? o2 != null : ! o1.equals(o2)) { 42 | return false; 43 | } 44 | } 45 | return i1.hasNext() == i2.hasNext(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/LRUMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import java.util.LinkedHashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | public class LRUMap extends LinkedHashMap { 28 | 29 | private static final long serialVersionUID = -4085177629568085771L; 30 | 31 | private int maxCapacity; 32 | 33 | public LRUMap(int maxCapacity) { 34 | super(maxCapacity, 0.8f, true); 35 | this.maxCapacity = maxCapacity; 36 | } 37 | 38 | protected boolean removeEldestEntry(Map.Entry eldest) { 39 | return (size() > maxCapacity); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/MarshallerFactoryTestMarshallerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import org.jboss.marshalling.MarshallerFactory; 22 | import org.jboss.marshalling.Marshaller; 23 | import org.jboss.marshalling.MarshallingConfiguration; 24 | import org.jboss.marshalling.ByteOutput; 25 | import java.io.IOException; 26 | 27 | /** 28 | * 29 | */ 30 | public class MarshallerFactoryTestMarshallerProvider implements TestMarshallerProvider { 31 | private final MarshallerFactory marshallerFactory; 32 | private final int version; 33 | 34 | public MarshallerFactoryTestMarshallerProvider(final MarshallerFactory factory) { 35 | marshallerFactory = factory; 36 | version = -1; 37 | } 38 | 39 | public MarshallerFactoryTestMarshallerProvider(final MarshallerFactory factory, final int version) { 40 | marshallerFactory = factory; 41 | this.version = version; 42 | } 43 | 44 | public Marshaller create(final MarshallingConfiguration config, final ByteOutput target) throws IOException { 45 | if (version != -1) { 46 | config.setVersion(version); 47 | } 48 | final Marshaller marshaller = marshallerFactory.createMarshaller(config); 49 | marshaller.start(target); 50 | return marshaller; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return marshallerFactory.getClass().getSimpleName() + " version " + version; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/MarshallerFactoryTestUnmarshallerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import org.jboss.marshalling.Unmarshaller; 22 | import org.jboss.marshalling.MarshallingConfiguration; 23 | import org.jboss.marshalling.ByteInput; 24 | import org.jboss.marshalling.MarshallerFactory; 25 | import java.io.IOException; 26 | 27 | /** 28 | * 29 | */ 30 | public final class MarshallerFactoryTestUnmarshallerProvider implements TestUnmarshallerProvider { 31 | private final MarshallerFactory marshallerFactory; 32 | private final int version; 33 | 34 | public MarshallerFactoryTestUnmarshallerProvider(final MarshallerFactory factory) { 35 | marshallerFactory = factory; 36 | version = -1; 37 | } 38 | 39 | public MarshallerFactoryTestUnmarshallerProvider(final MarshallerFactory factory, final int version) { 40 | marshallerFactory = factory; 41 | this.version = version; 42 | } 43 | 44 | public Unmarshaller create(final MarshallingConfiguration config, final ByteInput source) throws IOException { 45 | if (version != -1) { 46 | config.setVersion(version); 47 | } 48 | final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(config); 49 | unmarshaller.start(source); 50 | return unmarshaller; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return marshallerFactory.getClass().getSimpleName() + " version " + version; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/OtherMarshallerTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import java.io.Serializable; 22 | import java.util.concurrent.PriorityBlockingQueue; 23 | import org.jboss.marshalling.cloner.ClonerConfiguration; 24 | import org.jboss.marshalling.MarshallingConfiguration; 25 | import org.jboss.marshalling.cloner.ObjectCloner; 26 | import org.jboss.marshalling.cloner.ObjectClonerFactory; 27 | import org.jboss.marshalling.cloner.ObjectCloners; 28 | import org.testng.annotations.Test; 29 | 30 | 31 | /** 32 | * OtherMarshallerTests 33 | */ 34 | public final class OtherMarshallerTests extends TestBase { 35 | 36 | public OtherMarshallerTests(TestMarshallerProvider testMarshallerProvider, TestUnmarshallerProvider testUnmarshallerProvider, MarshallingConfiguration configuration) { 37 | super(testMarshallerProvider, testUnmarshallerProvider, configuration); 38 | } 39 | 40 | @Test 41 | public synchronized void testPriorityBlockingQueue() throws Throwable { 42 | final ObjectClonerFactory clonerFactory = ObjectCloners.getSerializingObjectClonerFactory(); 43 | final ClonerConfiguration configuration = new ClonerConfiguration(); 44 | final ObjectCloner cloner = clonerFactory.createCloner(configuration); 45 | PriorityBlockingQueueTestObject testObject = new PriorityBlockingQueueTestObject(); 46 | if(testObject != null) { 47 | testObject.add(new Integer(100)); 48 | cloner.clone(testObject); 49 | } 50 | } 51 | 52 | public static class PriorityBlockingQueueTestObject implements Serializable { 53 | private PriorityBlockingQueue queue = new PriorityBlockingQueue(); 54 | public void add(T item) { 55 | this.queue.add(item); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/ReadWriteTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import org.jboss.marshalling.Unmarshaller; 23 | import org.jboss.marshalling.MarshallingConfiguration; 24 | 25 | /** 26 | * 27 | */ 28 | public abstract class ReadWriteTest { 29 | public void configureRead(MarshallingConfiguration configuration) throws Throwable { 30 | configure(configuration); 31 | } 32 | 33 | public void configureWrite(MarshallingConfiguration configuration) throws Throwable { 34 | configure(configuration); 35 | } 36 | 37 | public void configure(MarshallingConfiguration configuration) throws Throwable {} 38 | 39 | public void runWrite(Marshaller marshaller) throws Throwable {}; 40 | 41 | public void runRead(Unmarshaller unmarshaller) throws Throwable {}; 42 | } 43 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/RiverVersionZeroMarshallerFactoryTestMarshallerProviderImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import org.jboss.marshalling.MarshallerFactory; 22 | import org.jboss.marshalling.Marshaller; 23 | import org.jboss.marshalling.MarshallingConfiguration; 24 | import org.jboss.marshalling.ByteOutput; 25 | import org.jboss.marshalling.StreamHeader; 26 | import org.jboss.marshalling.ByteInput; 27 | import java.io.IOException; 28 | 29 | /** 30 | * 31 | */ 32 | public final class RiverVersionZeroMarshallerFactoryTestMarshallerProviderImpl extends MarshallerFactoryTestMarshallerProvider { 33 | 34 | public RiverVersionZeroMarshallerFactoryTestMarshallerProviderImpl(final MarshallerFactory factory) { 35 | super(factory, 0); 36 | } 37 | 38 | public Marshaller create(final MarshallingConfiguration config, final ByteOutput target) throws IOException { 39 | final StreamHeader header = config.getStreamHeader(); 40 | config.setStreamHeader(new StreamHeader() { 41 | public void readHeader(final ByteInput input) throws IOException { 42 | if (header != null) header.readHeader(input); 43 | } 44 | 45 | public void writeHeader(final ByteOutput output) throws IOException { 46 | if (header != null) header.writeHeader(output); 47 | output.write(0); 48 | } 49 | }); 50 | return super.create(config, target); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/TestArrayList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import java.util.ArrayList; 22 | 23 | public final class TestArrayList extends ArrayList { 24 | private static final long serialVersionUID = -6650936046977193792L; 25 | } 26 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/TestCollectionHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import java.util.ArrayList; 22 | import java.util.HashSet; 23 | import java.util.LinkedHashSet; 24 | import java.util.LinkedList; 25 | import java.util.TreeSet; 26 | import java.util.HashMap; 27 | import java.util.LinkedHashMap; 28 | import java.util.IdentityHashMap; 29 | import java.util.Hashtable; 30 | import java.util.TreeMap; 31 | import java.util.EnumSet; 32 | import java.util.EnumMap; 33 | import java.lang.annotation.RetentionPolicy; 34 | import java.io.Serializable; 35 | 36 | @SuppressWarnings({ "unchecked" }) 37 | public final class TestCollectionHolder implements Serializable { 38 | private ArrayList arrayList = new ArrayList(); 39 | private LinkedList linkedList = new LinkedList(); 40 | 41 | private HashSet hashSet = new HashSet(); 42 | private LinkedHashSet linkedHashSet = new LinkedHashSet(); 43 | private TreeSet treeSet = new TreeSet(); 44 | 45 | private HashMap hashMap = new HashMap(); 46 | private LinkedHashMap linkedHashMap = new LinkedHashMap(); 47 | private IdentityHashMap identityHashMap = new IdentityHashMap(); 48 | private Hashtable hashtable = new Hashtable(); 49 | private TreeMap treeMap = new TreeMap(); 50 | 51 | private EnumSet enumSet = EnumSet.noneOf(RetentionPolicy.class); 52 | private EnumMap enumMap = new EnumMap(RetentionPolicy.class); 53 | private static final long serialVersionUID = 7939173274625487478L; 54 | } 55 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/TestComplexObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.jboss.test.marshalling; 19 | 20 | import java.io.Serializable; 21 | import java.util.Set; 22 | 23 | 24 | @SuppressWarnings({ "NonFinalFieldReferencedInHashCode", "NonFinalFieldReferenceInEquals" }) 25 | public class TestComplexObject implements Serializable 26 | { 27 | /** The serialVersionUID */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | private boolean b; 31 | private byte b8; 32 | private char c; 33 | private short s; 34 | private int i; 35 | private long l; 36 | private float f; 37 | private double d; 38 | private String str; 39 | private Set set; 40 | 41 | public TestComplexObject(boolean b, byte b8, char c, short s, int i, long l, float f, double d, String str, Set set) { 42 | this.b = b; 43 | this.b8 = b8; 44 | this.c = c; 45 | this.s = s; 46 | this.i = i; 47 | this.l = l; 48 | this.f = f; 49 | this.d = d; 50 | this.str = str; 51 | this.set = set; 52 | } 53 | 54 | public TestComplexObject() {} 55 | 56 | public int hashCode() { 57 | return Double.toString((b ? 1 : 2) * b8 * c * s * i * l * f * d * str.hashCode() * ((set == null) ? 1 : set.hashCode())).hashCode(); 58 | } 59 | 60 | public boolean equals(Object o) { 61 | if (o == null || !(o instanceof TestComplexObject)) { 62 | return false; 63 | } 64 | TestComplexObject c = (TestComplexObject) o; 65 | return c.b == b && c.b8 == b8 && c.c == this.c && c.s == s && c.i == i && c.l == l 66 | && Float.compare(c.f, f) == 0 && Double.compare(c.d, d) == 0 && str.equals(c.str) 67 | && ((set == null) ? c.set == null : set.equals(c.set)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/TestMarshallerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import org.jboss.marshalling.Marshaller; 22 | import org.jboss.marshalling.MarshallingConfiguration; 23 | import org.jboss.marshalling.ByteOutput; 24 | import java.io.IOException; 25 | 26 | /** 27 | * 28 | */ 29 | public interface TestMarshallerProvider { 30 | Marshaller create(MarshallingConfiguration config, ByteOutput target) throws IOException; 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/test/java/org/jboss/test/marshalling/TestUnmarshallerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2014 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.jboss.test.marshalling; 20 | 21 | import org.jboss.marshalling.MarshallingConfiguration; 22 | import org.jboss.marshalling.Unmarshaller; 23 | import org.jboss.marshalling.ByteInput; 24 | import java.io.IOException; 25 | 26 | /** 27 | * 28 | */ 29 | public interface TestUnmarshallerProvider { 30 | Unmarshaller create(MarshallingConfiguration config, ByteInput source) throws IOException; 31 | } 32 | --------------------------------------------------------------------------------