mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
remove all apache.commons
This commit is contained in:
parent
a05958865a
commit
38de8b0e47
@ -52,8 +52,8 @@ import org.springframework.util.StreamUtils;
|
|||||||
import org.springframework.web.servlet.HttpServletBean;
|
import org.springframework.web.servlet.HttpServletBean;
|
||||||
import org.springframework.web.util.UriComponents;
|
import org.springframework.web.util.UriComponents;
|
||||||
|
|
||||||
import static com.alibaba.cloud.commons.StringUtils.substringAfter;
|
import static com.alibaba.cloud.commons.lang.StringUtils.substringAfter;
|
||||||
import static com.alibaba.cloud.commons.StringUtils.substringBetween;
|
import static com.alibaba.cloud.commons.lang.StringUtils.substringBetween;
|
||||||
import static org.springframework.web.util.UriComponentsBuilder.fromUriString;
|
import static org.springframework.web.util.UriComponentsBuilder.fromUriString;
|
||||||
|
|
||||||
@WebServlet(urlPatterns = "/dsc/*")
|
@WebServlet(urlPatterns = "/dsc/*")
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013-2019 the original author or authors.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.alibaba.cloud.commons;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FileUtils. copy from apache commons.io.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
|
||||||
*/
|
|
||||||
public final class FileUtils {
|
|
||||||
|
|
||||||
private FileUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the contents of a file into a String. The file is always closed.
|
|
||||||
* @param file the file to read, must not be {@code null}
|
|
||||||
* @param encoding the encoding to use, {@code null} means platform default
|
|
||||||
* @return the file contents, never {@code null}
|
|
||||||
* @throws java.io.IOException in case of an I/O error
|
|
||||||
* @throws java.nio.charset.UnsupportedCharsetException thrown instead of
|
|
||||||
* {@link java.io .UnsupportedEncodingException} in version 2.2 if the encoding is
|
|
||||||
* not supported.
|
|
||||||
* @since 2.3
|
|
||||||
*/
|
|
||||||
public static String readFileToString(final File file, final String encoding)
|
|
||||||
throws IOException {
|
|
||||||
return readFileToString(file, Charsets.toCharset(encoding));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the contents of a file into a String using the default encoding for the VM.
|
|
||||||
* The file is always closed.
|
|
||||||
* @param file the file to read, must not be {@code null}
|
|
||||||
* @return the file contents, never {@code null}
|
|
||||||
* @throws IOException in case of an I/O error
|
|
||||||
* @since 1.3.1
|
|
||||||
* @deprecated 2.5 use {@link #readFileToString(File, java.nio.charset.Charset)}
|
|
||||||
* instead (and specify the appropriate encoding)
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static String readFileToString(final File file) throws IOException {
|
|
||||||
return readFileToString(file, Charset.defaultCharset());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,182 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.alibaba.cloud.commons.io;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Charsets constants, copy from apache commons-io.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
|
*/
|
||||||
|
public final class Charsets {
|
||||||
|
|
||||||
|
private Charsets() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a sorted map from canonical charset names to charset objects required of
|
||||||
|
* every implementation of the Java platform.
|
||||||
|
* <p>
|
||||||
|
* From the Java documentation
|
||||||
|
* <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">
|
||||||
|
* Standard charsets</a>:
|
||||||
|
* </p>
|
||||||
|
* @return An immutable, case-insensitive map from canonical charset names to charset
|
||||||
|
* objects.
|
||||||
|
* @see Charset#availableCharsets()
|
||||||
|
*/
|
||||||
|
public static SortedMap<String, Charset> requiredCharsets() {
|
||||||
|
// maybe cache?
|
||||||
|
final TreeMap<String, Charset> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
m.put(StandardCharsets.ISO_8859_1.name(), StandardCharsets.ISO_8859_1);
|
||||||
|
m.put(StandardCharsets.US_ASCII.name(), StandardCharsets.US_ASCII);
|
||||||
|
m.put(StandardCharsets.UTF_16.name(), StandardCharsets.UTF_16);
|
||||||
|
m.put(StandardCharsets.UTF_16BE.name(), StandardCharsets.UTF_16BE);
|
||||||
|
m.put(StandardCharsets.UTF_16LE.name(), StandardCharsets.UTF_16LE);
|
||||||
|
m.put(StandardCharsets.UTF_8.name(), StandardCharsets.UTF_8);
|
||||||
|
return Collections.unmodifiableSortedMap(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the given Charset or the default Charset if the given Charset is null.
|
||||||
|
* @param charset A charset or null.
|
||||||
|
* @return the given Charset or the default Charset if the given Charset is null
|
||||||
|
*/
|
||||||
|
public static Charset toCharset(final Charset charset) {
|
||||||
|
return charset == null ? Charset.defaultCharset() : charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Charset for the named charset. If the name is null, return the default
|
||||||
|
* Charset.
|
||||||
|
* @param charset The name of the requested charset, may be null.
|
||||||
|
* @return a Charset for the named charset
|
||||||
|
* @throws java.nio.charset.UnsupportedCharsetException If the named charset is
|
||||||
|
* unavailable
|
||||||
|
*/
|
||||||
|
public static Charset toCharset(final String charset) {
|
||||||
|
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
|
||||||
|
* <p>
|
||||||
|
* Every implementation of the Java platform is required to support this character
|
||||||
|
* encoding.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
|
||||||
|
* charsets</a>
|
||||||
|
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of
|
||||||
|
* the Unicode character set.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Every implementation of the Java platform is required to support this character
|
||||||
|
* encoding.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
|
||||||
|
* charsets</a>
|
||||||
|
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Charset US_ASCII = StandardCharsets.US_ASCII;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory
|
||||||
|
* initial byte-order mark (either order accepted on input, big-endian used on output)
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Every implementation of the Java platform is required to support this character
|
||||||
|
* encoding.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
|
||||||
|
* charsets</a>
|
||||||
|
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Charset UTF_16 = StandardCharsets.UTF_16;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Sixteen-bit Unicode Transformation Format, big-endian byte order.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Every implementation of the Java platform is required to support this character
|
||||||
|
* encoding.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
|
||||||
|
* charsets</a>
|
||||||
|
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Charset UTF_16BE = StandardCharsets.UTF_16BE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Sixteen-bit Unicode Transformation Format, little-endian byte order.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Every implementation of the Java platform is required to support this character
|
||||||
|
* encoding.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
|
||||||
|
* charsets</a>
|
||||||
|
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Charset UTF_16LE = StandardCharsets.UTF_16LE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Eight-bit Unicode Transformation Format.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Every implementation of the Java platform is required to support this character
|
||||||
|
* encoding.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
|
||||||
|
* charsets</a>
|
||||||
|
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.alibaba.cloud.commons.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileUtils. copy from apache commons-io.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
|
*/
|
||||||
|
public final class FileUtils {
|
||||||
|
|
||||||
|
private FileUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Opens a {@link java.io.FileInputStream} for the specified file, providing better
|
||||||
|
* error messages than simply calling <code>new FileInputStream(file)</code>.
|
||||||
|
* <p>
|
||||||
|
* At the end of the method either the stream will be successfully opened, or an
|
||||||
|
* exception will have been thrown.
|
||||||
|
* <p>
|
||||||
|
* An exception is thrown if the file does not exist. An exception is thrown if the
|
||||||
|
* file object exists but is a directory. An exception is thrown if the file exists
|
||||||
|
* but cannot be read.
|
||||||
|
* @param file the file to open for input, must not be {@code null}
|
||||||
|
* @return a new {@link java.io.FileInputStream} for the specified file
|
||||||
|
* @throws java.io.FileNotFoundException if the file does not exist
|
||||||
|
* @throws IOException if the file object is a directory
|
||||||
|
* @throws IOException if the file cannot be read
|
||||||
|
* @since 1.3
|
||||||
|
*/
|
||||||
|
public static FileInputStream openInputStream(final File file) throws IOException {
|
||||||
|
if (file.exists()) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
throw new IOException("File '" + file + "' exists but is a directory");
|
||||||
|
}
|
||||||
|
if (!file.canRead()) {
|
||||||
|
throw new IOException("File '" + file + "' cannot be read");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new FileNotFoundException("File '" + file + "' does not exist");
|
||||||
|
}
|
||||||
|
return new FileInputStream(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Reads the contents of a file into a String. The file is always closed.
|
||||||
|
* @param file the file to read, must not be {@code null}
|
||||||
|
* @param encoding the encoding to use, {@code null} means platform default
|
||||||
|
* @return the file contents, never {@code null}
|
||||||
|
* @throws IOException in case of an I/O error
|
||||||
|
*/
|
||||||
|
public static String readFileToString(final File file, final Charset encoding)
|
||||||
|
throws IOException {
|
||||||
|
try (InputStream in = openInputStream(file)) {
|
||||||
|
return IOUtils.toString(in, Charsets.toCharset(encoding));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the contents of a file into a String. The file is always closed.
|
||||||
|
* @param file the file to read, must not be {@code null}
|
||||||
|
* @param encoding the encoding to use, {@code null} means platform default
|
||||||
|
* @return the file contents, never {@code null}
|
||||||
|
* @throws java.io.IOException in case of an I/O error
|
||||||
|
* @throws java.nio.charset.UnsupportedCharsetException thrown instead of
|
||||||
|
* {@link java.io .UnsupportedEncodingException} in version 2.2 if the encoding is not
|
||||||
|
* supported.
|
||||||
|
*/
|
||||||
|
public static String readFileToString(final File file, final String encoding)
|
||||||
|
throws IOException {
|
||||||
|
return readFileToString(file, Charsets.toCharset(encoding));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the contents of a file into a String using the default encoding for the VM.
|
||||||
|
* The file is always closed.
|
||||||
|
* @param file the file to read, must not be {@code null}
|
||||||
|
* @return the file contents, never {@code null}
|
||||||
|
* @throws IOException in case of an I/O error
|
||||||
|
* @deprecated 2.5 use {@link #readFileToString(File, String)} instead (and specify
|
||||||
|
* the appropriate encoding)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static String readFileToString(final File file) throws IOException {
|
||||||
|
return readFileToString(file, Charset.defaultCharset());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,233 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.alibaba.cloud.commons.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The IOUtils. copy from apache commons-io.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
|
*/
|
||||||
|
public final class IOUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the end-of-file (or stream).
|
||||||
|
* @since 2.5 (made public)
|
||||||
|
*/
|
||||||
|
public static final int EOF = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default buffer size ({@value}) to use for.
|
||||||
|
* {@link #copyLarge(InputStream, java.io.OutputStream)} and
|
||||||
|
* {@link #copyLarge(Reader, Writer)}
|
||||||
|
*/
|
||||||
|
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
||||||
|
|
||||||
|
private IOUtils() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the contents of an <code>InputStream</code> as a String using the specified
|
||||||
|
* character encoding.
|
||||||
|
* <p>
|
||||||
|
* This method buffers the input internally, so there is no need to use a
|
||||||
|
* <code>BufferedInputStream</code>.
|
||||||
|
* </p>
|
||||||
|
* @param input the <code>InputStream</code> to read from
|
||||||
|
* @param encoding the encoding to use, null means platform default
|
||||||
|
* @return the requested String
|
||||||
|
* @throws NullPointerException if the input is null
|
||||||
|
* @throws java.io.IOException if an I/O error occurs
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
public static String toString(final InputStream input, final Charset encoding)
|
||||||
|
throws IOException {
|
||||||
|
try (StringBuilderWriter sw = new StringBuilderWriter()) {
|
||||||
|
copy(input, sw, encoding);
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy from Reader
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies chars from a <code>Reader</code> to a <code>Writer</code>.
|
||||||
|
* <p>
|
||||||
|
* This method buffers the input internally, so there is no need to use a
|
||||||
|
* <code>BufferedReader</code>.
|
||||||
|
* <p>
|
||||||
|
* Large streams (over 2GB) will return a chars copied value of <code>-1</code> after
|
||||||
|
* the copy has completed since the correct number of chars cannot be returned as an
|
||||||
|
* int. For large streams use the <code>copyLarge(Reader, Writer)</code> method.
|
||||||
|
* @param input the <code>Reader</code> to read from
|
||||||
|
* @param output the <code>Writer</code> to write to
|
||||||
|
* @return the number of characters copied, or -1 if > Integer.MAX_VALUE
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 1.1
|
||||||
|
*/
|
||||||
|
public static int copy(final Reader input, final Writer output) throws IOException {
|
||||||
|
final long count = copyLarge(input, output);
|
||||||
|
if (count > Integer.MAX_VALUE) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (int) count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies bytes from an <code>InputStream</code> to chars on a <code>Writer</code>
|
||||||
|
* using the specified character encoding.
|
||||||
|
* <p>
|
||||||
|
* This method buffers the input internally, so there is no need to use a
|
||||||
|
* <code>BufferedInputStream</code>.
|
||||||
|
* <p>
|
||||||
|
* This method uses {@link java.io.InputStreamReader}.
|
||||||
|
* @param input the <code>InputStream</code> to read from
|
||||||
|
* @param output the <code>Writer</code> to write to
|
||||||
|
* @param inputEncoding the encoding to use for the input stream, null means platform
|
||||||
|
* default
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
public static void copy(final InputStream input, final Writer output,
|
||||||
|
final Charset inputEncoding) throws IOException {
|
||||||
|
final InputStreamReader in = new InputStreamReader(input,
|
||||||
|
Charsets.toCharset(inputEncoding));
|
||||||
|
copy(in, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies bytes from an <code>InputStream</code> to an <code>OutputStream</code> using
|
||||||
|
* an internal buffer of the given size.
|
||||||
|
* <p>
|
||||||
|
* This method buffers the input internally, so there is no need to use a
|
||||||
|
* <code>BufferedInputStream</code>.
|
||||||
|
* <p>
|
||||||
|
* @param input the <code>InputStream</code> to read from
|
||||||
|
* @param output the <code>OutputStream</code> to write to
|
||||||
|
* @param bufferSize the bufferSize used to copy from the input to the output
|
||||||
|
* @return the number of bytes copied
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
public static long copy(final InputStream input, final OutputStream output,
|
||||||
|
final int bufferSize) throws IOException {
|
||||||
|
return copyLarge(input, output, new byte[bufferSize]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies chars from a large (over 2GB) <code>Reader</code> to a <code>Writer</code>.
|
||||||
|
* <p>
|
||||||
|
* This method buffers the input internally, so there is no need to use a
|
||||||
|
* <code>BufferedReader</code>.
|
||||||
|
* <p>
|
||||||
|
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
|
||||||
|
* @param input the <code>Reader</code> to read from
|
||||||
|
* @param output the <code>Writer</code> to write to
|
||||||
|
* @return the number of characters copied
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 1.3
|
||||||
|
*/
|
||||||
|
public static long copyLarge(final Reader input, final Writer output)
|
||||||
|
throws IOException {
|
||||||
|
return copyLarge(input, output, new char[DEFAULT_BUFFER_SIZE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies chars from a large (over 2GB) <code>Reader</code> to a <code>Writer</code>.
|
||||||
|
* <p>
|
||||||
|
* This method uses the provided buffer, so there is no need to use a
|
||||||
|
* <code>BufferedReader</code>.
|
||||||
|
* <p>
|
||||||
|
* @param input the <code>Reader</code> to read from
|
||||||
|
* @param output the <code>Writer</code> to write to
|
||||||
|
* @param buffer the buffer to be used for the copy
|
||||||
|
* @return the number of characters copied
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public static long copyLarge(final Reader input, final Writer output,
|
||||||
|
final char[] buffer) throws IOException {
|
||||||
|
long count = 0;
|
||||||
|
int n;
|
||||||
|
while (EOF != (n = input.read(buffer))) {
|
||||||
|
output.write(buffer, 0, n);
|
||||||
|
count += n;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies bytes from a large (over 2GB) <code>InputStream</code> to an
|
||||||
|
* <code>OutputStream</code>.
|
||||||
|
* <p>
|
||||||
|
* This method buffers the input internally, so there is no need to use a
|
||||||
|
* <code>BufferedInputStream</code>.
|
||||||
|
* <p>
|
||||||
|
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
|
||||||
|
* @param input the <code>InputStream</code> to read from
|
||||||
|
* @param output the <code>OutputStream</code> to write to
|
||||||
|
* @return the number of bytes copied
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 1.3
|
||||||
|
*/
|
||||||
|
public static long copyLarge(final InputStream input, final OutputStream output)
|
||||||
|
throws IOException {
|
||||||
|
return copy(input, output, DEFAULT_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies bytes from a large (over 2GB) <code>InputStream</code> to an
|
||||||
|
* <code>OutputStream</code>.
|
||||||
|
* <p>
|
||||||
|
* This method uses the provided buffer, so there is no need to use a
|
||||||
|
* <code>BufferedInputStream</code>.
|
||||||
|
* <p>
|
||||||
|
* @param input the <code>InputStream</code> to read from
|
||||||
|
* @param output the <code>OutputStream</code> to write to
|
||||||
|
* @param buffer the buffer to use for the copy
|
||||||
|
* @return the number of bytes copied
|
||||||
|
* @throws NullPointerException if the input or output is null
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public static long copyLarge(final InputStream input, final OutputStream output,
|
||||||
|
final byte[] buffer) throws IOException {
|
||||||
|
long count = 0;
|
||||||
|
int n;
|
||||||
|
while (EOF != (n = input.read(buffer))) {
|
||||||
|
output.write(buffer, 0, n);
|
||||||
|
count += n;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.alibaba.cloud.commons.io;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy from apache commons-io.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
|
*/
|
||||||
|
public class StringBuilderWriter extends Writer implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -146927496096066153L;
|
||||||
|
|
||||||
|
private final StringBuilder builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new {@link StringBuilder} instance with default capacity.
|
||||||
|
*/
|
||||||
|
public StringBuilderWriter() {
|
||||||
|
this.builder = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new {@link StringBuilder} instance with the specified capacity.
|
||||||
|
* @param capacity The initial capacity of the underlying {@link StringBuilder}
|
||||||
|
*/
|
||||||
|
public StringBuilderWriter(final int capacity) {
|
||||||
|
this.builder = new StringBuilder(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance with the specified {@link StringBuilder}.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* If {@code builder} is null a new instance with default capacity will be created.
|
||||||
|
* </p>
|
||||||
|
* @param builder The String builder. May be null.
|
||||||
|
*/
|
||||||
|
public StringBuilderWriter(final StringBuilder builder) {
|
||||||
|
this.builder = builder != null ? builder : new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a single character to this Writer.
|
||||||
|
* @param value The character to append
|
||||||
|
* @return This writer instance
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Writer append(final char value) {
|
||||||
|
builder.append(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a character sequence to this Writer.
|
||||||
|
* @param value The character to append
|
||||||
|
* @return This writer instance
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Writer append(final CharSequence value) {
|
||||||
|
builder.append(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a portion of a character sequence to the {@link StringBuilder}.
|
||||||
|
* @param value The character to append
|
||||||
|
* @param start The index of the first character
|
||||||
|
* @param end The index of the last character + 1
|
||||||
|
* @return This writer instance
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Writer append(final CharSequence value, final int start, final int end) {
|
||||||
|
builder.append(value, start, end);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closing this writer has no effect.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushing this writer has no effect.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a String to the {@link StringBuilder}.
|
||||||
|
* @param value The value to write
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write(final String value) {
|
||||||
|
if (value != null) {
|
||||||
|
builder.append(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a portion of a character array to the {@link StringBuilder}.
|
||||||
|
* @param value The value to write
|
||||||
|
* @param offset The index of the first character
|
||||||
|
* @param length The number of characters to write
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write(final char[] value, final int offset, final int length) {
|
||||||
|
if (value != null) {
|
||||||
|
builder.append(value, offset, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the underlying builder.
|
||||||
|
* @return The underlying builder
|
||||||
|
*/
|
||||||
|
public StringBuilder getBuilder() {
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@link StringBuilder#toString()}.
|
||||||
|
* @return The contents of the String builder.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.alibaba.cloud.commons;
|
package com.alibaba.cloud.commons.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringUtils. copy from apache common-lang3.
|
* StringUtils. copy from apache common-lang3.
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.sentinel.datasource.factorybean;
|
package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||||
|
|
||||||
import com.alibaba.cloud.commons.StringUtils;
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ package com.alibaba.cloud.sentinel.datasource;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.commons.io.FileUtils;
|
||||||
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
|
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
|
||||||
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
|
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
|
||||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
import com.alibaba.cloud.commons.FileUtils;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.alibaba.cloud.commons.StringUtils;
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.cloud.nacos.NacosServiceManager;
|
import com.alibaba.cloud.nacos.NacosServiceManager;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
@ -32,7 +32,8 @@ import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
|||||||
*/
|
*/
|
||||||
public class SeataFeignObjectWrapper {
|
public class SeataFeignObjectWrapper {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SeataFeignObjectWrapper.class);
|
private static final Logger LOG = LoggerFactory
|
||||||
|
.getLogger(SeataFeignObjectWrapper.class);
|
||||||
|
|
||||||
private final BeanFactory beanFactory;
|
private final BeanFactory beanFactory;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user