All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.beanio.internal.util.DebugUtil Maven / Gradle / Ivy

Go to download

A Java un/marshalling library for CSV, XML, delimited and fixed length stream formats.

There is a newer version: 3.1.0
Show newest version
package org.beanio.internal.util;

import java.io.*;

import org.beanio.internal.parser.format.FieldPadding;

/**
 * Utility methods for formatting debug output.
 * @author Kevin Seim
 * @since 2.1.0
 */
public class DebugUtil {

    private DebugUtil() { }
    
    public static String formatRange(int min, int max) {
        if (max == Integer.MAX_VALUE) {
            return min + "+";
        }
        else {
            return min + "-" + max;
        }
    }
    
    public static String formatOption(String option, boolean value) {
        if (value) {
            return option;
        }
        else {
            return "!" + option;
        }
    }
    
    public static String formatPadding(FieldPadding padding) {
        if (padding == null) {
            return "";
        }
        else {
            return ", padded[" +
                "length=" + padding.getLength() +
                ", filler=" + padding.getFiller() + 
                ", align=" + padding.getJustify() +
                "]";
        }
    }
    
    public static String toString(Debuggable c) {
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            c.debug(new PrintStream(out));
            return new String(out.toByteArray(), "ASCII");
        }
        catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy