Added helper methods to SerializationUtils.
Also exporting sources and Javadoc on build.
This commit is contained in:
parent
26d90ccc09
commit
4a739f91d1
@ -24,10 +24,5 @@
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</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"/>
|
||||
</classpath>
|
||||
|
@ -1,6 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
@ -1,15 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-module deploy-name="envoy-common">
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
|
||||
|
||||
</project-modules>
|
||||
|
31
pom.xml
31
pom.xml
@ -18,5 +18,36 @@
|
||||
|
||||
<build>
|
||||
<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>
|
||||
</project>
|
@ -1,16 +1,6 @@
|
||||
package envoy.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
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;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
@ -24,7 +14,27 @@ public class 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.
|
||||
@ -46,7 +56,7 @@ public class SerializationUtils {
|
||||
|
||||
/**
|
||||
* Deserializes an arbitrary {@link Serializable} object from a byte array.
|
||||
*
|
||||
*
|
||||
* @param <T> the type of the serialized object
|
||||
* @param bytes the array in which the serialized object is stored
|
||||
* @param serializedClass the class of the serialized object
|
||||
@ -63,7 +73,7 @@ public class SerializationUtils {
|
||||
|
||||
/**
|
||||
* Deserializes an arbitrary {@link Serializable} object from a stream.
|
||||
*
|
||||
*
|
||||
* @param <T> the type of the serialized object
|
||||
* @param in the {@link InputStream} of a serialized Object
|
||||
* @param serializedClass the object type to convert the deserialized object
|
||||
@ -103,7 +113,7 @@ public class SerializationUtils {
|
||||
|
||||
/**
|
||||
* Serializes an arbitrary object to a byte array.
|
||||
*
|
||||
*
|
||||
* @param obj the object to serialize
|
||||
* @return a byte array containing the serialized object
|
||||
* @throws IOException if the serialization failed
|
||||
|
Reference in New Issue
Block a user