// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.net.*;

public class Server2 {
   public static void main(String[] args) throws Exception {
      ServerSocket ss = new ServerSocket(9999);
      Socket s = ss.accept();
      DataInputStream is = new DataInputStream(s.getInputStream());
      save("C:\\z1copy.zip", is);
      save("C:\\z2copy.zip", is);
      save("C:\\z3copy.zip", is);
      is.close();
   }
   public static void save(String filename, DataInputStream is) throws Exception {
      int totsize = is.readInt();
      OutputStream os = new FileOutputStream(filename);
      byte[] b = new byte[10000];
      int n;
      int size = 0;
      while(size < totsize) {
         n = is.read(b, 0, Math.min(b.length, totsize - size));
         os.write(b, 0, n);
         size += n;
      }
      os.close();
   }
}
