private static String convertDisplay()

in nmr/core/src/main/java/org/apache/servicemix/nmr/core/util/ExchangeUtils.java [126:161]


    private static String convertDisplay(Object object) {
        try {
            String result;
            if (object instanceof ByteArrayInputStream) {
                InputStream is = (InputStream) object;
                byte[] data = new byte[is.available()];
                is.mark(0);
                is.read(data);
                is.reset();
                // Heuristic to check if this is a string
                if (isBinary(data)) {
                    result = Arrays.toString(data);
                } else {
                    result = new String(data);
                }
            } else if (object instanceof DOMSource) {
                StringWriter buffer = new StringWriter();
                Transformer transformer = TransformerFactory.newInstance().newTransformer();
                transformer.transform((DOMSource) object, new StreamResult(buffer));
                result = buffer.toString();
            } else if (object instanceof InternalExchange) {
                result = "";
            } else if (object != null) {
                result = object.toString();
            } else {
                result = "<null>";
            }
            // trim if too long
            if (result.length() > MAX_MSG_DISPLAY_SIZE) {
                result = result.substring(0, MAX_MSG_DISPLAY_SIZE) + "...";
            }
            return result;
        } catch (Throwable t) {
            return "Error display value (" + t.toString() + ")";
        }
    }