Java Array Length Get lengthToWrite(final byte[] data, final int offset, final int dataLength, final boolean rightTrim)

Here you can find the source of lengthToWrite(final byte[] data, final int offset, final int dataLength, final boolean rightTrim)

Description

lengthToWrite.

License

Open Source License

Parameter

Parameter Description
data an array of byte.
offset a int.
dataLength a int.
rightTrim a boolean.

Return

a int.

Declaration

public static int lengthToWrite(final byte[] data, final int offset,
        final int dataLength, final boolean rightTrim) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w w w . j a va  2s  .c om
     * <p>
     * lengthToWrite.
     * </p>
     *
     * @param data an array of byte.
     * @param offset a int.
     * @param dataLength a int.
     * @param rightTrim a boolean.
     * @return a int.
     */
    public static int lengthToWrite(final byte[] data, final int offset,
            final int dataLength, final boolean rightTrim) {
        int lengthToWrite = 0;
        if (!rightTrim)
            lengthToWrite = dataLength;
        else
            for (int i = offset + dataLength - 1; i >= offset; i--)
                if (data[i] != ' ') {
                    lengthToWrite = (i - offset) + 1;
                    break;
                }
        return lengthToWrite;
    }
}

Related

  1. lengthCheck(final byte[] buffer, final byte length)
  2. lengthNeeded(byte[] b)
  3. lengthOf(T[] array)
  4. lengthOfShortestIn(String[] strings)
  5. lengthSQ(double[] vector)
  6. lengthToZero(byte[] data, int offset)
  7. LengthVec3D(double[] vec)