summaryrefslogtreecommitdiffstats
path: root/simple/simple-common/src/test/java/org/simpleframework/common/buffer/queue/ByteQueueStream.java
blob: dbf73e18c007dcc1cbcf1cf69c027237ebb7ad51 (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
package org.simpleframework.common.buffer.queue;

import java.io.IOException;
import java.io.InputStream;

public class ByteQueueStream extends InputStream {
   
   private final ByteQueue queue;
   
   public ByteQueueStream(ByteQueue queue) {
      this.queue = queue;
   }

   @Override
   public int read() throws IOException {
      byte[] array = new byte[1];
      int count = read(array) ;
      
      if(count != -1) {
         return array[0] & 0xff;
      }
      return -1;
   }
   
   public int read(byte[] buffer) throws IOException {
      return queue.read(buffer, 0, buffer.length);
   }
   
   public int read(byte[] buffer, int off, int size) throws IOException {
      return queue.read(buffer, off, size);
   }
   
   public int available() throws IOException {
      return queue.available();
   }
   
   public void close() throws IOException {
      queue.close();
   }  
}