01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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.invokers.ejb;
23:
24: import java.io.InputStream;
25: import java.io.IOException;
26: import java.io.OutputStream;
27: import java.net.Socket;
28: import java.util.zip.GZIPInputStream;
29: import java.util.zip.GZIPOutputStream;
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@jboss.org
39: @version $Revision: 57211 $
40: */
41: class CompressionSocket extends Socket {
42:
43: /* InputStream used by socket */
44: private InputStream in;
45: /* OutputStream used by socket */
46: private OutputStream out;
47:
48: /*
49: * No-arg constructor for class CompressionSocket
50: */
51: public CompressionSocket() {
52: super ();
53: }
54:
55: /*
56: * Constructor for class CompressionSocket
57: */
58: public CompressionSocket(String host, int port) throws IOException {
59: super (host, port);
60: }
61:
62: /*
63: * Returns a stream of type CompressionInputStream
64: */
65: public InputStream getInputStream() throws IOException {
66: if (in == null) {
67: in = new CompressionInputStream(super .getInputStream());
68: }
69: return in;
70: }
71:
72: /*
73: * Returns a stream of type CompressionOutputStream
74: */
75: public OutputStream getOutputStream() throws IOException {
76: if (out == null) {
77: out = new CompressionOutputStream(super .getOutputStream());
78: }
79: return out;
80: }
81:
82: /*
83: * Flush the CompressionOutputStream before
84: * closing the socket.
85: */
86: public synchronized void close() throws IOException {
87: OutputStream o = getOutputStream();
88: o.flush();
89: super.close();
90: }
91: }
|