-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTestUtils.java
More file actions
47 lines (38 loc) · 1.47 KB
/
TestUtils.java
File metadata and controls
47 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package net.sharksystem.asap.mockAndTemplates;
import java.io.*;
public class TestUtils {
static final CharSequence ALICE = "Alice";
static final CharSequence BOB = "Bob";
static final CharSequence YOUR_APP_NAME = "yourAppName";
static final CharSequence YOUR_URI = "yourSchema://example";
/**
* a serialization example
* @param exampleLong
* @param exampleString
* @param exampleBoolean
* @return
*/
public static byte[] serializeExample(long exampleLong, String exampleString, boolean exampleBoolean) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream daos = new DataOutputStream(baos);
// serialize
daos.writeLong(exampleLong);
daos.writeUTF(exampleString);
daos.writeBoolean(exampleBoolean);
return baos.toByteArray();
}
/**
* a deserialization example
*/
public static void deserializeExample(byte[] serializedData) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(serializedData);
DataInputStream dais = new DataInputStream(bais);
// deserialize
long exampleLong = dais.readLong();
String exampleString = dais.readUTF();
boolean exampleBoolean = dais.readBoolean();
// call a methode in your app
// here: just print
System.out.println("received: " + exampleLong + " | " + exampleString + " | " + exampleBoolean);
}
}