Merge ThrowableUtils into ThrowableUtil.
Motivation: We should merge ThrowableUtils into ThrowableUtil as this name is more consistent with the naming of utility classes in netty. Modifications: Merge classes. Result: More consistent naming
This commit is contained in:
parent
f52b07dede
commit
278c36af0c
@ -15,6 +15,10 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public final class ThrowableUtil {
|
||||
|
||||
private ThrowableUtil() { }
|
||||
@ -26,4 +30,26 @@ public final class ThrowableUtil {
|
||||
cause.setStackTrace(new StackTraceElement[] { new StackTraceElement(clazz.getName(), method, null, -1)});
|
||||
return cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stack trace from a Throwable as a String.
|
||||
*
|
||||
* @param cause the {@link Throwable} to be examined
|
||||
* @return the stack trace as generated by {@link Throwable#printStackTrace(java.io.PrintWriter)} method.
|
||||
*/
|
||||
public static String stackTraceToString(Throwable cause) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream pout = new PrintStream(out);
|
||||
cause.printStackTrace(pout);
|
||||
pout.flush();
|
||||
try {
|
||||
return new String(out.toByteArray());
|
||||
} finally {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ignore) {
|
||||
// ignore as should never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The Netty Project
|
||||
*
|
||||
* The Netty Project 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 io.netty.util.internal;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public final class ThrowableUtils {
|
||||
|
||||
/**
|
||||
* <p>Gets the stack trace from a Throwable as a String.</p>
|
||||
*
|
||||
* @param throwable the <code>Throwable</code> to be examined
|
||||
* @return the stack trace as generated by the exception's
|
||||
* <code>printStackTrace(PrintWriter)</code> method
|
||||
*/
|
||||
public static String stackTraceToString(Throwable cause) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream pout = new PrintStream(out);
|
||||
cause.printStackTrace(pout);
|
||||
pout.flush();
|
||||
try {
|
||||
return new String(out.toByteArray());
|
||||
} finally {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ignore) {
|
||||
// ignore as should never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ThrowableUtils() { }
|
||||
}
|
@ -23,7 +23,7 @@ import io.netty.util.Recycler;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.ResourceLeakHint;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.internal.ThrowableUtils;
|
||||
import io.netty.util.internal.ThrowableUtil;
|
||||
import io.netty.util.internal.ObjectUtil;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
@ -281,7 +281,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap
|
||||
"An exception {}" +
|
||||
"was thrown by a user handler's exceptionCaught() " +
|
||||
"method while handling the following exception:",
|
||||
ThrowableUtils.stackTraceToString(error), cause);
|
||||
ThrowableUtil.stackTraceToString(error), cause);
|
||||
} else if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception '{}' [enable DEBUG level for full stacktrace] " +
|
||||
|
@ -25,7 +25,7 @@ import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.FastThreadLocal;
|
||||
import io.netty.util.internal.InternalThreadLocalMap;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.ThrowableUtils;
|
||||
import io.netty.util.internal.ThrowableUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
|
||||
@ -677,7 +677,7 @@ public final class ChannelOutboundBuffer {
|
||||
} else {
|
||||
logger.warn(
|
||||
"Failed to mark a promise as success because it has failed already: {}, unnotified cause {}",
|
||||
promise, ThrowableUtils.stackTraceToString(err));
|
||||
promise, ThrowableUtil.stackTraceToString(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -690,7 +690,7 @@ public final class ChannelOutboundBuffer {
|
||||
} else {
|
||||
logger.warn(
|
||||
"Failed to mark a promise as failure because it has failed already: {}, unnotified cause {}",
|
||||
promise, ThrowableUtils.stackTraceToString(err), cause);
|
||||
promise, ThrowableUtil.stackTraceToString(err), cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.util.Attribute;
|
||||
import io.netty.util.AttributeKey;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.internal.ThrowableUtils;
|
||||
import io.netty.util.internal.ThrowableUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
|
||||
@ -148,7 +148,7 @@ public class CombinedChannelDuplexHandler<I extends ChannelInboundHandler, O ext
|
||||
"An exception {}" +
|
||||
"was thrown by a user handler's exceptionCaught() " +
|
||||
"method while handling the following exception:",
|
||||
ThrowableUtils.stackTraceToString(error), cause);
|
||||
ThrowableUtil.stackTraceToString(error), cause);
|
||||
} else if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception '{}' [enable DEBUG level for full stacktrace] " +
|
||||
|
Loading…
Reference in New Issue
Block a user