aboutsummaryrefslogtreecommitdiff
path: root/java/com/xagasoft/gats/GatsOutputStream.java
blob: a0f450321117f06298977664dc0276e8709cb39b (plain)
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
package com.xagasoft.gats;

import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

public class GatsOutputStream
{
	private OutputStream os;

	public GatsOutputStream( OutputStream os )
	{
		this.os = os;
	}

	public int writeObject( GatsObject obj ) throws java.io.IOException
	{
		ByteArrayOutputStream bos1 = new ByteArrayOutputStream();

		obj.write( bos1 );

		ByteArrayOutputStream bos2 = new ByteArrayOutputStream(
			5 + bos1.size()
			);

		DataOutputStream dos = new DataOutputStream( bos2 );
		dos.writeByte( 1 );
		dos.writeInt( bos1.size()+5 );
		bos2.write( bos1.toByteArray() );

		os.write( bos2.toByteArray() );
		return bos1.size()+5;
	}
};