2 * Copyright (c) 2003 University of Murcia. All rights reserved.
\r
3 * --------------------------------------------------------------
\r
4 * For more information, please see <http://www.umu.euro6ix.org/>.
\r
7 package org.umu.cops.stack;
\r
9 import java.io.IOException;
\r
10 import java.io.InputStream;
\r
11 import java.io.OutputStream;
\r
12 import java.net.Socket;
\r
13 import java.util.Date;
\r
18 * @version COPSUtil.java, v 2.00 2004
\r
21 public class COPSUtil {
\r
26 * @param id a Socket
\r
27 * @param data a byte[]
\r
30 * @throws IOException
\r
33 static void writeData(Socket id, byte[] data, int len) throws IOException {
\r
34 OutputStream output;
\r
35 output = id.getOutputStream();
\r
37 output.write(data,0,len);
\r
41 * Reads nchar from a given sockets, blocks on read untill nchar are read of conenction has error
\r
42 * bRead returns the bytes read
\r
44 * @param connId a Socket
\r
45 * @param dataRead a byte[]
\r
46 * @param nchar an int
\r
50 * @throws IOException
\r
53 static int readData(Socket connId, byte[] dataRead, int nchar) throws IOException {
\r
55 input = connId.getInputStream();
\r
58 int startTime = (int) (new Date().getTime());
\r
60 if (input.available() != 0) {
\r
61 nread += input.read(dataRead,nread,nchar-nread);
\r
62 startTime = (int) (new Date().getTime());
\r
64 int nowTime = (int) (new Date().getTime());
\r
65 if ((int)(nowTime - startTime) > 2000)
\r
68 } while (nread != nchar);
\r