blob: 7632419d669245069bfef3730e5a25fcb8068932 [file] [log] [blame]
Adam Wojtuniak5ea07b12009-12-14 00:31:27 +00001/**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.apache.felix.io;
18
19import java.io.ByteArrayInputStream;
20import java.io.ByteArrayOutputStream;
21import java.io.DataInputStream;
22import java.io.DataOutputStream;
23import java.io.IOException;
24import java.io.InputStream;
25import java.io.OutputStream;
26
27import javax.microedition.io.Connection;
28import javax.microedition.io.InputConnection;
29import javax.microedition.io.OutputConnection;
30
31import org.osgi.service.io.ConnectionFactory;
32
33/**
34 * {@link ConnectionFactory} implementation for testing purpose. Creates fake connection @see {@link Connection}.
35 *
36 *
37 * @version $Rev$ $Date$
38 */
39public class ConnectionFactoryMock implements ConnectionFactory
40{
41
42 /**
43 * uri name.
44 */
45 private String m_name;
46 /**
47 * access mode.
48 */
49 private int m_mode;
50 /**
51 * connection timeout.
52 */
53 private boolean m_timeout;
54
55 /**
56 * @see org.osgi.service.io.ConnectionFactory#createConnection(String, int, boolean)
57 */
58 public Connection createConnection(String name, int mode, boolean timeout) throws IOException
59 {
60 this.m_mode = mode;
61 this.m_name = name;
62 this.m_timeout = timeout;
63 return new TestConnection();
64 }
65
66 public String getName()
67 {
68 return m_name;
69 }
70
71 public int getMode()
72 {
73 return m_mode;
74 }
75
76 public boolean isTimeout()
77 {
78 return m_timeout;
79 }
80
81 /**
82 * Mock implementation of {@link Connection}, {@link InputConnection}, {@link OutputConnection}.
83 *
84 */
85 private class TestConnection implements Connection, InputConnection, OutputConnection
86 {
87
88 /**
89 * @see javax.microedition.io.Connection#close()
90 */
91 public void close() throws IOException
92 {
93
94 }
95
96 /**
97 * @see javax.microedition.io.InputConnection#openDataInputStream()
98 */
99 public DataInputStream openDataInputStream() throws IOException
100 {
101 return new DataInputStream(new ByteArrayInputStream(new byte[]
102 {}));
103 }
104
105 /**
106 * @see javax.microedition.io.InputConnection#openInputStream()
107 */
108 public InputStream openInputStream() throws IOException
109 {
110 return new ByteArrayInputStream(new byte[]
111 {});
112 }
113
114 /**
115 * @see javax.microedition.io.OutputConnection#openDataOutputStream()
116 */
117 public DataOutputStream openDataOutputStream() throws IOException
118 {
119 return new DataOutputStream(new ByteArrayOutputStream());
120 }
121
122 /**
123 * @see javax.microedition.io.OutputConnection#openOutputStream()
124 */
125 public OutputStream openOutputStream() throws IOException
126 {
127 return new ByteArrayOutputStream();
128 }
129
130 }
131}