< prev index next >

src/share/classes/sun/net/httpserver/Request.java

Print this page
rev 1564 : 7090158: Networking Libraries don't build with javac -Werror
7125055: ContentHandler.getContent API changed in error
Summary: Minor changes to networking java files to remove warnings
Reviewed-by: chegar, weijun, hawtin, alanb
Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.httpserver;
  27 
  28 import java.util.*;
  29 import java.nio.*;
  30 import java.net.*;
  31 import java.io.*;
  32 import java.nio.channels.*;
  33 import com.sun.net.httpserver.*;
  34 import com.sun.net.httpserver.spi.*;
  35 
  36 /**
  37  */
  38 class Request {
  39 
  40     final static int BUF_LEN = 2048;
  41     final static byte CR = 13;
  42     final static byte LF = 10;
  43 
  44     private String startLine;
  45     private SocketChannel chan;
  46     private InputStream is;
  47     private OutputStream os;
  48 
  49     Request (InputStream rawInputStream, OutputStream rawout) throws IOException {
  50         this.chan = chan;
  51         is = rawInputStream;
  52         os = rawout;
  53         do {
  54             startLine = readLine();
  55             if (startLine == null) {
  56                 return;
  57             }
  58             /* skip blank lines */
  59         } while (startLine.equals (""));
  60     }
  61 
  62 
  63     char[] buf = new char [BUF_LEN];
  64     int pos;
  65     StringBuffer lineBuf;
  66 
  67     public InputStream inputStream () {
  68         return is;
  69     }
  70 


 104         lineBuf.append (buf, 0, pos);
 105         return new String (lineBuf);
 106     }
 107 
 108     private void consume (int c) {
 109         if (pos == BUF_LEN) {
 110             lineBuf.append (buf);
 111             pos = 0;
 112         }
 113         buf[pos++] = (char)c;
 114     }
 115 
 116     /**
 117      * returns the request line (first line of a request)
 118      */
 119     public String requestLine () {
 120         return startLine;
 121     }
 122 
 123     Headers hdrs = null;
 124 
 125     Headers headers () throws IOException {
 126         if (hdrs != null) {
 127             return hdrs;
 128         }
 129         hdrs = new Headers();
 130 
 131         char s[] = new char[10];
 132         int firstc = is.read();
 133         while (firstc != LF && firstc != CR && firstc >= 0) {
 134             int len = 0;
 135             int keyend = -1;
 136             int c;
 137             boolean inKey = firstc > ' ';
 138             s[len++] = (char) firstc;
 139     parseloop:{
 140                 while ((c = is.read()) >= 0) {
 141                     switch (c) {

 142                       case ':':
 143                         if (inKey && len > 0)
 144                             keyend = len;
 145                         inKey = false;
 146                         break;
 147                       case '\t':
 148                         c = ' ';
 149                       case ' ':
 150                         inKey = false;
 151                         break;
 152                       case CR:
 153                       case LF:
 154                         firstc = is.read();
 155                         if (c == CR && firstc == LF) {
 156                             firstc = is.read();
 157                             if (firstc == CR)
 158                                 firstc = is.read();
 159                         }
 160                         if (firstc == LF || firstc == CR || firstc > ' ')
 161                             break parseloop;




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.httpserver;
  27 
  28 import java.net.SocketTimeoutException;
  29 import java.nio.*;

  30 import java.io.*;
  31 import java.nio.channels.*;
  32 import com.sun.net.httpserver.*;

  33 
  34 /**
  35  */
  36 class Request {
  37 
  38     final static int BUF_LEN = 2048;
  39     final static byte CR = 13;
  40     final static byte LF = 10;
  41 
  42     private String startLine;
  43     private SocketChannel chan;
  44     private InputStream is;
  45     private OutputStream os;
  46 
  47     Request (InputStream rawInputStream, OutputStream rawout) throws IOException {

  48         is = rawInputStream;
  49         os = rawout;
  50         do {
  51             startLine = readLine();
  52             if (startLine == null) {
  53                 return;
  54             }
  55             /* skip blank lines */
  56         } while (startLine.equals (""));
  57     }
  58 
  59 
  60     char[] buf = new char [BUF_LEN];
  61     int pos;
  62     StringBuffer lineBuf;
  63 
  64     public InputStream inputStream () {
  65         return is;
  66     }
  67 


 101         lineBuf.append (buf, 0, pos);
 102         return new String (lineBuf);
 103     }
 104 
 105     private void consume (int c) {
 106         if (pos == BUF_LEN) {
 107             lineBuf.append (buf);
 108             pos = 0;
 109         }
 110         buf[pos++] = (char)c;
 111     }
 112 
 113     /**
 114      * returns the request line (first line of a request)
 115      */
 116     public String requestLine () {
 117         return startLine;
 118     }
 119 
 120     Headers hdrs = null;
 121     @SuppressWarnings("fallthrough")
 122     Headers headers () throws IOException {
 123         if (hdrs != null) {
 124             return hdrs;
 125         }
 126         hdrs = new Headers();
 127 
 128         char s[] = new char[10];
 129         int firstc = is.read();
 130         while (firstc != LF && firstc != CR && firstc >= 0) {
 131             int len = 0;
 132             int keyend = -1;
 133             int c;
 134             boolean inKey = firstc > ' ';
 135             s[len++] = (char) firstc;
 136     parseloop:{
 137                 while ((c = is.read()) >= 0) {
 138                     switch (c) {
 139                       /*fallthrough*/
 140                       case ':':
 141                         if (inKey && len > 0)
 142                             keyend = len;
 143                         inKey = false;
 144                         break;
 145                       case '\t':
 146                         c = ' ';
 147                       case ' ':
 148                         inKey = false;
 149                         break;
 150                       case CR:
 151                       case LF:
 152                         firstc = is.read();
 153                         if (c == CR && firstc == LF) {
 154                             firstc = is.read();
 155                             if (firstc == CR)
 156                                 firstc = is.read();
 157                         }
 158                         if (firstc == LF || firstc == CR || firstc > ' ')
 159                             break parseloop;


< prev index next >