diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 000000000..5d56b3594
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,41 @@
+# This is a basic workflow to help you get started with Actions
+
+name: CI
+
+# Controls when the workflow will run
+on:
+ # Triggers the workflow on push or pull request events but only for the firefly-5.0.0 branch
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+ # This workflow contains a single job called "build"
+ build:
+ # The type of runner that the job will run on
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ java: [8, 11, 17, 21]
+
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v2
+
+ - name: Install dependencies Ubuntu
+ run: sudo apt-get update && sudo apt-get install openssl
+
+ - name: Set up JDK
+ uses: actions/setup-java@v2
+ with:
+ java-version: '${{ matrix.java }}'
+ distribution: 'temurin'
+
+ - name: Build with Maven
+ run: mvn -B clean package
diff --git a/.gitignore b/.gitignore
index 0910ed97c..3b4776dfa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,14 @@
.settings
*.class
.DS_Store
+*.iml
+*.iws
+*.ipr
+.idea
+out
+target
+firefly-common/logs/
+firefly/temp/
+logs/
+temp/
+/.java-version
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..f907521b9
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+arch: arm64
+os: linux
+language: java
+jdk:
+ - openjdk8
+ - openjdk11
+ - openjdk16
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 000000000..d64569567
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/README.md b/README.md
new file mode 100644
index 000000000..fe011397a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,157 @@
+# What is Firefly?
+[](https://github.com/hypercube1024/firefly)
+[](https://search.maven.org/artifact/com.fireflysource/firefly-net/)
+[](https://opensource.org/licenses/Apache-2.0)
+
+Firefly framework is an asynchronous Java web framework. It helps you create a web application ***Easy*** and ***Quickly***.
+It provides asynchronous HTTP, Websocket, TCP Server/Client, and many other useful components for developing
+web applications, protocol servers, etc. That means you can easy deploy your web without any other java web containers,
+in short, it's containerless. Using Kotlin coroutines, Firefly is truly asynchronous and highly scalable. It taps into
+the fullest potential of hardware. Use the power of non-blocking development without the callback nightmare.
+
+Firefly core provides functionality for things like:
+
+- HTTP server and client
+- WebSocket server and client
+- HTTP, Socks proxy
+- HTTP Gateway
+- TCP server and client
+- UDP server and client
+
+# Event driven
+The Firefly APIs are largely event-driven. It means that when things happen in Firefly that you are interested in,
+Firefly will call you by sending you events.
+
+Some example events are:
+- some data has arrived on a socket
+- an HTTP server has received a request
+
+Firefly handles a lot of concurrencies using just a small number of threads, so ***don't block Firefly thread***, you
+must manage blocking call in the standalone thread pool.
+
+With a conventional blocking API the calling thread might block when:
+- Thread.sleep()
+- Waiting on a Lock
+- Waiting on a mutex or monitor
+- Doing a long-lived database operation and waiting for a result
+- Call blocking I/O APIs
+
+In all the above cases, when your thread is waiting for a result it can’t do anything else - it’s effectively useless.
+
+It means that if you want a lot of concurrencies using blocking APIs, then you need a lot of threads to prevent your
+application grinding to a halt.
+
+Threads have overhead regarding the memory they require (e.g. for their stack) and in context switching.
+
+For the levels of concurrency required in many modern applications, a blocking approach just doesn’t scale.
+
+# Quick start
+Add maven dependency in your pom.xml.
+```xml
+
- * Splits the provided text into an array, using whitespace as the - * separator. Whitespace is defined by {@link Character#isWhitespace(char)}. - *
- * - *- * The separator is not included in the returned String array. Adjacent - * separators are treated as one separator. For more control over the split - * use the StrTokenizer class. - *
- * - *
- * A null input String returns null.
- *
- * StringUtils.split(null) = null
- * StringUtils.split("") = []
- * StringUtils.split("abc def") = ["abc", "def"]
- * StringUtils.split("abc def") = ["abc", "def"]
- * StringUtils.split(" abc ") = ["abc"]
- *
- *
- * @param str
- * the String to parse, may be null
- * @return an array of parsed Strings, null if null String
- * input
- */
- public static String[] split(String str) {
- return split(str, null, -1);
- }
-
- /**
- * - * Splits the provided text into an array, separators specified. This is an - * alternative to using StringTokenizer. - *
- * - *- * The separator is not included in the returned String array. Adjacent - * separators are treated as one separator. For more control over the split - * use the StrTokenizer class. - *
- * - *
- * A null input String returns null. A
- * null separatorChars splits on whitespace.
- *
- * StringUtils.split(null, *) = null
- * StringUtils.split("", *) = []
- * StringUtils.split("abc def", null) = ["abc", "def"]
- * StringUtils.split("abc def", " ") = ["abc", "def"]
- * StringUtils.split("abc def", " ") = ["abc", "def"]
- * StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
- *
- *
- * @param str
- * the String to parse, may be null
- * @param separatorChars
- * the characters used as the delimiters, null
- * splits on whitespace
- * @return an array of parsed Strings, null if null String
- * input
- */
- public static String[] split(String str, String separatorChars) {
- return splitWorker(str, separatorChars, -1, false);
- }
-
- /**
- * - * Splits the provided text into an array, separator specified. This is an - * alternative to using StringTokenizer. - *
- * - *- * The separator is not included in the returned String array. Adjacent - * separators are treated as one separator. For more control over the split - * use the StrTokenizer class. - *
- * - *
- * A null input String returns null.
- *
- * StringUtils.split(null, *) = null
- * StringUtils.split("", *) = []
- * StringUtils.split("a.b.c", '.') = ["a", "b", "c"]
- * StringUtils.split("a..b.c", '.') = ["a", "b", "c"]
- * StringUtils.split("a:b:c", '.') = ["a:b:c"]
- * StringUtils.split("a b c", ' ') = ["a", "b", "c"]
- *
- *
- * @param str
- * the String to parse, may be null
- * @param separatorChar
- * the character used as the delimiter
- * @return an array of parsed Strings, null if null String
- * input
- * @since 2.0
- */
- public static String[] split(String str, char separatorChar) {
- return splitWorker(str, separatorChar, false);
- }
-
- /**
- * - * Splits the provided text into an array with a maximum length, separators - * specified. - *
- * - *- * The separator is not included in the returned String array. Adjacent - * separators are treated as one separator. - *
- * - *
- * A null input String returns null. A
- * null separatorChars splits on whitespace.
- *
- * If more than max delimited substrings are found, the last
- * returned string includes all characters after the first
- * max - 1 returned strings (including separator characters).
- *
- * StringUtils.split(null, *, *) = null
- * StringUtils.split("", *, *) = []
- * StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"]
- * StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"]
- * StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"]
- * StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
- *
- *
- * @param str
- * the String to parse, may be null
- * @param separatorChars
- * the characters used as the delimiters, null
- * splits on whitespace
- * @param max
- * the maximum number of elements to include in the array. A zero
- * or negative value implies no limit
- * @return an array of parsed Strings, null if null String
- * input
- */
- public static String[] split(String str, String separatorChars, int max) {
- return splitWorker(str, separatorChars, max, false);
- }
-
- /**
- * Performs the logic for the split and
- * splitPreserveAllTokens methods that return a maximum array
- * length.
- *
- * @param str
- * the String to parse, may be null
- * @param separatorChars
- * the separate character
- * @param max
- * the maximum number of elements to include in the array. A zero
- * or negative value implies no limit.
- * @param preserveAllTokens
- * if true, adjacent separators are treated as empty
- * token separators; if false, adjacent separators
- * are treated as one separator.
- * @return an array of parsed Strings, null if null String
- * input
- */
- private static String[] splitWorker(String str, String separatorChars,
- int max, boolean preserveAllTokens) {
- // Performance tuned for 2.0 (JDK1.4)
- // Direct code is quicker than StringTokenizer.
- // Also, StringTokenizer uses isSpace() not isWhitespace()
-
- if (str == null) {
- return null;
- }
- int len = str.length();
- if (len == 0) {
- return EMPTY_STRING_ARRAY;
- }
- Listsplit and
- * splitPreserveAllTokens methods that do not return a maximum
- * array length.
- *
- * @param str
- * the String to parse, may be null
- * @param separatorChar
- * the separate character
- * @param preserveAllTokens
- * if true, adjacent separators are treated as empty
- * token separators; if false, adjacent separators
- * are treated as one separator.
- * @return an array of parsed Strings, null if null String
- * input
- */
- private static String[] splitWorker(String str, char separatorChar,
- boolean preserveAllTokens) {
- // Performance tuned for 2.0 (JDK1.4)
-
- if (str == null) {
- return null;
- }
- int len = str.length();
- if (len == 0) {
- return EMPTY_STRING_ARRAY;
- }
- ListSplits the provided text into an array, separator string specified.
- * - *The separator(s) will not be included in the returned String array. - * Adjacent separators are treated as one separator.
- * - *A null input String returns null.
- * A null separator splits on whitespace.
- * StringUtils.splitByWholeSeparator(null, *) = null
- * StringUtils.splitByWholeSeparator("", *) = []
- * StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
- * StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
- * StringUtils.splitByWholeSeparator("ab:cd:ef", ":") = ["ab", "cd", "ef"]
- * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
- *
- *
- * @param str the String to parse, may be null
- * @param separator String containing the String to be used as a delimiter,
- * null splits on whitespace
- * @return an array of parsed Strings, null if null String was input
- */
- public static String[] splitByWholeSeparator(String str, String separator) {
- return splitByWholeSeparatorWorker( str, separator, -1, false ) ;
- }
-
- /**
- * Splits the provided text into an array, separator string specified.
- * Returns a maximum of max substrings.
The separator(s) will not be included in the returned String array. - * Adjacent separators are treated as one separator.
- * - *A null input String returns null.
- * A null separator splits on whitespace.
- * StringUtils.splitByWholeSeparator(null, *, *) = null
- * StringUtils.splitByWholeSeparator("", *, *) = []
- * StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
- * StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
- * StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
- * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
- * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]
- *
- *
- * @param str the String to parse, may be null
- * @param separator String containing the String to be used as a delimiter,
- * null splits on whitespace
- * @param max the maximum number of elements to include in the returned
- * array. A zero or negative value implies no limit.
- * @return an array of parsed Strings, null if null String was input
- */
- public static String[] splitByWholeSeparator( String str, String separator, int max ) {
- return splitByWholeSeparatorWorker(str, separator, max, false);
- }
-
- /**
- * Performs the logic for the splitByWholeSeparatorPreserveAllTokens methods.
- *
- * @param str the String to parse, may be null
- * @param separator String containing the String to be used as a delimiter,
- * null splits on whitespace
- * @param max the maximum number of elements to include in the returned
- * array. A zero or negative value implies no limit.
- * @param preserveAllTokens if true, adjacent separators are
- * treated as empty token separators; if false, adjacent
- * separators are treated as one separator.
- * @return an array of parsed Strings, null if null String input
- * @since 2.4
- */
- private static String[] splitByWholeSeparatorWorker(String str, String separator, int max,
- boolean preserveAllTokens)
- {
- if (str == null) {
- return null;
- }
-
- int len = str.length();
-
- if (len == 0) {
- return EMPTY_STRING_ARRAY;
- }
-
- if ((separator == null) || (EMPTY.equals(separator))) {
- // Split on whitespace.
- return splitWorker(str, null, max, preserveAllTokens);
- }
-
- int separatorLength = separator.length();
-
- ArrayListUsages of this class should typically be of the form: - * {@code ThreadLocalRandom.current().nextX(...)} (where - * {@code X} is {@code Int}, {@code Long}, etc). - * When all usages are of this form, it is never possible to - * accidently share a {@code ThreadLocalRandom} across multiple threads. - * - *
This class also provides additional commonly used bounded random
- * generation methods.
- *
- * @since 1.7
- * @author Doug Lea
- */
-public final class ThreadLocalRandom extends Random {
- // same constants as Random, but must be redeclared because private
- private final static long multiplier = 0x5DEECE66DL;
- private final static long addend = 0xBL;
- private final static long mask = (1L << 48) - 1;
-
- /**
- * The random seed. We can't use super.seed.
- */
- private long rnd;
-
- /**
- * Initialization flag to permit the first and only allowed call
- * to setSeed (inside Random constructor) to succeed. We can't
- * allow others since it would cause setting seed in one part of a
- * program to unintentionally impact other usages by the thread.
- */
- private boolean initialized;
-
- // Padding to help avoid memory contention among seed updates in
- // different TLRs in the common case that they are located near
- // each other.
- @SuppressWarnings("unused")
- private long pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7;
-
- /**
- * The actual ThreadLocal
- */
- private static final ThreadLocal
- * More formally, if this map contains a mapping from a key {@code k} to a
- * value {@code v} such that {@code key.equals(k)}, then this method returns
- * {@code v}; otherwise it returns {@code null}. (There can be at most one
- * such mapping.)
- *
- * @throws NullPointerException
- * if the specified key is null
- */
- public V get(Object key) {
- int hash = hash(key.hashCode());
- return segmentFor(hash).get(key, hash);
- }
-
- /**
- * Tests if the specified object is a key in this table.
- *
- * @param key
- * possible key
- * @return true if and only if the specified object is a key in
- * this table, as determined by the equals method;
- * false otherwise.
- * @throws NullPointerException
- * if the specified key is null
- */
- public boolean containsKey(Object key) {
- int hash = hash(key.hashCode());
- return segmentFor(hash).containsKey(key, hash);
- }
-
- /**
- * Returns true if this map maps one or more keys to the specified
- * value. Note: This method requires a full internal traversal of the hash
- * table, and so is much slower than method containsKey.
- *
- * @param value
- * value whose presence in this map is to be tested
- * @return true if this map maps one or more keys to the specified
- * value
- * @throws NullPointerException
- * if the specified value is null
- */
- public boolean containsValue(Object value) {
- if (value == null)
- throw new NullPointerException();
-
- // See explanation of modCount use above
-
- final Segment
- * The view's iterator is a "weakly consistent" iterator that will
- * never throw {@link ConcurrentModificationException}, and guarantees to
- * traverse elements as they existed upon construction of the iterator, and
- * may (but is not guaranteed to) reflect any modifications subsequent to
- * construction.
- */
- public Set
- * The view's iterator is a "weakly consistent" iterator that will
- * never throw {@link ConcurrentModificationException}, and guarantees to
- * traverse elements as they existed upon construction of the iterator, and
- * may (but is not guaranteed to) reflect any modifications subsequent to
- * construction.
- */
- public Collection
- * The view's iterator is a "weakly consistent" iterator that will
- * never throw {@link ConcurrentModificationException}, and guarantees to
- * traverse elements as they existed upon construction of the iterator, and
- * may (but is not guaranteed to) reflect any modifications subsequent to
- * construction.
- */
- public Set Beware that, unlike in most collections, the {@code size} method
- * is NOT a constant-time operation. Because of the
- * asynchronous nature of these queues, determining the current number
- * of elements requires a traversal of the elements, and so may report
- * inaccurate results if this collection is modified during traversal.
- * Additionally, the bulk operations {@code addAll},
- * {@code removeAll}, {@code retainAll}, {@code containsAll},
- * {@code equals}, and {@code toArray} are not guaranteed
- * to be performed atomically. For example, an iterator operating
- * concurrently with an {@code addAll} operation might view only some
- * of the added elements.
- *
- * This class and its iterator implement all of the
- * optional methods of the {@link Collection} and {@link
- * Iterator} interfaces.
- *
- * Memory consistency effects: As with other concurrent
- * collections, actions in a thread prior to placing an object into a
- * {@code LinkedTransferQueue}
- * happen-before
- * actions subsequent to the access or removal of that element from
- * the {@code LinkedTransferQueue} in another thread.
- *
- * This class is a member of the
- *
- * Java Collections Framework.
- *
- * @since 1.7
- * @author Doug Lea
- * @param More precisely, transfers the specified element immediately
- * if there exists a consumer already waiting to receive it (in
- * {@link #take} or timed {@link #poll(long,TimeUnit) poll}),
- * otherwise returning {@code false} without enqueuing the element.
- *
- * @throws NullPointerException if the specified element is null
- */
- public boolean tryTransfer(E e) {
- return xfer(e, true, NOW, 0) == null;
- }
-
- /**
- * Transfers the element to a consumer, waiting if necessary to do so.
- *
- * More precisely, transfers the specified element immediately
- * if there exists a consumer already waiting to receive it (in
- * {@link #take} or timed {@link #poll(long,TimeUnit) poll}),
- * else inserts the specified element at the tail of this queue
- * and waits until the element is received by a consumer.
- *
- * @throws NullPointerException if the specified element is null
- */
- public void transfer(E e) throws InterruptedException {
- if (xfer(e, true, SYNC, 0) != null) {
- Thread.interrupted(); // failure possible only due to interrupt
- throw new InterruptedException();
- }
- }
-
- /**
- * Transfers the element to a consumer if it is possible to do so
- * before the timeout elapses.
- *
- * More precisely, transfers the specified element immediately
- * if there exists a consumer already waiting to receive it (in
- * {@link #take} or timed {@link #poll(long,TimeUnit) poll}),
- * else inserts the specified element at the tail of this queue
- * and waits until the element is received by a consumer,
- * returning {@code false} if the specified wait time elapses
- * before the element can be transferred.
- *
- * @throws NullPointerException if the specified element is null
- */
- public boolean tryTransfer(E e, long timeout, TimeUnit unit)
- throws InterruptedException {
- if (xfer(e, true, TIMED, unit.toNanos(timeout)) == null)
- return true;
- if (!Thread.interrupted())
- return false;
- throw new InterruptedException();
- }
-
- public E take() throws InterruptedException {
- E e = xfer(null, false, SYNC, 0);
- if (e != null)
- return e;
- Thread.interrupted();
- throw new InterruptedException();
- }
-
- public E poll(long timeout, TimeUnit unit) throws InterruptedException {
- E e = xfer(null, false, TIMED, unit.toNanos(timeout));
- if (e != null || !Thread.interrupted())
- return e;
- throw new InterruptedException();
- }
-
- public E poll() {
- return xfer(null, false, NOW, 0);
- }
-
- /**
- * @throws NullPointerException {@inheritDoc}
- * @throws IllegalArgumentException {@inheritDoc}
- */
- public int drainTo(Collection super E> c) {
- if (c == null)
- throw new NullPointerException();
- if (c == this)
- throw new IllegalArgumentException();
- int n = 0;
- for (E e; (e = poll()) != null;) {
- c.add(e);
- ++n;
- }
- return n;
- }
-
- /**
- * @throws NullPointerException {@inheritDoc}
- * @throws IllegalArgumentException {@inheritDoc}
- */
- public int drainTo(Collection super E> c, int maxElements) {
- if (c == null)
- throw new NullPointerException();
- if (c == this)
- throw new IllegalArgumentException();
- int n = 0;
- for (E e; n < maxElements && (e = poll()) != null;) {
- c.add(e);
- ++n;
- }
- return n;
- }
-
- /**
- * Returns an iterator over the elements in this queue in proper sequence.
- * The elements will be returned in order from first (head) to last (tail).
- *
- * The returned iterator is a "weakly consistent" iterator that
- * will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException}, and guarantees to traverse
- * elements as they existed upon construction of the iterator, and
- * may (but is not guaranteed to) reflect any modifications
- * subsequent to construction.
- *
- * @return an iterator over the elements in this queue in proper sequence
- */
- public Iterator Beware that, unlike in most collections, this method is
- * NOT a constant-time operation. Because of the
- * asynchronous nature of these queues, determining the current
- * number of elements requires an O(n) traversal.
- *
- * @return the number of elements in this queue
- */
- public int size() {
- return countOfMode(true);
- }
-
- public int getWaitingConsumerCount() {
- return countOfMode(false);
- }
-
- /**
- * Removes a single instance of the specified element from this queue,
- * if it is present. More formally, removes an element {@code e} such
- * that {@code o.equals(e)}, if this queue contains one or more such
- * elements.
- * Returns {@code true} if this queue contained the specified element
- * (or equivalently, if this queue changed as a result of the call).
- *
- * @param o element to be removed from this queue, if present
- * @return {@code true} if this queue changed as a result of the call
- */
- public boolean remove(Object o) {
- return findAndRemove(o);
- }
-
- /**
- * Returns {@code true} if this queue contains the specified element.
- * More formally, returns {@code true} if and only if this queue contains
- * at least one element {@code e} such that {@code o.equals(e)}.
- *
- * @param o object to be checked for containment in this queue
- * @return {@code true} if this queue contains the specified element
- */
- public boolean contains(Object o) {
- if (o == null) return false;
- for (Node p = head; p != null; p = succ(p)) {
- Object item = p.item;
- if (p.isData) {
- if (item != null && item != p && o.equals(item))
- return true;
- }
- else if (item == null)
- break;
- }
- return false;
- }
-
- /**
- * Always returns {@code Integer.MAX_VALUE} because a
- * {@code LinkedTransferQueue} is not capacity constrained.
- *
- * @return {@code Integer.MAX_VALUE} (as specified by
- * {@link java.util.concurrent.BlockingQueue#remainingCapacity()
- * BlockingQueue.remainingCapacity})
- */
- public int remainingCapacity() {
- return Integer.MAX_VALUE;
- }
-
- /**
- * Saves the state to a stream (that is, serializes it).
- *
- * @serialData All of the elements (each an {@code E}) in
- * the proper order, followed by a null
- * @param s the stream
- */
- private void writeObject(java.io.ObjectOutputStream s)
- throws java.io.IOException {
- s.defaultWriteObject();
- for (E e : this)
- s.writeObject(e);
- // Use trailing null as sentinel
- s.writeObject(null);
- }
-
- /**
- * Reconstitutes the Queue instance from a stream (that is,
- * deserializes it).
- *
- * @param s the stream
- */
- private void readObject(java.io.ObjectInputStream s)
- throws java.io.IOException, ClassNotFoundException {
- s.defaultReadObject();
- for (;;) {
- @SuppressWarnings("unchecked")
- E item = (E) s.readObject();
- if (item == null)
- break;
- else
- offer(item);
- }
- }
-
- // Unsafe mechanics
-
- private static final sun.misc.Unsafe UNSAFE;
- private static final long headOffset;
- private static final long tailOffset;
- private static final long sweepVotesOffset;
- static {
- try {
- UNSAFE = getUnsafe();
- Class> k = LinkedTransferQueue.class;
- headOffset = UNSAFE.objectFieldOffset
- (k.getDeclaredField("head"));
- tailOffset = UNSAFE.objectFieldOffset
- (k.getDeclaredField("tail"));
- sweepVotesOffset = UNSAFE.objectFieldOffset
- (k.getDeclaredField("sweepVotes"));
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-
- /**
- * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package.
- * Replace with a simple call to Unsafe.getUnsafe when integrating
- * into a jdk.
- *
- * @return a sun.misc.Unsafe
- */
- static sun.misc.Unsafe getUnsafe() {
- try {
- return sun.misc.Unsafe.getUnsafe();
- } catch (SecurityException se) {
- try {
- return java.security.AccessController.doPrivileged
- (new java.security
- .PrivilegedExceptionAction Like other blocking queues, a {@code TransferQueue} may be
- * capacity bounded. If so, an attempted transfer operation may
- * initially block waiting for available space, and/or subsequently
- * block waiting for reception by a consumer. Note that in a queue
- * with zero capacity, such as {@link SynchronousQueue}, {@code put}
- * and {@code transfer} are effectively synonymous.
- *
- * This interface is a member of the
- *
- * Java Collections Framework.
- *
- * @since 1.7
- * @author Doug Lea
- * @param More precisely, transfers the specified element immediately
- * if there exists a consumer already waiting to receive it (in
- * {@link #take} or timed {@link #poll(long,TimeUnit) poll}),
- * otherwise returning {@code false} without enqueuing the element.
- *
- * @param e the element to transfer
- * @return {@code true} if the element was transferred, else
- * {@code false}
- * @throws ClassCastException if the class of the specified element
- * prevents it from being added to this queue
- * @throws NullPointerException if the specified element is null
- * @throws IllegalArgumentException if some property of the specified
- * element prevents it from being added to this queue
- */
- boolean tryTransfer(E e);
-
- /**
- * Transfers the element to a consumer, waiting if necessary to do so.
- *
- * More precisely, transfers the specified element immediately
- * if there exists a consumer already waiting to receive it (in
- * {@link #take} or timed {@link #poll(long,TimeUnit) poll}),
- * else waits until the element is received by a consumer.
- *
- * @param e the element to transfer
- * @throws InterruptedException if interrupted while waiting,
- * in which case the element is not left enqueued
- * @throws ClassCastException if the class of the specified element
- * prevents it from being added to this queue
- * @throws NullPointerException if the specified element is null
- * @throws IllegalArgumentException if some property of the specified
- * element prevents it from being added to this queue
- */
- void transfer(E e) throws InterruptedException;
-
- /**
- * Transfers the element to a consumer if it is possible to do so
- * before the timeout elapses.
- *
- * More precisely, transfers the specified element immediately
- * if there exists a consumer already waiting to receive it (in
- * {@link #take} or timed {@link #poll(long,TimeUnit) poll}),
- * else waits until the element is received by a consumer,
- * returning {@code false} if the specified wait time elapses
- * before the element can be transferred.
- *
- * @param e the element to transfer
- * @param timeout how long to wait before giving up, in units of
- * {@code unit}
- * @param unit a {@code TimeUnit} determining how to interpret the
- * {@code timeout} parameter
- * @return {@code true} if successful, or {@code false} if
- * the specified waiting time elapses before completion,
- * in which case the element is not left enqueued
- * @throws InterruptedException if interrupted while waiting,
- * in which case the element is not left enqueued
- * @throws ClassCastException if the class of the specified element
- * prevents it from being added to this queue
- * @throws NullPointerException if the specified element is null
- * @throws IllegalArgumentException if some property of the specified
- * element prevents it from being added to this queue
- */
- boolean tryTransfer(E e, long timeout, TimeUnit unit)
- throws InterruptedException;
-
- /**
- * Returns {@code true} if there is at least one consumer waiting
- * to receive an element via {@link #take} or
- * timed {@link #poll(long,TimeUnit) poll}.
- * The return value represents a momentary state of affairs.
- *
- * @return {@code true} if there is at least one waiting consumer
- */
- boolean hasWaitingConsumer();
-
- /**
- * Returns an estimate of the number of consumers waiting to
- * receive elements via {@link #take} or timed
- * {@link #poll(long,TimeUnit) poll}. The return value is an
- * approximation of a momentary state of affairs, that may be
- * inaccurate if consumers have completed or given up waiting.
- * The value may be useful for monitoring and heuristics, but
- * not for synchronization control. Implementations of this
- * method are likely to be noticeably slower than those for
- * {@link #hasWaitingConsumer}.
- *
- * @return the number of consumers waiting to receive elements
- */
- int getWaitingConsumerCount();
-}
diff --git a/firefly-common/src/main/java/com/firefly/utils/dom/DefaultDom.java b/firefly-common/src/main/java/com/firefly/utils/dom/DefaultDom.java
deleted file mode 100644
index 097f0d2d8..000000000
--- a/firefly-common/src/main/java/com/firefly/utils/dom/DefaultDom.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package com.firefly.utils.dom;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.CharacterData;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-public class DefaultDom implements Dom {
-
- private DocumentBuilderFactory dbf;
- private DocumentBuilder db;
-
- public DefaultDom() {
- // 得到dom解析器工厂实例
- dbf = DocumentBuilderFactory.newInstance();
- try {
- // 得到dom解析器
- db = dbf.newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public Document getDocument(String file) {
- Document doc = null;
- try {
- InputStream is = DefaultDom.class.getResourceAsStream("/" + file);
- doc = db.parse(is);
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return doc;
- }
-
- @Override
- public Element getRoot(Document doc) {
- return doc.getDocumentElement();
- }
-
- @Override
- public List
- * On Windows XP sp1 with 1.4.2_04 and later ;), this encoder and decoder is about 10 times faster
- * on small arrays (10 - 1000 bytes) and 2-3 times as fast on larger arrays (10000 - 1000000 bytes)
- * compared to sun.misc.Encoder()/Decoder().
- *
- * On byte arrays the encoder is about 20% faster than Jakarta Commons Base64 Codec for encode and
- * about 50% faster for decoding large arrays. This implementation is about twice as fast on very small
- * arrays (< 30 bytes). If source/destination is a String this
- * version is about three times as fast due to the fact that the Commons Codec result has to be recoded
- * to a String from byte[], which is very expensive.
- *
- * This encode/decode algorithm doesn't create any temporary arrays as many other codecs do, it only
- * allocates the resulting array. This produces less garbage and it is possible to handle arrays twice
- * as large as algorithms that create a temporary array. (E.g. Jakarta Commons Codec). It is unknown
- * whether Sun's sun.misc.Encoder()/Decoder() produce temporary arrays but since performance
- * is quite low it probably does.
- *
- * The encoder produces the same output as the Sun one except that the Sun's encoder appends
- * a trailing line separator if the last character isn't a pad. Unclear why but it only adds to the
- * length and is probably a side effect. Both are in conformance with RFC 2045 though.
- * Commons codec seem to always att a trailing line separator.
- *
- * Note!
- * The encode/decode method pairs (types) come in three versions with the exact same algorithm and
- * thus a lot of code redundancy. This is to not create any temporary arrays for transcoding to/from different
- * format types. The methods not used can simply be commented out.
- *
- * There is also a "fast" version of all decode methods that works the same way as the normal ones, but
- * har a few demands on the decoded input. Normally though, these fast verions should be used if the source if
- * the input is known and it hasn't bee tampered with.
- *
- * If you find the code useful or you find a bug, please send me a note at base64 @ miginfocom . com.
- *
- * Licence (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (base64 @ miginfocom . com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 2.2
- * @author Mikael Grev
- * Date: 2004-aug-02
- * Time: 11:31:11
- */
-
-public class Base64
-{
- private static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
- private static final int[] IA = new int[256];
- static {
- Arrays.fill(IA, -1);
- for (int i = 0, iS = CA.length; i < iS; i++)
- IA[CA[i]] = i;
- IA['='] = 0;
- }
-
- // ****************************************************************************************
- // * char[] version
- // ****************************************************************************************
-
- /** Encodes a raw byte array into a BASE64 char[] representation i accordance with RFC 2045.
- * @param sArr The bytes to convert. If null or length 0 an empty array will be returned.
- * @param lineSep Optional "\r\n" after 76 characters, unless end of file.
- * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
- * little faster.
- * @return A BASE64 encoded array. Never null.
- */
- public final static char[] encodeToChar(byte[] sArr, boolean lineSep)
- {
- // Check special case
- int sLen = sArr != null ? sArr.length : 0;
- if (sLen == 0)
- return new char[0];
-
- int eLen = (sLen / 3) * 3; // Length of even 24-bits.
- int cCnt = ((sLen - 1) / 3 + 1) << 2; // Returned character count
- int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
- char[] dArr = new char[dLen];
-
- // Encode even 24-bits
- for (int s = 0, d = 0, cc = 0; s < eLen;) {
- // Copy next three bytes into lower 24 bits of int, paying attension to sign.
- int i = (sArr[s++] & 0xff) << 16 | (sArr[s++] & 0xff) << 8 | (sArr[s++] & 0xff);
-
- // Encode the int into four chars
- dArr[d++] = CA[(i >>> 18) & 0x3f];
- dArr[d++] = CA[(i >>> 12) & 0x3f];
- dArr[d++] = CA[(i >>> 6) & 0x3f];
- dArr[d++] = CA[i & 0x3f];
-
- // Add optional line separator
- if (lineSep && ++cc == 19 && d < dLen - 2) {
- dArr[d++] = '\r';
- dArr[d++] = '\n';
- cc = 0;
- }
- }
-
- // Pad and encode last bits if source isn't even 24 bits.
- int left = sLen - eLen; // 0 - 2.
- if (left > 0) {
- // Prepare the int
- int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
-
- // Set last four chars
- dArr[dLen - 4] = CA[i >> 12];
- dArr[dLen - 3] = CA[(i >>> 6) & 0x3f];
- dArr[dLen - 2] = left == 2 ? CA[i & 0x3f] : '=';
- dArr[dLen - 1] = '=';
- }
- return dArr;
- }
-
- /** Decodes a BASE64 encoded char array. All illegal characters will be ignored and can handle both arrays with
- * and without line separators.
- * @param sArr The source array. null or length 0 will return an empty array.
- * @return The decoded array of bytes. May be of length 0. Will be null if the legal characters
- * (including '=') isn't divideable by 4. (I.e. definitely corrupted).
- */
- public final static byte[] decode(char[] sArr)
- {
- // Check special case
- int sLen = sArr != null ? sArr.length : 0;
- if (sLen == 0)
- return new byte[0];
-
- // Count illegal characters (including '\r', '\n') to know what size the returned array will be,
- // so we don't have to reallocate & copy it later.
- int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
- for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
- if (IA[sArr[i]] < 0)
- sepCnt++;
-
- // Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
- if ((sLen - sepCnt) % 4 != 0)
- return null;
-
- int pad = 0;
- for (int i = sLen; i > 1 && IA[sArr[--i]] <= 0;)
- if (sArr[i] == '=')
- pad++;
-
- int len = ((sLen - sepCnt) * 6 >> 3) - pad;
-
- byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
-
- for (int s = 0, d = 0; d < len;) {
- // Assemble three bytes into an int from four "valid" characters.
- int i = 0;
- for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
- int c = IA[sArr[s++]];
- if (c >= 0)
- i |= c << (18 - j * 6);
- else
- j--;
- }
- // Add the bytes
- dArr[d++] = (byte) (i >> 16);
- if (d < len) {
- dArr[d++]= (byte) (i >> 8);
- if (d < len)
- dArr[d++] = (byte) i;
- }
- }
- return dArr;
- }
-
- /** Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as
- * fast as {@link #decode(char[])}. The preconditions are:
- * + The array must have a line length of 76 chars OR no line separators at all (one line).
- * + Line separator must be "\r\n", as specified in RFC 2045
- * + The array must not contain illegal characters within the encoded string
- * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.
- * @param sArr The source array. Length 0 will return an empty array. null will throw an exception.
- * @return The decoded array of bytes. May be of length 0.
- */
- public final static byte[] decodeFast(char[] sArr)
- {
- // Check special case
- int sLen = sArr.length;
- if (sLen == 0)
- return new byte[0];
-
- int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
-
- // Trim illegal chars from start
- while (sIx < eIx && IA[sArr[sIx]] < 0)
- sIx++;
-
- // Trim illegal chars from end
- while (eIx > 0 && IA[sArr[eIx]] < 0)
- eIx--;
-
- // get the padding count (=) (0, 1 or 2)
- int pad = sArr[eIx] == '=' ? (sArr[eIx - 1] == '=' ? 2 : 1) : 0; // Count '=' at end.
- int cCnt = eIx - sIx + 1; // Content count including possible separators
- int sepCnt = sLen > 76 ? (sArr[76] == '\r' ? cCnt / 78 : 0) << 1 : 0;
-
- int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
- byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
-
- // Decode all but the last 0 - 2 bytes.
- int d = 0;
- for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
- // Assemble three bytes into an int from four "valid" characters.
- int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
-
- // Add the bytes
- dArr[d++] = (byte) (i >> 16);
- dArr[d++] = (byte) (i >> 8);
- dArr[d++] = (byte) i;
-
- // If line separator, jump over it.
- if (sepCnt > 0 && ++cc == 19) {
- sIx += 2;
- cc = 0;
- }
- }
-
- if (d < len) {
- // Decode last 1-3 bytes (incl '=') into 1-3 bytes
- int i = 0;
- for (int j = 0; sIx <= eIx - pad; j++)
- i |= IA[sArr[sIx++]] << (18 - j * 6);
-
- for (int r = 16; d < len; r -= 8)
- dArr[d++] = (byte) (i >> r);
- }
-
- return dArr;
- }
-
- // ****************************************************************************************
- // * byte[] version
- // ****************************************************************************************
-
- /** Encodes a raw byte array into a BASE64 byte[] representation i accordance with RFC 2045.
- * @param sArr The bytes to convert. If null or length 0 an empty array will be returned.
- * @param lineSep Optional "\r\n" after 76 characters, unless end of file.
- * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
- * little faster.
- * @return A BASE64 encoded array. Never null.
- */
- public final static byte[] encodeToByte(byte[] sArr, boolean lineSep)
- {
- // Check special case
- int sLen = sArr != null ? sArr.length : 0;
- if (sLen == 0)
- return new byte[0];
-
- int eLen = (sLen / 3) * 3; // Length of even 24-bits.
- int cCnt = ((sLen - 1) / 3 + 1) << 2; // Returned character count
- int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
- byte[] dArr = new byte[dLen];
-
- // Encode even 24-bits
- for (int s = 0, d = 0, cc = 0; s < eLen;) {
- // Copy next three bytes into lower 24 bits of int, paying attension to sign.
- int i = (sArr[s++] & 0xff) << 16 | (sArr[s++] & 0xff) << 8 | (sArr[s++] & 0xff);
-
- // Encode the int into four chars
- dArr[d++] = (byte) CA[(i >>> 18) & 0x3f];
- dArr[d++] = (byte) CA[(i >>> 12) & 0x3f];
- dArr[d++] = (byte) CA[(i >>> 6) & 0x3f];
- dArr[d++] = (byte) CA[i & 0x3f];
-
- // Add optional line separator
- if (lineSep && ++cc == 19 && d < dLen - 2) {
- dArr[d++] = '\r';
- dArr[d++] = '\n';
- cc = 0;
- }
- }
-
- // Pad and encode last bits if source isn't an even 24 bits.
- int left = sLen - eLen; // 0 - 2.
- if (left > 0) {
- // Prepare the int
- int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
-
- // Set last four chars
- dArr[dLen - 4] = (byte) CA[i >> 12];
- dArr[dLen - 3] = (byte) CA[(i >>> 6) & 0x3f];
- dArr[dLen - 2] = left == 2 ? (byte) CA[i & 0x3f] : (byte) '=';
- dArr[dLen - 1] = '=';
- }
- return dArr;
- }
-
- /** Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with
- * and without line separators.
- * @param sArr The source array. Length 0 will return an empty array. null will throw an exception.
- * @return The decoded array of bytes. May be of length 0. Will be null if the legal characters
- * (including '=') isn't divideable by 4. (I.e. definitely corrupted).
- */
- public final static byte[] decode(byte[] sArr)
- {
- // Check special case
- int sLen = sArr.length;
-
- // Count illegal characters (including '\r', '\n') to know what size the returned array will be,
- // so we don't have to reallocate & copy it later.
- int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
- for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
- if (IA[sArr[i] & 0xff] < 0)
- sepCnt++;
-
- // Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
- if ((sLen - sepCnt) % 4 != 0)
- return null;
-
- int pad = 0;
- for (int i = sLen; i > 1 && IA[sArr[--i] & 0xff] <= 0;)
- if (sArr[i] == '=')
- pad++;
-
- int len = ((sLen - sepCnt) * 6 >> 3) - pad;
-
- byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
-
- for (int s = 0, d = 0; d < len;) {
- // Assemble three bytes into an int from four "valid" characters.
- int i = 0;
- for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
- int c = IA[sArr[s++] & 0xff];
- if (c >= 0)
- i |= c << (18 - j * 6);
- else
- j--;
- }
-
- // Add the bytes
- dArr[d++] = (byte) (i >> 16);
- if (d < len) {
- dArr[d++]= (byte) (i >> 8);
- if (d < len)
- dArr[d++] = (byte) i;
- }
- }
-
- return dArr;
- }
-
-
- /** Decodes a BASE64 encoded byte array that is known to be resonably well formatted. The method is about twice as
- * fast as {@link #decode(byte[])}. The preconditions are:
- * + The array must have a line length of 76 chars OR no line separators at all (one line).
- * + Line separator must be "\r\n", as specified in RFC 2045
- * + The array must not contain illegal characters within the encoded string
- * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.
- * @param sArr The source array. Length 0 will return an empty array. null will throw an exception.
- * @return The decoded array of bytes. May be of length 0.
- */
- public final static byte[] decodeFast(byte[] sArr)
- {
- // Check special case
- int sLen = sArr.length;
- if (sLen == 0)
- return new byte[0];
-
- int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
-
- // Trim illegal chars from start
- while (sIx < eIx && IA[sArr[sIx] & 0xff] < 0)
- sIx++;
-
- // Trim illegal chars from end
- while (eIx > 0 && IA[sArr[eIx] & 0xff] < 0)
- eIx--;
-
- // get the padding count (=) (0, 1 or 2)
- int pad = sArr[eIx] == '=' ? (sArr[eIx - 1] == '=' ? 2 : 1) : 0; // Count '=' at end.
- int cCnt = eIx - sIx + 1; // Content count including possible separators
- int sepCnt = sLen > 76 ? (sArr[76] == '\r' ? cCnt / 78 : 0) << 1 : 0;
-
- int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
- byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
-
- // Decode all but the last 0 - 2 bytes.
- int d = 0;
- for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
- // Assemble three bytes into an int from four "valid" characters.
- int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
-
- // Add the bytes
- dArr[d++] = (byte) (i >> 16);
- dArr[d++] = (byte) (i >> 8);
- dArr[d++] = (byte) i;
-
- // If line separator, jump over it.
- if (sepCnt > 0 && ++cc == 19) {
- sIx += 2;
- cc = 0;
- }
- }
-
- if (d < len) {
- // Decode last 1-3 bytes (incl '=') into 1-3 bytes
- int i = 0;
- for (int j = 0; sIx <= eIx - pad; j++)
- i |= IA[sArr[sIx++]] << (18 - j * 6);
-
- for (int r = 16; d < len; r -= 8)
- dArr[d++] = (byte) (i >> r);
- }
-
- return dArr;
- }
-
- // ****************************************************************************************
- // * String version
- // ****************************************************************************************
-
- /** Encodes a raw byte array into a BASE64 String representation i accordance with RFC 2045.
- * @param sArr The bytes to convert. If null or length 0 an empty array will be returned.
- * @param lineSep Optional "\r\n" after 76 characters, unless end of file.
- * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
- * little faster.
- * @return A BASE64 encoded array. Never null.
- */
- public final static String encodeToString(byte[] sArr, boolean lineSep)
- {
- // Reuse char[] since we can't create a String incrementally anyway and StringBuffer/Builder would be slower.
- return new String(encodeToChar(sArr, lineSep));
- }
-
- /** Decodes a BASE64 encoded String. All illegal characters will be ignored and can handle both strings with
- * and without line separators.
- * Note! It can be up to about 2x the speed to call decode(str.toCharArray()) instead. That
- * will create a temporary array though. This version will use str.charAt(i) to iterate the string.
- * @param str The source string. null or length 0 will return an empty array.
- * @return The decoded array of bytes. May be of length 0. Will be null if the legal characters
- * (including '=') isn't divideable by 4. (I.e. definitely corrupted).
- */
- public final static byte[] decode(String str)
- {
- // Check special case
- int sLen = str != null ? str.length() : 0;
- if (sLen == 0)
- return new byte[0];
-
- // Count illegal characters (including '\r', '\n') to know what size the returned array will be,
- // so we don't have to reallocate & copy it later.
- int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
- for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
- if (IA[str.charAt(i)] < 0)
- sepCnt++;
-
- // Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
- if ((sLen - sepCnt) % 4 != 0)
- return null;
-
- // Count '=' at end
- int pad = 0;
- for (int i = sLen; i > 1 && IA[str.charAt(--i)] <= 0;)
- if (str.charAt(i) == '=')
- pad++;
-
- int len = ((sLen - sepCnt) * 6 >> 3) - pad;
-
- byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
-
- for (int s = 0, d = 0; d < len;) {
- // Assemble three bytes into an int from four "valid" characters.
- int i = 0;
- for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
- int c = IA[str.charAt(s++)];
- if (c >= 0)
- i |= c << (18 - j * 6);
- else
- j--;
- }
- // Add the bytes
- dArr[d++] = (byte) (i >> 16);
- if (d < len) {
- dArr[d++]= (byte) (i >> 8);
- if (d < len)
- dArr[d++] = (byte) i;
- }
- }
- return dArr;
- }
-
- /** Decodes a BASE64 encoded string that is known to be resonably well formatted. The method is about twice as
- * fast as {@link #decode(String)}. The preconditions are:
- * + The array must have a line length of 76 chars OR no line separators at all (one line).
- * + Line separator must be "\r\n", as specified in RFC 2045
- * + The array must not contain illegal characters within the encoded string
- * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.
- * @param s The source string. Length 0 will return an empty array. null will throw an exception.
- * @return The decoded array of bytes. May be of length 0.
- */
- public final static byte[] decodeFast(String s)
- {
- // Check special case
- int sLen = s.length();
- if (sLen == 0)
- return new byte[0];
-
- int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
-
- // Trim illegal chars from start
- while (sIx < eIx && IA[s.charAt(sIx) & 0xff] < 0)
- sIx++;
-
- // Trim illegal chars from end
- while (eIx > 0 && IA[s.charAt(eIx) & 0xff] < 0)
- eIx--;
-
- // get the padding count (=) (0, 1 or 2)
- int pad = s.charAt(eIx) == '=' ? (s.charAt(eIx - 1) == '=' ? 2 : 1) : 0; // Count '=' at end.
- int cCnt = eIx - sIx + 1; // Content count including possible separators
- int sepCnt = sLen > 76 ? (s.charAt(76) == '\r' ? cCnt / 78 : 0) << 1 : 0;
-
- int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
- byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
-
- // Decode all but the last 0 - 2 bytes.
- int d = 0;
- for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
- // Assemble three bytes into an int from four "valid" characters.
- int i = IA[s.charAt(sIx++)] << 18 | IA[s.charAt(sIx++)] << 12 | IA[s.charAt(sIx++)] << 6 | IA[s.charAt(sIx++)];
-
- // Add the bytes
- dArr[d++] = (byte) (i >> 16);
- dArr[d++] = (byte) (i >> 8);
- dArr[d++] = (byte) i;
-
- // If line separator, jump over it.
- if (sepCnt > 0 && ++cc == 19) {
- sIx += 2;
- cc = 0;
- }
- }
-
- if (d < len) {
- // Decode last 1-3 bytes (incl '=') into 1-3 bytes
- int i = 0;
- for (int j = 0; sIx <= eIx - pad; j++)
- i |= IA[s.charAt(sIx++)] << (18 - j * 6);
-
- for (int r = 16; d < len; r -= 8)
- dArr[d++] = (byte) (i >> r);
- }
-
- return dArr;
- }
-}
\ No newline at end of file
diff --git a/firefly-common/src/main/java/com/firefly/utils/collection/AtomicFieldUpdaterUtil.java b/firefly-common/src/main/java/com/firefly/utils/collection/AtomicFieldUpdaterUtil.java
deleted file mode 100644
index 633f5ffd3..000000000
--- a/firefly-common/src/main/java/com/firefly/utils/collection/AtomicFieldUpdaterUtil.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- *
- * Red Hat 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.
- */
-package com.firefly.utils.collection;
-
-import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-
-/**
- * @author The Netty Project
- * @author Trustin Lee
- * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
- */
-class AtomicFieldUpdaterUtil {
-
- private static final boolean AVAILABLE;
-
- static final class Node {
- volatile Node next;
- Node() {
- super();
- }
- }
-
- static {
- boolean available = false;
- try {
- AtomicReferenceFieldUpdater