Index: httpclient/src/java/org/apache/commons/httpclient/Authenticator.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java,v
retrieving revision 1.39
diff -u -r1.39 Authenticator.java
--- httpclient/src/java/org/apache/commons/httpclient/Authenticator.java 28 Jan 2003 04:40:20 -0000 1.39
+++ httpclient/src/java/org/apache/commons/httpclient/Authenticator.java 30 Jan 2003 20:54:18 -0000
@@ -848,7 +848,7 @@
private static String parseRealmFromChallenge(String challenge)
throws HttpException {
- // FIXME: Note that this won't work if there is more than one realm
+ // TODO: Note that this won't work if there is more than one realm
// within the challenge
try {
StringTokenizer strtok = new StringTokenizer(challenge, "=");
Index: httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java,v
retrieving revision 1.7
diff -u -r1.7 ChunkedOutputStream.java
--- httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java 28 Jan 2003 04:40:20 -0000 1.7
+++ httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java 30 Jan 2003 20:54:16 -0000
@@ -185,7 +185,7 @@
if (closed) {
throw new IllegalStateException("Output stream already closed");
}
- //FIXME: If using chunking, the chunks are ONE byte long!
+ //TODO: If using chunking, the chunks are ONE byte long!
stream.write(ONE, 0, ONE.length);
stream.write(CRLF, 0, CRLF.length);
stream.write(b);
Index: httpclient/src/java/org/apache/commons/httpclient/Cookie.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
retrieving revision 1.35
diff -u -r1.35 Cookie.java
--- httpclient/src/java/org/apache/commons/httpclient/Cookie.java 28 Jan 2003 04:40:20 -0000 1.35
+++ httpclient/src/java/org/apache/commons/httpclient/Cookie.java 30 Jan 2003 20:54:18 -0000
@@ -178,7 +178,7 @@
* @see #setComment(String)
*/
public String getComment() {
- return _comment;
+ return cookieComment;
}
/**
@@ -188,7 +188,7 @@
* @see #getComment()
*/
public void setComment(String comment) {
- _comment = comment;
+ cookieComment = comment;
}
/**
@@ -203,7 +203,7 @@
*
*/
public Date getExpiryDate() {
- return _expiryDate;
+ return cookieExpiryDate;
}
/**
@@ -229,7 +229,7 @@
*
*/
public void setExpiryDate (Date expiryDate) {
- _expiryDate = expiryDate;
+ cookieExpiryDate = expiryDate;
}
@@ -241,7 +241,7 @@
* of the "session"; true otherwise
*/
public boolean isPersistent() {
- return (null != _expiryDate);
+ return (null != cookieExpiryDate);
}
@@ -251,7 +251,7 @@
* @see #setDomain(java.lang.String)
*/
public String getDomain() {
- return _domain;
+ return cookieDomain;
}
/**
@@ -272,7 +272,7 @@
if (ndx != -1) {
domain = domain.substring(0, ndx);
}
- _domain = domain.toLowerCase();
+ cookieDomain = domain.toLowerCase();
}
}
@@ -282,7 +282,7 @@
* @see #setPath(java.lang.String)
*/
public String getPath() {
- return _path;
+ return cookiePath;
}
/**
@@ -297,7 +297,7 @@
*
*/
public void setPath(String path) {
- _path = path;
+ cookiePath = path;
}
/**
@@ -305,7 +305,7 @@
* @see #setSecure(boolean)
*/
public boolean getSecure() {
- return _secure;
+ return isSecure;
}
/**
@@ -319,7 +319,7 @@
* @see #getSecure()
*/
public void setSecure (boolean secure) {
- _secure = secure;
+ isSecure = secure;
}
/**
@@ -330,7 +330,7 @@
*
*/
public int getVersion() {
- return _version;
+ return cookieVersion;
}
/**
@@ -343,7 +343,7 @@
*
*/
public void setVersion(int version) {
- _version = version;
+ cookieVersion = version;
}
/**
@@ -351,8 +351,8 @@
* @return true if I have expired.
*/
public boolean isExpired() {
- return (_expiryDate != null
- && _expiryDate.getTime() <= System.currentTimeMillis());
+ return (cookieExpiryDate != null
+ && cookieExpiryDate.getTime() <= System.currentTimeMillis());
}
/**
@@ -361,8 +361,8 @@
* @return true if I have expired.
*/
public boolean isExpired(Date now) {
- return (_expiryDate != null
- && _expiryDate.getTime() <= now.getTime());
+ return (cookieExpiryDate != null
+ && cookieExpiryDate.getTime() <= now.getTime());
}
@@ -378,7 +378,7 @@
* @param value True if the cookie's path came from a Path attribute.
*/
public void setPathAttributeSpecified(boolean value) {
- _hasPathAttribute = value;
+ hasPathAttribute = value;
}
/**
@@ -389,7 +389,7 @@
* @return True if cookie's path was specified in the set-cookie header.
*/
public boolean isPathAttributeSpecified() {
- return _hasPathAttribute;
+ return hasPathAttribute;
}
/**
@@ -404,7 +404,7 @@
* @param value True if the cookie's domain came from a Domain attribute.
*/
public void setDomainAttributeSpecified(boolean value) {
- _hasDomainAttribute = value;
+ hasDomainAttribute = value;
}
/**
@@ -415,7 +415,7 @@
* @return True if cookie's domain was specified in the set-cookie header.
*/
public boolean isDomainAttributeSpecified() {
- return _hasDomainAttribute;
+ return hasDomainAttribute;
}
/**
@@ -425,8 +425,8 @@
*/
public int hashCode() {
return super.hashCode()
- ^ (null == _path ? 0 : _path.hashCode())
- ^ (null == _domain ? 0 : _domain.hashCode());
+ ^ (null == cookiePath ? 0 : cookiePath.hashCode())
+ ^ (null == cookieDomain ? 0 : cookieDomain.hashCode());
}
@@ -809,34 +809,34 @@
// ----------------------------------------------------- Instance Variables
/** My comment. */
- private String _comment;
+ private String cookieComment;
/** My domain. */
- private String _domain;
+ private String cookieDomain;
/** My expiration {@link Date}. */
- private Date _expiryDate;
+ private Date cookieExpiryDate;
/** My path. */
- private String _path;
+ private String cookiePath;
/** My secure flag. */
- private boolean _secure;
+ private boolean isSecure;
/**
* Specifies if the set-cookie header included a Path attribute for this
* cookie
*/
- private boolean _hasPathAttribute = false;
+ private boolean hasPathAttribute = false;
/**
* Specifies if the set-cookie header included a Domain attribute for this
* cookie
*/
- private boolean _hasDomainAttribute = false;
+ private boolean hasDomainAttribute = false;
/** The version of the cookie specification I was created from. */
- private int _version = 0;
+ private int cookieVersion = 0;
// -------------------------------------------------------------- Constants
Index: httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java,v
retrieving revision 1.15
diff -u -r1.15 HeaderElement.java
--- httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java 30 Jan 2003 05:01:53 -0000 1.15
+++ httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java 30 Jan 2003 20:54:15 -0000
@@ -233,7 +233,7 @@
// ----------------------------------------------------- Instance Variables
/** My parameters, if any. */
- private NameValuePair[] _parameters = null;
+ private NameValuePair[] parameters = null;
// ------------------------------------------------------------- Properties
@@ -244,7 +244,7 @@
* @return parameters as an array of {@link NameValuePair}s
*/
public NameValuePair[] getParameters() {
- return this._parameters;
+ return this.parameters;
}
/**
@@ -252,7 +252,7 @@
* @param pairs The new parameters. May be null.
*/
protected void setParameters(final NameValuePair[] pairs) {
- _parameters = pairs;
+ parameters = pairs;
}
// --------------------------------------------------------- Public Methods
@@ -281,7 +281,7 @@
while (tokenizer.countTokens() > 0) {
String nextToken = tokenizer.nextToken();
- // FIXME: refactor into private method named ?
+ // TODO: refactor into private method named ?
// careful... there may have been a comma in a quoted string
try {
while (HeaderElement.hasOddNumberOfQuotationMarks(nextToken)) {
Index: httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
retrieving revision 1.38
diff -u -r1.38 HttpConnection.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java 28 Jan 2003 04:40:20 -0000 1.38
+++ httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java 30 Jan 2003 20:54:17 -0000
@@ -242,11 +242,11 @@
throw new IllegalArgumentException("protocol is null");
}
- _proxyHost = proxyHost;
- _proxyPort = proxyPort;
- _host = host;
- _port = protocol.resolvePort(port);
- _protocol = protocol;
+ proxyHostName = proxyHost;
+ proxyPortNumber = proxyPort;
+ hostName = host;
+ portNumber = protocol.resolvePort(port);
+ protocolInUse = protocol;
}
@@ -258,7 +258,7 @@
* @return my host.
*/
public String getHost() {
- return _host;
+ return hostName;
}
/**
@@ -272,7 +272,7 @@
throw new NullPointerException("host parameter is null");
}
assertNotOpen();
- _host = host;
+ hostName = host;
}
/**
@@ -284,10 +284,10 @@
* @return my port.
*/
public int getPort() {
- if (_port < 0) {
+ if (portNumber < 0) {
return isSecure() ? 443 : 80;
} else {
- return _port;
+ return portNumber;
}
}
@@ -299,7 +299,7 @@
*/
public void setPort(int port) throws IllegalStateException {
assertNotOpen();
- _port = port;
+ portNumber = port;
}
/**
@@ -308,7 +308,7 @@
* @return my proxy host.
*/
public String getProxyHost() {
- return _proxyHost;
+ return proxyHostName;
}
/**
@@ -319,7 +319,7 @@
*/
public void setProxyHost(String host) throws IllegalStateException {
assertNotOpen();
- _proxyHost = host;
+ proxyHostName = host;
}
/**
@@ -328,7 +328,7 @@
* @return my proxy port.
*/
public int getProxyPort() {
- return _proxyPort;
+ return proxyPortNumber;
}
/**
@@ -339,7 +339,7 @@
*/
public void setProxyPort(int port) throws IllegalStateException {
assertNotOpen();
- _proxyPort = port;
+ proxyPortNumber = port;
}
/**
@@ -350,7 +350,7 @@
* secure (HTTPS/SSL) protocol.
*/
public boolean isSecure() {
- return _protocol.isSecure();
+ return protocolInUse.isSecure();
}
/**
@@ -358,7 +358,7 @@
* @return HTTPS if secure, HTTP otherwise
*/
public Protocol getProtocol() {
- return _protocol;
+ return protocolInUse;
}
/**
@@ -373,7 +373,7 @@
*/
public void setSecure(boolean secure) throws IllegalStateException {
assertNotOpen();
- _protocol =
+ protocolInUse =
(secure
? Protocol.getProtocol("https")
: Protocol.getProtocol("http"));
@@ -391,7 +391,7 @@
throw new IllegalArgumentException("protocol is null");
}
- _protocol = protocol;
+ protocolInUse = protocol;
}
@@ -402,7 +402,7 @@
* @return true if I am connected
*/
public boolean isOpen() {
- return _open;
+ return isOpen;
}
/**
@@ -413,7 +413,7 @@
* connected via a proxy, false otherwise.
*/
public boolean isProxied() {
- return (!(null == _proxyHost || 0 >= _proxyPort));
+ return (!(null == proxyHostName || 0 >= proxyPortNumber));
}
/**
@@ -427,7 +427,7 @@
* @param inStream The stream associated with an HttpMethod.
*/
public void setLastResponseInputStream(InputStream inStream) {
- _lastResponseInput = inStream;
+ lastResponseInputStream = inStream;
}
/**
@@ -444,7 +444,7 @@
* response.
*/
public InputStream getLastResponseInputStream() {
- return _lastResponseInput;
+ return lastResponseInputStream;
}
// --------------------------------------------------- Other Public Methods
@@ -465,8 +465,8 @@
throws SocketException, IllegalStateException {
LOG.debug("HttpConnection.setSoTimeout(" + timeout + ")");
soTimeout = timeout;
- if (_socket != null) {
- _socket.setSoTimeout(timeout);
+ if (socket != null) {
+ socket.setSoTimeout(timeout);
}
}
@@ -492,21 +492,21 @@
assertNotOpen(); // ??? is this worth doing?
try {
- if (null == _socket) {
+ if (null == socket) {
- final String host = (null == _proxyHost) ? _host : _proxyHost;
- final int port = (null == _proxyHost) ? _port : _proxyPort;
+ final String host = (null == proxyHostName) ? hostName : proxyHostName;
+ final int port = (null == proxyHostName) ? portNumber : proxyPortNumber;
- _usingSecureSocket = isSecure() && !isProxied();
+ usingSecureSocket = isSecure() && !isProxied();
final ProtocolSocketFactory socketFactory =
(isSecure()
&& !isProxied()
- ? _protocol.getSocketFactory()
+ ? protocolInUse.getSocketFactory()
: new DefaultProtocolSocketFactory());
if (connectTimeout == 0) {
- _socket = socketFactory.createSocket(host, port);
+ socket = socketFactory.createSocket(host, port);
} else {
SocketTask task = new SocketTask() {
public void doit() throws IOException {
@@ -514,7 +514,7 @@
}
};
TimeoutController.execute(task, connectTimeout);
- _socket = task.getSocket();
+ socket = task.getSocket();
if (task.exception != null) {
throw task.exception;
}
@@ -530,11 +530,11 @@
situations. In such cases, nagling may be turned off through
use of the TCP_NODELAY sockets option." */
- _socket.setTcpNoDelay(soNodelay);
- _socket.setSoTimeout(soTimeout);
- _input = _socket.getInputStream();
- _output = _socket.getOutputStream();
- _open = true;
+ socket.setTcpNoDelay(soNodelay);
+ socket.setSoTimeout(soTimeout);
+ inputStream = socket.getInputStream();
+ outputStream = socket.getOutputStream();
+ isOpen = true;
} catch (IOException e) {
// Connection wasn't opened properly
// so close everything out
@@ -544,13 +544,13 @@
if (LOG.isWarnEnabled()) {
LOG.warn(
"The host "
- + _host
+ + hostName
+ ":"
- + _port
+ + portNumber
+ " (or proxy "
- + _proxyHost
+ + proxyHostName
+ ":"
- + _proxyPort
+ + proxyPortNumber
+ ") did not accept the connection "
+ "within timeout of "
+ connectTimeout
@@ -579,18 +579,18 @@
+ "and proxied to use this feature");
}
- if (_usingSecureSocket) {
+ if (usingSecureSocket) {
throw new IllegalStateException("Already using a secure socket");
}
SecureProtocolSocketFactory socketFactory =
- (SecureProtocolSocketFactory) _protocol.getSocketFactory();
+ (SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
- _socket = socketFactory.createSocket(_socket, _host, _port, true);
- _input = _socket.getInputStream();
- _output = _socket.getOutputStream();
- _usingSecureSocket = true;
- _tunnelEstablished = true;
+ socket = socketFactory.createSocket(socket, hostName, portNumber, true);
+ inputStream = socket.getInputStream();
+ outputStream = socket.getOutputStream();
+ usingSecureSocket = true;
+ tunnelEstablished = true;
LOG.debug("Secure tunnel created");
}
@@ -601,7 +601,7 @@
* proxy; false otherwise.
*/
public boolean isTransparent() {
- return !isProxied() || _tunnelEstablished;
+ return !isProxied() || tunnelEstablished;
}
/**
@@ -616,7 +616,7 @@
throws IOException, IllegalStateException {
LOG.trace("enter HttpConnection.getRequestOutputStream()");
assertOpen();
- return _output;
+ return outputStream;
}
/**
@@ -636,9 +636,9 @@
assertOpen();
if (useChunking) {
- return new ChunkedOutputStream(_output);
+ return new ChunkedOutputStream(outputStream);
} else {
- return _output;
+ return outputStream;
}
}
@@ -673,7 +673,7 @@
throws IOException, IllegalStateException {
LOG.trace("enter HttpConnection.getResponseInputStream()");
assertOpen();
- return _input;
+ return inputStream;
}
/**
@@ -732,7 +732,7 @@
WIRE_LOG.debug(">> \"" + dataString + "\" [\\r\\n]");
}
try {
- _output.write(data, offset, length);
+ outputStream.write(data, offset, length);
} catch (SocketException se) {
LOG.debug(
"HttpConnection: Socket exception while writing data",
@@ -763,7 +763,7 @@
WIRE_LOG.debug(">> \"" + dataString.trim() + "\" [\\r\\n]");
}
try {
- _output.write(data);
+ outputStream.write(data);
writeLine();
} catch (SocketException se) {
LOG.info("SocketException while writing data to output", se);
@@ -788,7 +788,7 @@
WIRE_LOG.debug(">> [\\r\\n]");
try {
- _output.write(CRLF);
+ outputStream.write(CRLF);
} catch (SocketException se) {
LOG.warn("HttpConnection: Socket exception while writing data", se);
throw new HttpRecoverableException(se.toString());
@@ -856,7 +856,7 @@
assertOpen();
StringBuffer buf = new StringBuffer();
while (true) {
- int ch = _input.read();
+ int ch = inputStream.read();
if (ch < 0) {
if (buf.length() == 0) {
return null;
@@ -890,9 +890,9 @@
// we're running in an older VM
Class[] paramsClasses = new Class[0];
Method shutdownOutput =
- _socket.getClass().getMethod("shutdownOutput", paramsClasses);
+ socket.getClass().getMethod("shutdownOutput", paramsClasses);
Object[] params = new Object[0];
- shutdownOutput.invoke(_socket, params);
+ shutdownOutput.invoke(socket, params);
} catch (Exception ex) {
LOG.debug("Unexpected Exception caught", ex);
// Ignore, and hope everything goes right
@@ -943,40 +943,40 @@
LOG.trace("enter HttpConnection.closeSockedAndStreams()");
// no longer care about previous responses...
- _lastResponseInput = null;
+ lastResponseInputStream = null;
- if (null != _input) {
+ if (null != inputStream) {
try {
- _input.close();
+ inputStream.close();
} catch (Exception ex) {
LOG.debug("Exception caught when closing input", ex);
// ignored
}
- _input = null;
+ inputStream = null;
}
- if (null != _output) {
+ if (null != outputStream) {
try {
- _output.close();
+ outputStream.close();
} catch (Exception ex) {
LOG.debug("Exception caught when closing output", ex);
// ignored
}
- _output = null;
+ outputStream = null;
}
- if (null != _socket) {
+ if (null != socket) {
try {
- _socket.close();
+ socket.close();
} catch (Exception ex) {
LOG.debug("Exception caught when closing socket", ex);
// ignored
}
- _socket = null;
+ socket = null;
}
- _open = false;
- _tunnelEstablished = false;
- _usingSecureSocket = false;
+ isOpen = false;
+ tunnelEstablished = false;
+ usingSecureSocket = false;
}
/**
@@ -985,7 +985,7 @@
* @throws IllegalStateException if connected
*/
protected void assertNotOpen() throws IllegalStateException {
- if (_open) {
+ if (isOpen) {
throw new IllegalStateException("Connection is open");
}
}
@@ -996,7 +996,7 @@
* @throws IllegalStateException if not connected
*/
protected void assertOpen() throws IllegalStateException {
- if (!_open) {
+ if (!isOpen) {
throw new IllegalStateException("Connection is not open");
}
}
@@ -1054,40 +1054,58 @@
/** Log object for this class. */
private static final Log LOG = LogFactory.getLog(HttpConnection.class);
+
/** Log for any wire messages. */
private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
+
/** My host. */
- private String _host = null;
+ private String hostName = null;
+
/** My port. */
- private int _port = -1;
+ private int portNumber = -1;
+
/** My proxy host. */
- private String _proxyHost = null;
+ private String proxyHostName = null;
+
/** My proxy port. */
- private int _proxyPort = -1;
+ private int proxyPortNumber = -1;
+
/** My client Socket. */
- private Socket _socket = null;
+ private Socket socket = null;
+
/** My InputStream. */
- private InputStream _input = null;
+ private InputStream inputStream = null;
+
/** My OutputStream. */
- private OutputStream _output = null;
+ private OutputStream outputStream = null;
+
/** An {@link InputStream} for the response to an individual request. */
- private InputStream _lastResponseInput = null;
+ private InputStream lastResponseInputStream = null;
+
/** Whether or not I am connected. */
- private boolean _open = false;
+ private boolean isOpen = false;
+
/** the protocol being used */
- private Protocol _protocol;
+ private Protocol protocolInUse;
+
/** "\r\n", as bytes. */
private static final byte[] CRLF = HttpConstants.getBytes("\r\n");
+
/** SO_TIMEOUT socket value */
private int soTimeout = 0;
+
/** TCP_NODELAY socket value */
private boolean soNodelay = true;
+
/** Whether or not the _socket is a secure one. Note the difference to _ssl */
- private boolean _usingSecureSocket = false;
+ private boolean usingSecureSocket = false;
+
/** Whether I am tunneling a proxy or not */
- private boolean _tunnelEstablished = false;
+ private boolean tunnelEstablished = false;
+
/** Timeout until connection established (Socket created). 0 means no timeout. */
private int connectTimeout = 0;
+
/** the connection manager that created this connection or null */
private HttpConnectionManager httpConnectionManager;
}
Index: httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.104
diff -u -r1.104 HttpMethodBase.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java 30 Jan 2003 05:01:53 -0000 1.104
+++ httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java 30 Jan 2003 20:54:15 -0000
@@ -302,7 +302,7 @@
parsedURI.getScheme()
);
}
- // else { FIXME: just in case, is not abolsute uri, then?
+ // else { TODO: just in case, is not abolsute uri, then?
// set the path, defaulting to root
setPath(
Index: httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java,v
retrieving revision 1.13
diff -u -r1.13 NameValuePair.java
--- httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java 30 Jan 2003 05:01:54 -0000 1.13
+++ httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java 30 Jan 2003 20:54:14 -0000
@@ -84,7 +84,7 @@
*
*/
public NameValuePair() {
- this (null,null);
+ this (null, null);
}
/**
Index: httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java,v
retrieving revision 1.18
diff -u -r1.18 RequestOutputStream.java
--- httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java 30 Jan 2003 05:01:54 -0000 1.18
+++ httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java 30 Jan 2003 20:54:19 -0000
@@ -221,7 +221,7 @@
*/
public void write(int b) throws IOException {
- //FIXME: If using chunking, the chunks are ONE byte long!
+ //TODO: If using chunking, the chunks are ONE byte long!
if (useChunking) {
stream.write(ONE, 0, ONE.length);
stream.write(CRLF, 0, CRLF.length);
Index: httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java,v
retrieving revision 1.9
diff -u -r1.9 SimpleHttpConnectionManager.java
--- httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 30 Jan 2003 05:01:54 -0000 1.9
+++ httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 30 Jan 2003 20:54:18 -0000
@@ -173,7 +173,7 @@
try {
lastResponse.close();
} catch (IOException ioe) {
- //FIXME: badness - close to force reconnect.
+ //TODO: badness - close to force reconnect.
conn.close();
}
}
Index: httpclient/src/java/org/apache/commons/httpclient/URI.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v
retrieving revision 1.30
diff -u -r1.30 URI.java
--- httpclient/src/java/org/apache/commons/httpclient/URI.java 30 Jan 2003 05:01:54 -0000 1.30
+++ httpclient/src/java/org/apache/commons/httpclient/URI.java 30 Jan 2003 20:54:16 -0000
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002-2003 the Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -64,6 +64,8 @@
package org.apache.commons.httpclient;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
@@ -150,7 +152,7 @@
// ----------------------------------------------------------- Constructors
-
+ /** Create an instance */
protected URI() {
}
@@ -160,10 +162,11 @@
* "http://test.com/" and <http://test.com/>
*
* @param escaped the URI character sequence
- * @exception URIException
+ * @throws URIException If the URI cannot be created.
* @throws NullPointerException if escaped is null
*/
- public URI(char[] escaped) throws URIException {
+ public URI(char[] escaped)
+ throws URIException, NullPointerException {
parseUriReference(new String(escaped), true);
}
@@ -178,7 +181,7 @@
*
* @param original the string to be represented to URI character sequence
* It is one of absoluteURI and relativeURI.
- * @exception URIException
+ * @throws URIException If the URI cannot be created.
*/
public URI(String original) throws URIException {
parseUriReference(original, false);
@@ -188,7 +191,7 @@
* Construct a URI from a URL.
*
* @param url a valid URL.
- * @throws URIException
+ * @throws URIException If the URI cannot be created.
* @since 2.0
*/
public URI(URL url) throws URIException {
@@ -207,11 +210,11 @@
* <fragment>.
*
* @param scheme the scheme string
- * @param scheme_specific_part scheme_specific_part
+ * @param schemeSpecificPart scheme_specific_part
* @param fragment the fragment string
- * @exception URIException
+ * @exception URIException If the URI cannot be created.
*/
- public URI(String scheme, String scheme_specific_part, String fragment)
+ public URI(String scheme, String schemeSpecificPart, String fragment)
throws URIException {
// validate and contruct the URI character sequence
@@ -224,7 +227,7 @@
} else {
throw new URIException(URIException.PARSING, "incorrect scheme");
}
- _opaque = encode(scheme_specific_part, allowed_opaque_part);
+ _opaque = encode(schemeSpecificPart, allowed_opaque_part);
// Set flag
_is_opaque_part = true;
_fragment = fragment.toCharArray();
@@ -351,9 +354,9 @@
public URI(String scheme, String userinfo, String host, int port,
String path, String query, String fragment) throws URIException {
- this(scheme, (host == null) ? null :
- ((userinfo != null) ? userinfo + '@' : "") + host +
- ((port != -1) ? ":" + port : ""), path, query, fragment);
+ this(scheme, (host == null) ? null
+ : ((userinfo != null) ? userinfo + '@' : "") + host
+ + ((port != -1) ? ":" + port : ""), path, query, fragment);
}
@@ -446,8 +449,8 @@
}
if (base._is_opaque_part || relative._is_opaque_part) {
this._scheme = base._scheme;
- this._is_opaque_part = base._is_opaque_part ||
- relative._is_opaque_part;
+ this._is_opaque_part = base._is_opaque_part
+ || relative._is_opaque_part;
this._opaque = relative._opaque;
this._fragment = relative._fragment;
this.setURI();
@@ -497,10 +500,8 @@
}
// resolve the path and query if necessary
if (relative._scheme == null && relative._authority == null) {
- if (
- ( relative._path == null || relative._path.length == 0 )
- && relative._query == null
- ) {
+ if ((relative._path == null || relative._path.length == 0)
+ && relative._query == null) {
// handle a reference to the current document, see RFC 2396
// section 5.2 step 2
this._path = base._path;
@@ -522,6 +523,7 @@
// --------------------------------------------------- Instance Variables
+ /** Version ID for serialization */
static final long serialVersionUID = 604752400577948726L;
@@ -557,7 +559,7 @@
// in order to support backward compatiblity
_documentCharset = LocaleToCharsetMap.getCharset(locale);
} else {
- _documentCharset = (String)AccessController.doPrivileged(
+ _documentCharset = (String) AccessController.doPrivileged(
new GetPropertyAction("file.encoding"));
}
}
@@ -645,7 +647,7 @@
protected static final BitSet digit = new BitSet(256);
// Static initializer for digit
static {
- for(int i = '0'; i <= '9'; i++) {
+ for (int i = '0'; i <= '9'; i++) {
digit.set(i);
}
}
@@ -694,10 +696,10 @@
// Static initializer for hex
static {
hex.or(digit);
- for(int i = 'a'; i <= 'f'; i++) {
+ for (int i = 'a'; i <= 'f'; i++) {
hex.set(i);
}
- for(int i = 'A'; i <= 'F'; i++) {
+ for (int i = 'A'; i <= 'F'; i++) {
hex.set(i);
}
}
@@ -1525,6 +1527,8 @@
// ------------------------------------------- Flags for this URI-reference
+ // TODO: Figure out what all these variables are for and provide javadoc
+
// URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
// absoluteURI = scheme ":" ( hier_part | opaque_part )
protected boolean _is_hier_part;
@@ -1680,7 +1684,9 @@
throws URIException {
// unescape uri characters to octets
- if (component == null) return null;
+ if (component == null) {
+ return null;
+ }
byte[] octets;
try {
@@ -1693,7 +1699,7 @@
int oi = 0; // output index
for (int ii = 0; ii < length; oi++) {
byte aByte = (byte) octets[ii++];
- if (aByte == '%' && ii+2 <= length) {
+ if (aByte == '%' && ii + 2 <= length) {
byte high = (byte) Character.digit((char) octets[ii++], 16);
byte low = (byte) Character.digit((char) octets[ii++], 16);
if (high == -1 || low == -1) {
@@ -1770,16 +1776,17 @@
* if -1, it means the length of the component
* @param generous those characters that are allowed within a component
* @return if true, it's the correct URI character sequence
- * @throws NullPointerException null component
*/
protected boolean validate(char[] component, int soffset, int eoffset,
BitSet generous) {
// validate each component by generous characters
if (eoffset == -1) {
- eoffset = component.length -1;
+ eoffset = component.length - 1;
}
for (int i = soffset; i <= eoffset; i++) {
- if (!generous.get(component[i])) return false;
+ if (!generous.get(component[i])) {
+ return false;
+ }
}
return true;
}
@@ -1813,8 +1820,7 @@
*
* @param original the original character sequence
* @param escaped true if original is escaped
- * @return the original character sequence
- * @exception URIException
+ * @exception URIException If an error occurs.
*/
protected void parseUriReference(String original, boolean escaped)
throws URIException {
@@ -1873,7 +1879,9 @@
*
*/ int at = indexFirstOf(tmp, isStartedFromPath ? "/?#" : ":/?#", from); - if (at == -1) at = 0; + if (at == -1) { + at = 0; + } /* * Parse the scheme. @@ -1910,8 +1918,8 @@ // the temporary index to start the search from int next = indexFirstOf(tmp, "/?#", at + 2); if (next == -1) { - next = (tmp.substring(at + 2).length() == 0) ? at + 2 : - tmp.length(); + next = (tmp.substring(at + 2).length() == 0) ? at + 2 + : tmp.length(); } parseAuthority(tmp.substring(at + 2, next), escaped); from = at = next; @@ -1940,14 +1948,14 @@ } if (!_is_abs_path) { if (!escaped && prevalidate(tmp.substring(from, next), - disallowed_rel_path) || escaped && - validate(tmp.substring(from, next).toCharArray(), + disallowed_rel_path) || escaped + && validate(tmp.substring(from, next).toCharArray(), rel_path)) { // Set flag _is_rel_path = true; } else if (!escaped && prevalidate(tmp.substring(from, next), - disallowed_opaque_part) || escaped && - validate(tmp.substring(from, next).toCharArray(), + disallowed_opaque_part) || escaped + && validate(tmp.substring(from, next).toCharArray(), opaque_part)) { // Set flag _is_opaque_part = true; @@ -1972,13 +1980,13 @@ * ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? *
*/
- if (0 <= at && at+1 < length && tmp.charAt(at) == '?') {
+ if (0 <= at && at + 1 < length && tmp.charAt(at) == '?') {
int next = tmp.indexOf('#', at + 1);
if (next == -1) {
next = tmp.length();
}
- _query = (escaped) ? tmp.substring(at + 1, next).toCharArray() :
- encode(tmp.substring(at + 1, next), allowed_query);
+ _query = (escaped) ? tmp.substring(at + 1, next).toCharArray()
+ : encode(tmp.substring(at + 1, next), allowed_query);
at = next;
}
@@ -1994,8 +2002,8 @@
if (at + 1 == length) { // empty fragment
_fragment = "".toCharArray();
} else {
- _fragment = (escaped) ? tmp.substring(at + 1).toCharArray() :
- encode(tmp.substring(at + 1), allowed_fragment);
+ _fragment = (escaped) ? tmp.substring(at + 1).toCharArray()
+ : encode(tmp.substring(at + 1), allowed_fragment);
}
}
@@ -2071,6 +2079,7 @@
*
* @param s the character array to be indexed
* @param delim the delimiter used to index
+ * @param offset The offset.
* @return the ealier index if there is a delimiter
*/
protected int indexFirstOf(char[] s, char delim, int offset) {
@@ -2097,7 +2106,7 @@
*
* @param original the original character sequence of authority component
* @param escaped true if original is escaped
- * @exception URIException
+ * @exception URIException If an error occurs.
*/
protected void parseAuthority(String original, boolean escaped)
throws URIException {
@@ -2106,13 +2115,13 @@
_is_reg_name = _is_server =
_is_hostname = _is_IPv4address = _is_IPv6reference = false;
- boolean has_port = true;
+ boolean hasPort = true;
int from = 0;
int next = original.indexOf('@');
if (next != -1) { // neither -1 and 0
// each protocol extented from URI supports the specific userinfo
- _userinfo = (escaped) ? original.substring(0, next).toCharArray() :
- encode(original.substring(0, next), allowed_userinfo);
+ _userinfo = (escaped) ? original.substring(0, next).toCharArray()
+ : encode(original.substring(0, next), allowed_userinfo);
from = next + 1;
}
next = original.indexOf('[', from);
@@ -2124,15 +2133,15 @@
next++;
}
// In IPv6reference, '[', ']' should be excluded
- _host = (escaped) ? original.substring(from, next).toCharArray() :
- encode(original.substring(from, next), allowed_IPv6reference);
+ _host = (escaped) ? original.substring(from, next).toCharArray()
+ : encode(original.substring(from, next), allowed_IPv6reference);
// Set flag
_is_IPv6reference = true;
} else { // only for !_is_IPv6reference
next = original.indexOf(':', from);
if (next == -1) {
next = original.length();
- has_port = false;
+ hasPort = false;
}
// REMINDME: it doesn't need the pre-validation
_host = original.substring(from, next).toCharArray();
@@ -2152,11 +2161,11 @@
_is_server = _is_hostname = _is_IPv4address =
_is_IPv6reference = false;
// set a registry-based naming authority
- _authority = (escaped) ? original.toString().toCharArray() :
- encode(original.toString(), allowed_reg_name);
+ _authority = (escaped) ? original.toString().toCharArray()
+ : encode(original.toString(), allowed_reg_name);
} else {
- if (original.length()-1 > next && has_port &&
- original.charAt(next) == ':') { // not empty
+ if (original.length() - 1 > next && hasPort
+ && original.charAt(next) == ':') { // not empty
from = next + 1;
try {
_port = Integer.parseInt(original.substring(from));
@@ -2441,7 +2450,9 @@
* @param charset the default charset for each protocol
* @throws CharsetChanged charset changed
*/
- public static void setProtocolCharset(String charset) {
+ public static void setProtocolCharset(String charset)
+ throws CharsetChanged {
+
_protocolCharset = charset;
throw new CharsetChanged(CharsetChanged.PROTOCOL_CHARSET,
"the default protocol charset changed");
@@ -2503,7 +2514,9 @@
* @param charset the default charset for the document
* @throws CharsetChanged charset changed
*/
- public static void setDocumentCharset(String charset) {
+ public static void setDocumentCharset(String charset)
+ throws CharsetChanged {
+
_documentCharset = charset;
throw new CharsetChanged(CharsetChanged.DOCUMENT_CHARSET,
"the default document charset changed");
@@ -2551,10 +2564,13 @@
*
* * @param escapedAuthority the raw escaped authority - * @exception URIException + * @exception URIException If {@link + * #parseAuthority(java.lang.String,boolean)} fails * @throws NullPointerException null authority */ - public void setRawAuthority(char[] escapedAuthority) throws URIException { + public void setRawAuthority(char[] escapedAuthority) + throws URIException, NullPointerException { + parseAuthority(new String(escapedAuthority), true); setURI(); } @@ -2566,7 +2582,8 @@ * Note that there is no setAuthority method by the escape encoding reason. * * @param escapedAuthority the escaped authority string - * @exception URIException + * @exception URIException If {@link + * #parseAuthority(java.lang.String,boolean)} fails */ public void setEscapedAuthority(String escapedAuthority) throws URIException { @@ -2600,8 +2617,7 @@ * Get the authority. * * @return the authority - * @exception URIException - * @see #decode + * @exception URIException If {@link #decode(char[])} fails */ public String getAuthority() throws URIException { return (_authority == null) ? null : decode(_authority); @@ -2635,8 +2651,7 @@ * Get the userinfo. * * @return the userinfo - * @exception URIException - * @see #decode + * @exception URIException If {@link #decode(char[])} fails * @see #getAuthority */ public String getUserinfo() throws URIException { @@ -2666,8 +2681,7 @@ *
* * @return the host - * @exception URIException - * @see #decode + * @exception URIException If {@link #decode(char[])} fails * @see #getAuthority */ public String getHost() throws URIException { @@ -2707,28 +2721,34 @@ // remove the fragment identifier escapedPath = removeFragmentIdentifier(escapedPath); if (_is_net_path || _is_abs_path) { - if (escapedPath[0] != '/') + if (escapedPath[0] != '/') { throw new URIException(URIException.PARSING, "not absolute path"); - if (!validate(escapedPath, abs_path)) + } + if (!validate(escapedPath, abs_path)) { throw new URIException(URIException.ESCAPING, "escaped absolute path not valid"); + } _path = escapedPath; } else if (_is_rel_path) { int at = indexFirstOf(escapedPath, '/'); - if (at == 0) + if (at == 0) { throw new URIException(URIException.PARSING, "incorrect path"); - if (at > 0 && !validate(escapedPath, 0, at - 1, rel_segment) && - !validate(escapedPath, at, -1, abs_path) || - at < 0 && !validate(escapedPath, 0, -1, rel_segment)) + } + if (at > 0 && !validate(escapedPath, 0, at - 1, rel_segment) + && !validate(escapedPath, at, -1, abs_path) + || at < 0 && !validate(escapedPath, 0, -1, rel_segment)) { + throw new URIException(URIException.ESCAPING, "escaped relative path not valid"); + } _path = escapedPath; } else if (_is_opaque_part) { - if (!uric_no_slash.get(escapedPath[0]) && - !validate(escapedPath, 1, -1, uric)) + if (!uric_no_slash.get(escapedPath[0]) + && !validate(escapedPath, 1, -1, uric)) { throw new URIException(URIException.ESCAPING, "escaped opaque part not valid"); + } _opaque = escapedPath; } else { throw new URIException(URIException.PARSING, "incorrect path"); @@ -2773,9 +2793,10 @@ } else if (_is_rel_path) { StringBuffer buff = new StringBuffer(path.length()); int at = path.indexOf('/'); - if (at == 0) // never 0 + if (at == 0) { // never 0 throw new URIException(URIException.PARSING, "incorrect relative path"); + } if (at > 0) { buff.append(encode(path.substring(0, at), allowed_rel_path)); buff.append(encode(path.substring(at), allowed_abs_path)); @@ -2798,31 +2819,31 @@ /** * Resolve the base and relative path. * - * @param base_path a character array of the base_path - * @param rel_path a character array of the rel_path + * @param basePath a character array of the basePath + * @param relPath a character array of the relPath * @return the resolved path * @exception URIException no more higher path level to be resolved */ - protected char[] resolvePath(char[] base_path, char[] rel_path) + protected char[] resolvePath(char[] basePath, char[] relPath) throws URIException { // REMINDME: paths are never null - String base = (base_path == null) ? "" : new String(base_path); + String base = (basePath == null) ? "" : new String(basePath); int at = base.lastIndexOf('/'); if (at != -1) { - base_path = base.substring(0, at + 1).toCharArray(); + basePath = base.substring(0, at + 1).toCharArray(); } // _path could be empty - if (rel_path == null || rel_path.length == 0) { - return normalize(base_path); - } else if (rel_path[0] == '/') { - return rel_path; + if (relPath == null || relPath.length == 0) { + return normalize(basePath); + } else if (relPath[0] == '/') { + return relPath; } else { - StringBuffer buff = new StringBuffer(base.length() + - rel_path.length); + StringBuffer buff = new StringBuffer(base.length() + + relPath.length); if (at != -1) { buff.append(base.substring(0, at + 1)); - buff.append(rel_path); + buff.append(relPath); } return normalize(buff.toString().toCharArray()); } @@ -2854,7 +2875,7 @@ } else if (first != last && last != -1) { return buff.substring(0, last).toCharArray(); } - // FIXME: it could be a document on the server side + // TODO: it could be a document on the server side return path; } @@ -2967,7 +2988,7 @@ * path = [ abs_path | opaque_part ] *
* @return the path string - * @exception URIException + * @exception URIException If {@link #decode(char[])} fails. * @see #decode */ public String getPath() throws URIException { @@ -2982,7 +3003,9 @@ * @return the raw-escaped basename */ public char[] getRawName() { - if (_path == null) return null; + if (_path == null) { + return null; + } int at = 0; for (int i = _path.length - 1; i >= 0; i--) { @@ -3086,9 +3109,10 @@ } // remove the fragment identifier escapedQuery = removeFragmentIdentifier(escapedQuery); - if (!validate(escapedQuery, query)) + if (!validate(escapedQuery, query)) { throw new URIException(URIException.ESCAPING, "escaped query not valid"); + } _query = escapedQuery; setURI(); } @@ -3183,9 +3207,10 @@ hash = 0; return; } - if (!validate(escapedFragment, fragment)) + if (!validate(escapedFragment, fragment)) { throw new URIException(URIException.ESCAPING, "escaped fragment not valid"); + } _fragment = escapedFragment; hash = 0; } @@ -3211,7 +3236,7 @@ * Set the fragment. * * @param fragment the fragment string. - * @exception URIException + * @exception URIException If an error occurs. */ public void setFragment(String fragment) throws URIException { if (fragment == null || fragment.length() == 0) { @@ -3275,7 +3300,9 @@ * @return the component that the fragment identifier is removed */ protected char[] removeFragmentIdentifier(char[] component) { - if (component == null) return null; + if (component == null) { + return null; + } int lastIndex = new String(component).indexOf('#'); if (lastIndex != -1) { component = new String(component).substring(0, @@ -3294,7 +3321,9 @@ */ protected char[] normalize(char[] path) throws URIException { - if (path == null) return null; + if (path == null) { + return null; + } String normalized = new String(path); boolean endsWithSlash = true; @@ -3312,15 +3341,15 @@ if (at == -1) { break; } - normalized = normalized.substring(0, at) + - normalized.substring(at + 2); + normalized = normalized.substring(0, at) + + normalized.substring(at + 2); } while (true) { // Resolve occurrences of "//" in the normalized path int at = normalized.indexOf("//"); if (at != -1) { - normalized = normalized.substring(0, at) + - normalized.substring(at+ 1); + normalized = normalized.substring(0, at) + + normalized.substring(at + 1); continue; } // Resolve occurrences of "/../" in the normalized path @@ -3331,7 +3360,7 @@ if (at == 0) { // no more higher path level to be normalized if (!endsWithSlash && normalized.endsWith("/")) { - normalized = normalized.substring(0, normalized.length()-1); + normalized = normalized.substring(0, normalized.length() - 1); } else if (endsWithSlash && !normalized.endsWith("/")) { normalized = normalized + "/"; } @@ -3342,12 +3371,12 @@ // consider the rel_path normalized = normalized.substring(at + 4); } else { - normalized = normalized.substring(0, backward) + - normalized.substring(at + 3); + normalized = normalized.substring(0, backward) + + normalized.substring(at + 3); } } if (!endsWithSlash && normalized.endsWith("/")) { - normalized = normalized.substring(0, normalized.length()-1); + normalized = normalized.substring(0, normalized.length() - 1); } else if (endsWithSlash && !normalized.endsWith("/")) { normalized = normalized + "/"; } @@ -3443,8 +3472,9 @@ * Write the content of this URI. * * @param oos the object-output stream + * @throws IOException If an IO problem occurs. */ - protected void writeObject(java.io.ObjectOutputStream oos) + protected void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); @@ -3455,8 +3485,11 @@ * Read a URI. * * @param ois the object-input stream + * @throws ClassNotFoundException If one of the classes specified in the + * input stream cannot be found. + * @throws IOException If an IO problem occurs. */ - protected void readObject(java.io.ObjectInputStream ois) + protected void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); @@ -3496,12 +3529,13 @@ * @return 0, if it's same, * -1, if failed, first being compared with in the authority component * @exception ClassCastException not URI argument - * @throws NullPointerException null object */ - public int compareTo(Object obj) { + public int compareTo(Object obj) throws ClassCastException { URI another = (URI) obj; - if (!equals(_authority, another.getRawAuthority())) return -1; + if (!equals(_authority, another.getRawAuthority())) { + return -1; + } return toString().compareTo(another.toString()); } @@ -3598,8 +3632,12 @@ * @return the URI reference character sequence */ public char[] getRawURIReference() { - if (_fragment == null) return _uri; - if (_uri == null) return _fragment; + if (_fragment == null) { + return _uri; + } + if (_uri == null) { + return _fragment; + } // if _uri != null && _fragment != null String uriReference = new String(_uri) + "#" + new String(_fragment); return uriReference.toCharArray(); @@ -3621,8 +3659,7 @@ * Get the original URI reference string. * * @return the original URI reference string - * @exception URIException - * @see #decode + * @throws URIException If {@link #decode(char[])} fails. */ public String getURIReference() throws URIException { char[] uriReference = getRawURIReference(); @@ -3657,6 +3694,10 @@ /** * The charset-changed normal operation to represent to be required to * alert to user the fact the default charset is changed. + * + * TODO: This should be renamed to CharsetChangedException and made a top + * level class. There is no reason (that I can see) to have this as an + * inner class. */ public static class CharsetChanged extends RuntimeException { @@ -3676,31 +3717,21 @@ // ---------------------------------------------------------- constants - /* - * No specified reason code. - */ + /** No specified reason code. */ public static final int UNKNOWN = 0; - /* - * Protocol charset changed. - */ + /** Protocol charset changed. */ public static final int PROTOCOL_CHARSET = 1; - /* - * Document charset changed. - */ + /** Document charset changed. */ public static final int DOCUMENT_CHARSET = 2; // ------------------------------------------------- instance variables - /* - * The reason code. - */ + /** The reason code. */ private int reasonCode; - /* - * The reason message. - */ + /** The reason message. */ private String reason; // ------------------------------------------------------------ methods @@ -3727,72 +3758,75 @@ /** - * A mapping to determine the (somewhat arbitrarily) preferred charset for - * a given locale. Supports all locales recognized in JDK 1.1. + * A mapping to determine the (somewhat arbitrarily) preferred charset for a + * given locale. Supports all locales recognized in JDK 1.1. *
* The distribution of this class is Servlets.com. It was originally * written by Jason Hunter [jhunter at acm.org] and used by with permission. */ public static class LocaleToCharsetMap { - private static Hashtable map; + /** A mapping of language code to charset */ + private static final Hashtable LOCALE_TO_CHARSET_MAP; static { - map = new Hashtable(); - map.put("ar", "ISO-8859-6"); - map.put("be", "ISO-8859-5"); - map.put("bg", "ISO-8859-5"); - map.put("ca", "ISO-8859-1"); - map.put("cs", "ISO-8859-2"); - map.put("da", "ISO-8859-1"); - map.put("de", "ISO-8859-1"); - map.put("el", "ISO-8859-7"); - map.put("en", "ISO-8859-1"); - map.put("es", "ISO-8859-1"); - map.put("et", "ISO-8859-1"); - map.put("fi", "ISO-8859-1"); - map.put("fr", "ISO-8859-1"); - map.put("hr", "ISO-8859-2"); - map.put("hu", "ISO-8859-2"); - map.put("is", "ISO-8859-1"); - map.put("it", "ISO-8859-1"); - map.put("iw", "ISO-8859-8"); - map.put("ja", "Shift_JIS"); - map.put("ko", "EUC-KR"); - map.put("lt", "ISO-8859-2"); - map.put("lv", "ISO-8859-2"); - map.put("mk", "ISO-8859-5"); - map.put("nl", "ISO-8859-1"); - map.put("no", "ISO-8859-1"); - map.put("pl", "ISO-8859-2"); - map.put("pt", "ISO-8859-1"); - map.put("ro", "ISO-8859-2"); - map.put("ru", "ISO-8859-5"); - map.put("sh", "ISO-8859-5"); - map.put("sk", "ISO-8859-2"); - map.put("sl", "ISO-8859-2"); - map.put("sq", "ISO-8859-2"); - map.put("sr", "ISO-8859-5"); - map.put("sv", "ISO-8859-1"); - map.put("tr", "ISO-8859-9"); - map.put("uk", "ISO-8859-5"); - map.put("zh", "GB2312"); - map.put("zh_TW", "Big5"); + LOCALE_TO_CHARSET_MAP = new Hashtable(); + LOCALE_TO_CHARSET_MAP.put("ar", "ISO-8859-6"); + LOCALE_TO_CHARSET_MAP.put("be", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("bg", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("ca", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("cs", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("da", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("de", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("el", "ISO-8859-7"); + LOCALE_TO_CHARSET_MAP.put("en", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("es", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("et", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("fi", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("fr", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("hr", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("hu", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("is", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("it", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("iw", "ISO-8859-8"); + LOCALE_TO_CHARSET_MAP.put("ja", "Shift_JIS"); + LOCALE_TO_CHARSET_MAP.put("ko", "EUC-KR"); + LOCALE_TO_CHARSET_MAP.put("lt", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("lv", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("mk", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("nl", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("no", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("pl", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("pt", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("ro", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("ru", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("sh", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("sk", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("sl", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("sq", "ISO-8859-2"); + LOCALE_TO_CHARSET_MAP.put("sr", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("sv", "ISO-8859-1"); + LOCALE_TO_CHARSET_MAP.put("tr", "ISO-8859-9"); + LOCALE_TO_CHARSET_MAP.put("uk", "ISO-8859-5"); + LOCALE_TO_CHARSET_MAP.put("zh", "GB2312"); + LOCALE_TO_CHARSET_MAP.put("zh_TW", "Big5"); } /** * Get the preferred charset for the given locale. * * @param locale the locale - * @return the preferred charset - * or null if the locale is not recognized + * @return the preferred charset or null if the locale is not + * recognized. */ public static String getCharset(Locale locale) { // try for an full name match (may include country) - String charset = (String) map.get(locale.toString()); - if (charset != null) return charset; + String charset = (String) LOCALE_TO_CHARSET_MAP.get(locale.toString()); + if (charset != null) { + return charset; + } // if a full name didn't match, try just the language - charset = (String) map.get(locale.getLanguage()); + charset = (String) LOCALE_TO_CHARSET_MAP.get(locale.getLanguage()); return charset; // may be null } Index: httpclient/src/java/org/apache/commons/httpclient/URIException.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIException.java,v retrieving revision 1.7 diff -u -r1.7 URIException.java --- httpclient/src/java/org/apache/commons/httpclient/URIException.java 30 Jan 2003 05:01:54 -0000 1.7 +++ httpclient/src/java/org/apache/commons/httpclient/URIException.java 30 Jan 2003 20:54:16 -0000 @@ -7,7 +7,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 2002-2003 the Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: httpclient/src/java/org/apache/commons/httpclient/UsernamePasswordCredentials.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/UsernamePasswordCredentials.java,v retrieving revision 1.10 diff -u -r1.10 UsernamePasswordCredentials.java --- httpclient/src/java/org/apache/commons/httpclient/UsernamePasswordCredentials.java 28 Jan 2003 04:40:21 -0000 1.10 +++ httpclient/src/java/org/apache/commons/httpclient/UsernamePasswordCredentials.java 30 Jan 2003 20:54:18 -0000 @@ -68,6 +68,7 @@ * * @author Remy Maucherat * @author Sean C. Sullivan + * @author Mike Bowler * * @version $Revision: 1.10 $ $Date: 2003/01/28 04:40:21 $ * @@ -86,16 +87,16 @@ /** * The constructor with the username and password combined string argument. * - * @param UsernamePassword the username:password formed string + * @param usernamePassword the username:password formed string * @see #toString */ - public UsernamePasswordCredentials(String UsernamePassword) { - int atColon = UsernamePassword.indexOf(':'); + public UsernamePasswordCredentials(String usernamePassword) { + int atColon = usernamePassword.indexOf(':'); if (atColon >= 0) { - this.userName = UsernamePassword.substring(0, atColon); - this.password = UsernamePassword.substring(atColon+1); + this.userName = usernamePassword.substring(0, atColon); + this.password = usernamePassword.substring(atColon + 1); } else { - this.userName = UsernamePassword; + this.userName = usernamePassword; } } Index: httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v retrieving revision 1.7 diff -u -r1.7 WireLogInputStream.java --- httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java 28 Jan 2003 04:40:21 -0000 1.7 +++ httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java 30 Jan 2003 20:54:17 -0000 @@ -63,40 +63,62 @@ package org.apache.commons.httpclient; -import java.io.*; -import org.apache.commons.logging.*; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Logs all data read to the wire LOG. * * @author Ortwin Glück + * @author Mike Bowler * * @since 2.0 */ class WireLogInputStream extends FilterInputStream { /** Log for any wire messages. */ - private static final Log wireLog = LogFactory.getLog("httpclient.wire"); + private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire"); + /** + * Create an instance that wraps the specified input stream. + * @param in The input stream. + */ public WireLogInputStream(InputStream in) { super(in); } - public int read(byte[] b, int off, int len) throws java.io.IOException { + /** + * + * @see java.io.InputStream#read(byte[], int, int) + */ + public int read(byte[] b, int off, int len) throws IOException { int l = super.read(b, off, len); - wireLog.debug("<< "+ new String(b, off, len)); + WIRE_LOG.debug("<< " + new String(b, off, len)); return l; } - public int read() throws java.io.IOException { + /** + * + * @see java.io.InputStream#read() + */ + public int read() throws IOException { int l = super.read(); - if (l > 0) wireLog.debug("<< "+ (char) l); + if (l > 0) { + WIRE_LOG.debug("<< " + (char) l); + } return l; } - public int read(byte[] b) throws java.io.IOException { + /** + * + * @see java.io.InputStream#read(byte[]) + */ + public int read(byte[] b) throws IOException { int l = super.read(b); - wireLog.debug("<< "+ HttpConstants.getString(b)); + WIRE_LOG.debug("<< " + HttpConstants.getString(b)); return l; } } Index: httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v retrieving revision 1.11 diff -u -r1.11 RFC2109Spec.java --- httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 30 Jan 2003 05:01:55 -0000 1.11 +++ httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 30 Jan 2003 20:54:20 -0000 @@ -177,7 +177,7 @@ } // host minus domain may not contain any dots String hostWithoutDomain = host.substring(0, host.length() - - cookie.getDomain().length()); + - cookie.getDomain().length()); if (hostWithoutDomain.indexOf('.') != -1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() Index: httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v retrieving revision 1.15 diff -u -r1.15 HeadMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java 28 Jan 2003 22:25:25 -0000 1.15 +++ httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java 30 Jan 2003 20:54:20 -0000 @@ -66,7 +66,6 @@ import java.io.IOException; import org.apache.commons.httpclient.HttpConnection; -import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpState; import org.apache.commons.logging.Log; @@ -140,12 +139,11 @@ * @param conn the http connection to read from * * @throws IOException when there's an error reading data - * @throws HttpException never FIXME * * @since 2.0 */ protected void readResponseBody(HttpState state, HttpConnection conn) - throws IOException, HttpException { + throws IOException { LOG.trace( "enter HeadMethod.readResponseBody(HttpState, HttpConnection)"); Index: httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java,v retrieving revision 1.12 diff -u -r1.12 UrlPutMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java 30 Jan 2003 05:01:56 -0000 1.12 +++ httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java 30 Jan 2003 20:54:21 -0000 @@ -78,6 +78,7 @@ */ public class UrlPutMethod extends PutMethod implements HttpUrlMethod { // ----------------------------------------------------- Instance Variables + /** The URL */ private String url; /** Index: httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java,v retrieving revision 1.4 diff -u -r1.4 DefaultProtocolSocketFactory.java --- httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java 30 Jan 2003 05:01:56 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java 30 Jan 2003 20:54:20 -0000 @@ -29,7 +29,7 @@ * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. Index: httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java,v retrieving revision 1.4 diff -u -r1.4 Protocol.java --- httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java 30 Jan 2003 05:01:56 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java 30 Jan 2003 20:54:20 -0000 @@ -29,7 +29,7 @@ * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. Index: httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java,v retrieving revision 1.4 diff -u -r1.4 ProtocolSocketFactory.java --- httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java 30 Jan 2003 05:01:56 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java 30 Jan 2003 20:54:20 -0000 @@ -29,7 +29,7 @@ * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. Index: httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java,v retrieving revision 1.4 diff -u -r1.4 SSLProtocolSocketFactory.java --- httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java 30 Jan 2003 05:01:56 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java 30 Jan 2003 20:54:20 -0000 @@ -29,7 +29,7 @@ * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. Index: httpclient/src/java/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.java,v retrieving revision 1.3 diff -u -r1.3 SecureProtocolSocketFactory.java --- httpclient/src/java/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.java 30 Jan 2003 05:01:56 -0000 1.3 +++ httpclient/src/java/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.java 30 Jan 2003 20:54:20 -0000 @@ -29,7 +29,7 @@ * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. Index: httpclient/src/java/org/apache/commons/httpclient/util/Base64.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/Base64.java,v retrieving revision 1.4 diff -u -r1.4 Base64.java --- httpclient/src/java/org/apache/commons/httpclient/util/Base64.java 30 Jan 2003 05:01:57 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/util/Base64.java 30 Jan 2003 20:54:19 -0000 @@ -68,84 +68,120 @@ /** *
Base64 encoder and decoder.
*- * This class provides encoding/decoding methods for - * the Base64 encoding as defined by RFC 2045, - * N. Freed and N. Borenstein. - * RFC 2045: Multipurpose Internet Mail Extensions (MIME) - * Part One: Format of Internet Message Bodies. Reference - * 1996. Available at: - * + * This class provides encoding/decoding methods for the Base64 encoding as + * defined by RFC 2045, N. Freed and N. Borenstein. RFC 2045: Multipurpose + * Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. + * Reference 1996. Available at: * http://www.ietf.org/rfc/rfc2045.txt *
* * @author Jeffrey Rodriguez + * @author Mike Bowler * @version $Revision: 1.4 $ $Date: 2003/01/30 05:01:57 $ * */ public final class Base64 { - private static final int BASELENGTH = 255; - private static final int LOOKUPLENGTH = 64; + + /** */ + private static final int BASELENGTH = 255; + + /** */ + private static final int LOOKUPLENGTH = 64; + + /** */ private static final int TWENTYFOURBITGROUP = 24; - private static final int EIGHTBIT = 8; - private static final int SIXTEENBIT = 16; - private static final int SIXBIT = 6; - private static final int FOURBYTE = 4; - private static final int SIGN = -128; - private static final byte PAD = (byte) '='; - private static byte [] base64Alphabet = new byte[BASELENGTH]; - private static byte [] lookUpBase64Alphabet = new byte[LOOKUPLENGTH]; + + /** */ + private static final int EIGHTBIT = 8; + + /** */ + private static final int SIXTEENBIT = 16; + + /** */ + private static final int SIXBIT = 6; + + /** */ + private static final int FOURBYTE = 4; + + /** The sign bit as an int */ + private static final int SIGN = -128; + + /** The padding character */ + private static final byte PAD = (byte) '='; + + /** The alphabet */ + private static final byte [] BASE64_ALPHABET = new byte[BASELENGTH]; + + /** The lookup alphabet */ + private static final byte [] LOOKUP_BASE64_ALPHABET = new byte[LOOKUPLENGTH]; static { for (int i = 0; i < BASELENGTH; i++) { - base64Alphabet[i] = -1; + BASE64_ALPHABET[i] = -1; } for (int i = 'Z'; i >= 'A'; i--) { - base64Alphabet[i] = (byte) (i - 'A'); + BASE64_ALPHABET[i] = (byte) (i - 'A'); } for (int i = 'z'; i >= 'a'; i--) { - base64Alphabet[i] = (byte) (i - 'a' + 26); + BASE64_ALPHABET[i] = (byte) (i - 'a' + 26); } for (int i = '9'; i >= '0'; i--) { - base64Alphabet[i] = (byte) (i - '0' + 52); + BASE64_ALPHABET[i] = (byte) (i - '0' + 52); } - base64Alphabet['+'] = 62; - base64Alphabet['/'] = 63; + BASE64_ALPHABET['+'] = 62; + BASE64_ALPHABET['/'] = 63; for (int i = 0; i <= 25; i++) { - lookUpBase64Alphabet[i] = (byte) ('A' + i); + LOOKUP_BASE64_ALPHABET[i] = (byte) ('A' + i); } for (int i = 26, j = 0; i <= 51; i++, j++) { - lookUpBase64Alphabet[i] = (byte) ('a' + j); + LOOKUP_BASE64_ALPHABET[i] = (byte) ('a' + j); } for (int i = 52, j = 0; i <= 61; i++, j++) { - lookUpBase64Alphabet[i] = (byte) ('0' + j); + LOOKUP_BASE64_ALPHABET[i] = (byte) ('0' + j); } - lookUpBase64Alphabet[62] = (byte) '+'; - lookUpBase64Alphabet[63] = (byte) '/'; + LOOKUP_BASE64_ALPHABET[62] = (byte) '+'; + LOOKUP_BASE64_ALPHABET[63] = (byte) '/'; } - private Base64() - { - // the constructor is intentionally private - } - + /** + * Create an instance. + */ + private Base64() { + // the constructor is intentionally private + } + + /** + * Return true if the specified string is base64 encoded. + * @param isValidString The string to test. + * @return boolean True if the string is base64. + */ public static boolean isBase64(String isValidString) { return isArrayByteBase64(HttpConstants.getAsciiBytes(isValidString)); } + /** + * Return true if the specified octect is base64 + * @param octect The octet to test. + * @return boolean True if the octect is base64. + */ static boolean isBase64(byte octect) { // Should we ignore white space? - return (octect == PAD || base64Alphabet[octect] != -1); + return (octect == PAD || BASE64_ALPHABET[octect] != -1); } - + /** + * Return true if the specified byte array is base64 + * @param arrayOctect The array to test. + * @return boolean true if the specified byte array is base64 + */ public static boolean isArrayByteBase64(byte[] arrayOctect) { int length = arrayOctect.length; if (length == 0) { @@ -198,20 +234,20 @@ k = (byte) (b1 & 0x03); encodedIndex = i * 4; - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : - (byte) ((b1) >> 2 ^ 0xc0); + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) + : (byte) ((b1) >> 2 ^ 0xc0); - byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : - (byte) ((b2) >> 4 ^ 0xf0); - byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : - (byte) ((b3) >> 6 ^ 0xfc); + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) + : (byte) ((b2) >> 4 ^ 0xf0); + byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) + : (byte) ((b3) >> 6 ^ 0xfc); - encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 + encodedData[encodedIndex] = LOOKUP_BASE64_ALPHABET[val1]; + encodedData[encodedIndex + 1] = LOOKUP_BASE64_ALPHABET[val2 | (k << 4)]; - encodedData[encodedIndex + 2] = lookUpBase64Alphabet[(l << 2) + encodedData[encodedIndex + 2] = LOOKUP_BASE64_ALPHABET[(l << 2) | val3]; - encodedData[encodedIndex + 3] = lookUpBase64Alphabet[b3 & 0x3f]; + encodedData[encodedIndex + 3] = LOOKUP_BASE64_ALPHABET[b3 & 0x3f]; } // form integral number of 6-bit groups @@ -220,10 +256,10 @@ if (fewerThan24bits == EIGHTBIT) { b1 = binaryData[dataIndex]; k = (byte) (b1 & 0x03); - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : - (byte) ((b1) >> 2 ^ 0xc0); - encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4]; + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) + : (byte) ((b1) >> 2 ^ 0xc0); + encodedData[encodedIndex] = LOOKUP_BASE64_ALPHABET[val1]; + encodedData[encodedIndex + 1] = LOOKUP_BASE64_ALPHABET[k << 4]; encodedData[encodedIndex + 2] = PAD; encodedData[encodedIndex + 3] = PAD; } else if (fewerThan24bits == SIXTEENBIT) { @@ -232,15 +268,15 @@ l = (byte) (b2 & 0x0f); k = (byte) (b1 & 0x03); - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : - (byte) ((b1) >> 2 ^ 0xc0); - byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : - (byte) ((b2) >> 4 ^ 0xf0); - - encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 | - (k << 4)]; - encodedData[encodedIndex + 2] = lookUpBase64Alphabet[l << 2]; + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) + : (byte) ((b1) >> 2 ^ 0xc0); + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) + : (byte) ((b2) >> 4 ^ 0xf0); + + encodedData[encodedIndex] = LOOKUP_BASE64_ALPHABET[val1]; + encodedData[encodedIndex + 1] = LOOKUP_BASE64_ALPHABET[val2 + | (k << 4)]; + encodedData[encodedIndex + 2] = LOOKUP_BASE64_ALPHABET[l << 2]; encodedData[encodedIndex + 3] = PAD; } return encodedData; @@ -282,12 +318,12 @@ marker0 = base64Data[dataIndex + 2]; marker1 = base64Data[dataIndex + 3]; - b1 = base64Alphabet[base64Data[dataIndex]]; - b2 = base64Alphabet[base64Data[dataIndex + 1]]; + b1 = BASE64_ALPHABET[base64Data[dataIndex]]; + b2 = BASE64_ALPHABET[base64Data[dataIndex + 1]]; if (marker0 != PAD && marker1 != PAD) { //No PAD e.g 3cQl - b3 = base64Alphabet[marker0]; - b4 = base64Alphabet[marker1]; + b3 = BASE64_ALPHABET[marker0]; + b4 = BASE64_ALPHABET[marker1]; decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex + 1] = (byte) (((b2 & 0xf) << 4) @@ -296,7 +332,7 @@ } else if (marker0 == PAD) { //Two PAD e.g. 3c[Pad][Pad] decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4) ; } else if (marker1 == PAD) { //One PAD e.g. 3cQ[Pad] - b3 = base64Alphabet[marker0]; + b3 = BASE64_ALPHABET[marker0]; decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex + 1] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); @@ -305,5 +341,4 @@ } return decodedData; } - } Index: httpclient/src/java/org/apache/commons/httpclient/util/HttpURLConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/HttpURLConnection.java,v retrieving revision 1.10 diff -u -r1.10 HttpURLConnection.java --- httpclient/src/java/org/apache/commons/httpclient/util/HttpURLConnection.java 30 Jan 2003 05:01:57 -0000 1.10 +++ httpclient/src/java/org/apache/commons/httpclient/util/HttpURLConnection.java 30 Jan 2003 20:54:20 -0000 @@ -91,6 +91,7 @@ * * @author Vincent Massol * @author Jeff Dever + * @author Mike Bowler * * @since 2.0 * @@ -101,7 +102,7 @@ // -------------------------------------------------------- Class Variables /** Log object for this class. */ - private static final Log log = LogFactory.getLog(HttpURLConnection.class); + private static final Log LOG = LogFactory.getLog(HttpURLConnection.class); // ----------------------------------------------------- Instance Variables @@ -122,8 +123,7 @@ // ----------------------------------------------------------- Constructors /** - * Creates anHttpURLConnection from a
- * HttpMethod.
+ * Creates an HttpURLConnection from a HttpMethod.
*
* @param method the theMethod that was used to connect to the HTTP
* server and which contains the returned data.
@@ -136,6 +136,8 @@
}
/**
+ * Create an instance.
+ * @param url The URL.
* @see java.net.HttpURLConnection#HttpURLConnection(URL)
*/
protected HttpURLConnection(URL url) {
@@ -147,21 +149,25 @@
// --------------------------------------------------------- Public Methods
- /** Gets an input stream for the HttpMethod response body.
+ /**
+ * Gets an input stream for the HttpMethod response body.
+ * @throws IOException If an IO problem occurs.
+ * @return The input stream.
* @see java.net.HttpURLConnection#getInputStream()
* @see org.apache.commons.httpclient.HttpMethod#getResponseBodyAsStream()
*/
public InputStream getInputStream() throws IOException {
- log.trace("enter HttpURLConnection.getInputStream()");
+ LOG.trace("enter HttpURLConnection.getInputStream()");
return this.method.getResponseBodyAsStream();
}
/**
* Not yet implemented.
+ * Return the error stream.
* @see java.net.HttpURLConnection#getErrorStream()
*/
public InputStream getErrorStream() {
- log.trace("enter HttpURLConnection.getErrorStream()");
+ LOG.trace("enter HttpURLConnection.getErrorStream()");
throw new RuntimeException("Not implemented yet");
}
@@ -170,62 +176,75 @@
* @see java.net.HttpURLConnection#disconnect()
*/
public void disconnect() {
- log.trace("enter HttpURLConnection.disconnect()");
+ LOG.trace("enter HttpURLConnection.disconnect()");
throw new RuntimeException("Not implemented yet");
}
/**
* Not available: the data must have already been retrieved.
+ * @throws IOException If an IO problem occurs.
* @see java.net.HttpURLConnection#connect()
*/
public void connect() throws IOException {
- log.trace("enter HttpURLConnection.connect()");
+ LOG.trace("enter HttpURLConnection.connect()");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
/**
* Not yet implemented.
+ * @return true if we are using a proxy.
* @see java.net.HttpURLConnection#usingProxy()
*/
public boolean usingProxy() {
- log.trace("enter HttpURLConnection.usingProxy()");
+ LOG.trace("enter HttpURLConnection.usingProxy()");
throw new RuntimeException("Not implemented yet");
}
/**
+ * Return the request method.
+ * @return The request method.
* @see java.net.HttpURLConnection#getRequestMethod()
* @see org.apache.commons.httpclient.HttpMethod#getName()
*/
public String getRequestMethod() {
- log.trace("enter HttpURLConnection.getRequestMethod()");
+ LOG.trace("enter HttpURLConnection.getRequestMethod()");
return this.method.getName();
}
/**
+ * Return the response code.
+ * @return The response code.
+ * @throws IOException If an IO problem occurs.
* @see java.net.HttpURLConnection#getResponseCode()
* @see org.apache.commons.httpclient.HttpMethod#getStatusCode()
*/
public int getResponseCode() throws IOException {
- log.trace("enter HttpURLConnection.getResponseCode()");
+ LOG.trace("enter HttpURLConnection.getResponseCode()");
return this.method.getStatusCode();
}
/**
+ * Return the response message
+ * @return The response message
+ * @throws IOException If an IO problem occurs.
* @see java.net.HttpURLConnection#getResponseMessage()
* @see org.apache.commons.httpclient.HttpMethod#getStatusText()
*/
public String getResponseMessage() throws IOException {
- log.trace("enter HttpURLConnection.getResponseMessage()");
+ LOG.trace("enter HttpURLConnection.getResponseMessage()");
return this.method.getStatusText();
}
/**
+ * Return the header field
+ * @param name the name of the header
+ * @return the header field.
* @see java.net.HttpURLConnection#getHeaderField(String)
* @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
*/
public String getHeaderField(String name) {
- log.trace("enter HttpURLConnection.getHeaderField(String)");
+ LOG.trace("enter HttpURLConnection.getHeaderField(String)");
// Note: Return the last matching header in the Header[] array, as in
// the JDK implementation.
Header[] headers = this.method.getResponseHeaders();
@@ -239,11 +258,14 @@
}
/**
+ * Return the header field key
+ * @param keyPosition The key position
+ * @return The header field key.
* @see java.net.HttpURLConnection#getHeaderFieldKey(int)
* @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
*/
public String getHeaderFieldKey(int keyPosition) {
- log.trace("enter HttpURLConnection.getHeaderFieldKey(int)");
+ LOG.trace("enter HttpURLConnection.getHeaderFieldKey(int)");
// Note: HttpClient does not consider the returned Status Line as
// a response header. However, getHeaderFieldKey(0) is supposed to
@@ -265,11 +287,14 @@
}
/**
+ * Return the header field at the specified position
+ * @param position The position
+ * @return The header field.
* @see java.net.HttpURLConnection#getHeaderField(int)
* @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
*/
public String getHeaderField(int position) {
- log.trace("enter HttpURLConnection.getHeaderField(int)");
+ LOG.trace("enter HttpURLConnection.getHeaderField(int)");
// Note: HttpClient does not consider the returned Status Line as
// a response header. However, getHeaderField(0) is supposed to
@@ -291,10 +316,12 @@
}
/**
+ * Return the URL
+ * @return The URL.
* @see java.net.HttpURLConnection#getURL()
*/
public URL getURL() {
- log.trace("enter HttpURLConnection.getURL()");
+ LOG.trace("enter HttpURLConnection.getURL()");
return this.url;
}
@@ -316,7 +343,7 @@
* @see java.net.HttpURLConnection#setInstanceFollowRedirects(boolean)
*/
public void setInstanceFollowRedirects(boolean isFollowingRedirects) {
- log.trace("enter HttpURLConnection.setInstanceFollowRedirects(boolean)");
+ LOG.trace("enter HttpURLConnection.setInstanceFollowRedirects(boolean)");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -326,7 +353,7 @@
* @see java.net.HttpURLConnection#getInstanceFollowRedirects()
*/
public boolean getInstanceFollowRedirects() {
- log.trace("enter HttpURLConnection.getInstanceFollowRedirects()");
+ LOG.trace("enter HttpURLConnection.getInstanceFollowRedirects()");
throw new RuntimeException("Not implemented yet");
}
@@ -335,7 +362,7 @@
* @see java.net.HttpURLConnection#setRequestMethod(String)
*/
public void setRequestMethod(String method) throws ProtocolException {
- log.trace("enter HttpURLConnection.setRequestMethod(String)");
+ LOG.trace("enter HttpURLConnection.setRequestMethod(String)");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -345,7 +372,7 @@
* @see java.net.HttpURLConnection#getPermission()
*/
public Permission getPermission() throws IOException {
- log.trace("enter HttpURLConnection.getPermission()");
+ LOG.trace("enter HttpURLConnection.getPermission()");
throw new RuntimeException("Not implemented yet");
}
@@ -354,7 +381,7 @@
* @see java.net.HttpURLConnection#getContent()
*/
public Object getContent() throws IOException {
- log.trace("enter HttpURLConnection.getContent()");
+ LOG.trace("enter HttpURLConnection.getContent()");
throw new RuntimeException("Not implemented yet");
}
@@ -363,7 +390,7 @@
* @see java.net.HttpURLConnection#getContent(Class[])
*/
public Object getContent(Class[] classes) throws IOException {
- log.trace("enter HttpURLConnection.getContent(Class[])");
+ LOG.trace("enter HttpURLConnection.getContent(Class[])");
throw new RuntimeException("Not implemented yet");
}
@@ -371,7 +398,7 @@
* @see java.net.HttpURLConnection#getOutputStream()
*/
public OutputStream getOutputStream() throws IOException {
- log.trace("enter HttpURLConnection.getOutputStream()");
+ LOG.trace("enter HttpURLConnection.getOutputStream()");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -381,7 +408,7 @@
* @see java.net.HttpURLConnection#setDoInput(boolean)
*/
public void setDoInput(boolean isInput) {
- log.trace("enter HttpURLConnection.setDoInput()");
+ LOG.trace("enter HttpURLConnection.setDoInput()");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -391,7 +418,7 @@
* @see java.net.HttpURLConnection#getDoInput()
*/
public boolean getDoInput() {
- log.trace("enter HttpURLConnection.getDoInput()");
+ LOG.trace("enter HttpURLConnection.getDoInput()");
throw new RuntimeException("Not implemented yet");
}
@@ -400,7 +427,7 @@
* @see java.net.HttpURLConnection#setDoOutput(boolean)
*/
public void setDoOutput(boolean isOutput) {
- log.trace("enter HttpURLConnection.setDoOutput()");
+ LOG.trace("enter HttpURLConnection.setDoOutput()");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -410,7 +437,7 @@
* @see java.net.HttpURLConnection#getDoOutput()
*/
public boolean getDoOutput() {
- log.trace("enter HttpURLConnection.getDoOutput()");
+ LOG.trace("enter HttpURLConnection.getDoOutput()");
throw new RuntimeException("Not implemented yet");
}
@@ -419,7 +446,7 @@
* @see java.net.HttpURLConnection#setAllowUserInteraction(boolean)
*/
public void setAllowUserInteraction(boolean isAllowInteraction) {
- log.trace("enter HttpURLConnection.setAllowUserInteraction(boolean)");
+ LOG.trace("enter HttpURLConnection.setAllowUserInteraction(boolean)");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -429,7 +456,7 @@
* @see java.net.HttpURLConnection#getAllowUserInteraction()
*/
public boolean getAllowUserInteraction() {
- log.trace("enter HttpURLConnection.getAllowUserInteraction()");
+ LOG.trace("enter HttpURLConnection.getAllowUserInteraction()");
throw new RuntimeException("Not implemented yet");
}
@@ -438,7 +465,7 @@
* @see java.net.HttpURLConnection#setUseCaches(boolean)
*/
public void setUseCaches(boolean isUsingCaches) {
- log.trace("enter HttpURLConnection.setUseCaches(boolean)");
+ LOG.trace("enter HttpURLConnection.setUseCaches(boolean)");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -448,7 +475,7 @@
* @see java.net.HttpURLConnection#getUseCaches()
*/
public boolean getUseCaches() {
- log.trace("enter HttpURLConnection.getUseCaches()");
+ LOG.trace("enter HttpURLConnection.getUseCaches()");
throw new RuntimeException("Not implemented yet");
}
@@ -457,7 +484,7 @@
* @see java.net.HttpURLConnection#setIfModifiedSince(long)
*/
public void setIfModifiedSince(long modificationDate) {
- log.trace("enter HttpURLConnection.setIfModifiedSince(long)");
+ LOG.trace("enter HttpURLConnection.setIfModifiedSince(long)");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -467,7 +494,7 @@
* @see java.net.HttpURLConnection#getIfModifiedSince()
*/
public long getIfModifiedSince() {
- log.trace("enter HttpURLConnection.getIfmodifiedSince()");
+ LOG.trace("enter HttpURLConnection.getIfmodifiedSince()");
throw new RuntimeException("Not implemented yet");
}
@@ -476,7 +503,7 @@
* @see java.net.HttpURLConnection#getDefaultUseCaches()
*/
public boolean getDefaultUseCaches() {
- log.trace("enter HttpURLConnection.getDefaultUseCaches()");
+ LOG.trace("enter HttpURLConnection.getDefaultUseCaches()");
throw new RuntimeException("Not implemented yet");
}
@@ -485,7 +512,7 @@
* @see java.net.HttpURLConnection#setDefaultUseCaches(boolean)
*/
public void setDefaultUseCaches(boolean isUsingCaches) {
- log.trace("enter HttpURLConnection.setDefaultUseCaches(boolean)");
+ LOG.trace("enter HttpURLConnection.setDefaultUseCaches(boolean)");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -495,7 +522,7 @@
* @see java.net.HttpURLConnection#setRequestProperty(String,String)
*/
public void setRequestProperty(String key, String value) {
- log.trace("enter HttpURLConnection.setRequestProperty()");
+ LOG.trace("enter HttpURLConnection.setRequestProperty()");
throw new RuntimeException("This class can only be used with already"
+ "retrieved data");
}
@@ -505,7 +532,7 @@
* @see java.net.HttpURLConnection#getRequestProperty(String)
*/
public String getRequestProperty(String key) {
- log.trace("enter HttpURLConnection.getRequestProperty()");
+ LOG.trace("enter HttpURLConnection.getRequestProperty()");
throw new RuntimeException("Not implemented yet");
}
Index: httpclient/src/java/org/apache/commons/httpclient/util/TimeoutController.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/TimeoutController.java,v
retrieving revision 1.3
diff -u -r1.3 TimeoutController.java
--- httpclient/src/java/org/apache/commons/httpclient/util/TimeoutController.java 30 Jan 2003 05:01:57 -0000 1.3
+++ httpclient/src/java/org/apache/commons/httpclient/util/TimeoutController.java 30 Jan 2003 20:54:19 -0000
@@ -68,6 +68,7 @@
* Executes a task with a specified timeout.
*
* @author Ortwin Glück
+ * @author Mike Bowler
* @version $Revision: 1.3 $
* @since 2.0
*/
@@ -94,7 +95,7 @@
task.start();
try {
task.join(timeout);
- } catch(InterruptedException e) {
+ } catch (InterruptedException e) {
/* if somebody interrupts us he knows what he is doing */
}
if (task.isAlive()) {
@@ -119,6 +120,7 @@
* Signals that the task timed out.
*/
public static class TimeoutException extends Exception {
+ /** Create an instance */
public TimeoutException() {
}
}
Index: httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v
retrieving revision 1.16
diff -u -r1.16 URIUtil.java
--- httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java 30 Jan 2003 05:01:57 -0000 1.16
+++ httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java 30 Jan 2003 20:54:19 -0000
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002-2003 the Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -69,11 +69,12 @@
import org.apache.commons.httpclient.URIException;
/**
- * The URI escape and character encoding and decoding utility.
- * It's compatible with {@link org.apache.commons.httpclient.HttpURL} rather
- * than {@link org.apache.commons.httpclient.URI}.
+ * The URI escape and character encoding and decoding utility. It's compatible
+ * with {@link org.apache.commons.httpclient.HttpURL} rather than {@link
+ * org.apache.commons.httpclient.URI}.
*
* @author Sung-Gu
+ * @author Mike Bowler
* @version $Revision: 1.16 $ $Date: 2002/03/14 15:14:01
*/
@@ -81,6 +82,7 @@
// ----------------------------------------------------- Instance variables
+ /** An empty bitset */
protected static final BitSet empty = new BitSet(1);
// ---------------------------------------------------------- URI utilities
@@ -92,7 +94,9 @@
* @return the basename string; an empty string if the path ends with slash
*/
public static String getName(String uri) {
- if (uri == null || uri.length() == 0) return uri;
+ if (uri == null || uri.length() == 0) {
+ return uri;
+ }
String path = URIUtil.getPath(uri);
int at = path.lastIndexOf("/");
int to = path.length();
@@ -107,21 +111,26 @@
* @return the query string; null if empty or undefined
*/
public static String getQuery(String uri) {
- if (uri == null || uri.length() == 0) return null;
+ if (uri == null || uri.length() == 0) {
+ return null;
+ }
// consider of net_path
int at = uri.indexOf("//");
- int from = uri.indexOf("/", at >= 0 ?
- (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
+ int from = uri.indexOf("/", at >= 0
+ ? (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
// the authority part of URI ignored
int to = uri.length();
// reuse the at and from variables to consider the query
at = uri.indexOf("?", from);
if (at >= 0) {
from = at + 1;
- } else return null;
+ } else {
+ return null;
+ }
// check the fragment
- if (uri.lastIndexOf("#") > from)
+ if (uri.lastIndexOf("#") > from) {
to = uri.lastIndexOf("#");
+ }
// get the path and query.
return (from < 0 || from == to) ? null : uri.substring(from, to);
}
@@ -134,19 +143,23 @@
* @return the path string
*/
public static String getPath(String uri) {
- if (uri == null) return null;
+ if (uri == null) {
+ return null;
+ }
// consider of net_path
int at = uri.indexOf("//");
- int from = uri.indexOf("/", at >= 0 ?
- (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
+ int from = uri.indexOf("/", at >= 0
+ ? (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
// the authority part of URI ignored
int to = uri.length();
// check the query
- if (uri.indexOf('?', from) != -1)
+ if (uri.indexOf('?', from) != -1) {
to = uri.indexOf('?', from);
+ }
// check the fragment
- if (uri.lastIndexOf("#") > from && uri.lastIndexOf("#") < to)
+ if (uri.lastIndexOf("#") > from && uri.lastIndexOf("#") < to) {
to = uri.lastIndexOf("#");
+ }
// get only the path.
return (from < 0) ? (at >= 0 ? "/" : uri) : uri.substring(from, to);
}
@@ -159,17 +172,20 @@
* @return the path and query string
*/
public static String getPathQuery(String uri) {
- if (uri == null) return null;
+ if (uri == null) {
+ return null;
+ }
// consider of net_path
int at = uri.indexOf("//");
- int from = uri.indexOf("/", at >= 0 ?
- (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
+ int from = uri.indexOf("/", at >= 0
+ ? (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
// the authority part of URI ignored
int to = uri.length();
// Ignore the '?' mark so to ignore the query.
// check the fragment
- if (uri.lastIndexOf("#") > from)
+ if (uri.lastIndexOf("#") > from) {
to = uri.lastIndexOf("#");
+ }
// get the path and query.
return (from < 0) ? (at >= 0 ? "/" : uri) : uri.substring(from, to);
}
@@ -182,11 +198,13 @@
* @return the string from the path part
*/
public static String getFromPath(String uri) {
- if (uri == null) return null;
+ if (uri == null) {
+ return null;
+ }
// consider of net_path
int at = uri.indexOf("//");
- int from = uri.indexOf("/", at >= 0 ?
- (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
+ int from = uri.indexOf("/", at >= 0
+ ? (uri.lastIndexOf("/", at - 1) >= 0 ? 0 : at + 2) : 0);
// get the path and its rest.
return (from < 0) ? (at >= 0 ? "/" : uri) : uri.substring(from);
}
@@ -200,7 +218,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see #encode
*/
@@ -217,7 +235,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodeAll(String unescaped, String charset)
@@ -235,7 +253,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see #encode
*/
@@ -255,7 +273,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodeWithinAuthority(String unescaped, String charset)
@@ -271,7 +289,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see #encode
*/
@@ -287,7 +305,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodePathQuery(String unescaped, String charset)
@@ -313,7 +331,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see #encode
*/
@@ -334,7 +352,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodeWithinPath(String unescaped, String charset)
@@ -350,7 +368,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see #encode
*/
@@ -366,7 +384,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodePath(String unescaped, String charset)
@@ -385,7 +403,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see #encode
*/
@@ -406,7 +424,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodeWithinQuery(String unescaped, String charset)
@@ -425,9 +443,7 @@
*
* @param unescaped an unescaped string
* @return the escaped string
- * @exception URIException
- * @see URI#getProtocolCharset
- * @see #encode
+ * @throws URIException If the string cannot be encoded.
*/
public static String encodeQuery(String unescaped) throws URIException {
return encodeQuery(unescaped, URI.getProtocolCharset());
@@ -444,7 +460,7 @@
* @param unescaped an unescaped string
* @param charset the charset
* @return the escaped string
- * @exception URIException
+ * @throws URIException If the string cannot be encoded.
* @see #encode
*/
public static String encodeQuery(String unescaped, String charset)
@@ -461,7 +477,7 @@
* @param unescaped a string
* @param allowed allowed characters not to be escaped
* @return the escaped string
- * @exception URIException
+ * @exception URIException If the string cannot be encoded.
* @see URI#getProtocolCharset
* @see Coder#encode
*/
@@ -480,8 +496,8 @@
* @param allowed allowed characters not to be escaped
* @param charset the charset
* @return the escaped string
- * @exception URIException
- * @see Coder#encode
+ * @exception URIException If {@link
+ * Coder#encode(java.lang.String,java.util.BitSet,java.lang.String)} fails
*/
public static String encode(String unescaped, BitSet allowed,
String charset) throws URIException {
@@ -496,7 +512,8 @@
*
* @param escaped a string
* @return the unescaped string
- * @exception URIException
+ * @exception URIException If {@link Coder#decode(char[],java.lang.String)}
+ * fails
* @see URI#getProtocolCharset
* @see Coder#decode
*/
@@ -511,8 +528,8 @@
* @param escaped a string
* @param charset the charset
* @return the unescaped string
- * @exception URIException
- * @see Coder#decode
+ * @exception URIException If {@link
+ * Coder#decode(java.lang.String,java.lang.String)} fails.
*/
public static String decode(String escaped, String charset)
throws URIException {
@@ -528,7 +545,7 @@
*
* @param target a target string
* @return the protocol character encoded string
- * @exception URIException
+ * @throws URIException If the encoding is not supported.
* @see URI#getProtocolCharset
*/
public static String toProtocolCharset(String target) throws URIException {
@@ -544,7 +561,7 @@
* @param target a target string
* @param charset the transformed protocol charset
* @return the protocol character encoded string
- * @exception URIException
+ * @throws URIException If the encoding is not supported.
*/
public static String toProtocolCharset(String target, String charset)
throws URIException {
@@ -559,7 +576,7 @@
*
* @param target a target string
* @return the document character encoded string
- * @exception URIException
+ * @throws URIException If the encoding is not supported.
* @see URI#getDocumentCharset
*/
public static String toDocumentCharset(String target) throws URIException {
@@ -575,7 +592,7 @@
* @param target a target string
* @param charset the transformed document charset
* @return the document character encoded string
- * @exception URIException
+ * @throws URIException If the encoding is not supported.
*/
public static String toDocumentCharset(String target, String charset)
throws URIException {
@@ -585,8 +602,8 @@
/**
- * Convert a target string from the fromCharset charset to
- * the toCharset charset.
+ * Convert a target string from the fromCharset charset to the
+ * toCharset charset.
* * What if the document charset is ISO-8859-1 and the protocol charset is * UTF-8, when it's read from the document part and is used in the protocol @@ -597,7 +614,7 @@ * @param fromCharset the previous charset * @param toCharset the changing charset * @return the document character encoded string - * @exception URIException + * @throws URIException If the encoding is not supported. */ public static String toUsingCharset(String target, String fromCharset, @@ -626,7 +643,9 @@ * @param unescapedComponent an unescaped component * @param allowed allowed characters not to be escaped * @param charset the charset to encode - * @exception URIException + * @exception URIException If {@link + * URI#encode(java.lang.String,java.util.BitSet,java.lang.String)} + * fails. * @return the escaped and encoded string */ public static char[] encode(String unescapedComponent, BitSet allowed, @@ -641,7 +660,8 @@ * * @param escapedComponent an being-unescaped component * @param charset the charset to decode - * @exception URIException + * @exception URIException If {@link + * URI#decode(char[],java.lang.String)} fails. * @return the escaped and encoded string */ public static String decode(char[] escapedComponent, String charset) @@ -663,9 +683,10 @@ if (c > 128) { return false; } else if (c == '%') { - if (Character.digit(original[++i], 16) == -1 || - Character.digit(original[++i], 16) == -1) + if (Character.digit(original[++i], 16) == -1 + || Character.digit(original[++i], 16) == -1) { return false; + } } } return true;