/** * Creates a URLName object from the specified protocol, * host, port number, file, username, and password. Specifying a port * number of -1 indicates that the URL should use the default port for * the protocol. */ public URLName( String protocol, String host, int port, String file, String username, String password ) { this.protocol = protocol; this.host = host; this.port = port; int refStart; if (file != null && (refStart = file.indexOf('#')) != -1) { this.file = file.substring(0, refStart); this.ref = file.substring(refStart + 1); } else { this.file = file; this.ref = null; } this.username = doEncode ? encode(username) : username; this.password = doEncode ? encode(password) : password; }
/** * Creates a URLName object from the specified protocol, * host, port number, file, username, and password. Specifying a port * number of -1 indicates that the URL should use the default port for * the protocol. */ public URLName( String protocol, String host, int port, String file, String username, String password ) { this.protocol = protocol; this.host = host; this.port = port; int refStart; if (file != null && (refStart = file.indexOf('#')) != -1) { this.file = file.substring(0, refStart); this.ref = file.substring(refStart + 1); } else { this.file = file; this.ref = null; } this.username = doEncode ? encode(username) : username; this.password = doEncode ? encode(password) : password; }
private void updateFullURL() { hashCode = 0; StringBuffer buf = new StringBuffer(100); if (protocol != null) { buf.append(protocol).append(':'); if (host != null) { buf.append("//"); if (username != null) { buf.append(encode(username)); if (password != null) { buf.append(':').append(encode(password)); } buf.append('@'); } buf.append(host); if (port != -1) { buf.append(':').append(port); } if (file != null) { buf.append('/').append(file); } hashCode = buf.toString().hashCode(); if (ref != null) { buf.append('#').append(ref); } } } fullURL = buf.toString(); }
public URLName(String protocol, String host, int port, String file, String username, String password) { this.protocol = checkBlank(protocol); this.host = checkBlank(host); this.port = port; if (file == null || file.length() == 0) { this.file = null; ref = null; } else { int pos = file.indexOf('#'); if (pos == -1) { this.file = file; ref = null; } else { this.file = file.substring(0, pos); ref = file.substring(pos + 1); } } this.username = checkBlank(username); if (this.username != null) { this.password = checkBlank(password); } else { this.password = null; } username = encode(username); password = encode(password); updateFullURL(); }