org.hebe.mps
Class OutputStream

java.lang.Object
  |
  +--org.hebe.mps.OutputStream

public class OutputStream
extends java.lang.Object

Flattens the bitstream going to an MPS server from MPS primitive types. Uses a Connection object to talk to the other end.

Author:
Tony Garnock-Jones
See Also:
Connection, InputStream

Field Summary
private  java.lang.StringBuffer buffer
           
private  Connection connection
           
private  java.io.OutputStream output
           
 
Constructor Summary
OutputStream(Connection c)
          Construct an OutputStream which encodes the bits going to a Connection object.
OutputStream(java.io.OutputStream o)
          Construct an OutputStream which sends bits to an arbitrary inputstream.
 
Method Summary
 void flush()
          Sends the total accumulated buffer of bytes over the connection.
private  void open()
          Causes the connection to the server to open, if it isn't already open.
 void resetBuffer()
          Resets our internal buffer to empty.
private  void setupBuffer()
          Creates and initialises a fresh StringBuffer in member variable buffer.
private  void write(int ch)
          Buffer up a single byte to send.
 void writebool(boolean b)
          Writes a single boolean to the server.
 void writechar(char ch)
          Writes a single char to the server.
 void writefloat(float f)
          Writes a single float to the server.
 void writeint(int i)
          Writes a single int to the server.
 void writelong(long i)
          Writes a single long to the server.
 void writeReference(java.lang.Object o)
          Writes a reference to an MPS object to the remote end.
 void writestring(java.lang.String s)
          Writes a single java.lang.String to the server.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

connection

private Connection connection

output

private java.io.OutputStream output

buffer

private java.lang.StringBuffer buffer
Constructor Detail

OutputStream

public OutputStream(Connection c)
Construct an OutputStream which encodes the bits going to a Connection object.
Parameters:
c - the raw connection to use

OutputStream

public OutputStream(java.io.OutputStream o)
Construct an OutputStream which sends bits to an arbitrary inputstream.
Parameters:
o - the raw outputstream to use
Method Detail

setupBuffer

private void setupBuffer()
Creates and initialises a fresh StringBuffer in member variable buffer.

resetBuffer

public void resetBuffer()
Resets our internal buffer to empty.

write

private void write(int ch)
Buffer up a single byte to send. The buffer is not flushed to the server until the flush() method is called.
Parameters:
ch - the byte to buffer up
See Also:
flush()

open

private void open()
           throws MPSException
Causes the connection to the server to open, if it isn't already open.
Throws:
MPSException - from connection.getOutputStream() if there's a problem
See Also:
Connection.getOutputStream()

writeint

public void writeint(int i)
Writes a single int to the server.
Parameters:
i - the 32-bit signed value to write

writestring

public void writestring(java.lang.String s)
Writes a single java.lang.String to the server.
Parameters:
s - the string to write

writebool

public void writebool(boolean b)
Writes a single boolean to the server.
Parameters:
b - the boolean to write

writelong

public void writelong(long i)
Writes a single long to the server.
Parameters:
i - the long to write

writechar

public void writechar(char ch)
Writes a single char to the server.
Parameters:
ch - the char to write

writeReference

public void writeReference(java.lang.Object o)
                    throws MPSException
Writes a reference to an MPS object to the remote end. Sends a canonical name for the object as a string. The remote end will then construct a proxy on the other side of the connection to make use of the reference that has been sent to it.
Parameters:
o - the MPS Interface to write
Throws:
MPSException - if there's a problem writing
MPSException - if o is not being served by an instance of Server and o is not an instance of Proxy
See Also:
Proxy, InputStream.readReference()

writefloat

public void writefloat(float f)
                throws MPSException
Writes a single float to the server.
Parameters:
f - the float to write
Throws:
MPSException - if there's a problem writing

flush

public void flush()
           throws MPSException
Sends the total accumulated buffer of bytes over the connection. Empties the buffer ready for the next batch of bytes.
Throws:
MPSException - if there's a problem writing.