Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: mas_gui/CompressedConnection.java


1   /* Copyright 1998 - 2003: Jim Cochrane - see file forum.txt */
2   
3   package mas_gui;
4   
5   import java.io.*;
6   import java.net.*;
7   import java.util.*;
8   import java.util.zip.*;
9   import common.*;
10  import graph.*;
11  import support.*;
12  
13  /** A Connection that receives compressed data from the server */
14  public class CompressedConnection extends Connection
15  {
16    // args[0]: hostname, args[1]: port_number
17    public CompressedConnection(String hostname, Integer port_number) {
18      super(hostname, port_number);
19    }
20  
21  
22  // Implementation
23  
24    protected Reader new_reader_from_socket() {
25      Reader result = null;
26      try {
27        result = new BufferedReader(new InputStreamReader(
28          new InflaterInputStream(socket.getInputStream(),
29          new Inflater(), 850000)));
30      } catch (Exception e) {
31        System.err.println("Failed to read from server (" + e + ")");
32        System.exit(1);
33      }
34  //System.out.println("decompressing");
35      return result;
36    }
37  
38    // Send the `msgID', the session key, the compression-on flag,
39    // and `msg' - with field delimiters according to the client/server
40    // protocol.
41    void send_msg(int msgID, String msg, int session_key) {
42      out.print(msgID);
43      out.print(Input_field_separator + session_key);
44      out.print(Input_field_separator + Compression_on_flag + msg);
45      out.print(Eom);
46      out.flush();
47    }
48  }