package vicazh.hyperpool.stream.net;
import java.io.*;
import java.net.Socket;
import java.util.*;
import vicazh.hyperpool.stream.*;
public class AntivirusClamAVConnection extends Connection {
AntivirusClamAVConnection(Element element) {
super(element);
}
public void setServer(OutputStream outputstream) {
setServer(new AntivirusClamAVStream(this));
}
public boolean c;
private Socket socket;
synchronized public void close() {
c = true;
try {
socket.close();
} catch (Exception e) {
}
super.close();
notifyAll();
}
public OutputStream open(String host, int timeout) throws IOException {
synchronized (this) {
// getClient().write("PING\n".getBytes());
getClient().write("STREAM\n".getBytes());
getClient().flush();
try {
wait(60000);
} catch (InterruptedException e) {
}
}
StringTokenizer st = new StringTokenizer(
((AntivirusClamAVStream) getServer()).result);
st.nextToken();
socket = new Socket(host, Integer.parseInt(st.nextToken()));
((AntivirusClamAVStream) getServer()).result = null;
socket.setSoTimeout(timeout);
return socket.getOutputStream();
}
public String getResult() {
try {
socket.close();
} catch (Exception e) {
}
synchronized (this) {
if (((AntivirusClamAVStream) getServer()).result == null && !c)
try {
wait(60000);
} catch (InterruptedException e) {
}
}
try {
getClient().close();
} catch (Exception e) {
}
return ((AntivirusClamAVStream) getServer()).result;
}
}