You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/07/22 09:34:29 UTC

[GitHub] [shardingsphere-elasticjob] terrymanu commented on a change in pull request #1252: Resolve license incompatibility.

terrymanu commented on a change in pull request #1252:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1252#discussion_r458659989



##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/HttpClientUtils.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.exception.HttpClientException;
+
+/**
+ * Http client utils.
+ */
+public class HttpClientUtils {
+    
+    /**
+     * http get request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url) {
+        return httpGet(url, null, null, 3000L);
+    }
+    
+    /**
+     * http get request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {
+        HttpURLConnection conn = null;
+        try {
+            String encodedContent = encodingParams(paramValues, encoding);
+            String urlWithParam = url + (null == encodedContent ? "" : ("?" + encodedContent));
+            conn = (HttpURLConnection) new URL(urlWithParam).openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout((int) readTimeoutMs);
+            conn.setReadTimeout((int) readTimeoutMs);
+            conn.connect();
+            String resp;
+            if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
+                resp = IOUtils.toString(conn.getInputStream(), encoding);
+            } else {
+                resp = IOUtils.toString(conn.getErrorStream(), encoding);
+            }
+            return new HttpResult(conn.getResponseCode(), resp);
+        } catch (IOException ex) {
+            throw new HttpClientException(ex);
+        } finally {
+            if (conn != null) {

Review comment:
       Please change `conn != null` to `null != conn`

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/HttpClientUtils.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.exception.HttpClientException;
+
+/**
+ * Http client utils.
+ */
+public class HttpClientUtils {
+    
+    /**
+     * http get request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url) {
+        return httpGet(url, null, null, 3000L);
+    }
+    
+    /**
+     * http get request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {
+        HttpURLConnection conn = null;
+        try {
+            String encodedContent = encodingParams(paramValues, encoding);
+            String urlWithParam = url + (null == encodedContent ? "" : ("?" + encodedContent));
+            conn = (HttpURLConnection) new URL(urlWithParam).openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout((int) readTimeoutMs);
+            conn.setReadTimeout((int) readTimeoutMs);
+            conn.connect();
+            String resp;
+            if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
+                resp = IOUtils.toString(conn.getInputStream(), encoding);
+            } else {
+                resp = IOUtils.toString(conn.getErrorStream(), encoding);
+            }
+            return new HttpResult(conn.getResponseCode(), resp);
+        } catch (IOException ex) {

Review comment:
       Please add final for exception catch

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/HttpClientUtils.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.exception.HttpClientException;
+
+/**
+ * Http client utils.
+ */
+public class HttpClientUtils {
+    
+    /**
+     * http get request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url) {
+        return httpGet(url, null, null, 3000L);
+    }
+    
+    /**
+     * http get request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {
+        HttpURLConnection conn = null;
+        try {
+            String encodedContent = encodingParams(paramValues, encoding);
+            String urlWithParam = url + (null == encodedContent ? "" : ("?" + encodedContent));
+            conn = (HttpURLConnection) new URL(urlWithParam).openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout((int) readTimeoutMs);
+            conn.setReadTimeout((int) readTimeoutMs);
+            conn.connect();
+            String resp;
+            if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
+                resp = IOUtils.toString(conn.getInputStream(), encoding);
+            } else {
+                resp = IOUtils.toString(conn.getErrorStream(), encoding);
+            }
+            return new HttpResult(conn.getResponseCode(), resp);
+        } catch (IOException ex) {
+            throw new HttpClientException(ex);
+        } finally {
+            if (conn != null) {
+                conn.disconnect();
+            }
+        }
+    }
+    
+    private static String encodingParams(final List<String> paramValues, final String encoding) throws UnsupportedEncodingException {
+        if (null == paramValues) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();
+        for (Iterator<String> iter = paramValues.iterator(); iter.hasNext();) {
+            sb.append(iter.next()).append("=");
+            sb.append(URLEncoder.encode(iter.next(), encoding));
+            if (iter.hasNext()) {
+                sb.append("&");
+            }
+        }
+        return sb.toString();
+    }
+    
+    /**
+     * http post request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpPost(final String url) {
+        return httpPost(url, null, null, 3000L);
+    }
+    
+    /**
+     * http post request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpPost(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {

Review comment:
       Please do not use abbreviation, `readTimeoutMs` should be renamed as `readTimeoutMillisecond`

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/console/HttpTestUtil.java
##########
@@ -28,19 +30,24 @@
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.exception.HttpClientException;
 
-public final class HttpTestsUtil {
+/**
+ * Http utils.
+ */
+public final class HttpTestUtil {

Review comment:
       Please use lombok to add private constructor for static util class

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeService.java
##########
@@ -136,17 +132,15 @@ public void addRunning(final TaskContext taskContext) {
     
     /**
      * Update daemon task status.
-     * 
      * @param taskContext task running context
-     * @param isIdle set to idle or not
+     * @param isIdle      set to idle or not

Review comment:
       Please keep original java doc format

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/HttpClientUtils.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.exception.HttpClientException;
+
+/**
+ * Http client utils.
+ */
+public class HttpClientUtils {
+    
+    /**
+     * http get request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url) {
+        return httpGet(url, null, null, 3000L);
+    }
+    
+    /**
+     * http get request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {
+        HttpURLConnection conn = null;
+        try {
+            String encodedContent = encodingParams(paramValues, encoding);
+            String urlWithParam = url + (null == encodedContent ? "" : ("?" + encodedContent));
+            conn = (HttpURLConnection) new URL(urlWithParam).openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout((int) readTimeoutMs);
+            conn.setReadTimeout((int) readTimeoutMs);
+            conn.connect();
+            String resp;
+            if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
+                resp = IOUtils.toString(conn.getInputStream(), encoding);
+            } else {
+                resp = IOUtils.toString(conn.getErrorStream(), encoding);
+            }
+            return new HttpResult(conn.getResponseCode(), resp);
+        } catch (IOException ex) {
+            throw new HttpClientException(ex);
+        } finally {
+            if (conn != null) {
+                conn.disconnect();
+            }
+        }
+    }
+    
+    private static String encodingParams(final List<String> paramValues, final String encoding) throws UnsupportedEncodingException {
+        if (null == paramValues) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();

Review comment:
       Please use better name, `stringBuilder` maybe better

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/HttpClientUtils.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.exception.HttpClientException;
+
+/**
+ * Http client utils.
+ */
+public class HttpClientUtils {
+    
+    /**
+     * http get request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url) {
+        return httpGet(url, null, null, 3000L);
+    }
+    
+    /**
+     * http get request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpGet(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {
+        HttpURLConnection conn = null;
+        try {
+            String encodedContent = encodingParams(paramValues, encoding);
+            String urlWithParam = url + (null == encodedContent ? "" : ("?" + encodedContent));
+            conn = (HttpURLConnection) new URL(urlWithParam).openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout((int) readTimeoutMs);
+            conn.setReadTimeout((int) readTimeoutMs);
+            conn.connect();
+            String resp;
+            if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
+                resp = IOUtils.toString(conn.getInputStream(), encoding);
+            } else {
+                resp = IOUtils.toString(conn.getErrorStream(), encoding);
+            }
+            return new HttpResult(conn.getResponseCode(), resp);
+        } catch (IOException ex) {
+            throw new HttpClientException(ex);
+        } finally {
+            if (conn != null) {
+                conn.disconnect();
+            }
+        }
+    }
+    
+    private static String encodingParams(final List<String> paramValues, final String encoding) throws UnsupportedEncodingException {
+        if (null == paramValues) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();
+        for (Iterator<String> iter = paramValues.iterator(); iter.hasNext();) {
+            sb.append(iter.next()).append("=");
+            sb.append(URLEncoder.encode(iter.next(), encoding));
+            if (iter.hasNext()) {
+                sb.append("&");
+            }
+        }
+        return sb.toString();
+    }
+    
+    /**
+     * http post request.
+     * @param url thr url
+     * @return http result
+     */
+    public static HttpResult httpPost(final String url) {
+        return httpPost(url, null, null, 3000L);
+    }
+    
+    /**
+     * http post request.
+     * @param url           thr url
+     * @param paramValues   the param values
+     * @param encoding      the encoding
+     * @param readTimeoutMs the read timeout
+     * @return http result
+     */
+    public static HttpResult httpPost(final String url, final List<String> paramValues, final String encoding, final long readTimeoutMs) {
+        HttpURLConnection conn = null;
+        try {
+            conn = (HttpURLConnection) new URL(url).openConnection();

Review comment:
       Please rename `conn` to `connection`

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/IOUtils.java
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * IO utils.
+ */
+public class IOUtils {
+    
+    /**
+     * convert input stream to string.
+     * @param input    the input stream
+     * @param encoding the encoding
+     * @return string
+     * @throws IOException IOException
+     */
+    public static String toString(final InputStream input, final String encoding) throws IOException {
+        return (null == encoding) ? toString(new InputStreamReader(input, StandardCharsets.UTF_8)) : toString(new InputStreamReader(input, encoding));
+    }
+    
+    /**
+     * convert input stream to string.
+     * @param reader the reader
+     * @return string
+     * @throws IOException IOException
+     */
+    public static String toString(final Reader reader) throws IOException {
+        CharArrayWriter sw = new CharArrayWriter();
+        copy(reader, sw);
+        return sw.toString();
+    }
+    
+    private static void copy(final Reader input, final Writer output) throws IOException {
+        char[] buffer = new char[1 << 12];
+        for (int n; (n = input.read(buffer)) >= 0;) {

Review comment:
       Please do not use `n` as variable name, just use meaningful name 

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/IOUtils.java
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * IO utils.
+ */
+public class IOUtils {

Review comment:
       Please add final for class if not for extension, and please use lombok to add private constructor for static util class 

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/console/HttpTestUtil.java
##########
@@ -99,9 +109,8 @@ public static String get(final String url) throws Exception {
      * @param url     the url

Review comment:
       Please remove `the`, it is better to keep java doc' style consist with original

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/console/HttpTestUtil.java
##########
@@ -67,30 +75,32 @@ public static int post(final String url, final String content) throws Exception
      * @param url     the url

Review comment:
       The javadoc format is not keep consist with current format

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeService.java
##########
@@ -136,17 +132,15 @@ public void addRunning(final TaskContext taskContext) {
     
     /**
      * Update daemon task status.
-     * 
      * @param taskContext task running context
-     * @param isIdle set to idle or not
+     * @param isIdle      set to idle or not
      */
     public void updateDaemonStatus(final TaskContext taskContext, final boolean isIdle) {
         runningService.updateIdle(taskContext, isIdle);
     }
     
     /**
      * Remove task from running queue.
-     *

Review comment:
       Please keep original java doc format, keep a blank line between title and parameter

##########
File path: elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/util/IOUtils.java
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.cloud.scheduler.util;
+
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * IO utils.
+ */
+public class IOUtils {
+    
+    /**
+     * convert input stream to string.
+     * @param input    the input stream
+     * @param encoding the encoding
+     * @return string
+     * @throws IOException IOException
+     */
+    public static String toString(final InputStream input, final String encoding) throws IOException {
+        return (null == encoding) ? toString(new InputStreamReader(input, StandardCharsets.UTF_8)) : toString(new InputStreamReader(input, encoding));
+    }
+    
+    /**
+     * convert input stream to string.
+     * @param reader the reader
+     * @return string
+     * @throws IOException IOException
+     */
+    public static String toString(final Reader reader) throws IOException {
+        CharArrayWriter sw = new CharArrayWriter();
+        copy(reader, sw);
+        return sw.toString();
+    }
+    
+    private static void copy(final Reader input, final Writer output) throws IOException {
+        char[] buffer = new char[1 << 12];

Review comment:
       What is useful of `1 << 12`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org