HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Jini Surrogate as a Platform for J2ME Games"
Vol. 7, Issue 5, p. 72

	


Listing 1

/**
 * An encapsulation of an http connector registration protocol. 
 *
 * @author  William Swaney
 * @version 1.0
 */
import java.io.*;

public class HttpInterconnectRegistration implements InterconnectProtocol
{
    public static final int VERSION_NUMBER = 1;

    private short surrogateUrlLength=0;
    private byte[] surrogateUrl;
    
    private int initializationDataLength=0;
    private byte[] initializationData;
    
    private int lengthOfSurrogate=0;
    private byte[] surrogate;
    
    private java.io.DataInputStream din;
    
    public HttpInterconnectRegistration()
    {
    }
    
    public void read(InputStream in) throws IOException
    {
        throw new IOException(); 
		//We should create our own exception here
    }

    public void write(OutputStream out) throws IOException
    {
        if (out == null) throw new IOException();
        
        if ((surrogate == null && surrogateUrl == null) || (surrogateUrlLength == 0 && lengthOfSurrogate == 0))
            throw new IOException();
       
        
        DataOutputStream dataOut = new DataOutputStream(out);

        dataOut.writeInt(VERSION_NUMBER);
            
        dataOut.writeShort(surrogateUrlLength);
        if (surrogateUrlLength > 0) dataOut.write(surrogateUrl);

        dataOut.writeInt(initializationDataLength);
        if (initializationDataLength > 0) 										dataOut.write(initializationData);

        dataOut.writeInt(lengthOfSurrogate);
        if (lengthOfSurrogate > 0) dataOut.write(surrogate);

        dataOut.flush();
    }
    
    public void setSurrogateUrl(byte[] surrogateUrl)
    {
        this.surrogateUrl = surrogateUrl;
        surrogateUrlLength = (short)this.surrogateUrl.length;
    }
    
    public void setSurrogateUrl(String surrogateUrl)
    {
        setSurrogateUrl(surrogateUrl.getBytes());
    }

    public void setInitializationData(byte[] initializationData)
    {
        this.initializationData = initializationData;
        initializationDataLength = this.initializationData.length;
    }
    
    public void setSurrogate(byte[] surrogate)
    {
        this.surrogate = surrogate;
        lengthOfSurrogate = this.surrogate.length;
    }
}




Listing 2

 /**
 * An encapsulation of the response message sent from the http 						connector to the device.
 *
 * @author  William Swaney
 * @version 1.0
 */
import java.io.*;

public class HttpInterconnectResponse implements InterconnectProtocol
{
    
    private int protocolVersion;
    private short surrogateConnectUrlLength=0;
    private byte[] surrogateConnectUrl;
  
    private java.io.DataInputStream din;
    
    public HttpInterconnectResponse()
    {
    }

    public void read(InputStream in) throws IOException
    {
        din = new DataInputStream(in);

        protocolVersion = din.readInt();

        surrogateConnectUrlLength = din.readShort();
        surrogateConnectUrl = new byte[surrogateConnectUrlLength];
        din.readFully(surrogateConnectUrl);
    }

    public void write(OutputStream out) throws IOException
    {
        throw new java.io.IOException(); //We should create our 								own exception here
    }
    
    public int getProtocolVersion()
    {
        return protocolVersion;
    }

    public short getSurrogateConnectUrlLength()
    {
        return surrogateConnectUrlLength;
    }

    public byte[] getSurrogateConnectUrl()
    {
        return surrogateConnectUrl;
    }
}

 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.