xref: /unit/src/java/nginx/unit/OutputStream.java (revision 977:4f9268f27b57)
1 package nginx.unit;
2 
3 import java.io.IOException;
4 
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.WriteListener;
7 
8 public class OutputStream extends ServletOutputStream {
9 
10     private long req_info_ptr;
11 
OutputStream(long ptr)12     public OutputStream(long ptr) {
13         req_info_ptr = ptr;
14     }
15 
16     @Override
write(int b)17     public void write(int b) throws IOException
18     {
19         write(req_info_ptr, b);
20     }
21 
write(long req_info_ptr, int b)22     private static native void write(long req_info_ptr, int b);
23 
24 
25     @Override
write(byte b[], int off, int len)26     public void write(byte b[], int off, int len) throws IOException
27     {
28         if (b == null) {
29             throw new NullPointerException();
30         } else if ((off < 0) || (off > b.length) || (len < 0) ||
31                    ((off + len) > b.length) || ((off + len) < 0)) {
32             throw new IndexOutOfBoundsException();
33         } else if (len == 0) {
34             return;
35         }
36 
37         write(req_info_ptr, b, off, len);
38     }
39 
write(long req_info_ptr, byte b[], int off, int len)40     private static native void write(long req_info_ptr, byte b[], int off, int len);
41 
42     @Override
flush()43     public void flush()
44     {
45         flush(req_info_ptr);
46     }
47 
flush(long req_info_ptr)48     private static native void flush(long req_info_ptr);
49 
50     @Override
close()51     public void close()
52     {
53         close(req_info_ptr);
54     }
55 
close(long req_info_ptr)56     private static native void close(long req_info_ptr);
57 
58     @Override
isReady()59     public boolean isReady()
60     {
61         return true;
62     }
63 
64     @Override
setWriteListener(WriteListener listener)65     public void setWriteListener(WriteListener listener)
66     {
67     }
68 }
69