1 2 3 27 28 29 package org.apache.coyote.tomcat5; 30 31 import java.io.IOException ; 32 import java.security.AccessController ; 33 import java.security.PrivilegedAction ; 34 import java.security.PrivilegedExceptionAction ; 35 import java.security.PrivilegedActionException ; 36 import javax.servlet.ServletInputStream ; 37 38 import org.apache.catalina.security.SecurityUtil; 39 40 46 public class CoyoteInputStream 47 extends ServletInputStream { 48 49 50 52 53 protected InputBuffer ib; 54 55 56 58 59 public CoyoteInputStream(InputBuffer ib) { 60 this.ib = ib; 61 } 62 63 64 66 67 70 protected Object clone() 71 throws CloneNotSupportedException { 72 throw new CloneNotSupportedException (); 73 } 74 75 76 78 79 82 void clear() { 83 ib = null; 84 } 85 86 87 89 90 public int read() 91 throws IOException { 92 93 if (SecurityUtil.isPackageProtectionEnabled()){ 94 95 try{ 96 Integer result = 97 (Integer )AccessController.doPrivileged( 98 new PrivilegedExceptionAction (){ 99 100 public Object run() throws IOException { 101 Integer integer = new Integer (ib.readByte()); 102 return integer; 103 } 104 105 }); 106 return result.intValue(); 107 } catch(PrivilegedActionException pae){ 108 Exception e = pae.getException(); 109 if (e instanceof IOException ){ 110 throw (IOException )e; 111 } else { 112 throw new RuntimeException (e.getMessage()); 113 } 114 } 115 } else { 116 return ib.readByte(); 117 } 118 } 119 120 public int available() throws IOException { 121 if (SecurityUtil.isPackageProtectionEnabled()){ 122 try{ 123 Integer result = 124 (Integer )AccessController.doPrivileged( 125 new PrivilegedExceptionAction (){ 126 127 public Object run() throws IOException { 128 Integer integer = new Integer (ib.available()); 129 return integer; 130 } 131 132 }); 133 return result.intValue(); 134 } catch(PrivilegedActionException pae){ 135 Exception e = pae.getException(); 136 if (e instanceof IOException ){ 137 throw (IOException )e; 138 } else { 139 throw new RuntimeException (e.getMessage()); 140 } 141 } 142 } else { 143 return ib.available(); 144 } 145 } 146 147 public int read(final byte[] b) throws IOException { 148 if (SecurityUtil.isPackageProtectionEnabled()){ 149 try{ 150 Integer result = 151 (Integer )AccessController.doPrivileged( 152 new PrivilegedExceptionAction (){ 153 154 public Object run() throws IOException { 155 Integer integer = 156 new Integer (ib.read(b, 0, b.length)); 157 return integer; 158 } 159 160 }); 161 return result.intValue(); 162 } catch(PrivilegedActionException pae){ 163 Exception e = pae.getException(); 164 if (e instanceof IOException ){ 165 throw (IOException )e; 166 } else { 167 throw new RuntimeException (e.getMessage()); 168 } 169 } 170 } else { 171 return ib.read(b, 0, b.length); 172 } 173 } 174 175 176 public int read(final byte[] b, final int off, final int len) 177 throws IOException { 178 179 if (SecurityUtil.isPackageProtectionEnabled()){ 180 try{ 181 Integer result = 182 (Integer )AccessController.doPrivileged( 183 new PrivilegedExceptionAction (){ 184 185 public Object run() throws IOException { 186 Integer integer = 187 new Integer (ib.read(b, off, len)); 188 return integer; 189 } 190 191 }); 192 return result.intValue(); 193 } catch(PrivilegedActionException pae){ 194 Exception e = pae.getException(); 195 if (e instanceof IOException ){ 196 throw (IOException )e; 197 } else { 198 throw new RuntimeException (e.getMessage()); 199 } 200 } 201 } else { 202 return ib.read(b, off, len); 203 } 204 } 205 206 207 public int readLine(byte[] b, int off, int len) throws IOException { 208 return super.readLine(b, off, len); 209 } 210 211 212 217 public void close() throws IOException { 218 if (SecurityUtil.isPackageProtectionEnabled()){ 219 try{ 220 AccessController.doPrivileged( 221 new PrivilegedExceptionAction (){ 222 223 public Object run() throws IOException { 224 ib.close(); 225 return null; 226 } 227 228 }); 229 } catch(PrivilegedActionException pae){ 230 Exception e = pae.getException(); 231 if (e instanceof IOException ){ 232 throw (IOException )e; 233 } else { 234 throw new RuntimeException (e.getMessage()); 235 } 236 } 237 } else { 238 ib.close(); 239 } 240 } 241 242 } 243 | Popular Tags |