This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
import java.net.*;
import java.io.*;
import java.awt.*;
class AdviseThread extends Thread
{
SocketControl mSocketControl=null;
List mList;
public final int AdvisePort=200;
private boolean mIsCancelled=false;
private final String mUserTalkDirective=new String("USERTALK(");
private final String mUserEnterDirective=new String("USERENTER(");
private final String mUserLeaveDirective=new String("USERLEAVE(");
private final String mQuitDirective=new String("QUIT");
public AdviseThread(List list)
{
mList=list;
isCancelled(false);
mSocketControl=new SocketControl();
}
public void run()
{
String strLine=null;
String strAdvise=new String();
try{mSocketControl.accept(AdvisePort);}
catch(IOException exception){return;}
mSocketControl.writeLine("TESTCONNECT");
while(true)
{
strLine=new String();
strLine=mSocketControl.readLine();
if(isCancelled())break;
if(0==strLine.length())continue;
if(strLine.regionMatches(0,mUserTalkDirective,0,mUserTalkDirective.length()))strLine=parseTalk(strLine);
else if(strLine.regionMatches(0,mUserEnterDirective,0,mUserEnterDirective.length()))strLine=parseEnter(strLine);
else if(strLine.regionMatches(0,mUserLeaveDirective,0,mUserLeaveDirective.length()))strLine=parseLeave(strLine);
else if(strLine.regionMatches(0,mQuitDirective,0,mQuitDirective.length()))break;
mList.addItem(strLine);
mList.select(mList.getItemCount()-1);
}
stop();
}
public void isCancelled(boolean isCancelled)
{
mIsCancelled=isCancelled;
if(mIsCancelled)
{
try{mSocketControl.closeSocket();}
catch(IOException exception){return;}
}
}
public boolean isCancelled()
{
return mIsCancelled;
}
private String parseTalk(String strLine)
{
int strLength=strLine.length();
String strUser=new String();
String strString=new String();
String strReturn=new String();
int index=0;
while(index<strLength){if('('==strLine.charAt(index))break;index++;}
index++;
while(index<strLength){if(','==strLine.charAt(index))break;strUser+=strLine.charAt(index);index++;}
index++;
while(index<strLength){if(')'==strLine.charAt(index))break;strString+=strLine.charAt(index);index++;}
strReturn+=new String("'")+strUser+new String("' said \"")+strString+new String("\".");
return strReturn;
}
private String parseEnter(String strLine)
{
String strUser=new String();
String strReturn=new String();
int strLength=strLine.length();
int index=0;
while(index<strLength){if('('==strLine.charAt(index))break;index++;}
index++;
while(index<strLength){if(')'==strLine.charAt(index))break;strUser+=strLine.charAt(index);index++;}
strReturn+=new String("'")+strUser+new String("' just entered.");
return strReturn;
}
private String parseLeave(String strLine)
{
String strUser=new String();
String strReturn=new String();
int strLength=strLine.length();
int index=0;
while(index<strLength){if('('==strLine.charAt(index))break;index++;}
index++;
while(index<strLength){if(')'==strLine.charAt(index))break;strUser+=strLine.charAt(index);index++;}
strReturn+=new String("'")+strUser+new String("' just left.");
return strReturn;
}
public static String getAdviseAddress()
{
String strReturn=new String();
InetAddress inetAddress=null;
try{inetAddress=InetAddress.getLocalHost();}
catch(UnknownHostException exception){return strReturn;}
strReturn=new String(inetAddress.getHostAddress());
return strReturn;
}
}

1
java/JCHAT/CODEBASE.DAT Normal file
View File

@@ -0,0 +1 @@
file:/C:\WORK\java\jchat

108
java/JCHAT/ChatAdapter.java Normal file
View File

@@ -0,0 +1,108 @@
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import java.lang.reflect.*;
import com.ms.security.*;
public class ChatAdapter extends Applet
{
String mStrLabel=new String();
IOManager mIOManager=new IOManager();
AdviseThread mAdviseThread=null;
GUIControls mGUIControls=null;
public void init()
{
setFont(new Font("Courier New",Font.BOLD,12));
setBackground(Color.lightGray);
mGUIControls=new GUIControls(this);
try{if(Class.forName("com.ms.security.PolicyEngine") != null)PolicyEngine.assertPermission(PermissionID.NETIO);}
catch(Throwable cnfe){;}
mGUIControls.status().setText("Not connected.");
}
public void stop()
{
mAdviseThread.isCancelled(true);
mIOManager.shutdown();
}
public void destroy()
{
}
public void paint(Graphics graphics)
{
}
public void showUsers()
{
StringArray userList=new StringArray();
mIOManager.who(userList);
if(0==userList.size())mGUIControls.list().addItem(new String("There are no users logged in at this time."));
for(int index=0;index<userList.size();index++)
{
mGUIControls.list().addItem(new String("User;'")+ userList.getAt(index)+new String("' is here."));
}
}
public boolean action(Event event,Object object)
{
if(mGUIControls.connect()==event.target)
{
StringArray receiveStrings=new StringArray();
String strResponse=new String();
String strIPAddress=null;
String strAdviseAddress=null;
String strPort=null;
strAdviseAddress=new String(getParameter("advise"));
if(null==strAdviseAddress||0==strAdviseAddress.length())strAdviseAddress=new String(AdviseThread.getAdviseAddress());
strIPAddress=new String(getParameter("ip"));
if(null==strIPAddress||0==strIPAddress.length())strIPAddress=new String("");
strPort=new String(getParameter("port"));
if(null==strPort||0==strPort.length())strPort=new String("");
if(0==mGUIControls.userName().getText().length()){mGUIControls.status().setText("'User Name' cannot be empty.");return false;}
if(0!=strIPAddress.length())mGUIControls.status().setText(new String("trying '")+strIPAddress+new String("'"));
else mGUIControls.status().setText(new String("trying 'localhost'"));
if(0==strPort.length())strPort="100";
mIOManager.connect(strIPAddress,Integer.parseInt(strPort));
if(!mIOManager.isConnected()){mGUIControls.status().setText("Failed to connect to host.");return true;}
else mGUIControls.status().setText("Connection established.");
mAdviseThread=new AdviseThread(mGUIControls.list());
mAdviseThread.start();
mGUIControls.status().setText(new String("Advising server of talkback '")+strAdviseAddress+new String("'"));
mIOManager.advise(strAdviseAddress,mAdviseThread.AdvisePort);
mGUIControls.status().setText("Logging into server...");
if(!mIOManager.user(mGUIControls.userName().getText(),receiveStrings))
{
mGUIControls.status().setText("Login failed");
for(int index=0;index<receiveStrings.size();index++)mGUIControls.list().addItem(receiveStrings.getAt(index));
mAdviseThread.isCancelled(true);
mIOManager.shutdown();
return true;
}
mStrLabel=mIOManager.version();
mGUIControls.connect().setEnabled(false);
mGUIControls.disconnect().setEnabled(true);
mGUIControls.send().setEnabled(true);
mGUIControls.status().setText("Connected.");
mGUIControls.list().removeAll();
showUsers();
}
else if(mGUIControls.disconnect()==event.target)
{
mAdviseThread.isCancelled(true);
mIOManager.shutdown();
mGUIControls.connect().setEnabled(true);
mGUIControls.disconnect().setEnabled(false);
mGUIControls.send().setEnabled(false);
mGUIControls.status().setText("Not connected.");
}
else if(mGUIControls.send()==event.target&&mIOManager.isConnected())
{
mIOManager.talk(mGUIControls.text().getText());
mGUIControls.status().setText("Message sent.");
mGUIControls.text().setText("");
}
return true;
}
}

120
java/JCHAT/GUIControls.java Normal file
View File

@@ -0,0 +1,120 @@
import java.awt.*;
import java.applet.*;
class GUIControls
{
private TextField mUserName=null;
private TextField mPort=null;
private TextField mText=null;
private List mList=null;
private Button mCtlConnectButton=null;
private Button mCtlDisconnectButton=null;
private Button mCtlSendButton=null;
private Label mStatus=null;
GUIControls(Applet applet)
{
createControls(applet);
disconnect().setEnabled(false);
send().setEnabled(false);
}
public TextField text()
{
return mText;
}
public Button send()
{
return mCtlSendButton;
}
public TextField userName()
{
return mUserName;
}
public TextField port()
{
return mPort;
}
public List list()
{
return mList;
}
public Button disconnect()
{
return mCtlDisconnectButton;
}
public Button connect()
{
return mCtlConnectButton;
}
public Label status()
{
return mStatus;
}
private void createControls(Applet applet)
{
GridBagLayout layout=new GridBagLayout();
GridBagConstraints constraints=new GridBagConstraints();
applet.setLayout(layout);
constraints.fill=GridBagConstraints.RELATIVE;
constraints.anchor=GridBagConstraints.WEST;
constraints.weightx=1.00;
Label nameLabel=new Label("User",Label.LEFT);
layout.setConstraints(nameLabel,constraints);
applet.add(nameLabel);
constraints.fill=GridBagConstraints.BOTH;
constraints.gridwidth=GridBagConstraints.REMAINDER;
mUserName=new TextField("");
layout.setConstraints(mUserName,constraints);
applet.add(mUserName);
constraints.gridwidth=GridBagConstraints.RELATIVE;
constraints.anchor=GridBagConstraints.WEST;
Label portLabel=new Label("Port",Label.LEFT);
layout.setConstraints(portLabel,constraints);
applet.add(portLabel);
constraints.fill=GridBagConstraints.BOTH;
constraints.gridwidth=GridBagConstraints.REMAINDER;
mPort=new TextField("100");
layout.setConstraints(mPort,constraints);
applet.add(mPort);
constraints.gridwidth=GridBagConstraints.REMAINDER;
constraints.anchor=GridBagConstraints.WEST;
mCtlConnectButton=new Button("Connect");
layout.setConstraints(mCtlConnectButton,constraints);
applet.add(mCtlConnectButton);
constraints.gridwidth=GridBagConstraints.REMAINDER;
constraints.anchor=GridBagConstraints.WEST;
mCtlDisconnectButton=new Button("Disconnect");
layout.setConstraints(mCtlDisconnectButton,constraints);
applet.add(mCtlDisconnectButton);
constraints.gridwidth=GridBagConstraints.REMAINDER;
constraints.anchor=GridBagConstraints.WEST;
mList=new List(10);
layout.setConstraints(mList,constraints);
applet.add(mList);
constraints.fill=GridBagConstraints.BOTH;
constraints.gridwidth=GridBagConstraints.REMAINDER;
mText=new TextField("");
layout.setConstraints(mText,constraints);
applet.add(mText);
constraints.gridwidth=GridBagConstraints.REMAINDER;
constraints.anchor=GridBagConstraints.WEST;
mCtlSendButton=new Button("Send");
layout.setConstraints(mCtlSendButton,constraints);
applet.add(mCtlSendButton);
constraints.fill=GridBagConstraints.BOTH;
constraints.gridwidth=GridBagConstraints.REMAINDER;
mStatus=new Label("");
layout.setConstraints(mStatus,constraints);
applet.add(mStatus);
}
}

19
java/JCHAT/INDEX~1.HTM Normal file
View File

@@ -0,0 +1,19 @@
<HTML>
<HEAD>
<TITLE>Chat Control Panel</TITLE>
</HEAD>
<BODY BGCOLOR="#C0C0C0">
<P ALIGN="center"><B><I><FONT FACE="Times New Roman" SIZE="+3">Chat Control Panel</FONT><FONT FACE="Courier New" SIZE="+1"></FONT></I></B></P>
<HR>
<P><APPLET CODE="ChatAdapter.class" ip="" port="100" WIDTH="640" HEIGHT="320"></APPLET>
<pr>
<HR>
</P>
</BODY>
</HTML>

203
java/JCHAT/IOManager.java Normal file
View File

@@ -0,0 +1,203 @@
import java.net.*;
import java.io.*;
public class IOManager
{
public static final int OkResult=220;
public static final int ErrorResult=500;
private final int MaxNetworkPacket=1024;
private final int InvalidPort=-1;
private SocketControl mTCPSocket=null;
private boolean mIsLoggedIn=false;
private StringArray mAckResponseStrings;
public IOManager()
{
mAckResponseStrings=new StringArray();
mAckResponseStrings.insert("220");
}
public void shutdown()
{
if(!mTCPSocket.isConnected())return;
if(isLoggedIn())quit();
try{mTCPSocket.closeSocket();}
catch(IOException exception){return;}
}
public boolean isConnected()
{
if(mTCPSocket==null||!mTCPSocket.isConnected())return false;
return true;
}
private void isLoggedIn(boolean isLoggedIn)
{
mIsLoggedIn=isLoggedIn;
}
public boolean isLoggedIn()
{
return mIsLoggedIn;
}
public boolean connect(String strHost,int port)
{
int bytesRead;
byte streamBytes[];
int clientPort;
String strLine=new String();
if(isConnected())return false;
streamBytes=new byte[MaxNetworkPacket];
InetAddress inetAddress=null;
SocketControl socket=null;
if(0!=strHost.length())
{
try{inetAddress=InetAddress.getByName(strHost);}
catch(UnknownHostException exception){return false;}
try{socket=new SocketControl(inetAddress,port);}
catch(IOException exception){return false;}
catch(SecurityException exception){return false;}
}
else
{
try{socket=new SocketControl("",port);}
catch(IOException exception){return false;}
catch(SecurityException exception){return false;}
}
if(!socket.isConnected())return false;
strLine=socket.readLine();
if(0==strLine.length())return false;
clientPort=getPort(strLine);
if(InvalidPort==clientPort)return false;
socket.writeLine("OK");
try{socket.closeSocket();}
catch(IOException exception){return false;}
if(0!=strHost.length())
{
try{inetAddress=InetAddress.getByName(strHost);}
catch(UnknownHostException exception){return false;}
try{mTCPSocket=new SocketControl(inetAddress,clientPort);}
catch(IOException exception){return false;}
}
else
{
try{mTCPSocket=new SocketControl("",clientPort);}
catch(IOException exception){return false;}
}
strLine=mTCPSocket.readLine();
return isConnected();
}
public boolean advise(String strAddress,int port)
{
String strRequest=null;
if(!isConnected())return false;
strRequest=new String("ADVISE(")+new String(strAddress)+new String(",")+String.valueOf(port)+new String(")");
mTCPSocket.writeLine(strRequest);
strRequest=mTCPSocket.readLine();
return true;
}
private String readLine(InputStream inputStream)
{
byte streamByte[];
String strLine=new String();
strLine=new String();
while(true)
{
streamByte=new byte[1];
try{inputStream.read(streamByte);}
catch(IOException exception){break;}
if(13==streamByte[0])continue;
else if(10==streamByte[0])break;
strLine+=new String(streamByte);
}
return strLine;
}
private boolean writeLine(String strLine,OutputStream outputStream)
{
if(0==strLine.length())return false;
strLine+=new String("\r\n");
byte streamData[]=strLine.getBytes();
try{outputStream.write(streamData);}
catch(IOException exception){return false;}
return true;
}
private int getPort(String strLine)
{
String strPort;
int strIndex;
int port;
strIndex=strLine.length()-1;
port=InvalidPort;
strPort=new String();
if(strIndex<0)return -1;
while(true)
{
if(strIndex<0)break;
if(' '==strLine.charAt(strIndex))break;
strIndex--;
}
strIndex++;
if(strIndex<0)return port;
strPort=strLine.substring(strIndex);
return Integer.parseInt(strPort);
}
private boolean isInResponse(String responseString,StringArray responseStrings)
{
if(0==responseString.length())return false;
for(int index=0;index<responseStrings.size();index++)
{
if(responseString.equals(responseStrings.getAt(index)))return true;
}
return false;
}
public boolean user(String strUserName,StringArray receiveStrings)
{
receiveStrings.clear();
if(!isConnected())return false;
String strLine=new String("USER(")+strUserName+new String(")");
mTCPSocket.writeLine(strLine);
if(!mTCPSocket.receive(receiveStrings,mAckResponseStrings))return false;
isLoggedIn(true);
return isLoggedIn();
}
public boolean who(StringArray userList)
{
StringArray responseLines=new StringArray();
userList.clear();
if(!isConnected())return false;
String strLine=new String("WHO");
mTCPSocket.writeLine(strLine);
if(!mTCPSocket.receive(responseLines,mAckResponseStrings))return false;
for(int index=1;index<responseLines.size()-1;index++)
userList.insert(responseLines.getAt(index).substring(4,responseLines.getAt(index).length()));
return true;
}
public boolean quit()
{
if(!isConnected()||!isLoggedIn())return false;
String strLine=new String("QUIT");
mTCPSocket.writeLine(strLine);
strLine=mTCPSocket.readLine();
return true;
}
public boolean talk(String strLine)
{
if(!isConnected()||0==strLine.length())return false;
String strString=new String("TALK(")+strLine+new String(")");
mTCPSocket.writeLine(strString);
strLine=mTCPSocket.readLine();
return true;
}
public String version()
{
String strVersion=new String();
String strLine=new String();
if(!isConnected())return strVersion;
mTCPSocket.writeLine("VERSION");
strLine=mTCPSocket.readLine();
if(mTCPSocket.OkResult!=mTCPSocket.getResultCode(strLine))return strVersion;
strVersion=mTCPSocket.getResult(strLine);
return strVersion;
}
};

BIN
java/JCHAT/JCHAT.CAB Normal file

Binary file not shown.

13
java/JCHAT/JCHAT.SLN Normal file
View File

@@ -0,0 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 1.00
Project("{66355F20-A65B-11D0-BFB5-00A0C91EBFA0}") = "jchat", "jchat.vjp", "{7E7E3541-3CF9-11D3-A128-A1AE86F20E65}"
EndProject
Global
GlobalSection(LocalDeployment) = postSolution
StartupProject = {7E7E3541-3CF9-11D3-A128-A1AE86F20E65}
EndGlobalSection
GlobalSection(BuildOrder) = postSolution
0 = {7E7E3541-3CF9-11D3-A128-A1AE86F20E65}
EndGlobalSection
GlobalSection(DeploymentRoot) = postSolution
EndGlobalSection
EndGlobal

BIN
java/JCHAT/JCHAT.SUO Normal file

Binary file not shown.

BIN
java/JCHAT/JCHAT.VJP Normal file

Binary file not shown.

26
java/JCHAT/JCHAT~1.HTM Normal file
View File

@@ -0,0 +1,26 @@
<HTML>
<HEAD>
<TITLE>Chat Control Panel</TITLE>
</HEAD>
<BODY BGCOLOR="#C0C0C0">
<P ALIGN="center"><B><I><FONT FACE="Times New Roman" SIZE="+3">Chat Control Panel</FONT><FONT FACE="Courier New" SIZE="+1"></FONT></I></B></P>
<P><I><FONT FACE="Courier New" SIZE="1" COLOR="Red">This applet may not work correctly if y</FONT><FONT FACE="Courier New" SIZE="1"></FONT><FONT FACE="Courier New" SIZE="1" COLOR="Red">our browser is configured through a proxy server.</FONT></I><FONT COLOR="Yellow">
<HR>
</FONT></P>
<P>
<APPLET CODEBASE="." ARCHIVE="jchat.zip" CODE="ChatAdapter.class" "ip="" port="100" WIDTH="640" HEIGHT="320">
<PARAM NAME=cabbase VALUE="jchat.cab">
<PARAM NAME="port" VALUE="100">
<PARAM NAME="ip" VALUE="diversified-software.com">
<PARAM NAME="advise" VALUE="">
</APPLET>
<pr>
<HR>
</P>
</BODY>
</HTML>

6
java/JCHAT/SCRAPS.TXT Normal file
View File

@@ -0,0 +1,6 @@
// if(null==getParameter("advise"))strAdviseAddress=new String(AdviseThread.getAdviseAddress());
// else strAdviseAddress=new String(getParameter("advise"));
// if(null==getParameter("ip"))strIPAddress=new String("");
// else strIPAddress=new String(getParameter("ip"));
// if(null==getParameter("port"))strPort=new String("100");
// else strPort=new String(getParameter("port"));

View File

@@ -0,0 +1,18 @@
import java.net.*;
import java.io.*;
public class ServerSocketControl extends ServerSocket
{
public ServerSocketControl(int port)throws IOException
{
super(port);
}
public void accept(SocketControl socketControl)throws IOException
{
implAccept(socketControl);
}
}

View File

@@ -0,0 +1,202 @@
import java.net.*;
import java.io.*;
public class SocketControl extends Socket
{
public final int OkResult=220;
public final int ErrorResult=500;
private InputStream mInputStream=null;
private OutputStream mOutputStream=null;
private boolean mIsConnected=false;
public SocketControl()
{
}
public SocketControl(String strHost,int port)throws IOException
{
super(strHost,port);
try{mInputStream=getInputStream();}
catch(IOException exception){close();return;}
try{mOutputStream=getOutputStream();}
catch(IOException exception){close();return;}
isConnected(true);
}
public SocketControl(InetAddress inetAddress,int port)throws IOException
{
super(inetAddress,port);
try{mInputStream=getInputStream();}
catch(IOException exception){close();return;}
try{mOutputStream=getOutputStream();}
catch(IOException exception){close();return;}
isConnected(true);
}
public void closeSocket()throws IOException
{
isConnected(false);
close();
}
public boolean isConnected()
{
return mIsConnected;
}
private void isConnected(boolean isConnected)
{
mIsConnected=isConnected;
}
public String readLine()
{
byte streamByte[];
String strLine=new String();
if(!isConnected())return strLine;
strLine=new String();
while(true)
{
streamByte=new byte[1];
try{mInputStream.read(streamByte);}
catch(IOException exception){break;}
if(13==streamByte[0])continue;
else if(10==streamByte[0])break;
strLine+=new String(streamByte);
}
return strLine;
}
public boolean writeLine(String strLine)
{
if(!isConnected()||0==strLine.length())return false;
strLine+=new String("\r\n");
byte streamData[]=strLine.getBytes();
try{mOutputStream.write(streamData);}
catch(IOException exception){return false;}
return true;
}
public int getResultCode(String strLine)
{
if(0==strLine.length())return 0;
String strResult=new String();
int strIndex=0;
while(true)
{
if(strIndex>=3)break;
if(' '==strLine.charAt(strIndex))break;
strResult+=strLine.charAt(strIndex);
strIndex++;
}
if(0==strResult.length())return 0;
return Integer.parseInt(strResult);
}
public String getResult(String strLine)
{
String strResult=new String();
int strIndex=0;
int strLength=strLine.length();
if(0==strLength)return strResult;
while(' '!=strLine.charAt(strIndex)&&strIndex<strLength)strIndex++;
strIndex++;
if(strIndex>=strLength)return strResult;
while(strIndex<strLength)
{
strResult+=strLine.charAt(strIndex);
strIndex++;
}
return strResult;
}
public boolean receive(StringArray receiveStrings,StringArray responseStrings)
{
boolean isInMultiLine=false;
boolean returnCode=true;
String seriesItem=new String();
String stringData=new String();
receiveStrings.clear();
if(!isConnected())return false;
while(true)
{
stringData=readLine();
if(0==stringData.length())break;
if(0==receiveStrings.size())
{
seriesItem=stringData.substring(0,3);
if(!isInResponse(seriesItem,responseStrings))
{
returnCode=false;
receiveStrings.insert(stringData);
break;
}
if('-'==stringData.charAt(3))isInMultiLine=true;
}
if(0!=receiveStrings.size()&&isInMultiLine&&'-'!=stringData.charAt(3)&&stringData.substring(0,3)==seriesItem)
{
receiveStrings.insert(stringData);
break;
}
receiveStrings.insert(stringData);
if(!isInMultiLine)break;
}
return returnCode;
}
public boolean receive(StringArray receiveStrings)
{
boolean isInMultiLine=false;
boolean returnCode=false;
String seriesItem=new String();
String stringData=new String();
receiveStrings.clear();
if(!isConnected())return false;
while(true)
{
stringData=readLine();
if(0==stringData.length())break;
if(0==receiveStrings.size())
{
seriesItem=stringData.substring(0,3);
if('-'==stringData.charAt(3))isInMultiLine=true;
}
if(0!=receiveStrings.size()&&isInMultiLine&&'-'!=stringData.charAt(3)&&stringData.substring(0,3)==seriesItem)
{
receiveStrings.insert(stringData);
break;
}
receiveStrings.insert(stringData);
if(!isInMultiLine)break;
}
if(0!=receiveStrings.size())return true;
return false;
}
public boolean isInResponse(String responseString,StringArray responseStrings)
{
if(0==responseString.length())return false;
for(int index=0;index<responseStrings.size();index++)
{
if(responseString.equals(responseStrings.getAt(index)))return true;
}
return false;
}
public boolean accept(int port)throws IOException
{
ServerSocketControl serverSocketControl=null;
try{serverSocketControl=new ServerSocketControl(port);}
catch(IOException exception){return false;}
try{serverSocketControl.accept(this);}
catch(IOException exception){return false;}
try{mInputStream=getInputStream();}
catch(IOException exception)
{
try{closeSocket();}
finally{return false;}
}
try{mOutputStream=getOutputStream();}
catch(IOException exception)
{
try{closeSocket();}
finally{return false;}
}
isConnected(true);
return isConnected();
}
}

View File

@@ -0,0 +1,67 @@
import java.lang.ArrayIndexOutOfBoundsException;
class StringArray
{
private final int BlockSize=16;
private int mGrowBy=BlockSize;
private int mActualItemCount=0;
private int mVirtualItemCount=mGrowBy;
private String mStringArray[]=new String[mGrowBy];
public String getAt(int arrayIndex)throws ArrayIndexOutOfBoundsException
{
if(arrayIndex>=size())throw new ArrayIndexOutOfBoundsException();
return mStringArray[arrayIndex];
}
public void setAt(String strItem,int arrayIndex)throws ArrayIndexOutOfBoundsException
{
if(arrayIndex>=size())throw new ArrayIndexOutOfBoundsException();
mStringArray[arrayIndex]=strItem;
}
public boolean insert(String strItem)
{
guarantee(size()+1);
mStringArray[size()]=strItem;
size(size()+1);
return true;
}
public void guarantee(int requiredSize)
{
if(virtualSize()>=requiredSize)return;
String tmpArray[]=new String[virtualSize()+growBy()];
for(int index=0;index<virtualSize();index++)tmpArray[index]=mStringArray[index];
mStringArray=new String[virtualSize()+growBy()];
virtualSize(virtualSize()+growBy());
for(int index=0;index<virtualSize();index++)mStringArray[index]=tmpArray[index];
}
public int size()
{
return mActualItemCount;
}
private void size(int actualItemCount)
{
mActualItemCount=actualItemCount;
}
private int virtualSize()
{
return mVirtualItemCount;
}
private void virtualSize(int virtualSize)
{
mVirtualItemCount=virtualSize;
}
public int growBy()
{
return mGrowBy;
}
public void growBy(int growBy)
{
mGrowBy=growBy;
}
public void clear()
{
mStringArray=new String[growBy()];
size(0);
virtualSize(growBy());
}
}