Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for SLF4J 1.7.31 Extensions
SLF4J Extensions is a library of 3 components: Profiler, Extended logger, Event Logging, Logging added with Java agent.
Here is the source code for SLF4J Extensions You can download its pre-compiled version slf4j-ext-1.7.31.jar at SLF4J Download Website.
✍: FYIcenter.com
⏎ org/slf4j/instrumentation/ToStringHelper.java
/** * Copyright (c) 2004-2011 QOS.ch * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package org.slf4j.instrumentation; import java.util.Map; import java.util.WeakHashMap; public class ToStringHelper { /** * Prefix to use at the start of the representation. Always used. */ private static final String ARRAY_PREFIX = "["; /** * Suffix to use at the end of the representation. Always used. */ private static final char ARRAY_SUFFIX = ']'; /** * String separating each element when rendering an array. To be compatible * with lists comma-space is used. */ private static final char[] ELEMENT_SEPARATOR = ", ".toCharArray(); /** * unrenderableClasses is essentially a Set of Class objects which has for * some reason failed to render properly when invoked through a toString * method call. To avoid memory leaks a data structure using weak references * is needed, but unfortunately the runtime library does not contain a * WeakHashSet class, so the behavior is emulated with a WeakHashmap with * the class as the key, and a Long containing the value of * System.currentTimeMilis when an instance of the class failed to render. */ final static Map<Class<?>, Object> unrenderableClasses = new WeakHashMap<Class<?>, Object>(); /** * Returns o.toString() unless it throws an exception (which causes it to be * stored in unrenderableClasses) or already was present in * unrenderableClasses. If so, the same string is returned as would have * been returned by Object.toString(). Arrays get special treatment as they * don't have usable toString methods. * * @param o * incoming object to render. * @return */ public static String render(Object o) { if (o == null) { return String.valueOf(o); } Class<?> objectClass = o.getClass(); if (unrenderableClasses.containsKey(objectClass) == false) { try { if (objectClass.isArray()) { return renderArray(o, objectClass).toString(); } else { return o.toString(); } } catch (Exception e) { Long now = new Long(System.currentTimeMillis()); System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage()); unrenderableClasses.put(objectClass, now); } } String name = o.getClass().getName(); return name + "@" + Integer.toHexString(o.hashCode()); } /** * renderArray returns an array similar to a List. If the array type is an * object they are rendered with "render(object)" for each. If the array * type is a primitive each element is added directly to the string buffer * collecting the result. * * @param o * @param objectClass * @return */ private static StringBuilder renderArray(Object o, Class<?> objectClass) { Class<?> componentType = objectClass.getComponentType(); StringBuilder sb = new StringBuilder(ARRAY_PREFIX); if (componentType.isPrimitive() == false) { Object[] oa = (Object[]) o; for (int i = 0; i < oa.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(render(oa[i])); } } else { if (Boolean.TYPE.equals(componentType)) { boolean[] ba = (boolean[]) o; for (int i = 0; i < ba.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ba[i]); } } else if (Integer.TYPE.equals(componentType)) { int[] ia = (int[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Long.TYPE.equals(componentType)) { long[] ia = (long[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Double.TYPE.equals(componentType)) { double[] ia = (double[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Float.TYPE.equals(componentType)) { float[] ia = (float[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Character.TYPE.equals(componentType)) { char[] ia = (char[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Short.TYPE.equals(componentType)) { short[] ia = (short[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Byte.TYPE.equals(componentType)) { byte[] ia = (byte[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } } sb.append(ARRAY_SUFFIX); return sb; } }
⏎ org/slf4j/instrumentation/ToStringHelper.java
Or download all of them as a single archive file:
File name: slf4j-ext-1.7.31-sources.jar File size: 40408 bytes Release date: 2021-06-17 Download
⇒ Source Code for SLF4J 1.7.31 Migrator
⇐ Source Code for SLF4J 1.7.31 Bridge to Log4J 1.3
2023-03-17, 1950👍, 0💬
Popular Posts:
JDK 11 jdk.jshell.jmod is the JMOD file for JDK 11 JShell tool, which can be invoked by the "jshell"...
How to perform XML Schema validation with dom\Writer.java provided in the Apache Xerces package? You...
What Is poi-scratchpad-5.2.3.jar ?poi-scratchpad-5.2.3.jar is one of the JAR files for Apache POI 5....
JSP(tm) Standard Tag Library 1.1 implementation - Jakarta Taglibs hosts the Standard Taglib 1.1, an ...
jlGui is a music player for the Java platform. It is based on Java Sound 1.0 (i.e. JDK 1.3+). It sup...