📄 remoteindyclient.java~1~
字号:
/*
* @(#)RemoteIndyClient
*
* Copyright (c) 1998 Karl Moss. All Rights Reserved.
*
* You may study, use, modify, and distribute this software for any
* purpose provided that this copyright notice appears in all copies.
*
* This software is provided WITHOUT WARRANTY either expressed or
* implied.
*
* @author Karl Moss
* @version 1.0
* @date 17Apr98
*
*/
package javaservlets.tunnel;
import java.io.*;
import javaservlets.tunnel.client.*;
/**
* <p>This class implements the client for tunneling
* calls to the Indy object.
*/
public class RemoteIndyClient
extends TunnelClient
implements IndyInterface
{
/**
* <p>Constructs a new RemoteMathLiteClient for the
* given URL. The URL should contain the location of
* servlet scripts (i.e. http://larryboy/servlet/).
*/
public RemoteIndyClient(String url)
throws TunnelException, IOException
{
// Append the remote server name
url += "RemoteIndyServer";
// Set the URL
_setURL(new java.net.URL(url));
// Initialize the client and server
_initialize();
}
/**
* <p>Connects to the database.
*
* @return True if the database connection was established
*/
public boolean connect()
{
boolean rc = false;
try {
// Create an internal buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create an object stream to write the request
ObjectOutputStream out =
(ObjectOutputStream) _createHeader(baos, 0);
// Invoke the method and read the response
ObjectInputStream in =
(ObjectInputStream) _invokeMethod(baos.toByteArray());
// Read the return value
Boolean b = (Boolean) in.readObject();
rc = b.booleanValue();
// Wrap up
out.close();
in.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
return rc;
}
/**
* <p>Closes the database connection
*/
public void close()
{
try {
// Create an internal buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create an object stream to write the request
ObjectOutputStream out =
(ObjectOutputStream) _createHeader(baos, 1);
// Invoke the method
_invokeMethod(baos.toByteArray());
// Wrap up
out.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* <p>Given the year return the corresponding Indianapolis
* 500 record
*
* @param year Year of the race
* @return Indy 500 record or null if not found
*/
public IndyRecord[] query()
{
IndyRecord[] record=new IndyRecord[100];
try {
// Create an internal buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create an object stream to write the request
ObjectOutputStream out =
(ObjectOutputStream) _createHeader(baos, 2);
// Write the parameters
// out.writeObject(new Integer(year));
// Invoke the method and read the response
ObjectInputStream in =
(ObjectInputStream) _invokeMethod(baos.toByteArray());
// Read the return value
//There are maybe problems,cant get array data
////////////////////////////////////////////////////////////
record = (IndyRecord[]) in.readObject();
// Wrap up
out.close();
in.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
return record;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -