KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jrmp > ejb > CompressionSocket


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jrmp.ejb;
23
24 import java.io.InputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.net.Socket JavaDoc;
28 import java.util.zip.GZIPInputStream JavaDoc;
29 import java.util.zip.GZIPOutputStream JavaDoc;
30
31 /** A custom socket that uses the GZIPInputStream and GZIPOutputStream streams
32 for compression.
33
34 @see java.net.ServerSocket
35 @see java.util.zip.GZIPInputStream
36 @see java.util.zip.GZIPOutputStream
37
38 @author Scott_Stark@displayscape.com
39 @version $Revision: 37406 $
40 */

41 class CompressionSocket extends Socket JavaDoc
42 {
43
44     /* InputStream used by socket */
45     private InputStream JavaDoc in;
46     /* OutputStream used by socket */
47     private OutputStream JavaDoc out;
48
49     /*
50      * No-arg constructor for class CompressionSocket
51      */

52     public CompressionSocket()
53     {
54         super();
55     }
56
57     /*
58      * Constructor for class CompressionSocket
59      */

60     public CompressionSocket(String JavaDoc host, int port) throws IOException JavaDoc
61     {
62         super(host, port);
63     }
64
65     /*
66      * Returns a stream of type CompressionInputStream
67      */

68     public InputStream JavaDoc getInputStream() throws IOException JavaDoc
69     {
70         if (in == null)
71         {
72             in = new CompressionInputStream(super.getInputStream());
73         }
74         return in;
75     }
76
77     /*
78      * Returns a stream of type CompressionOutputStream
79      */

80     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc
81     {
82         if (out == null)
83         {
84             out = new CompressionOutputStream(super.getOutputStream());
85         }
86         return out;
87     }
88
89     /*
90      * Flush the CompressionOutputStream before
91      * closing the socket.
92      */

93     public synchronized void close() throws IOException JavaDoc
94     {
95         OutputStream JavaDoc o = getOutputStream();
96         o.flush();
97     super.close();
98     }
99 }
100
Popular Tags