1 23 24 package com.sun.enterprise.web.ara.algorithms; 25 26 import com.sun.enterprise.web.connector.grizzly.StreamAlgorithm; 27 import com.sun.enterprise.web.connector.grizzly.Handler; 28 29 import java.nio.ByteBuffer ; 30 import java.nio.BufferUnderflowException ; 31 import java.nio.channels.SocketChannel ; 32 33 34 40 public class ContextRootAlgorithm implements StreamAlgorithm{ 41 42 private int port = 8080; 43 44 private SocketChannel socketChannel; 45 46 public ContextRootAlgorithm() { 47 } 48 49 50 56 public ByteBuffer allocate(boolean useDirect, boolean useView) { 57 throw new UnsupportedOperationException (); 58 } 59 60 61 65 public int contentLength() { 66 throw new UnsupportedOperationException (); 67 } 68 69 70 74 public int headerLength() { 75 throw new UnsupportedOperationException (); 76 } 77 78 79 86 public boolean parse(ByteBuffer byteBuffer) { 87 boolean isFound = false; 88 89 int curPosition = byteBuffer.position(); 90 int curLimit = byteBuffer.limit(); 91 92 if (byteBuffer.position() == 0) 94 return false; 95 96 byteBuffer.position(0); 97 byteBuffer.limit(curPosition); 98 int state =0; 99 int start =0; 100 int end = 0; 101 102 try { 103 byte c; 104 105 while(byteBuffer.hasRemaining()) { 107 c = byteBuffer.get(); 108 109 switch(state) { 115 case 0: if (c == 0x20){ 117 state = 1; 118 start = byteBuffer.position() + 1; 119 } 120 break; 121 case 1: if (c == 0x20){ 123 end = byteBuffer.position() - 1; 124 return true; 125 } 126 break; 127 default: 128 throw new IllegalArgumentException ("Unexpected state"); 129 } 130 } 131 return false; 132 } catch (BufferUnderflowException bue) { 133 return false; 134 } finally { 135 if ( end > 0 ){ 136 byteBuffer.position(start); 137 byteBuffer.limit(end); 138 } else { 139 byteBuffer.limit(curLimit); 140 byteBuffer.position(curPosition); 141 } 142 } 143 } 144 145 146 151 public ByteBuffer postParse(ByteBuffer byteBuffer) { 152 throw new UnsupportedOperationException (); 153 } 154 155 156 161 public ByteBuffer preParse(ByteBuffer byteBuffer) { 162 throw new UnsupportedOperationException (); 163 } 164 165 166 169 public void recycle() { 170 } 171 172 173 177 public ByteBuffer rollbackParseState(ByteBuffer byteBuffer) { 178 throw new UnsupportedOperationException (); 179 } 180 181 182 184 185 188 private String dump(ByteBuffer byteBuffer){ 189 ByteBuffer dd = byteBuffer.duplicate(); 190 dd.flip(); 191 192 int length = dd.limit(); 193 byte[] dump = new byte[length]; 194 dd.get(dump,0,length); 195 return(new String (dump) + "\n----------------------------" + dd); 196 } 197 198 199 202 public void setSocketChannel(SocketChannel socketChannel){ 203 this.socketChannel = socketChannel; 204 } 205 206 207 210 public Handler getHandler(){ 211 return null; 212 } 213 214 217 public void setPort(int port){ 218 this.port = port; 219 } 220 221 222 225 public int getPort(){ 226 return port; 227 } 228 } 229 | Popular Tags |