Added helper methods to SerializationUtils.

Also exporting sources and Javadoc on build.
This commit is contained in:
Kai S. K. Engelbart 2020-01-06 17:41:23 +01:00
parent 867f989802
commit 407a5bdbd8
5 changed files with 64 additions and 27 deletions

View File

@ -24,10 +24,5 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -1,6 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8 encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8 encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

View File

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="envoy-common"> <wb-module deploy-name="envoy-common">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

31
pom.xml
View File

@ -18,5 +18,36 @@
<build> <build>
<finalName>envoy-common</finalName> <finalName>envoy-common</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<doclint>none</doclint>
</configuration>
</plugin>
</plugins>
</build> </build>
</project> </project>

View File

@ -1,16 +1,6 @@
package envoy.util; package envoy.util;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -24,7 +14,27 @@ public class SerializationUtils {
private SerializationUtils() {} private SerializationUtils() {}
private static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } /**
* Converts an integer into a byte array.
*
* @param n the integer to convert
* @return a byte array of length 4
* @since Envoy Common v0.2-alpha
*/
public static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; }
/**
* Converts four bytes in byte array to an integer
*
* @param bytes the bytes to convert from
* @param offset the offset at which four bytes are read
* @return the converted integer
* @since Envoy Common v0.2-alpha
*/
public static int bytesToInt(byte[] bytes, int offset) {
return ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8)
| ((bytes[offset + 3] & 0xFF) << 0);
}
/** /**
* Deserializes an arbitrary {@link Serializable} object from a file. * Deserializes an arbitrary {@link Serializable} object from a file.