DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
NetworkInputStream.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 using System;
17 using System.IO;
18 using System.Net.Sockets;
19 
20 namespace Deveel.Data.Protocol {
21  public class NetworkInputStream : Stream, IInputStream {
22  public NetworkInputStream(Socket socket) {
23  stream = new NISNetworkStream(socket);
24  }
25 
26  private readonly NISNetworkStream stream;
27 
28  private class NISNetworkStream : NetworkStream {
29  public NISNetworkStream(Socket socket)
30  : base(socket, FileAccess.Read) {
31  }
32 
33  public int Available {
34  get { return (Socket.Connected ? Socket.Available : 0); }
35  }
36 
37  public override int Read(byte[] buffer, int offset, int size) {
38  if (!Socket.Connected)
39  return 0;
40 
41  return base.Read(buffer, offset, size);
42  }
43  }
44 
45  public int Available {
46  get { return stream.Available; }
47  }
48 
49  public override bool CanRead {
50  get { return true; }
51  }
52 
53  public override bool CanWrite {
54  get { return false; }
55  }
56 
57  public override long Seek(long offset, SeekOrigin origin) {
58  throw new NotSupportedException();
59  }
60 
61  public override void Flush() {
62  }
63 
64  public override void SetLength(long value) {
65  throw new NotSupportedException();
66  }
67 
68  public override int Read(byte[] buffer, int offset, int count) {
69  return stream.Read(buffer, offset, count);
70  }
71 
72  public override void Write(byte[] buffer, int offset, int count) {
73  throw new NotSupportedException();
74  }
75 
76  public override bool CanSeek {
77  get { return false; }
78  }
79 
80  public override long Length {
81  get { throw new NotSupportedException(); }
82  }
83 
84  public override long Position {
85  get { throw new NotSupportedException(); }
86  set { throw new NotSupportedException(); }
87  }
88  }
89 }
Represents a stream that supports required functionalities for a LengthMarkedBufferedInputStream ...
Definition: IInputStream.cs:10
override long Seek(long offset, SeekOrigin origin)
override void Write(byte[] buffer, int offset, int count)
override int Read(byte[] buffer, int offset, int size)
override int Read(byte[] buffer, int offset, int count)