1 /*
2 * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
53 in.mark(0); // prevent resetting back to old marks
54
55 // pull out header, looking for content length
56
57 DataInputStream dis = new DataInputStream(in);
58 String key = "Content-length:".toLowerCase();
59 boolean contentLengthFound = false;
60 String line;
61 do {
62 line = dis.readLine();
63
64 if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.VERBOSE)) {
65 RMIMasterSocketFactory.proxyLog.log(Log.VERBOSE,
66 "received header line: \"" + line + "\"");
67 }
68
69 if (line == null)
70 throw new EOFException();
71
72 if (line.toLowerCase().startsWith(key)) {
73 // if contentLengthFound is true
74 // we should probably do something here
75 bytesLeft =
76 Integer.parseInt(line.substring(key.length()).trim());
77 contentLengthFound = true;
78 }
79
80 // The idea here is to go past the first blank line.
81 // Some DataInputStream.readLine() documentation specifies that
82 // it does include the line-terminating character(s) in the
83 // returned string, but it actually doesn't, so we'll cover
84 // all cases here...
85 } while ((line.length() != 0) &&
86 (line.charAt(0) != '\r') && (line.charAt(0) != '\n'));
87
88 if (!contentLengthFound || bytesLeft < 0) {
89 // This really shouldn't happen, but if it does, shoud we fail??
90 // For now, just give up and let a whole lot of bytes through...
91 bytesLeft = Integer.MAX_VALUE;
92 }
93 bytesLeftAtMark = bytesLeft;
94
95 if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.VERBOSE)) {
96 RMIMasterSocketFactory.proxyLog.log(Log.VERBOSE,
97 "content length: " + bytesLeft);
|
1 /*
2 * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
53 in.mark(0); // prevent resetting back to old marks
54
55 // pull out header, looking for content length
56
57 DataInputStream dis = new DataInputStream(in);
58 String key = "Content-length:".toLowerCase();
59 boolean contentLengthFound = false;
60 String line;
61 do {
62 line = dis.readLine();
63
64 if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.VERBOSE)) {
65 RMIMasterSocketFactory.proxyLog.log(Log.VERBOSE,
66 "received header line: \"" + line + "\"");
67 }
68
69 if (line == null)
70 throw new EOFException();
71
72 if (line.toLowerCase().startsWith(key)) {
73 if (contentLengthFound) {
74 throw new IOException(
75 "Multiple Content-length entries found.");
76 } else {
77 bytesLeft =
78 Integer.parseInt(line.substring(key.length()).trim());
79 contentLengthFound = true;
80 }
81 }
82
83 // The idea here is to go past the first blank line.
84 // Some DataInputStream.readLine() documentation specifies that
85 // it does include the line-terminating character(s) in the
86 // returned string, but it actually doesn't, so we'll cover
87 // all cases here...
88 } while ((line.length() != 0) &&
89 (line.charAt(0) != '\r') && (line.charAt(0) != '\n'));
90
91 if (!contentLengthFound || bytesLeft < 0) {
92 // This really shouldn't happen, but if it does, shoud we fail??
93 // For now, just give up and let a whole lot of bytes through...
94 bytesLeft = Integer.MAX_VALUE;
95 }
96 bytesLeftAtMark = bytesLeft;
97
98 if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.VERBOSE)) {
99 RMIMasterSocketFactory.proxyLog.log(Log.VERBOSE,
100 "content length: " + bytesLeft);
|