EMMA Coverage Report (generated Wed Jul 26 14:28:59 CDT 2006)
[all classes][com.mysql.jdbc]

COVERAGE SUMMARY FOR SOURCE FILE [NamedPipeSocketFactory.java]

nameclass, %method, %block, %line, %
NamedPipeSocketFactory.java0%   (0/4)0%   (0/20)0%   (0/157)0%   (0/42)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NamedPipeSocketFactory0%   (0/1)0%   (0/4)0%   (0/47)0%   (0/11)
NamedPipeSocketFactory (): void 0%   (0/1)0%   (0/3)0%   (0/2)
afterHandshake (): Socket 0%   (0/1)0%   (0/3)0%   (0/1)
beforeHandshake (): Socket 0%   (0/1)0%   (0/3)0%   (0/1)
connect (String, int, Properties): Socket 0%   (0/1)0%   (0/38)0%   (0/7)
     
class NamedPipeSocketFactory$NamedPipeSocket0%   (0/1)0%   (0/5)0%   (0/53)0%   (0/12)
NamedPipeSocketFactory$NamedPipeSocket (NamedPipeSocketFactory, String): void 0%   (0/1)0%   (0/27)0%   (0/6)
close (): void 0%   (0/1)0%   (0/7)0%   (0/3)
getInputStream (): InputStream 0%   (0/1)0%   (0/8)0%   (0/1)
getOutputStream (): OutputStream 0%   (0/1)0%   (0/8)0%   (0/1)
isClosed (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
     
class NamedPipeSocketFactory$RandomAccessFileInputStream0%   (0/1)0%   (0/6)0%   (0/31)0%   (0/9)
NamedPipeSocketFactory$RandomAccessFileInputStream (NamedPipeSocketFactory, R... 0%   (0/1)0%   (0/9)0%   (0/3)
available (): int 0%   (0/1)0%   (0/2)0%   (0/1)
close (): void 0%   (0/1)0%   (0/4)0%   (0/2)
read (): int 0%   (0/1)0%   (0/4)0%   (0/1)
read (byte []): int 0%   (0/1)0%   (0/5)0%   (0/1)
read (byte [], int, int): int 0%   (0/1)0%   (0/7)0%   (0/1)
     
class NamedPipeSocketFactory$RandomAccessFileOutputStream0%   (0/1)0%   (0/5)0%   (0/26)0%   (0/10)
NamedPipeSocketFactory$RandomAccessFileOutputStream (NamedPipeSocketFactory, ... 0%   (0/1)0%   (0/9)0%   (0/3)
close (): void 0%   (0/1)0%   (0/4)0%   (0/2)
write (byte []): void 0%   (0/1)0%   (0/5)0%   (0/2)
write (byte [], int, int): void 0%   (0/1)0%   (0/7)0%   (0/2)
write (int): void 0%   (0/1)0%   (0/1)0%   (0/1)

1/*
2 Copyright (C) 2002-2004 MySQL AB
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of version 2 of the GNU General Public License as 
6 published by the Free Software Foundation.
7 
8 There are special exceptions to the terms and conditions of the GPL 
9 as it is applied to this software. View the full text of the 
10 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
11 software distribution.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 
23 
24 */
25package com.mysql.jdbc;
26 
27import java.io.IOException;
28import java.io.InputStream;
29import java.io.OutputStream;
30import java.io.RandomAccessFile;
31 
32import java.net.Socket;
33import java.net.SocketException;
34 
35import java.util.Properties;
36 
37/**
38 * A socket factory for named pipes (on Windows)
39 * 
40 * @author Mark Matthews
41 */
42public class NamedPipeSocketFactory implements SocketFactory {
43        /**
44         * A socket that encapsulates named pipes on Windows
45         */
46        class NamedPipeSocket extends Socket {
47                private boolean isClosed = false;
48 
49                private RandomAccessFile namedPipeFile;
50 
51                NamedPipeSocket(String filePath) throws IOException {
52                        if ((filePath == null) || (filePath.length() == 0)) {
53                                throw new IOException(Messages
54                                                .getString("NamedPipeSocketFactory.4")); //$NON-NLS-1$
55                        }
56 
57                        this.namedPipeFile = new RandomAccessFile(filePath, "rw"); //$NON-NLS-1$
58                }
59 
60                /**
61                 * @see java.net.Socket#close()
62                 */
63                public synchronized void close() throws IOException {
64                        this.namedPipeFile.close();
65                        this.isClosed = true;
66                }
67 
68                /**
69                 * @see java.net.Socket#getInputStream()
70                 */
71                public InputStream getInputStream() throws IOException {
72                        return new RandomAccessFileInputStream(this.namedPipeFile);
73                }
74 
75                /**
76                 * @see java.net.Socket#getOutputStream()
77                 */
78                public OutputStream getOutputStream() throws IOException {
79                        return new RandomAccessFileOutputStream(this.namedPipeFile);
80                }
81 
82                /**
83                 * @see java.net.Socket#isClosed()
84                 */
85                public boolean isClosed() {
86                        return this.isClosed;
87                }
88        }
89 
90        /**
91         * Enables OutputStream-type functionality for a RandomAccessFile
92         */
93        class RandomAccessFileInputStream extends InputStream {
94                RandomAccessFile raFile;
95 
96                RandomAccessFileInputStream(RandomAccessFile file) {
97                        this.raFile = file;
98                }
99 
100                /**
101                 * @see java.io.InputStream#available()
102                 */
103                public int available() throws IOException {
104                        return -1;
105                }
106 
107                /**
108                 * @see java.io.InputStream#close()
109                 */
110                public void close() throws IOException {
111                        this.raFile.close();
112                }
113 
114                /**
115                 * @see java.io.InputStream#read()
116                 */
117                public int read() throws IOException {
118                        return this.raFile.read();
119                }
120 
121                /**
122                 * @see java.io.InputStream#read(byte[])
123                 */
124                public int read(byte[] b) throws IOException {
125                        return this.raFile.read(b);
126                }
127 
128                /**
129                 * @see java.io.InputStream#read(byte[], int, int)
130                 */
131                public int read(byte[] b, int off, int len) throws IOException {
132                        return this.raFile.read(b, off, len);
133                }
134        }
135 
136        /**
137         * Enables OutputStream-type functionality for a RandomAccessFile
138         */
139        class RandomAccessFileOutputStream extends OutputStream {
140                RandomAccessFile raFile;
141 
142                RandomAccessFileOutputStream(RandomAccessFile file) {
143                        this.raFile = file;
144                }
145 
146                /**
147                 * @see java.io.OutputStream#close()
148                 */
149                public void close() throws IOException {
150                        this.raFile.close();
151                }
152 
153                /**
154                 * @see java.io.OutputStream#write(byte[])
155                 */
156                public void write(byte[] b) throws IOException {
157                        this.raFile.write(b);
158                }
159 
160                /**
161                 * @see java.io.OutputStream#write(byte[], int, int)
162                 */
163                public void write(byte[] b, int off, int len) throws IOException {
164                        this.raFile.write(b, off, len);
165                }
166 
167                /**
168                 * @see java.io.OutputStream#write(int)
169                 */
170                public void write(int b) throws IOException {
171                }
172        }
173 
174        private static final String NAMED_PIPE_PROP_NAME = "namedPipePath"; //$NON-NLS-1$
175 
176        private Socket namedPipeSocket;
177 
178        /**
179         * Constructor for NamedPipeSocketFactory.
180         */
181        public NamedPipeSocketFactory() {
182                super();
183        }
184 
185        /**
186         * @see com.mysql.jdbc.SocketFactory#afterHandshake()
187         */
188        public Socket afterHandshake() throws SocketException, IOException {
189                return this.namedPipeSocket;
190        }
191 
192        /**
193         * @see com.mysql.jdbc.SocketFactory#beforeHandshake()
194         */
195        public Socket beforeHandshake() throws SocketException, IOException {
196                return this.namedPipeSocket;
197        }
198 
199        /**
200         * @see com.mysql.jdbc.SocketFactory#connect(String, Properties)
201         */
202        public Socket connect(String host, int portNumber /* ignored */,
203                        Properties props) throws SocketException, IOException {
204                String namedPipePath = props.getProperty(NAMED_PIPE_PROP_NAME);
205 
206                if (namedPipePath == null) {
207                        namedPipePath = "\\\\.\\pipe\\MySQL"; //$NON-NLS-1$
208                } else if (namedPipePath.length() == 0) {
209                        throw new SocketException(Messages
210                                        .getString("NamedPipeSocketFactory.2") //$NON-NLS-1$
211                                        + NAMED_PIPE_PROP_NAME
212                                        + Messages.getString("NamedPipeSocketFactory.3")); //$NON-NLS-1$
213                }
214 
215                this.namedPipeSocket = new NamedPipeSocket(namedPipePath);
216 
217                return this.namedPipeSocket;
218        }
219}

[all classes][com.mysql.jdbc]
EMMA 2.0.4217 (C) Vladimir Roubtsov