Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/**
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 *
19
 * Contains some contributions under the Thrift Software License.
20
 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21
 * details.
22
 */
23
 
24
using System;
25
using System.IO;
26
 
27
namespace Thrift.Transport
28
{
29
	public class TStreamTransport : TTransport
30
	{
31
		protected Stream inputStream;
32
		protected Stream outputStream;
33
 
34
		public TStreamTransport()
35
		{
36
		}
37
 
38
		public TStreamTransport(Stream inputStream, Stream outputStream)
39
		{
40
			this.inputStream = inputStream;
41
			this.outputStream = outputStream;
42
		}
43
 
44
		public Stream OutputStream
45
		{
46
			get { return outputStream; }
47
		}
48
 
49
		public Stream InputStream
50
		{
51
			get { return inputStream; }
52
		}
53
 
54
		public override bool IsOpen
55
		{
56
			get { return true; }
57
		}
58
 
59
		public override void Open()
60
		{
61
		}
62
 
63
		public override void Close()
64
		{
65
			if (inputStream != null)
66
			{
67
				inputStream.Close();
68
				inputStream = null;
69
			}
70
			if (outputStream != null)
71
			{
72
				outputStream.Close();
73
				outputStream = null;
74
			}
75
		}
76
 
77
		public override int Read(byte[] buf, int off, int len)
78
		{
79
			if (inputStream == null)
80
			{
81
				throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot read from null inputstream");
82
			}
83
 
84
			return inputStream.Read(buf, off, len);
85
		}
86
 
87
		public override void Write(byte[] buf, int off, int len)
88
		{
89
			if (outputStream == null)
90
			{
91
				throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot write to null outputstream");
92
			}
93
 
94
			outputStream.Write(buf, off, len);
95
		}
96
 
97
		public override void Flush()
98
		{
99
			if (outputStream == null)
100
			{
101
				throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot flush null outputstream");
102
			}
103
 
104
			outputStream.Flush();
105
		}
106
	}
107
}