You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/09/19 10:18:37 UTC

[httpcomponents-client] 03/04: Replaced deprecated TokenParser

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit cb88274e1abdf0756f857cbf829cac902ab0bf51
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 17:14:11 2020 +0200

    Replaced deprecated TokenParser
---
 .../http/impl/auth/AuthChallengeParser.java        | 10 ++++-----
 .../http/impl/cookie/LaxExpiresHandler.java        |  8 +++----
 .../http/impl/cookie/RFC6265CookieSpec.java        | 19 ++++++++--------
 .../client5/http/ssl/DistinguishedNameParser.java  | 25 +++++++++++-----------
 4 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
index 8fd57fe..3a7d1a7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
@@ -37,8 +37,8 @@ import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
 import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Authentication challenge parser.
@@ -49,7 +49,7 @@ public class AuthChallengeParser {
 
     public static final AuthChallengeParser INSTANCE = new AuthChallengeParser();
 
-    private final TokenParser tokenParser = TokenParser.INSTANCE;
+    private final Tokenizer tokenParser = Tokenizer.INSTANCE;
 
     private final static char BLANK            = ' ';
     private final static char COMMA_CHAR       = ',';
@@ -57,9 +57,9 @@ public class AuthChallengeParser {
 
     // IMPORTANT!
     // These private static variables must be treated as immutable and never exposed outside this class
-    private static final BitSet TERMINATORS = TokenParser.INIT_BITSET(BLANK, EQUAL_CHAR, COMMA_CHAR);
-    private static final BitSet DELIMITER = TokenParser.INIT_BITSET(COMMA_CHAR);
-    private static final BitSet SPACE = TokenParser.INIT_BITSET(BLANK);
+    private static final BitSet TERMINATORS = Tokenizer.INIT_BITSET(BLANK, EQUAL_CHAR, COMMA_CHAR);
+    private static final BitSet DELIMITER = Tokenizer.INIT_BITSET(COMMA_CHAR);
+    private static final BitSet SPACE = Tokenizer.INIT_BITSET(BLANK);
 
     static class ChallengeInt {
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
index c48be4f..357f8a8 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
@@ -41,9 +41,9 @@ import org.apache.hc.client5.http.cookie.MalformedCookieException;
 import org.apache.hc.client5.http.cookie.SetCookie;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.message.ParserCursor;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Cookie {@code expires} attribute handler conformant to the more relaxed interpretation
@@ -111,7 +111,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         if (TextUtils.isBlank(value)) {
             return;
         }
-        final ParserCursor cursor = new ParserCursor(0, value.length());
+        final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, value.length());
         final StringBuilder content = new StringBuilder();
 
         int second = 0, minute = 0, hour = 0, day = 0, month = 0, year = 0;
@@ -188,7 +188,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         cookie.setExpiryDate(c.getTime());
     }
 
-    private void skipDelims(final CharSequence buf, final ParserCursor cursor) {
+    private void skipDelims(final CharSequence buf, final Tokenizer.Cursor cursor) {
         int pos = cursor.getPos();
         final int indexFrom = cursor.getPos();
         final int indexTo = cursor.getUpperBound();
@@ -203,7 +203,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         cursor.updatePos(pos);
     }
 
-    private void copyContent(final CharSequence buf, final ParserCursor cursor, final StringBuilder dst) {
+    private void copyContent(final CharSequence buf, final Tokenizer.Cursor cursor, final StringBuilder dst) {
         int pos = cursor.getPos();
         final int indexFrom = cursor.getPos();
         final int indexTo = cursor.getUpperBound();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
index 97668f0..c815bc0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
@@ -50,10 +50,9 @@ import org.apache.hc.core5.http.FormattedHeader;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.BufferedHeader;
-import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Cookie management functions shared by RFC C6265 compliant specification.
@@ -71,14 +70,14 @@ public class RFC6265CookieSpec implements CookieSpec {
 
     // IMPORTANT!
     // These private static variables must be treated as immutable and never exposed outside this class
-    private static final BitSet TOKEN_DELIMS = TokenParser.INIT_BITSET(EQUAL_CHAR, PARAM_DELIMITER);
-    private static final BitSet VALUE_DELIMS = TokenParser.INIT_BITSET(PARAM_DELIMITER);
-    private static final BitSet SPECIAL_CHARS = TokenParser.INIT_BITSET(' ',
+    private static final BitSet TOKEN_DELIMS = Tokenizer.INIT_BITSET(EQUAL_CHAR, PARAM_DELIMITER);
+    private static final BitSet VALUE_DELIMS = Tokenizer.INIT_BITSET(PARAM_DELIMITER);
+    private static final BitSet SPECIAL_CHARS = Tokenizer.INIT_BITSET(' ',
             DQUOTE_CHAR, COMMA_CHAR, PARAM_DELIMITER, ESCAPE_CHAR);
 
     private final CookieAttributeHandler[] attribHandlers;
     private final Map<String, CookieAttributeHandler> attribHandlerMap;
-    private final TokenParser tokenParser;
+    private final Tokenizer tokenParser;
 
     protected RFC6265CookieSpec(final CommonCookieAttributeHandler... handlers) {
         super();
@@ -87,7 +86,7 @@ public class RFC6265CookieSpec implements CookieSpec {
         for (final CommonCookieAttributeHandler handler: handlers) {
             this.attribHandlerMap.put(handler.getAttributeName().toLowerCase(Locale.ROOT), handler);
         }
-        this.tokenParser = TokenParser.INSTANCE;
+        this.tokenParser = Tokenizer.INSTANCE;
     }
 
     static String getDefaultPath(final CookieOrigin origin) {
@@ -115,10 +114,10 @@ public class RFC6265CookieSpec implements CookieSpec {
             throw new MalformedCookieException("Unrecognized cookie header: '" + header + "'");
         }
         final CharArrayBuffer buffer;
-        final ParserCursor cursor;
+        final Tokenizer.Cursor cursor;
         if (header instanceof FormattedHeader) {
             buffer = ((FormattedHeader) header).getBuffer();
-            cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
+            cursor = new Tokenizer.Cursor(((FormattedHeader) header).getValuePos(), buffer.length());
         } else {
             final String s = header.getValue();
             if (s == null) {
@@ -126,7 +125,7 @@ public class RFC6265CookieSpec implements CookieSpec {
             }
             buffer = new CharArrayBuffer(s.length());
             buffer.append(s);
-            cursor = new ParserCursor(0, buffer.length());
+            cursor = new Tokenizer.Cursor(0, buffer.length());
         }
         final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
         if (name.isEmpty()) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
index 0053c1c..4e3dc8a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
@@ -33,32 +33,31 @@ import java.util.List;
 
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
-import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.Tokenizer;
 
 final class DistinguishedNameParser {
 
     public final static DistinguishedNameParser INSTANCE = new DistinguishedNameParser();
 
-    private static final BitSet EQUAL_OR_COMMA_OR_PLUS      = TokenParser.INIT_BITSET('=', ',', '+');
-    private static final BitSet COMMA_OR_PLUS               = TokenParser.INIT_BITSET(',', '+');
+    private static final BitSet EQUAL_OR_COMMA_OR_PLUS      = Tokenizer.INIT_BITSET('=', ',', '+');
+    private static final BitSet COMMA_OR_PLUS               = Tokenizer.INIT_BITSET(',', '+');
 
-    private final TokenParser tokenParser;
+    private final Tokenizer tokenParser;
 
     DistinguishedNameParser() {
         this.tokenParser = new InternalTokenParser();
     }
 
-    private String parseToken(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
+    private String parseToken(final CharArrayBuffer buf, final Tokenizer.Cursor cursor, final BitSet delimiters) {
         return tokenParser.parseToken(buf, cursor, delimiters);
     }
 
-    private String parseValue(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
+    private String parseValue(final CharArrayBuffer buf, final Tokenizer.Cursor cursor, final BitSet delimiters) {
         return tokenParser.parseValue(buf, cursor, delimiters);
     }
 
-    private NameValuePair parseParameter(final CharArrayBuffer buf, final ParserCursor cursor) {
+    private NameValuePair parseParameter(final CharArrayBuffer buf, final Tokenizer.Cursor cursor) {
         final String name = parseToken(buf, cursor, EQUAL_OR_COMMA_OR_PLUS);
         if (cursor.atEnd()) {
             return new BasicNameValuePair(name, null);
@@ -75,7 +74,7 @@ final class DistinguishedNameParser {
         return new BasicNameValuePair(name, value);
     }
 
-    List<NameValuePair> parse(final CharArrayBuffer buf, final ParserCursor cursor) {
+    List<NameValuePair> parse(final CharArrayBuffer buf, final Tokenizer.Cursor cursor) {
         final List<NameValuePair> params = new ArrayList<>();
         tokenParser.skipWhiteSpace(buf, cursor);
         while (!cursor.atEnd()) {
@@ -91,16 +90,16 @@ final class DistinguishedNameParser {
         }
         final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
         buffer.append(s);
-        final ParserCursor cursor = new ParserCursor(0, s.length());
+        final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, s.length());
         return parse(buffer, cursor);
     }
 
-    static class InternalTokenParser extends TokenParser {
+    static class InternalTokenParser extends Tokenizer {
 
         @Override
         public void copyUnquotedContent(
                 final CharSequence buf,
-                final ParserCursor cursor,
+                final Tokenizer.Cursor cursor,
                 final BitSet delimiters,
                 final StringBuilder dst) {
             int pos = cursor.getPos();
@@ -114,7 +113,7 @@ final class DistinguishedNameParser {
                     escaped = false;
                 } else {
                     if ((delimiters != null && delimiters.get(current))
-                            || TokenParser.isWhitespace(current) || current == '\"') {
+                            || Tokenizer.isWhitespace(current) || current == '\"') {
                         break;
                     } else if (current == '\\') {
                         escaped = true;