1 28 29 package com.caucho.server.http; 30 31 import java.io.*; 32 import java.net.*; 33 import java.util.*; 34 35 import com.caucho.util.*; 36 import com.caucho.vfs.*; 37 38 41 public class JniStream extends StreamImpl { 42 private static boolean hasInitJni; 43 44 private static NullPath nullPath; 45 46 private int fd; 47 private boolean flushOnNewline; 48 private boolean closeChildOnClose = true; 49 50 53 public JniStream(int fd) 54 { 55 if (! hasInitJni) 56 initJni(); 57 58 init(fd); 59 if (nullPath == null) 60 nullPath = new NullPath("jni-stream"); 61 setPath(nullPath); 62 } 63 64 public JniStream() 65 { 66 if (! hasInitJni) 67 initJni(); 68 69 if (nullPath == null) 70 nullPath = new NullPath("jni-stream"); 71 setPath(nullPath); 72 } 73 74 public void init(int fd) 75 { 76 this.fd = fd; 77 } 78 79 void initJni() 80 { 81 hasInitJni = true; 82 } 83 84 public boolean canRead() 85 { 86 return true; 87 } 88 89 public int read(byte []buf, int offset, int length) 90 throws IOException 91 { 92 if (buf == null) 93 throw new NullPointerException(); 94 else if (offset < 0 || buf.length < offset + length) 95 throw new ArrayIndexOutOfBoundsException(); 96 97 return readNative(fd, buf, offset, length); 98 } 99 100 native int readNative(int fd, byte []buf, int offset, int length) 101 throws IOException; 102 103 public int getAvailable() throws IOException 105 { 106 return -1; 107 } 108 109 public boolean canWrite() 110 { 111 return true; 112 } 113 114 public void write(byte []buf, int offset, int length, boolean isEnd) 115 throws IOException 116 { 117 if (buf == null) 118 throw new NullPointerException(); 119 else if (offset < 0 || buf.length < offset + length) 120 throw new ArrayIndexOutOfBoundsException(); 121 122 int result = writeNative(fd, buf, offset, length); 123 124 if (result < 0) 125 throw new ClientDisconnectException("connection reset by peer"); 126 } 127 128 native int writeNative(int fd, byte []buf, int offset, int length) 129 throws IOException; 130 131 public void flush() 132 throws IOException 133 { 134 int result = flushNative(fd); 135 136 if (result < 0) 137 throw new ClientDisconnectException("connection reset by peer"); 138 } 139 140 native int flushNative(int fd) throws IOException; 141 142 public void close() throws IOException 143 { 144 } 145 } 146 | Popular Tags |