You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/12/29 22:39:41 UTC
svn commit: r491110 [1/2] - in
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni:
internal/net/www/ internal/net/www/protocol/file/
internal/net/www/protocol/ftp/ internal/net/www/protocol/http/
internal/net/www/protoc...
Author: tellison
Date: Fri Dec 29 13:39:40 2006
New Revision: 491110
URL: http://svn.apache.org/viewvc?view=rev&rev=491110
Log:
Clean-up compiler warnings, externalize messages, annotations, removing tabs of www.protocol packages.
No function change.
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/Handler.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java Fri Dec 29 13:39:40 2006
@@ -17,7 +17,6 @@
package org.apache.harmony.luni.internal.net.www;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.FileNameMap;
@@ -35,63 +34,69 @@
public class MimeTable implements FileNameMap {
- public static final String UNKNOWN = "content/unknown"; //$NON-NLS-1$
+ public static final String UNKNOWN = "content/unknown"; //$NON-NLS-1$
- /**
- * A hash table containing the mapping between extensions and mime types.
- */
- public static final Properties types = new Properties();
-
- // Default mapping.
- static {
- types.put("text", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
- types.put("txt", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
- types.put("htm", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
- types.put("html", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Contructs a MIME table using the default values defined in this class.
- * <p>
- * It then augments this table by reading pairs of extensions and matching
- * content types from the file "types.properties", which is represented in
- * standard java.util.Properties.load(...) format.
- */
- public MimeTable() {
- InputStream str = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
- public InputStream run() {
- return MimeTable.this.getClass().getResourceAsStream(
- "types.properties"); //$NON-NLS-1$
- }
- });
-
- try {
- if (str != null)
- types.load(str);
- } catch (IOException ex) {
- }
- }
-
- /**
- * Determines the MIME type for the given filename.
- *
- * @return java.lang.String The mime type associated with the file's
- * extension or null if no mapping is known.
- * @param filename
- * java.lang.String The file whose extension will be mapped.
- */
- public String getContentTypeFor(String filename) {
- if (filename.endsWith("/")) //$NON-NLS-1$
- // a directory, return html
- return (String) types.get("html"); //$NON-NLS-1$
- int lastCharInExtension = filename.lastIndexOf('#');
- if (lastCharInExtension < 0)
- lastCharInExtension = filename.length();
- int firstCharInExtension = filename.lastIndexOf('.') + 1;
- String ext = ""; //$NON-NLS-1$
- if (firstCharInExtension > filename.lastIndexOf('/'))
- ext = filename.substring(firstCharInExtension, lastCharInExtension);
- return (String) types.get(ext.toLowerCase());
- }
+ /**
+ * A hash table containing the mapping between extensions and mime types.
+ */
+ public static final Properties types = new Properties();
+
+ // Default mapping.
+ static {
+ types.put("text", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
+ types.put("txt", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
+ types.put("htm", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
+ types.put("html", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Contructs a MIME table using the default values defined in this class.
+ * <p>
+ * It then augments this table by reading pairs of extensions and matching
+ * content types from the file "types.properties", which is represented in
+ * standard java.util.Properties.load(...) format.
+ */
+ public MimeTable() {
+ InputStream str = AccessController
+ .doPrivileged(new PrivilegedAction<InputStream>() {
+ public InputStream run() {
+ return MimeTable.this.getClass().getResourceAsStream(
+ "types.properties"); //$NON-NLS-1$
+ }
+ });
+
+ try {
+ if (str != null) {
+ types.load(str);
+ }
+ } catch (IOException ex) {
+ // Ignored
+ }
+ }
+
+ /**
+ * Determines the MIME type for the given filename.
+ *
+ * @return java.lang.String The mime type associated with the file's
+ * extension or null if no mapping is known.
+ * @param filename
+ * java.lang.String The file whose extension will be mapped.
+ */
+ public String getContentTypeFor(String filename) {
+ if (filename.endsWith("/")) { //$NON-NLS-1$
+ // a directory, return html
+ return (String) types.get("html"); //$NON-NLS-1$
+ }
+ int lastCharInExtension = filename.lastIndexOf('#');
+ if (lastCharInExtension < 0) {
+ lastCharInExtension = filename.length();
+ }
+ int firstCharInExtension = filename.lastIndexOf('.') + 1;
+ String ext = ""; //$NON-NLS-1$
+ if (firstCharInExtension > filename.lastIndexOf('/')) {
+ ext = filename.substring(firstCharInExtension, lastCharInExtension);
+ }
+ return (String) types.get(ext.toLowerCase());
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java Fri Dec 29 13:39:40 2006
@@ -58,16 +58,16 @@
*/
public FileURLConnection(URL url) {
super(url);
- fileName = url.getFile();
- if (url.getRef() != null) {
- fileName += "#" + url.getRef();
- }
- if (fileName == null) {
- fileName = "";
+ fileName = url.getFile();
+ if (url.getRef() != null) {
+ fileName += "#" + url.getRef(); //$NON-NLS-1$
+ }
+ if (fileName == null) {
+ fileName = ""; //$NON-NLS-1$
}
String host = url.getHost();
if (host != null && host.length() > 0) {
- fileName = "//" + host + fileName;
+ fileName = "//" + host + fileName; //$NON-NLS-1$
}
fileName = Util.decode(fileName, false);
}
@@ -77,7 +77,8 @@
* by this <code>URL</code>. If the file is a directory, it will return
* that directory listing as an input stream.
*
- * @throws IOException if an IO error occurs while connecting
+ * @throws IOException
+ * if an IO error occurs while connecting
*/
@Override
public void connect() throws IOException {
@@ -128,7 +129,7 @@
return MimeTable.UNKNOWN;
}
if (isDir) {
- return "text/html";
+ return "text/html"; //$NON-NLS-1$
}
String result = guessContentTypeFromName(url.getFile());
if (result == null) {
@@ -146,12 +147,13 @@
String fileList[] = f.list();
ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
PrintStream out = new PrintStream(bytes);
- out.print("<title>Directory Listing</title>\n");
- out.print("<base href=\"file:");
- out.print(f.getPath().replace('\\', '/') + "/\"><h1>" + f.getPath() + "</h1>\n<hr>\n");
+ out.print("<title>Directory Listing</title>\n"); //$NON-NLS-1$
+ out.print("<base href=\"file:"); //$NON-NLS-1$
+ out.print(f.getPath().replace('\\', '/') + "/\"><h1>" + f.getPath() //$NON-NLS-1$
+ + "</h1>\n<hr>\n"); //$NON-NLS-1$
int i;
for (i = 0; i < fileList.length; i++) {
- out.print(fileList[i] + "<br>\n");
+ out.print(fileList[i] + "<br>\n"); //$NON-NLS-1$
}
out.close();
return new ByteArrayInputStream(bytes.toByteArray());
@@ -168,7 +170,8 @@
*
* @return input stream of the object
*
- * @throws IOException if an IO error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
@Override
public InputStream getInputStream() throws IOException {
@@ -185,8 +188,8 @@
*
* @return the permission required for this URLConnection.
*
- * @throws IOException if an IO exception occurs while creating the
- * permission.
+ * @throws IOException
+ * if an IO exception occurs while creating the permission.
*/
@Override
public java.security.Permission getPermission() throws IOException {
@@ -195,7 +198,7 @@
if (File.separatorChar != '/') {
path = path.replace('/', File.separatorChar);
}
- permission = new FilePermission(path, "read");
+ permission = new FilePermission(path, "read"); //$NON-NLS-1$
}
return permission;
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java Fri Dec 29 13:39:40 2006
@@ -36,7 +36,8 @@
* the file system
*
* @return A connection to the resource pointed by this url.
- * @param url URL The URL to which the connection is pointing to
+ * @param url
+ * URL The URL to which the connection is pointing to
*
*/
@Override
@@ -48,20 +49,25 @@
* The behaviour of this method is the same as openConnection(URL).
* <code>proxy</code> is not used in FileURLConnection.
*
- * @param u the URL which the connection is pointing to
- * @param proxy Proxy
+ * @param u
+ * the URL which the connection is pointing to
+ * @param proxy
+ * Proxy
* @return a connection to the resource pointed by this url.
*
- * @throws IOException if this handler fails to establish a connection.
- * @throws IllegalArgumentException if any argument is null or of an invalid
- * type.
- * @throws UnsupportedOperationException if the protocol handler doesn't
- * support this method.
+ * @throws IOException
+ * if this handler fails to establish a connection.
+ * @throws IllegalArgumentException
+ * if any argument is null or of an invalid type.
+ * @throws UnsupportedOperationException
+ * if the protocol handler doesn't support this method.
*/
@Override
- public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
+ public URLConnection openConnection(URL url, Proxy proxy)
+ throws IOException {
if (null == url || null == proxy) {
- throw new IllegalArgumentException(Msg.getString("K034b"));
+ // K034b=url and proxy can not be null
+ throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
}
return new FileURLConnection(url);
}
@@ -71,10 +77,14 @@
* already have the context properties. The string generally have the
* following format: <code><center>/c:/windows/win.ini</center></code>.
*
- * @param u The URL object that's parsed into
- * @param str The string equivalent of the specification URL
- * @param start The index in the spec string from which to begin parsing
- * @param end The index to stop parsing
+ * @param u
+ * The URL object that's parsed into
+ * @param str
+ * The string equivalent of the specification URL
+ * @param start
+ * The index in the spec string from which to begin parsing
+ * @param end
+ * The index to stop parsing
*
* @see java.net.URLStreamHandler#toExternalForm(URL)
* @see java.net.URL
@@ -84,7 +94,7 @@
if (end < start) {
return;
}
- String parseString = "";
+ String parseString = ""; //$NON-NLS-1$
if (start < end) {
parseString = str.substring(start, end).replace('\\', '/');
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java Fri Dec 29 13:39:40 2006
@@ -86,9 +86,9 @@
private int dataPort;
- private String username = "anonymous";
+ private String username = "anonymous"; //$NON-NLS-1$
- private String password = "";
+ private String password = ""; //$NON-NLS-1$
private String replyCode;
@@ -145,14 +145,14 @@
if (idx > 0) {
String dir = url.getFile().substring(0, idx);
- write("CWD " + dir + "\r\n");
+ write("CWD " + dir + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
int reply = getReply();
if (reply != FTP_FILEOK && dir.length() > 0 && dir.charAt(0) == '/') {
- write("CWD " + dir.substring(1) + "\r\n");
+ write("CWD " + dir.substring(1) + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
reply = getReply();
}
if (reply != FTP_FILEOK) {
- throw new IOException(Msg.getString("K0094"));
+ throw new IOException(Msg.getString("K0094")); //$NON-NLS-1$
}
}
}
@@ -192,12 +192,13 @@
// If connect failed, callback "connectFailed"
// should be invoked.
if (null != selector && Proxy.NO_PROXY != currentProxy) {
- selector.connectFailed(uri, currentProxy.address(), ioe);
+ selector
+ .connectFailed(uri, currentProxy.address(), ioe);
}
}
}
if (!connectOK) {
- throw new IOException(Msg.getString("K0097"));
+ throw new IOException(Msg.getString("K0097")); //$NON-NLS-1$
}
}
}
@@ -243,11 +244,11 @@
dataSocket.setSoTimeout(getReadTimeout());
acceptSocket.close();
} catch (InterruptedIOException e) {
- throw new IOException(Msg.getString("K0095"));
+ throw new IOException(Msg.getString("K0095")); //$NON-NLS-1$
}
if (getDoInput()) {
- inputStream = new FtpURLInputStream(new BufferedInputStream(dataSocket
- .getInputStream()), controlSocket);
+ inputStream = new FtpURLInputStream(new BufferedInputStream(
+ dataSocket.getInputStream()), controlSocket);
}
}
@@ -268,14 +269,14 @@
private void getFile() throws IOException {
int reply;
String file = url.getFile();
- write("RETR " + file + "\r\n");
+ write("RETR " + file + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
reply = getReply();
if (reply == FTP_NOTFOUND && file.length() > 0 && file.charAt(0) == '/') {
- write("RETR " + file.substring(1) + "\r\n");
+ write("RETR " + file.substring(1) + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
reply = getReply();
}
if (!(reply == FTP_OPENDATA || reply == FTP_TRANSFEROK)) {
- throw new FileNotFoundException(Msg.getString("K0096", reply));
+ throw new FileNotFoundException(Msg.getString("K0096", reply)); //$NON-NLS-1$
}
}
@@ -283,7 +284,8 @@
* Creates a input stream for writing to this URL Connection.
*
* @return The input stream to write to
- * @throws IOException Cannot read from URL or error creating InputStream
+ * @throws IOException
+ * Cannot read from URL or error creating InputStream
*
* @see #getContent()
* @see #getOutputStream()
@@ -305,8 +307,9 @@
* action list.
*
* @return the permission object required for this connection
- * @throws IOException thrown when an IO exception occurs during the
- * creation of the permission object.
+ * @throws IOException
+ * thrown when an IO exception occurs during the creation of the
+ * permission object.
*/
@Override
public Permission getPermission() throws IOException {
@@ -314,14 +317,15 @@
if (port <= 0) {
port = FTP_PORT;
}
- return new SocketPermission(hostName + ":" + port, "connect, resolve");
+ return new SocketPermission(hostName + ":" + port, "connect, resolve"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Creates a output stream for writing to this URL Connection.
*
* @return The output stream to write to
- * @throws IOException when the OutputStream could not be created
+ * @throws IOException
+ * when the OutputStream could not be created
*
* @see #getContent()
* @see #getInputStream()
@@ -340,7 +344,7 @@
private int getReply() throws IOException {
byte[] code = new byte[3];
ctrlInput.read(code, 0, code.length);
- replyCode = new String(code, "ISO8859_1");
+ replyCode = new String(code, "ISO8859_1"); //$NON-NLS-1$
boolean multiline = false;
if (ctrlInput.read() == '-') {
multiline = true;
@@ -350,7 +354,7 @@
while (readMultiLine()) {/* Read all of a multiline reply */
}
}
- return Integer.parseInt(new String(code, "ISO8859_1"));
+ return Integer.parseInt(new String(code, "ISO8859_1")); //$NON-NLS-1$
}
private void login() throws IOException {
@@ -358,28 +362,31 @@
reply = getReply();
if (reply == FTP_USERREADY) {
} else {
- throw new IOException(Msg.getString("K0097", url.getHost()));
+ throw new IOException(Msg.getString("K0097", url.getHost())); //$NON-NLS-1$
}
- write("USER " + username + "\r\n");
+ write("USER " + username + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
reply = getReply();
if (reply == FTP_PASWD || reply == FTP_LOGGEDIN) {
} else {
- throw new IOException(Msg.getString("K0098", url.getHost()));
+ throw new IOException(Msg.getString("K0098", url.getHost())); //$NON-NLS-1$
}
if (reply == FTP_PASWD) {
- write("PASS " + password + "\r\n");
+ write("PASS " + password + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
reply = getReply();
if (!(reply == FTP_OK || reply == FTP_USERREADY || reply == FTP_LOGGEDIN)) {
- throw new IOException(Msg.getString("K0098", url.getHost()));
+ throw new IOException(Msg.getString("K0098", url.getHost())); //$NON-NLS-1$
}
}
}
private void port() throws IOException {
- write("PORT " + controlSocket.getLocalAddress().getHostAddress().replace('.', ',')
- + ',' + (dataPort >> 8) + ',' + (dataPort & 255) + "\r\n");
+ write("PORT " //$NON-NLS-1$
+ + controlSocket.getLocalAddress().getHostAddress().replace('.',
+ ',') + ',' + (dataPort >> 8) + ','
+ + (dataPort & 255)
+ + "\r\n"); //$NON-NLS-1$
if (getReply() != FTP_OK) {
- throw new IOException(Msg.getString("K0099"));
+ throw new IOException(Msg.getString("K0099")); //$NON-NLS-1$
}
}
@@ -400,7 +407,8 @@
if (line.length() < 4) {
return true;
}
- if (line.substring(0, 3).equals(replyCode) && (line.charAt(3) == (char) 32)) {
+ if (line.substring(0, 3).equals(replyCode)
+ && (line.charAt(3) == (char) 32)) {
return false;
}
return true;
@@ -411,12 +419,12 @@
*/
private void sendFile() throws IOException {
int reply;
- write("STOR "
+ write("STOR " //$NON-NLS-1$
+ url.getFile().substring(url.getFile().lastIndexOf('/') + 1,
- url.getFile().length()) + "\r\n");
+ url.getFile().length()) + "\r\n"); //$NON-NLS-1$
reply = getReply();
if (!(reply == FTP_OPENDATA || reply == FTP_OK || reply == FTP_DATAOPEN)) {
- throw new IOException(Msg.getString("K009a"));
+ throw new IOException(Msg.getString("K009a")); //$NON-NLS-1$
}
}
@@ -426,8 +434,8 @@
* support both input and output
*
* @param newValue *
- * @throws IllegalAccessError when this method attempts to change the flag
- * after connected
+ * @throws IllegalAccessError
+ * when this method attempts to change the flag after connected
*
* @see #doInput
* @see #getDoInput()
@@ -449,10 +457,9 @@
* support both input and output.
*
* @param newValue
- *
+ *
* @throws IllegalAccessError
- * when this method attempts to change the
- * flag after connected
+ * when this method attempts to change the flag after connected
*
* @see #doOutput
* @see java.lang.IllegalAccessError
@@ -471,13 +478,13 @@
* Set the type of the file transfer. Only Image is supported
*/
private void setType() throws IOException {
- write("TYPE I\r\n");
+ write("TYPE I\r\n"); //$NON-NLS-1$
if (getReply() != FTP_OK) {
- throw new IOException(Msg.getString("K009b"));
+ throw new IOException(Msg.getString("K009b")); //$NON-NLS-1$
}
}
private void write(String command) throws IOException {
- ctrlOutput.write(command.getBytes("ISO8859_1"));
+ ctrlOutput.write(command.getBytes("ISO8859_1")); //$NON-NLS-1$
}
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/Handler.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/Handler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/Handler.java Fri Dec 29 13:39:40 2006
@@ -40,20 +40,24 @@
* <code>proxy</code> is DIRECT type, the connection is made in normal
* way.
*
- * @param u the URL which the connection is pointing to
- * @param proxy the proxy which is used to make the connection
+ * @param u
+ * the URL which the connection is pointing to
+ * @param proxy
+ * the proxy which is used to make the connection
* @return a connection to the resource pointed by this url.
*
- * @throws IOException if this handler fails to establish a connection.
- * @throws IllegalArgumentException if any argument is null or the type of
- * proxy is wrong.
- * @throws UnsupportedOperationException if the protocol handler doesn't
- * support this method.
+ * @throws IOException
+ * if this handler fails to establish a connection.
+ * @throws IllegalArgumentException
+ * if any argument is null or the type of proxy is wrong.
+ * @throws UnsupportedOperationException
+ * if the protocol handler doesn't support this method.
*/
@Override
- protected URLConnection openConnection(URL u, Proxy proxy) throws IOException {
+ protected URLConnection openConnection(URL u, Proxy proxy)
+ throws IOException {
if (null == u || null == proxy) {
- throw new IllegalArgumentException(Msg.getString("K034b"));
+ throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
}
return new FtpURLConnection(u, proxy);
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java Fri Dec 29 13:39:40 2006
@@ -28,7 +28,6 @@
/**
* This is the handler that manages all transactions between the client and a
* HTTP remote server.
- *
*/
public class Handler extends URLStreamHandler {
@@ -36,10 +35,12 @@
* Answers a connection to the HTTP server specified by this
* <code>URL</code>.
*
- * @param u the URL to which the connection is pointing to
+ * @param u
+ * the URL to which the connection is pointing to
* @return a connection to the resource pointed by this url.
*
- * @throws IOException if this handler fails to establish a connection
+ * @throws IOException
+ * if this handler fails to establish a connection
*/
@Override
protected URLConnection openConnection(URL u) throws IOException {
@@ -52,20 +53,24 @@
* <code>proxy</code> is DIRECT type, the connection is made in normal
* way.
*
- * @param u the URL which the connection is pointing to
- * @param proxy the proxy which is used to make the connection
+ * @param u
+ * the URL which the connection is pointing to
+ * @param proxy
+ * the proxy which is used to make the connection
* @return a connection to the resource pointed by this url.
*
- * @throws IOException if this handler fails to establish a connection.
- * @throws IllegalArgumentException if any argument is null or the type of
- * proxy is wrong.
- * @throws UnsupportedOperationException if the protocol handler doesn't
- * support this method.
+ * @throws IOException
+ * if this handler fails to establish a connection.
+ * @throws IllegalArgumentException
+ * if any argument is null or the type of proxy is wrong.
+ * @throws UnsupportedOperationException
+ * if the protocol handler doesn't support this method.
*/
@Override
- protected URLConnection openConnection(URL u, Proxy proxy) throws IOException {
+ protected URLConnection openConnection(URL u, Proxy proxy)
+ throws IOException {
if (null == u || null == proxy) {
- throw new IllegalArgumentException(Msg.getString("K034b"));
+ throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
}
return new HttpURLConnection(u, getDefaultPort(), proxy);
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java Fri Dec 29 13:39:40 2006
@@ -28,7 +28,6 @@
/**
* The general structure for request / response header. It is essentially
* constructed by hashtable with key indexed in a vector for position lookup.
- *
*/
public class Header implements Cloneable {
/*
@@ -56,10 +55,11 @@
* The alternative constructor which sets the input map as its initial
* keyTable.
*
- * @param map the initial keyTable as a map
+ * @param map
+ * the initial keyTable as a map
*/
public Header(Map<String, List<String>> map) {
- this(); //initialize fields
+ this(); // initialize fields
for (Entry<String, List<String>> next : map.entrySet()) {
String key = next.getKey();
props.add(key);
@@ -80,8 +80,10 @@
Header clone = (Header) super.clone();
clone.props = (ArrayList<String>) props.clone();
clone.keyTable = new HashMap<String, LinkedList<String>>(20);
- for (Map.Entry<String, LinkedList<String>> next : this.keyTable.entrySet()) {
- LinkedList<String> v = (LinkedList<String>) next.getValue().clone();
+ for (Map.Entry<String, LinkedList<String>> next : this.keyTable
+ .entrySet()) {
+ LinkedList<String> v = (LinkedList<String>) next.getValue()
+ .clone();
clone.keyTable.put(next.getKey(), v);
}
return clone;
@@ -94,9 +96,7 @@
* Add a field with the specified value.
*
* @param key
- *
* @param value
- *
*/
public void add(String key, String value) {
if (key == null) {
@@ -116,10 +116,8 @@
* Set a field with the specified value. If the field is not found, it is
* added. If the field is found, the existing value(s) are overwritten.
*
- *
* @param key
* @param value
- *
*/
public void set(String key, String value) {
if (key == null) {
@@ -150,7 +148,8 @@
* @since 1.4
*/
public Map<String, List<String>> getFieldMap() {
- Map<String, List<String>> result = new HashMap<String, List<String>>(keyTable.size());
+ Map<String, List<String>> result = new HashMap<String, List<String>>(
+ keyTable.size());
for (Map.Entry<String, LinkedList<String>> next : keyTable.entrySet()) {
List<String> v = next.getValue();
result.put(next.getKey(), Collections.unmodifiableList(v));
@@ -163,7 +162,8 @@
* exist.
*
* @return java.lang.String the value of the key
- * @param pos int the position to look for
+ * @param pos
+ * int the position to look for
*/
public String get(int pos) {
if (pos >= 0 && pos < props.size() / 2) {
@@ -178,7 +178,8 @@
*
*
* @return the key the desired position
- * @param pos the position to look for
+ * @param pos
+ * the position to look for
*/
public String getKey(int pos) {
if (pos >= 0 && pos < props.size() / 2) {
@@ -191,10 +192,8 @@
* Answers the value corresponding to the specified key, null if no such key
* exists.
*
- *
- * @return
* @param key
- *
+ * @return
*/
public String get(String key) {
LinkedList<String> result = keyTable.get(key.toLowerCase());
@@ -207,7 +206,6 @@
/**
* Answers the number of keys stored in this header
*
- *
* @return
*/
public int length() {
@@ -242,5 +240,4 @@
public String getStatusLine() {
return statusLine;
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java Fri Dec 29 13:39:40 2006
@@ -61,13 +61,13 @@
* server.
*/
public class HttpURLConnection extends java.net.HttpURLConnection {
- private static final String POST = "POST";
+ private static final String POST = "POST"; //$NON-NLS-1$
- private static final String GET = "GET";
+ private static final String GET = "GET"; //$NON-NLS-1$
- private static final String PUT = "PUT";
+ private static final String PUT = "PUT"; //$NON-NLS-1$
- private static final String HEAD = "HEAD";
+ private static final String HEAD = "HEAD"; //$NON-NLS-1$
private final int defaultPort;
@@ -155,7 +155,8 @@
return -1;
}
int result = is.read();
- //if user has set useCache to true and cache exists, writes to cache
+ // if user has set useCache to true and cache exists, writes to
+ // cache
if (useCaches && null != cacheOut) {
cacheOut.write(result);
}
@@ -169,7 +170,8 @@
throw new NullPointerException();
}
// avoid int overflow
- if (offset < 0 || length < 0 || offset > buf.length || buf.length - offset < length) {
+ if (offset < 0 || length < 0 || offset > buf.length
+ || buf.length - offset < length) {
throw new ArrayIndexOutOfBoundsException();
}
if (bytesRemaining <= 0) {
@@ -181,7 +183,8 @@
int result = is.read(buf, offset, length);
if (result > 0) {
bytesRemaining -= result;
- // if user has set useCache to true and cache exists, writes to it
+ // if user has set useCache to true and cache exists, writes to
+ // it
if (useCaches && null != cacheOut) {
cacheOut.write(buf, offset, result);
}
@@ -240,7 +243,7 @@
readln(); // read CR/LF
}
String size = readln();
- int index = size.indexOf(";");
+ int index = size.indexOf(";"); //$NON-NLS-1$
if (index >= 0) {
size = size.substring(0, index);
}
@@ -274,7 +277,8 @@
throw new NullPointerException();
}
// avoid int overflow
- if (offset < 0 || length < 0 || offset > buf.length || buf.length - offset < length) {
+ if (offset < 0 || length < 0 || offset > buf.length
+ || buf.length - offset < length) {
throw new ArrayIndexOutOfBoundsException();
}
if (bytesRemaining <= 0) {
@@ -289,7 +293,8 @@
int result = is.read(buf, offset, length);
if (result > 0) {
bytesRemaining -= result;
- // if user has set useCache to true and cache exists, write to it
+ // if user has set useCache to true and cache exists, write to
+ // it
if (useCaches && null != cacheOut) {
cacheOut.write(buf, offset, result);
}
@@ -373,12 +378,13 @@
* here is the calculated head size, not real size (for 19, it
* counts 3, not real size 4)
*/
- int headSize = (Integer.toHexString(defaultCacheSize - bitSize - 2).length()) + 2;
+ int headSize = (Integer.toHexString(defaultCacheSize - bitSize - 2)
+ .length()) + 2;
return defaultCacheSize - headSize;
}
private void output(String output) throws IOException {
- socketOut.write(output.getBytes("ISO8859_1"));
+ socketOut.write(output.getBytes("ISO8859_1")); //$NON-NLS-1$
}
private void sendCache(boolean close) throws IOException {
@@ -386,13 +392,13 @@
if (size > 0 || close) {
if (limit < 0) {
if (size > 0) {
- output(Integer.toHexString(size) + "\r\n");
+ output(Integer.toHexString(size) + "\r\n"); //$NON-NLS-1$
socketOut.write(cache.toByteArray());
cache.reset();
- output("\r\n");
+ output("\r\n"); //$NON-NLS-1$
}
if (close) {
- output("0\r\n\r\n");
+ output("0\r\n\r\n"); //$NON-NLS-1$
}
}
}
@@ -401,7 +407,7 @@
@Override
public synchronized void flush() throws IOException {
if (closed) {
- throw new IOException(Msg.getString("K0059"));
+ throw new IOException(Msg.getString("K0059")); //$NON-NLS-1$
}
if (writeToSocket) {
sendCache(false);
@@ -417,7 +423,7 @@
closed = true;
if (writeToSocket) {
if (limit > 0) {
- throw new IOException(Msg.getString("K00a4"));
+ throw new IOException(Msg.getString("K00a4")); //$NON-NLS-1$
}
sendCache(closed);
}
@@ -426,11 +432,11 @@
@Override
public synchronized void write(int data) throws IOException {
if (closed) {
- throw new IOException(Msg.getString("K0059"));
+ throw new IOException(Msg.getString("K0059")); //$NON-NLS-1$
}
if (limit >= 0) {
if (limit == 0) {
- throw new IOException(Msg.getString("K00b2"));
+ throw new IOException(Msg.getString("K00b2")); //$NON-NLS-1$
}
limit--;
}
@@ -441,9 +447,10 @@
}
@Override
- public synchronized void write(byte[] buffer, int offset, int count) throws IOException {
+ public synchronized void write(byte[] buffer, int offset, int count)
+ throws IOException {
if (closed) {
- throw new IOException(Msg.getString("K0059"));
+ throw new IOException(Msg.getString("K0059")); //$NON-NLS-1$
}
if (buffer == null) {
throw new NullPointerException();
@@ -451,12 +458,12 @@
// avoid int overflow
if (offset < 0 || count < 0 || offset > buffer.length
|| buffer.length - offset < count) {
- throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f"));
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
if (limit >= 0) {
if (count > limit) {
- throw new IOException(Msg.getString("K00b2"));
+ throw new IOException(Msg.getString("K00b2")); //$NON-NLS-1$
}
limit -= count;
cache.write(buffer, offset, count);
@@ -467,18 +474,18 @@
if (!writeToSocket || cache.size() + count < cacheLength) {
cache.write(buffer, offset, count);
} else {
- output(Integer.toHexString(cacheLength) + "\r\n");
+ output(Integer.toHexString(cacheLength) + "\r\n"); //$NON-NLS-1$
int writeNum = cacheLength - cache.size();
cache.write(buffer, offset, writeNum);
socketOut.write(cache.toByteArray());
- output("\r\n");
+ output("\r\n"); //$NON-NLS-1$
cache.reset();
int left = count - writeNum;
int position = offset + writeNum;
while (left > cacheLength) {
- output(Integer.toHexString(cacheLength) + "\r\n");
+ output(Integer.toHexString(cacheLength) + "\r\n"); //$NON-NLS-1$
socketOut.write(buffer, position, cacheLength);
- output("\r\n");
+ output("\r\n"); //$NON-NLS-1$
left = left - cacheLength;
position = position + cacheLength;
}
@@ -507,7 +514,7 @@
/**
* Creates an instance of the <code>HttpURLConnection</code> using default
* port 80.
- *
+ *
* @param url
* URL The URL this connection is connecting
*/
@@ -517,7 +524,7 @@
/**
* Creates an instance of the <code>HttpURLConnection</code>
- *
+ *
* @param url
* URL The URL this connection is connecting
* @param port
@@ -533,16 +540,17 @@
} catch (URISyntaxException e) {
// do nothing.
}
- responseCache = AccessController.doPrivileged(new PrivilegedAction<ResponseCache>() {
- public ResponseCache run() {
- return ResponseCache.getDefault();
- }
- });
+ responseCache = AccessController
+ .doPrivileged(new PrivilegedAction<ResponseCache>() {
+ public ResponseCache run() {
+ return ResponseCache.getDefault();
+ }
+ });
}
/**
* Creates an instance of the <code>HttpURLConnection</code>
- *
+ *
* @param url
* URL The URL this connection is connecting
* @param port
@@ -557,12 +565,12 @@
/**
* Establishes the connection to the remote HTTP server
- *
+ *
* Any methods that requires a valid connection to the resource will call
* this method implicitly. After the connection is established,
* <code>connected</code> is set to true.
- *
- *
+ *
+ *
* @see #connected
* @see java.io.IOException
* @see URLStreamHandler
@@ -615,8 +623,8 @@
}
/**
- * Returns connected socket to be used for this HTTP connection.
- * TODO: implement persistent connections.
+ * Returns connected socket to be used for this HTTP connection. TODO:
+ * implement persistent connections.
*/
protected Socket getHTTPConnection(Proxy proxy) throws IOException {
Socket socket;
@@ -639,7 +647,9 @@
/**
* Sets up the data streams used to send request[s] and read response[s].
- * @param socket socket to be used for connection
+ *
+ * @param socket
+ * socket to be used for connection
*/
protected void setUpTransportIO(Socket socket) throws IOException {
this.socket = socket;
@@ -647,7 +657,8 @@
is = new BufferedInputStream(socket.getInputStream());
}
- // Tries to get head and body from cache, return true if has got this time or
+ // Tries to get head and body from cache, return true if has got this time
+ // or
// already got before
private boolean getFromCache() throws IOException {
if (useCaches && null != responseCache && !hasTriedCache) {
@@ -655,7 +666,8 @@
if (null == resHeader) {
resHeader = new Header();
}
- cacheResponse = responseCache.get(uri, method, resHeader.getFieldMap());
+ cacheResponse = responseCache.get(uri, method, resHeader
+ .getFieldMap());
if (null != cacheResponse) {
Map<String, List<String>> headMap = cacheResponse.getHeaders();
if (null != headMap) {
@@ -686,8 +698,8 @@
/**
* Closes the connection with the HTTP server
- *
- *
+ *
+ *
* @see URLConnection#connect()
*/
@Override
@@ -725,9 +737,8 @@
* <p>
* If the content type is not what stated above,
* <code>FileNotFoundException</code> is thrown.
- *
- * @return InputStream the error input stream returned by the
- * server.
+ *
+ * @return InputStream the error input stream returned by the server.
*/
@Override
public InputStream getErrorStream() {
@@ -764,14 +775,14 @@
/**
* Answers the value of the field corresponding to the <code>key</code>
* Answers <code>null</code> if there is no such field.
- *
+ *
* If there are multiple fields with that key, the last field value is
* returned.
- *
+ *
* @return java.lang.String The value of the header field
* @param key
* java.lang.String the name of the header field
- *
+ *
* @see #getHeaderField(int)
* @see #getHeaderFieldKey
*/
@@ -805,9 +816,9 @@
* Provides an unmodifiable map of the connection header values. The map
* keys are the String header field names. Each map value is a list of the
* header field values associated with that key name.
- *
+ *
* @return the mapping of header field names to values
- *
+ *
* @since 1.4
*/
@Override
@@ -835,7 +846,7 @@
@Override
public InputStream getInputStream() throws IOException {
if (!doInput) {
- throw new ProtocolException(Msg.getString("K008d"));
+ throw new ProtocolException(Msg.getString("K008d")); //$NON-NLS-1$
}
doRequest();
@@ -858,12 +869,12 @@
return uis;
}
- String encoding = resHeader.get("Transfer-Encoding");
- if (encoding != null && encoding.toLowerCase().equals("chunked")) {
+ String encoding = resHeader.get("Transfer-Encoding"); //$NON-NLS-1$
+ if (encoding != null && encoding.toLowerCase().equals("chunked")) { //$NON-NLS-1$
return uis = new ChunkedInputStream();
}
- String sLength = resHeader.get("Content-Length");
+ String sLength = resHeader.get("Content-Length"); //$NON-NLS-1$
if (sLength != null) {
try {
int length = Integer.parseInt(sLength);
@@ -877,12 +888,12 @@
@Override
public OutputStream getOutputStream() throws IOException {
if (!doOutput) {
- throw new ProtocolException(Msg.getString("K008e"));
+ throw new ProtocolException(Msg.getString("K008e")); //$NON-NLS-1$
}
// you can't write after you read
if (sentRequest) {
- throw new ProtocolException(Msg.getString("K0090"));
+ throw new ProtocolException(Msg.getString("K0090")); //$NON-NLS-1$
}
if (os != null) {
@@ -896,19 +907,19 @@
// If the request method is neither PUT or POST, then you're not writing
if (method != PUT && method != POST) {
- throw new ProtocolException(Msg.getString("K008f", method));
+ throw new ProtocolException(Msg.getString("K008f", method)); //$NON-NLS-1$
}
int limit = -1;
- String contentLength = reqHeader.get("Content-Length");
+ String contentLength = reqHeader.get("Content-Length"); //$NON-NLS-1$
if (contentLength != null) {
limit = Integer.parseInt(contentLength);
}
- String encoding = reqHeader.get("Transfer-Encoding");
+ String encoding = reqHeader.get("Transfer-Encoding"); //$NON-NLS-1$
if (httpVersion > 0 && encoding != null) {
encoding = encoding.toLowerCase();
- if ("chunked".equals(encoding)) {
+ if ("chunked".equals(encoding)) { //$NON-NLS-1$
sendChunked = true;
limit = -1;
}
@@ -936,7 +947,8 @@
@Override
public Permission getPermission() throws IOException {
- return new SocketPermission(getHostName() + ":" + getHostPort(), "connect, resolve");
+ return new SocketPermission(getHostName() + ":" + getHostPort(), //$NON-NLS-1$
+ "connect, resolve"); //$NON-NLS-1$
}
@Override
@@ -949,7 +961,7 @@
/**
* Answers a line read from the input stream. Does not include the \n
- *
+ *
* @return The line that was read.
*/
String readln() throws IOException {
@@ -983,7 +995,7 @@
}
String file = url.getFile();
if (file == null || file.length() == 0) {
- file = "/";
+ file = "/"; //$NON-NLS-1$
}
return file;
}
@@ -992,7 +1004,7 @@
* Sends the request header to the remote HTTP server Not all of them are
* guaranteed to have any effect on the content the server will return,
* depending on if the server supports that field.
- *
+ *
* Examples : Accept: text/*, text/html, text/html;level=1, Accept-Charset:
* iso-8859-5, unicode-1-1;q=0.8
*/
@@ -1036,7 +1048,8 @@
} while (getResponseCode() == 100);
if (method == HEAD || (responseCode >= 100 && responseCode < 200)
- || responseCode == HTTP_NO_CONTENT || responseCode == HTTP_NOT_MODIFIED) {
+ || responseCode == HTTP_NO_CONTENT
+ || responseCode == HTTP_NOT_MODIFIED) {
closeSocket();
uis = new LimitedInputStream(0);
}
@@ -1053,11 +1066,11 @@
return responseCode;
}
String response = resHeader.getStatusLine();
- if (response == null || !response.startsWith("HTTP/")) {
+ if (response == null || !response.startsWith("HTTP/")) { //$NON-NLS-1$
return -1;
}
response = response.trim();
- int mark = response.indexOf(" ") + 1;
+ int mark = response.indexOf(" ") + 1; //$NON-NLS-1$
if (mark == 0) {
return -1;
}
@@ -1081,10 +1094,11 @@
while (((line = readln()) != null) && (line.length() > 1)) {
// Header parsing
int idx;
- if ((idx = line.indexOf(":")) < 0) {
- resHeader.add("", line.trim());
+ if ((idx = line.indexOf(":")) < 0) { //$NON-NLS-1$
+ resHeader.add("", line.trim()); //$NON-NLS-1$
} else {
- resHeader.add(line.substring(0, idx), line.substring(idx + 1).trim());
+ resHeader.add(line.substring(0, idx), line.substring(idx + 1)
+ .trim());
}
}
}
@@ -1095,50 +1109,51 @@
output.append(' ');
output.append(requestString());
output.append(' ');
- output.append("HTTP/1.");
+ output.append("HTTP/1."); //$NON-NLS-1$
if (httpVersion == 0) {
- output.append("0\r\n");
+ output.append("0\r\n"); //$NON-NLS-1$
} else {
- output.append("1\r\n");
+ output.append("1\r\n"); //$NON-NLS-1$
}
- if (reqHeader.get("User-Agent") == null) {
- output.append("User-Agent: ");
- String agent = getSystemProperty("http.agent");
+ if (reqHeader.get("User-Agent") == null) { //$NON-NLS-1$
+ output.append("User-Agent: "); //$NON-NLS-1$
+ String agent = getSystemProperty("http.agent"); //$NON-NLS-1$
if (agent == null) {
- output.append("Java");
- output.append(getSystemProperty("java.version"));
+ output.append("Java"); //$NON-NLS-1$
+ output.append(getSystemProperty("java.version")); //$NON-NLS-1$
} else {
output.append(agent);
}
- output.append("\r\n");
+ output.append("\r\n"); //$NON-NLS-1$
}
- if (reqHeader.get("Host") == null) {
- output.append("Host: ");
+ if (reqHeader.get("Host") == null) { //$NON-NLS-1$
+ output.append("Host: "); //$NON-NLS-1$
output.append(url.getHost());
int port = url.getPort();
if (port > 0 && port != defaultPort) {
output.append(':');
output.append(Integer.toString(port));
}
- output.append("\r\n");
+ output.append("\r\n"); //$NON-NLS-1$
}
- if (httpVersion > 0 && reqHeader.get("Connection") == null) {
- output.append("Connection: Keep-Alive\r\n");
+ if (httpVersion > 0 && reqHeader.get("Connection") == null) { //$NON-NLS-1$
+ output.append("Connection: Keep-Alive\r\n"); //$NON-NLS-1$
}
// if we are doing output make sure the appropriate headers are sent
if (os != null) {
- if (reqHeader.get("Content-Type") == null) {
- output.append("Content-Type: application/x-www-form-urlencoded\r\n");
+ if (reqHeader.get("Content-Type") == null) { //$NON-NLS-1$
+ output
+ .append("Content-Type: application/x-www-form-urlencoded\r\n"); //$NON-NLS-1$
}
if (os.isCached()) {
- if (reqHeader.get("Content-Length") == null) {
- output.append("Content-Length: ");
+ if (reqHeader.get("Content-Length") == null) { //$NON-NLS-1$
+ output.append("Content-Length: "); //$NON-NLS-1$
output.append(Integer.toString(os.size()));
- output.append("\r\n");
+ output.append("\r\n"); //$NON-NLS-1$
}
} else if (os.isChunked()) {
- output.append("Transfer-Encoding: chunked\r\n");
+ output.append("Transfer-Encoding: chunked\r\n"); //$NON-NLS-1$
}
}
@@ -1149,42 +1164,45 @@
if (key != null) {
String lKey = key.toLowerCase();
if ((os != null && !os.isChunked())
- || (!lKey.equals("transfer-encoding") && !lKey.equals("content-length"))) {
+ || (!lKey.equals("transfer-encoding") && !lKey //$NON-NLS-1$
+ .equals("content-length"))) { //$NON-NLS-1$
output.append(key);
- output.append(": ");
+ output.append(": "); //$NON-NLS-1$
/*
* duplicates are allowed under certain conditions see
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
*/
- if (lKey.equals("content-length")) {
+ if (lKey.equals("content-length")) { //$NON-NLS-1$
hasContentLength = true;
/*
* if both setFixedLengthStreamingMode and
* content-length are set, use fixedContentLength first
*/
- output.append((fixedContentLength >= 0) ? String
- .valueOf(fixedContentLength) : reqHeader.get(i));
+ output
+ .append((fixedContentLength >= 0) ? String
+ .valueOf(fixedContentLength)
+ : reqHeader.get(i));
} else {
output.append(reqHeader.get(i));
}
- output.append("\r\n");
+ output.append("\r\n"); //$NON-NLS-1$
}
}
}
if (fixedContentLength >= 0 && !hasContentLength) {
- output.append("content-length: ");
+ output.append("content-length: "); //$NON-NLS-1$
output.append(String.valueOf(fixedContentLength));
- output.append("\r\n");
+ output.append("\r\n"); //$NON-NLS-1$
}
// end the headers
- output.append("\r\n");
- return output.toString().getBytes("ISO8859_1");
+ output.append("\r\n"); //$NON-NLS-1$
+ return output.toString().getBytes("ISO8859_1"); //$NON-NLS-1$
}
/**
* Sets the default request header fields to be sent to the remote server.
* This does not affect the current URL Connection, only newly created ones.
- *
+ *
* @param field
* java.lang.String The name of the field to be changed
* @param value
@@ -1201,24 +1219,27 @@
* with the new value.
*
*
- * @param newValue the number of millisecond since epoch
+ * @param newValue
+ * the number of millisecond since epoch
*
- * @throws IllegalStateException if already connected.
+ * @throws IllegalStateException
+ * if already connected.
*/
@Override
public void setIfModifiedSince(long newValue) {
super.setIfModifiedSince(newValue);
// convert from millisecond since epoch to date string
- SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
- sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+ SimpleDateFormat sdf = new SimpleDateFormat(
+ "E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); //$NON-NLS-1$
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
String date = sdf.format(new Date(newValue));
- reqHeader.add("If-Modified-Since", date);
+ reqHeader.add("If-Modified-Since", date); //$NON-NLS-1$
}
@Override
public void setRequestProperty(String field, String newValue) {
if (connected) {
- throw new IllegalStateException(Msg.getString("K0092"));
+ throw new IllegalStateException(Msg.getString("K0092")); //$NON-NLS-1$
}
if (field == null) {
throw new NullPointerException();
@@ -1229,7 +1250,7 @@
@Override
public void addRequestProperty(String field, String value) {
if (connected) {
- throw new IllegalAccessError(Msg.getString("K0092"));
+ throw new IllegalAccessError(Msg.getString("K0092")); //$NON-NLS-1$
}
if (field == null) {
throw new NullPointerException();
@@ -1264,7 +1285,8 @@
if (hostAddress == null) {
// the value was not set yet
if (proxy != null && proxy.type() != Proxy.Type.DIRECT) {
- hostAddress = ((InetSocketAddress) proxy.address()).getAddress();
+ hostAddress = ((InetSocketAddress) proxy.address())
+ .getAddress();
} else {
hostAddress = InetAddress.getByName(url.getHost());
}
@@ -1325,14 +1347,16 @@
// proxy authorization failed ?
if (responseCode == HTTP_PROXY_AUTH) {
if (!usingProxy()) {
- throw new IOException("Received HTTP_PROXY_AUTH (407) "
- + "code while not using proxy");
+ // KA017=Received HTTP_PROXY_AUTH (407) code while not using
+ // proxy
+ throw new IOException(Msg.getString("KA017")); //$NON-NLS-1$
}
// username/password
// until authorized
- String challenge = resHeader.get("Proxy-Authenticate");
+ String challenge = resHeader.get("Proxy-Authenticate"); //$NON-NLS-1$
if (challenge == null) {
- throw new IOException("Received authentication challenge is null.");
+ // KA016=Received authentication challenge is null.
+ throw new IOException(Msg.getString("KA016")); //$NON-NLS-1$
}
// drop everything and reconnect, might not be required for
// HTTP/1.1
@@ -1345,16 +1369,17 @@
break;
}
// set up the authorization credentials
- setRequestProperty("Proxy-Authorization", credentials);
+ setRequestProperty("Proxy-Authorization", credentials); //$NON-NLS-1$
// continue to send request
continue;
}
// HTTP authorization failed ?
- if (responseCode == HTTP_UNAUTHORIZED) {
+ if (responseCode == HTTP_UNAUTHORIZED) {
// keep asking for username/password until authorized
- String challenge = resHeader.get("WWW-Authenticate");
+ String challenge = resHeader.get("WWW-Authenticate"); //$NON-NLS-1$
if (challenge == null) {
- throw new IOException("Received authentication challenge is null.");
+ // KA018=Received authentication challenge is null
+ throw new IOException(Msg.getString("KA018")); //$NON-NLS-1$
}
// drop everything and reconnect, might not be required for
// HTTP/1.1
@@ -1367,7 +1392,7 @@
break;
}
// set up the authorization credentials
- setRequestProperty("Authorization", credentials);
+ setRequestProperty("Authorization", credentials); //$NON-NLS-1$
// continue to send request
continue;
}
@@ -1377,14 +1402,16 @@
* an infinite loop
*/
if (getInstanceFollowRedirects()) {
- if ((responseCode == HTTP_MULT_CHOICE || responseCode == HTTP_MOVED_PERM
- || responseCode == HTTP_MOVED_TEMP || responseCode == HTTP_SEE_OTHER || responseCode == HTTP_USE_PROXY)
+ if ((responseCode == HTTP_MULT_CHOICE
+ || responseCode == HTTP_MOVED_PERM
+ || responseCode == HTTP_MOVED_TEMP
+ || responseCode == HTTP_SEE_OTHER || responseCode == HTTP_USE_PROXY)
&& os == null) {
if (++redirect > 4) {
- throw new ProtocolException(Msg.getString("K0093"));
+ throw new ProtocolException(Msg.getString("K0093")); //$NON-NLS-1$
}
- String location = getHeaderField("Location");
+ String location = getHeaderField("Location"); //$NON-NLS-1$
if (location != null) {
// start over
if (responseCode == HTTP_USE_PROXY) {
@@ -1392,7 +1419,7 @@
if (location.startsWith(url.getProtocol() + ':')) {
start = url.getProtocol().length() + 1;
}
- if (location.startsWith("//", start)) {
+ if (location.startsWith("//", start)) { //$NON-NLS-1$
start += 2;
}
setProxy(location.substring(start));
@@ -1423,11 +1450,12 @@
* @return
* @throws IOException
*/
- private String getAuthorizationCredentials(String challenge) throws IOException {
+ private String getAuthorizationCredentials(String challenge)
+ throws IOException {
- int idx = challenge.indexOf(" ");
+ int idx = challenge.indexOf(" "); //$NON-NLS-1$
String scheme = challenge.substring(0, idx);
- int realm = challenge.indexOf("realm=\"") + 7;
+ int realm = challenge.indexOf("realm=\"") + 7; //$NON-NLS-1$
String prompt = null;
if (realm != -1) {
int end = challenge.indexOf('"', realm);
@@ -1437,17 +1465,18 @@
}
// The following will use the user-defined authenticator to get
// the password
- PasswordAuthentication pa = Authenticator.requestPasswordAuthentication(
- getHostAddress(), getHostPort(), url.getProtocol(), prompt, scheme);
+ PasswordAuthentication pa = Authenticator
+ .requestPasswordAuthentication(getHostAddress(), getHostPort(),
+ url.getProtocol(), prompt, scheme);
if (pa == null) {
// could not retrieve the credentials
return null;
}
// base64 encode the username and password
- byte[] bytes = (pa.getUserName() + ":" + new String(pa.getPassword()))
- .getBytes("ISO8859_1");
- String encoded = Base64.encode(bytes, "ISO8859_1");
- return scheme + " " + encoded;
+ byte[] bytes = (pa.getUserName() + ":" + new String(pa.getPassword())) //$NON-NLS-1$
+ .getBytes("ISO8859_1"); //$NON-NLS-1$
+ String encoded = Base64.encode(bytes, "ISO8859_1"); //$NON-NLS-1$
+ return scheme + " " + encoded; //$NON-NLS-1$
}
private void setProxy(String proxy) {
@@ -1461,10 +1490,10 @@
try {
hostPort = Integer.parseInt(port);
} catch (NumberFormatException e) {
- throw new IllegalArgumentException(Msg.getString("K00af", port));
+ throw new IllegalArgumentException(Msg.getString("K00af", port)); //$NON-NLS-1$
}
if (hostPort < 0 || hostPort > 65535) {
- throw new IllegalArgumentException(Msg.getString("K00b0"));
+ throw new IllegalArgumentException(Msg.getString("K00b0")); //$NON-NLS-1$
}
}
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java Fri Dec 29 13:39:40 2006
@@ -23,6 +23,8 @@
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import org.apache.harmony.luni.util.Msg;
+
/**
* Handler for HttpsURLConnection implementation.
*/
@@ -34,9 +36,11 @@
}
@Override
- protected URLConnection openConnection(URL url, Proxy proxy) throws IOException {
+ protected URLConnection openConnection(URL url, Proxy proxy)
+ throws IOException {
if ((url == null) || (proxy == null)) {
- throw new IllegalArgumentException("Some of the parameters is null");
+ // K034b=url and proxy can not be null
+ throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
}
return new HttpsURLConnection(url, getDefaultPort(), proxy);
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java Fri Dec 29 13:39:40 2006
@@ -74,7 +74,8 @@
}
@Override
- public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
+ public Certificate[] getServerCertificates()
+ throws SSLPeerUnverifiedException {
if (sslSocket == null) {
throw new IllegalStateException(Messages.getString("luni.00")); //$NON-NLS-1$
}
@@ -145,7 +146,7 @@
@Override
public void connect() throws IOException {
httpsEngine.connect();
- };
+ }
@Override
public boolean getAllowUserInteraction() {
@@ -157,6 +158,7 @@
return httpsEngine.getContent();
}
+ @SuppressWarnings("unchecked") // Spec does not generify
@Override
public Object getContent(Class[] types) throws IOException {
return httpsEngine.getContent(types);
@@ -399,36 +401,34 @@
}
}
+ @Override
protected String requestString() {
if (usingProxy()) {
if (makingSSLTunnel) {
// we are making the SSL Tunneling, return remotehost:port
int port = url.getPort();
- return (port > 0)
- ? url.getHost()+":"+port //$NON-NLS-1$
- : url.getHost();
- } else {
- // we has made SSL Tunneling, return /requested.data
- String file = url.getFile();
- if (file == null || file.length() == 0) {
- file = "/"; //$NON-NLS-1$
- }
- return file;
+ return (port > 0) ? url.getHost() + ":" + port //$NON-NLS-1$
+ : url.getHost();
}
- } else {
- return super.requestString();
+ // we has made SSL Tunneling, return /requested.data
+ String file = url.getFile();
+ if (file == null || file.length() == 0) {
+ file = "/"; //$NON-NLS-1$
+ }
+ return file;
}
+ return super.requestString();
}
/**
- * Create the secure socket over the connected socket and
- * verify remote hostname.
+ * Create the secure socket over the connected socket and verify remote
+ * hostname.
*/
private Socket wrapConnection(Socket socket) throws IOException {
String hostname = url.getHost();
// create the wrapper over connected socket
- sslSocket = (SSLSocket) getSSLSocketFactory().createSocket(socket, hostname,
- url.getPort(), true);
+ sslSocket = (SSLSocket) getSSLSocketFactory().createSocket(socket,
+ hostname, url.getPort(), true);
sslSocket.setUseClientMode(true);
sslSocket.startHandshake();
if (!getHostnameVerifier().verify(hostname, sslSocket.getSession())) {
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java?view=diff&rev=491110&r1=491109&r2=491110
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java Fri Dec 29 13:39:40 2006
@@ -17,7 +17,6 @@
package org.apache.harmony.luni.internal.net.www.protocol.jar;
-
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -27,70 +26,78 @@
import org.apache.harmony.luni.util.Msg;
public class Handler extends URLStreamHandler {
- /**
- * Answers a connection to the jar file pointed by this <code>URL</code>
- * in the file system
- *
- * @return java.net.URLConnection A connection to the resource pointed by
- * this url.
- * @param u
- * java.net.URL The URL to which the connection is pointing to
- *
- * @thows IOException thrown if an IO error occurs when this method tries to
- * establish connection.
- */
- protected URLConnection openConnection(URL u) throws IOException {
- return new JarURLConnection(u);
- }
+ /**
+ * Answers a connection to the jar file pointed by this <code>URL</code>
+ * in the file system
+ *
+ * @return java.net.URLConnection A connection to the resource pointed by
+ * this url.
+ * @param u
+ * java.net.URL The URL to which the connection is pointing to
+ *
+ * @thows IOException thrown if an IO error occurs when this method tries to
+ * establish connection.
+ */
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException {
+ return new JarURLConnection(u);
+ }
- /**
- *
- * @param url
- * URL the context URL
- * @param spec
- * java.lang.String the spec string
- * @param start
- * int the location to start parsing from
- * @param limit
- * int the location where parsing ends
- */
- protected void parseURL(URL url, String spec, int start, int limit) {
- String file = url.getFile();
- if (file == null)
- file = "";
- if (limit > start)
- spec = spec.substring(start, limit);
- else
- spec = "";
- if (spec.indexOf("!/") == -1 && (file.indexOf("!/") == -1))
- throw new NullPointerException(Msg.getString("K01b6"));
- if (spec.charAt(0) == '/')// File is absolute
- file = file.substring(0, file.indexOf('!') + 1) + spec;
- else
- file = file.substring(0, file.lastIndexOf('/') + 1) + spec;
- try {
- // check that the embedded url is valid
- new URL(file);
- } catch (MalformedURLException e) {
- throw new NullPointerException(e.toString());
- }
- setURL(url, "jar", "", -1, null, null, file, null, null);
- }
+ /**
+ *
+ * @param url
+ * URL the context URL
+ * @param spec
+ * java.lang.String the spec string
+ * @param start
+ * int the location to start parsing from
+ * @param limit
+ * int the location where parsing ends
+ */
+ @Override
+ protected void parseURL(URL url, String spec, int start, int limit) {
+ String file = url.getFile();
+ if (file == null) {
+ file = ""; //$NON-NLS-1$
+ }
+ if (limit > start) {
+ spec = spec.substring(start, limit);
+ } else {
+ spec = ""; //$NON-NLS-1$
+ }
+ if (spec.indexOf("!/") == -1 && (file.indexOf("!/") == -1)) { //$NON-NLS-1$ //$NON-NLS-2$
+ throw new NullPointerException(Msg.getString("K01b6")); //$NON-NLS-1$
+ }
+ if (spec.charAt(0) == '/') {
+ file = file.substring(0, file.indexOf('!') + 1) + spec;
+ } else {
+ file = file.substring(0, file.lastIndexOf('/') + 1) + spec;
+ }
+ try {
+ // check that the embedded url is valid
+ new URL(file);
+ } catch (MalformedURLException e) {
+ throw new NullPointerException(e.toString());
+ }
+ setURL(url, "jar", "", -1, null, null, file, null, null); //$NON-NLS-1$//$NON-NLS-2$
+ }
- /**
- * Build and return the externalized string representation of url.
- *
- * @return String the externalized string representation of url
- * @param url
- * a URL
- */
- protected String toExternalForm(URL url) {
- StringBuffer sb = new StringBuffer();
- sb.append("jar:");
- sb.append(url.getFile());
- String ref = url.getRef();
- if (ref != null)
- sb.append(ref);
- return sb.toString();
- }
+ /**
+ * Build and return the externalized string representation of url.
+ *
+ * @return String the externalized string representation of url
+ * @param url
+ * a URL
+ */
+ @Override
+ protected String toExternalForm(URL url) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("jar:"); //$NON-NLS-1$
+ sb.append(url.getFile());
+ String ref = url.getRef();
+ if (ref != null) {
+ sb.append(ref);
+ }
+ return sb.toString();
+ }
}