xref: /unit/src/java/nginx/unit/InputStream.java (revision 977:4f9268f27b57)
1 package nginx.unit;
2 
3 import java.io.IOException;
4 
5 import javax.servlet.ReadListener;
6 import javax.servlet.ServletInputStream;
7 
8 public class InputStream extends ServletInputStream {
9 
10     private long req_info_ptr;
11 
InputStream(long ptr)12     public InputStream(long ptr)
13     {
14         req_info_ptr = ptr;
15     }
16 
17     @Override
readLine(byte[] b, int off, int len)18     public int readLine(byte[] b, int off, int len) throws IOException {
19 
20         if (len <= 0) {
21             return 0;
22         }
23         return readLine(req_info_ptr, b, off, len);
24     }
25 
readLine(long req_info_ptr, byte[] b, int off, int len)26     private static native int readLine(long req_info_ptr, byte[] b, int off, int len);
27 
28 
29     @Override
isFinished()30     public boolean isFinished()
31     {
32         return isFinished(req_info_ptr);
33     }
34 
isFinished(long req_info_ptr)35     private static native boolean isFinished(long req_info_ptr);
36 
37 
38     @Override
isReady()39     public boolean isReady()
40     {
41         return true;
42     }
43 
44 
45     @Override
setReadListener(ReadListener listener)46     public void setReadListener(ReadListener listener)
47     {
48     }
49 
50 
51     @Override
read()52     public int read() throws IOException
53     {
54         return read(req_info_ptr);
55     }
56 
read(long req_info_ptr)57     private static native int read(long req_info_ptr);
58 
59 
60     @Override
read(byte b[], int off, int len)61     public int read(byte b[], int off, int len) throws IOException {
62         if (b == null) {
63             throw new NullPointerException();
64         } else if (off < 0 || len < 0 || len > b.length - off) {
65             throw new IndexOutOfBoundsException();
66         } else if (len == 0) {
67             return 0;
68         }
69 
70         return read(req_info_ptr, b, off, len);
71     }
72 
read(long req_info_ptr, byte b[], int off, int len)73     private static native int read(long req_info_ptr, byte b[], int off, int len);
74 
75 
76     @Override
skip(long n)77     public long skip(long n) throws IOException {
78         return skip(req_info_ptr, n);
79     }
80 
skip(long req_info_ptr, long n)81     private static native long skip(long req_info_ptr, long n);
82 
83 
84     @Override
available()85     public int available() throws IOException {
86         return available(req_info_ptr);
87     }
88 
available(long req_info_ptr)89     private static native int available(long req_info_ptr);
90 }
91