You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2017/03/21 20:37:58 UTC
[2/6] flink git commit: [hotfix] Clean up StringUtils and remove
unused methods.
[hotfix] Clean up StringUtils and remove unused methods.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/52d3e4d6
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/52d3e4d6
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/52d3e4d6
Branch: refs/heads/master
Commit: 52d3e4d6c8a44f8e822f82efa276d89ca8b08c9f
Parents: fc2325a
Author: Stephan Ewen <se...@apache.org>
Authored: Mon Mar 20 16:52:16 2017 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Tue Mar 21 21:37:21 2017 +0100
----------------------------------------------------------------------
.../kafka/internals/SimpleConsumerThread.java | 6 +-
.../java/org/apache/flink/util/StringUtils.java | 71 +++-----------------
.../org/apache/flink/util/StringUtilsTest.java | 7 --
3 files changed, 11 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/52d3e4d6/flink-connectors/flink-connector-kafka-0.8/src/main/java/org/apache/flink/streaming/connectors/kafka/internals/SimpleConsumerThread.java
----------------------------------------------------------------------
diff --git a/flink-connectors/flink-connector-kafka-0.8/src/main/java/org/apache/flink/streaming/connectors/kafka/internals/SimpleConsumerThread.java b/flink-connectors/flink-connector-kafka-0.8/src/main/java/org/apache/flink/streaming/connectors/kafka/internals/SimpleConsumerThread.java
index e9cfdac..c78c085 100644
--- a/flink-connectors/flink-connector-kafka-0.8/src/main/java/org/apache/flink/streaming/connectors/kafka/internals/SimpleConsumerThread.java
+++ b/flink-connectors/flink-connector-kafka-0.8/src/main/java/org/apache/flink/streaming/connectors/kafka/internals/SimpleConsumerThread.java
@@ -30,7 +30,7 @@ import kafka.javaapi.message.ByteBufferMessageSet;
import kafka.message.MessageAndOffset;
import org.apache.flink.streaming.util.serialization.KeyedDeserializationSchema;
-import org.apache.flink.util.StringUtils;
+import org.apache.flink.util.ExceptionUtils;
import org.apache.kafka.common.Node;
@@ -295,7 +295,7 @@ class SimpleConsumerThread<T> extends Thread {
}
else if (code != ErrorMapping.NoError()) {
exception += "\nException for " + fp.getTopic() +":"+ fp.getPartition() + ": " +
- StringUtils.stringifyException(ErrorMapping.exceptionFor(code));
+ ExceptionUtils.stringifyException(ErrorMapping.exceptionFor(code));
}
}
if (partitionsToGetOffsetsFor.size() > 0) {
@@ -502,7 +502,7 @@ class SimpleConsumerThread<T> extends Thread {
if ((code = response.errorCode(part.getTopic(), part.getPartition())) != ErrorMapping.NoError()) {
exception.append("\nException for topic=").append(part.getTopic())
.append(" partition=").append(part.getPartition()).append(": ")
- .append(StringUtils.stringifyException(ErrorMapping.exceptionFor(code)));
+ .append(ExceptionUtils.stringifyException(ErrorMapping.exceptionFor(code)));
}
}
if (++retries >= 3) {
http://git-wip-us.apache.org/repos/asf/flink/blob/52d3e4d6/flink-core/src/main/java/org/apache/flink/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/StringUtils.java b/flink-core/src/main/java/org/apache/flink/util/StringUtils.java
index fc945c6..b84f602 100644
--- a/flink-core/src/main/java/org/apache/flink/util/StringUtils.java
+++ b/flink-core/src/main/java/org/apache/flink/util/StringUtils.java
@@ -38,21 +38,7 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
@PublicEvolving
public final class StringUtils {
- /**
- * Empty private constructor to overwrite public one.
- */
- private StringUtils() {}
-
- /**
- * Makes a string representation of the exception.
- *
- * @param e
- * the exception to stringify
- * @return A string with exception name and call stack.
- */
- public static String stringifyException(final Throwable e) {
- return ExceptionUtils.stringifyException(e);
- }
+ private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
/**
* Given an array of bytes it will convert the bytes to a hex string
@@ -65,15 +51,13 @@ public final class StringUtils {
* @param end
* end index, exclusively
* @return hex string representation of the byte array
- *
- * @see org.apache.commons.codec.binary.Hex#encodeHexString(byte[])
*/
public static String byteToHexString(final byte[] bytes, final int start, final int end) {
if (bytes == null) {
throw new IllegalArgumentException("bytes == null");
}
- final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
int length = end - start;
char[] out = new char[length * 2];
@@ -114,50 +98,6 @@ public final class StringUtils {
}
return bts;
}
-
- /**
- * Helper function to escape Strings for display in HTML pages. The function replaces
- * certain characters by their HTML coded correspondent.
- *
- * @param str The string to escape.
- * @return The escaped string.
- */
- public static String escapeHtml(String str) {
- int len = str.length();
- char[] s = str.toCharArray();
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < len; i += 1) {
- char c = s[i];
- if ((c == '\\') || (c == '"') || (c == '/')) {
- sb.append('\\');
- sb.append(c);
- }
- else if (c == '\b') {
- sb.append("\\b");
- } else if (c == '\t') {
- sb.append("\\t");
- } else if (c == '\n') {
- sb.append("<br>");
- } else if (c == '\f') {
- sb.append("\\f");
- } else if (c == '\r') {
- sb.append("\\r");
- } else if (c == '>') {
- sb.append(">");
- } else if (c == '<') {
- sb.append("<");
- } else if (c == '&') {
- sb.append("&");
- } else if (c < ' ') {
- // Unreadable throw away
- } else {
- sb.append(c);
- }
- }
-
- return sb.toString();
- }
/**
* This method calls {@link Object#toString()} on the given object, unless the
@@ -310,7 +250,7 @@ public final class StringUtils {
/**
* Writes a String to the given output.
- * The written string can be read with {@link #readNullableString(DataInputView)}.
+ * The written string can be read with {@link #readString(DataInputView)}.
*
* @param str The string to write
* @param out The output to write to
@@ -382,4 +322,9 @@ public final class StringUtils {
}
return true;
}
+
+ // ------------------------------------------------------------------------
+
+ /** Prevent instantiation of this utility class */
+ private StringUtils() {}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/52d3e4d6/flink-core/src/test/java/org/apache/flink/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/util/StringUtilsTest.java b/flink-core/src/test/java/org/apache/flink/util/StringUtilsTest.java
index 3f6b16d..ca28e95 100644
--- a/flink-core/src/test/java/org/apache/flink/util/StringUtilsTest.java
+++ b/flink-core/src/test/java/org/apache/flink/util/StringUtilsTest.java
@@ -41,13 +41,6 @@ public class StringUtilsTest extends TestLogger {
}
@Test
- public void testEscapeHTML() {
- String testString = "\b \t / \n \f \r <default>";
- String controlString = StringUtils.escapeHtml(testString);
- assertEquals("\\b \\t \\/ <br> \\f \\r <default>", controlString);
- }
-
- @Test
public void testStringToHexArray() {
String hex = "019f314a";
byte[] hexArray = StringUtils.hexStringToByte(hex);