summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/StreamTransport.java
blob: 9ca5fe7c7a835eebe6993e254e498801fb093d6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.simpleframework.http;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Map;

import javax.net.ssl.SSLEngine;

import org.simpleframework.transport.Certificate;
import org.simpleframework.transport.Transport;
import org.simpleframework.transport.trace.Trace;

public class StreamTransport implements Transport {
   
   private final WritableByteChannel write;
   private final ReadableByteChannel read;
   private final OutputStream out;
   
   public StreamTransport(InputStream in, OutputStream out) {
      this.write = Channels.newChannel(out);
      this.read = Channels.newChannel(in);
      this.out = out;
   }

   public void close() throws IOException {
      write.close();
      read.close();
   }

   public void flush() throws IOException {
      out.flush();
   }

   public int read(ByteBuffer buffer) throws IOException {
      return read.read(buffer);
   }

   public void write(ByteBuffer buffer) throws IOException {
      write.write(buffer);
   }

   public Map getAttributes() {
      return null;
   }

   public SocketChannel getChannel() {
      return null;
   }   

   public SSLEngine getEngine() {
      return null;
   }

   public Certificate getCertificate() {
      return null;
   }

   public Trace getTrace() {
      return new MockTrace();
   }
}