hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [1/4] httpcomponents-client git commit: Moved ByteArrayBuilder class (no functional changes)
Date Wed, 03 Jan 2018 18:47:25 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master eb1cab46e -> 47a0eb8b6


Moved ByteArrayBuilder class (no functional changes)


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/db4b6db7
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/db4b6db7
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/db4b6db7

Branch: refs/heads/master
Commit: db4b6db79fbb7f36d02d2b401658f36a91a47028
Parents: eb1cab4
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Wed Jan 3 14:35:51 2018 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Wed Jan 3 14:36:20 2018 +0100

----------------------------------------------------------------------
 .../hc/client5/http/auth/ByteArrayBuilder.java  | 211 +++++++++++++++++++
 .../http/auth/util/ByteArrayBuilder.java        | 211 -------------------
 .../hc/client5/http/impl/auth/BasicScheme.java  |   2 +-
 .../hc/client5/http/impl/auth/DigestScheme.java |   2 +-
 .../client5/http/impl/auth/NTLMEngineImpl.java  |   2 +-
 .../http/auth/util/TestByteArrayBuilder.java    |   1 +
 6 files changed, 215 insertions(+), 214 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/db4b6db7/httpclient5/src/main/java/org/apache/hc/client5/http/auth/ByteArrayBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/ByteArrayBuilder.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/ByteArrayBuilder.java
new file mode 100644
index 0000000..1d12878
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/ByteArrayBuilder.java
@@ -0,0 +1,211 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.http.auth;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+
+/**
+ * Builder class for sequences of bytes.
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class ByteArrayBuilder {
+
+    private CharsetEncoder charsetEncoder;
+    private ByteBuffer buffer;
+
+    public ByteArrayBuilder() {
+    }
+
+    public ByteArrayBuilder(final int initialCapacity) {
+        this.buffer = ByteBuffer.allocate(initialCapacity);
+    }
+
+    public int capacity() {
+        return this.buffer != null ? this.buffer.capacity() : 0;
+    }
+
+    static ByteBuffer ensureFreeCapacity(final ByteBuffer buffer, final int capacity) {
+        if (buffer == null) {
+            return ByteBuffer.allocate(capacity);
+        }
+        if (buffer.remaining() < capacity) {
+            final ByteBuffer newBuffer = ByteBuffer.allocate(buffer.position() + capacity);
+            buffer.flip();
+            newBuffer.put(buffer);
+            return newBuffer;
+        }
+        return buffer;
+    }
+
+    static ByteBuffer encode(
+            final ByteBuffer buffer, final CharBuffer in, final CharsetEncoder encoder) throws
CharacterCodingException {
+
+        final int capacity = (int) (in.remaining() * encoder.averageBytesPerChar());
+        ByteBuffer out = ensureFreeCapacity(buffer, capacity);
+        for (;;) {
+            CoderResult result = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
+            if (result.isError()) {
+                result.throwException();
+            }
+            if (result.isUnderflow()) {
+                result = encoder.flush(out);
+            }
+            if (result.isUnderflow()) {
+                break;
+            }
+            if (result.isOverflow()) {
+                out = ensureFreeCapacity(out, capacity);
+            }
+        }
+        return out;
+    }
+
+    public void ensureFreeCapacity(final int freeCapacity) {
+        this.buffer = ensureFreeCapacity(this.buffer, freeCapacity);
+    }
+
+    private void doAppend(final CharBuffer charBuffer) {
+        if (this.charsetEncoder == null) {
+            this.charsetEncoder = StandardCharsets.US_ASCII.newEncoder()
+                    .onMalformedInput(CodingErrorAction.IGNORE)
+                    .onUnmappableCharacter(CodingErrorAction.REPLACE);
+        }
+        this.charsetEncoder.reset();
+        try {
+            this.buffer = encode(this.buffer, charBuffer, this.charsetEncoder);
+        } catch (final CharacterCodingException ex) {
+            // Should never happen
+            throw new IllegalStateException("Unexpected character coding error", ex);
+        }
+    }
+
+    public ByteArrayBuilder charset(final Charset charset) {
+        if (charset == null) {
+            this.charsetEncoder = null;
+        } else {
+            this.charsetEncoder = charset.newEncoder()
+                    .onMalformedInput(CodingErrorAction.IGNORE)
+                    .onUnmappableCharacter(CodingErrorAction.REPLACE);
+        }
+        return this;
+    }
+
+    public ByteArrayBuilder append(final byte[] b, final int off, final int len) {
+        if (b == null) {
+            return this;
+        }
+        if ((off < 0) || (off > b.length) || (len < 0) ||
+                ((off + len) < 0) || ((off + len) > b.length)) {
+            throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length:
" + b.length);
+        }
+        ensureFreeCapacity(len);
+        this.buffer.put(b, off, len);
+        return this;
+    }
+
+    public ByteArrayBuilder append(final byte[] b) {
+        if (b == null) {
+            return this;
+        }
+        return append(b, 0, b.length);
+    }
+
+    public ByteArrayBuilder append(final CharBuffer charBuffer) {
+        if (charBuffer == null) {
+            return this;
+        }
+        doAppend(charBuffer);
+        return this;
+    }
+
+    public ByteArrayBuilder append(final char[] b, final int off, final int len) {
+        if (b == null) {
+            return this;
+        }
+        if ((off < 0) || (off > b.length) || (len < 0) ||
+                ((off + len) < 0) || ((off + len) > b.length)) {
+            throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length:
" + b.length);
+        }
+        return append(CharBuffer.wrap(b, off, len));
+    }
+
+    public ByteArrayBuilder append(final char[] b) {
+        if (b == null) {
+            return this;
+        }
+        return append(b, 0, b.length);
+    }
+
+    public ByteArrayBuilder append(final String s) {
+        if (s == null) {
+            return this;
+        }
+        return append(CharBuffer.wrap(s));
+    }
+
+    public ByteBuffer toByteBuffer() {
+        return this.buffer != null ? this.buffer.duplicate() : ByteBuffer.allocate(0);
+    }
+
+    public byte[] toByteArray() {
+        if (this.buffer == null) {
+            return new byte[] {};
+        }
+        this.buffer.flip();
+        final byte[] b = new byte[this.buffer.remaining()];
+        this.buffer.get(b);
+        this.buffer.clear();
+        return b;
+    }
+
+    public void reset() {
+        if (this.charsetEncoder != null) {
+            this.charsetEncoder.reset();
+        }
+        if (this.buffer != null) {
+            this.buffer.clear();
+        }
+    }
+
+    @Override
+    public String toString() {
+        return this.buffer != null ? this.buffer.toString() : "null";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/db4b6db7/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/ByteArrayBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/ByteArrayBuilder.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/ByteArrayBuilder.java
deleted file mode 100644
index 138f681..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/ByteArrayBuilder.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.auth.util;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.hc.core5.annotation.Contract;
-import org.apache.hc.core5.annotation.ThreadingBehavior;
-
-/**
- * Builder class for sequences of bytes.
- *
- * @since 5.0
- */
-@Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class ByteArrayBuilder {
-
-    private CharsetEncoder charsetEncoder;
-    private ByteBuffer buffer;
-
-    public ByteArrayBuilder() {
-    }
-
-    public ByteArrayBuilder(final int initialCapacity) {
-        this.buffer = ByteBuffer.allocate(initialCapacity);
-    }
-
-    public int capacity() {
-        return this.buffer != null ? this.buffer.capacity() : 0;
-    }
-
-    static ByteBuffer ensureFreeCapacity(final ByteBuffer buffer, final int capacity) {
-        if (buffer == null) {
-            return ByteBuffer.allocate(capacity);
-        }
-        if (buffer.remaining() < capacity) {
-            final ByteBuffer newBuffer = ByteBuffer.allocate(buffer.position() + capacity);
-            buffer.flip();
-            newBuffer.put(buffer);
-            return newBuffer;
-        }
-        return buffer;
-    }
-
-    static ByteBuffer encode(
-            final ByteBuffer buffer, final CharBuffer in, final CharsetEncoder encoder) throws
CharacterCodingException {
-
-        final int capacity = (int) (in.remaining() * encoder.averageBytesPerChar());
-        ByteBuffer out = ensureFreeCapacity(buffer, capacity);
-        for (;;) {
-            CoderResult result = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
-            if (result.isError()) {
-                result.throwException();
-            }
-            if (result.isUnderflow()) {
-                result = encoder.flush(out);
-            }
-            if (result.isUnderflow()) {
-                break;
-            }
-            if (result.isOverflow()) {
-                out = ensureFreeCapacity(out, capacity);
-            }
-        }
-        return out;
-    }
-
-    public void ensureFreeCapacity(final int freeCapacity) {
-        this.buffer = ensureFreeCapacity(this.buffer, freeCapacity);
-    }
-
-    private void doAppend(final CharBuffer charBuffer) {
-        if (this.charsetEncoder == null) {
-            this.charsetEncoder = StandardCharsets.US_ASCII.newEncoder()
-                    .onMalformedInput(CodingErrorAction.IGNORE)
-                    .onUnmappableCharacter(CodingErrorAction.REPLACE);
-        }
-        this.charsetEncoder.reset();
-        try {
-            this.buffer = encode(this.buffer, charBuffer, this.charsetEncoder);
-        } catch (final CharacterCodingException ex) {
-            // Should never happen
-            throw new IllegalStateException("Unexpected character coding error", ex);
-        }
-    }
-
-    public ByteArrayBuilder charset(final Charset charset) {
-        if (charset == null) {
-            this.charsetEncoder = null;
-        } else {
-            this.charsetEncoder = charset.newEncoder()
-                    .onMalformedInput(CodingErrorAction.IGNORE)
-                    .onUnmappableCharacter(CodingErrorAction.REPLACE);
-        }
-        return this;
-    }
-
-    public ByteArrayBuilder append(final byte[] b, final int off, final int len) {
-        if (b == null) {
-            return this;
-        }
-        if ((off < 0) || (off > b.length) || (len < 0) ||
-                ((off + len) < 0) || ((off + len) > b.length)) {
-            throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length:
" + b.length);
-        }
-        ensureFreeCapacity(len);
-        this.buffer.put(b, off, len);
-        return this;
-    }
-
-    public ByteArrayBuilder append(final byte[] b) {
-        if (b == null) {
-            return this;
-        }
-        return append(b, 0, b.length);
-    }
-
-    public ByteArrayBuilder append(final CharBuffer charBuffer) {
-        if (charBuffer == null) {
-            return this;
-        }
-        doAppend(charBuffer);
-        return this;
-    }
-
-    public ByteArrayBuilder append(final char[] b, final int off, final int len) {
-        if (b == null) {
-            return this;
-        }
-        if ((off < 0) || (off > b.length) || (len < 0) ||
-                ((off + len) < 0) || ((off + len) > b.length)) {
-            throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length:
" + b.length);
-        }
-        return append(CharBuffer.wrap(b, off, len));
-    }
-
-    public ByteArrayBuilder append(final char[] b) {
-        if (b == null) {
-            return this;
-        }
-        return append(b, 0, b.length);
-    }
-
-    public ByteArrayBuilder append(final String s) {
-        if (s == null) {
-            return this;
-        }
-        return append(CharBuffer.wrap(s));
-    }
-
-    public ByteBuffer toByteBuffer() {
-        return this.buffer != null ? this.buffer.duplicate() : ByteBuffer.allocate(0);
-    }
-
-    public byte[] toByteArray() {
-        if (this.buffer == null) {
-            return new byte[] {};
-        }
-        this.buffer.flip();
-        final byte[] b = new byte[this.buffer.remaining()];
-        this.buffer.get(b);
-        this.buffer.clear();
-        return b;
-    }
-
-    public void reset() {
-        if (this.charsetEncoder != null) {
-            this.charsetEncoder.reset();
-        }
-        if (this.buffer != null) {
-            this.buffer.clear();
-        }
-    }
-
-    @Override
-    public String toString() {
-        return this.buffer != null ? this.buffer.toString() : "null";
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/db4b6db7/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
index d700184..a198b8f 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
@@ -48,7 +48,7 @@ import org.apache.hc.client5.http.auth.AuthenticationException;
 import org.apache.hc.client5.http.auth.Credentials;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
 import org.apache.hc.client5.http.auth.MalformedChallengeException;
-import org.apache.hc.client5.http.auth.util.ByteArrayBuilder;
+import org.apache.hc.client5.http.auth.ByteArrayBuilder;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.NameValuePair;

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/db4b6db7/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
index 2c754f1..ed87755 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
@@ -51,7 +51,7 @@ import org.apache.hc.client5.http.auth.AuthenticationException;
 import org.apache.hc.client5.http.auth.Credentials;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
 import org.apache.hc.client5.http.auth.MalformedChallengeException;
-import org.apache.hc.client5.http.auth.util.ByteArrayBuilder;
+import org.apache.hc.client5.http.auth.ByteArrayBuilder;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHost;

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/db4b6db7/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
index c8e5db0..e3a4dc3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
@@ -41,7 +41,7 @@ import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.codec.binary.Base64;
-import org.apache.hc.client5.http.auth.util.ByteArrayBuilder;
+import org.apache.hc.client5.http.auth.ByteArrayBuilder;
 
 /**
  * Provides an implementation for NTLMv1, NTLMv2, and NTLM2 Session forms of the NTLM

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/db4b6db7/httpclient5/src/test/java/org/apache/hc/client5/http/auth/util/TestByteArrayBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/util/TestByteArrayBuilder.java
b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/util/TestByteArrayBuilder.java
index 3438ad9..a6a2f4e 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/util/TestByteArrayBuilder.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/util/TestByteArrayBuilder.java
@@ -29,6 +29,7 @@ package org.apache.hc.client5.http.auth.util;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.hc.client5.http.auth.ByteArrayBuilder;
 import org.junit.Assert;
 import org.junit.Test;
 


Mime
View raw message