提交 52d3e4d6 编写于 作者: S Stephan Ewen

[hotfix] Clean up StringUtils and remove unused methods.

上级 fc2325ab
......@@ -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) {
......
......@@ -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("&gt;");
} else if (c == '<') {
sb.append("&lt;");
} else if (c == '&') {
sb.append("&amp;");
} 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() {}
}
......@@ -40,13 +40,6 @@ public class StringUtilsTest extends TestLogger {
assertEquals("[1.0]", controlString);
}
@Test
public void testEscapeHTML() {
String testString = "\b \t / \n \f \r <default>";
String controlString = StringUtils.escapeHtml(testString);
assertEquals("\\b \\t \\/ <br> \\f \\r &lt;default&gt;", controlString);
}
@Test
public void testStringToHexArray() {
String hex = "019f314a";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册