Package vicazh.hyperpool.stream.net

Source Code of vicazh.hyperpool.stream.net.AntivirusClamAVConnection

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;
  }

}
TOP

Related Classes of vicazh.hyperpool.stream.net.AntivirusClamAVConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.