aboutsummaryrefslogtreecommitdiff
path: root/java/com/xagasoft/gats/GatsOutputStream.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--java/com/xagasoft/gats/GatsOutputStream.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/java/com/xagasoft/gats/GatsOutputStream.java b/java/com/xagasoft/gats/GatsOutputStream.java
index a0f4503..c67d345 100644
--- a/java/com/xagasoft/gats/GatsOutputStream.java
+++ b/java/com/xagasoft/gats/GatsOutputStream.java
@@ -4,6 +4,34 @@ import java.io.OutputStream;
4import java.io.ByteArrayOutputStream; 4import java.io.ByteArrayOutputStream;
5import java.io.DataOutputStream; 5import java.io.DataOutputStream;
6 6
7/**
8 * Facilitates writing GatsObjects to an OutputStream. This doesn't really
9 * inherit from OutputStream, so maybe it would make more sense to call it
10 * something else, but this is how it is right now. Use the writeObject
11 * function to write any given GatsObject to the OutputStream.
12 * <p>
13 * Each time you write an object with this class it actually writes a Gats
14 * Packet data structure which consists of a 5 byte header followed by the
15 * encoded GatsObject data. In the packet header is information about which
16 * version of gats is in use, which options are enabled, etc. This ensures
17 * that Gats is backward compatible.
18 * <p>
19 * According to the GATS standard only fully formed gats packets may be written
20 * to files or sockets to ensure integrity and context. Since each packet can
21 * only contain one GatsObject that means that each writeObject call should
22 * write one fully formed message or data structure to ensure maximum
23 * efficiency.
24 * <p>
25 * The OutputStream is written to frequently, and often in small increments, so
26 * it is highly advisable to pass in a BufferedOutputStream or similar structure
27 * to ensure maximum performance.
28 * <p>
29 * The gats format stipulates that all zero bytes found in between packets are
30 * simply ignored, which allows you to pad streams of sequential gats objects
31 * if necesarry. This can be handy in some encoding/compression/encryption
32 * schemes.
33 *@see com.xagasoft.gats.GatsInputStream
34 */
7public class GatsOutputStream 35public class GatsOutputStream
8{ 36{
9 private OutputStream os; 37 private OutputStream os;
@@ -13,6 +41,10 @@ public class GatsOutputStream
13 this.os = os; 41 this.os = os;
14 } 42 }
15 43
44 /**
45 * Write an object to the provided output stream.
46 *@return The total number of bytes written.
47 */
16 public int writeObject( GatsObject obj ) throws java.io.IOException 48 public int writeObject( GatsObject obj ) throws java.io.IOException
17 { 49 {
18 ByteArrayOutputStream bos1 = new ByteArrayOutputStream(); 50 ByteArrayOutputStream bos1 = new ByteArrayOutputStream();