Java File Size Readable Format formatRow(String[] values, int[] sizes)

Here you can find the source of formatRow(String[] values, int[] sizes)

Description

Format row.

License

Open Source License

Parameter

Parameter Description
values the values
sizes the sizes

Return

the string

Declaration

public static String formatRow(String[] values, int[] sizes) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String SPACES = "                                                ";

    /**/*from w  w  w .j a  v  a 2  s.  c  om*/
     * Format row.
     * 
     * @param values
     *            the values
     * @param sizes
     *            the sizes
     * 
     * @return the string
     */
    public static String formatRow(String[] values, int[] sizes) {
        return formatRow(" ", values, sizes);
    }

    /**
     * Format row.
     * 
     * @param prefix
     *            the prefix
     * @param values
     *            the values
     * @param sizes
     *            the sizes
     * 
     * @return the string
     */
    public static String formatRow(String prefix, String[] values, int[] sizes) {
        StringBuffer sb = new StringBuffer();

        sb.append(prefix);
        for (int i = 0; i < sizes.length; i++) {
            if (i != 0) {
                sb.append(" ");
            }
            sb.append(fixLength(values[i], sizes[i]));
        }

        return sb.toString();
    }

    /**
     * Fix length.
     * 
     * @param str
     *            the str
     * @param len
     *            the len
     * 
     * @return the string
     */
    public static String fixLength(String str, int len) {
        if (str != null) {
            str = str + SPACES;
        } else {
            str = SPACES;
        }
        return str.substring(0, len);
    }
}

Related

  1. formatFilesize(String filesize, int decimalPlaces)
  2. formatFileStats(final String label, final long fileCount, final Object rawSize)
  3. formatGroup(String str, int groupSize, int lineBreak)
  4. formatIndex(int index, int totalSize)
  5. formatInt(int val, int size)
  6. formatSeperatorRow(int[] sizes)
  7. formatShortByte(long size)
  8. formatSize(double size)
  9. formatSize(Integer size)