Debian Codegraph @

ssl-proxies/src/main/java/org/globus/util/http/HTTPResponseParser.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.util.http;
16
17 import java.io.InputStream;
18 import java.io.IOException;
19
20 public class HTTPResponseParser extends HTTPParser {
21
22 protected String _httpType;
23 protected int _httpCode;
24 protected String _httpMsg;
25
26 public HTTPResponseParser(InputStream is)
27 throws IOException {
28 super(is);
29 }
30
31 public String getMessage() {
32 return _httpMsg;
33 }
34
35 public int getStatusCode() {
36 return _httpCode;
37 }
38
39 public boolean isOK() {
40 return (_httpCode == 200);
41 }
42
43 public void parseHead(String line)
44 throws IOException {
45 int st = line.indexOf(" ");
46 if (st == -1) {
47 throw new IOException("Bad HTTP header");
48 }
49 _httpType = line.substring(0, st);
50
51 st++;
52 int et = line.indexOf(" ", st);
53 if (et == -1) {
54 throw new IOException("Bad HTTP header");
55 }
56
57 try {
58 _httpCode = Integer.parseInt(line.substring(st, et).trim());
59 } catch(Exception e) {
60 throw new IOException("Bad HTTP header");
61 }
62
63 et++;
64 _httpMsg = line.substring(et);
65 }
66
67 }