< prev index next >

src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestBuilderImpl.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


 173     }
 174 
 175     @Override
 176     public HttpRequest.Builder POST(BodyPublisher body) {
 177         return method0("POST", requireNonNull(body));
 178     }
 179 
 180     @Override
 181     public HttpRequest.Builder DELETE() {
 182         return method0("DELETE", null);
 183     }
 184 
 185     @Override
 186     public HttpRequest.Builder PUT(BodyPublisher body) {
 187         return method0("PUT", requireNonNull(body));
 188     }
 189 
 190     @Override
 191     public HttpRequest.Builder method(String method, BodyPublisher body) {
 192         requireNonNull(method);
 193         if (method.equals(""))
 194             throw newIAE("illegal method <empty string>");
 195         if (method.equals("CONNECT"))
 196             throw newIAE("method CONNECT is not supported");
 197         if (!Utils.isValidName(method))
 198             throw newIAE("illegal method \""
 199                     + method.replace("\n","\\n")
 200                     .replace("\r", "\\r")
 201                     .replace("\t", "\\t")
 202                     + "\"");
 203         return method0(method, requireNonNull(body));
 204     }
 205 
 206     private HttpRequest.Builder method0(String method, BodyPublisher body) {
 207         assert method != null;
 208         assert !method.equals("");
 209         this.method = method;
 210         this.bodyPublisher = body;
 211         return this;
 212     }
 213 
 214     @Override
 215     public HttpRequest build() {
 216         if (uri == null)
 217             throw new IllegalStateException("uri is null");
 218         assert method != null;
 219         return new ImmutableHttpRequest(this);
 220     }
 221 
 222     public HttpRequestImpl buildForWebSocket() {
 223         if (uri == null)
 224             throw new IllegalStateException("uri is null");
 225         assert method != null;
 226         return new HttpRequestImpl(this);
 227     }
 228 


 173     }
 174 
 175     @Override
 176     public HttpRequest.Builder POST(BodyPublisher body) {
 177         return method0("POST", requireNonNull(body));
 178     }
 179 
 180     @Override
 181     public HttpRequest.Builder DELETE() {
 182         return method0("DELETE", null);
 183     }
 184 
 185     @Override
 186     public HttpRequest.Builder PUT(BodyPublisher body) {
 187         return method0("PUT", requireNonNull(body));
 188     }
 189 
 190     @Override
 191     public HttpRequest.Builder method(String method, BodyPublisher body) {
 192         requireNonNull(method);
 193         if (method.isEmpty())
 194             throw newIAE("illegal method <empty string>");
 195         if (method.equals("CONNECT"))
 196             throw newIAE("method CONNECT is not supported");
 197         if (!Utils.isValidName(method))
 198             throw newIAE("illegal method \""
 199                     + method.replace("\n","\\n")
 200                     .replace("\r", "\\r")
 201                     .replace("\t", "\\t")
 202                     + "\"");
 203         return method0(method, requireNonNull(body));
 204     }
 205 
 206     private HttpRequest.Builder method0(String method, BodyPublisher body) {
 207         assert method != null;
 208         assert !method.isEmpty();
 209         this.method = method;
 210         this.bodyPublisher = body;
 211         return this;
 212     }
 213 
 214     @Override
 215     public HttpRequest build() {
 216         if (uri == null)
 217             throw new IllegalStateException("uri is null");
 218         assert method != null;
 219         return new ImmutableHttpRequest(this);
 220     }
 221 
 222     public HttpRequestImpl buildForWebSocket() {
 223         if (uri == null)
 224             throw new IllegalStateException("uri is null");
 225         assert method != null;
 226         return new HttpRequestImpl(this);
 227     }
 228 
< prev index next >