Java Array Trim safeTrim(byte[] ba, int len)

Here you can find the source of safeTrim(byte[] ba, int len)

Description

safe Trim

License

Open Source License

Declaration

private static byte[] safeTrim(byte[] ba, int len) 

Method Source Code

//package com.java2s;
/*// ww w. j  av  a2  s .co  m
 * #%L
 * Tesora Inc.
 * Database Virtualization Engine
 * %%
 * Copyright (C) 2011 - 2014 Tesora Inc.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

import java.util.Arrays;

public class Main {
    private static byte[] safeTrim(byte[] ba, int len) {
        if (ba == null)
            return null;
        if (len == ba.length)
            return ba;
        else
            return Arrays.copyOf(ba, len);
    }

    private static char[] safeTrim(char[] ca, int len) {
        if (ca == null)
            return null;
        if (len == ca.length)
            return ca;
        else
            return Arrays.copyOf(ca, len);
    }
}

Related

  1. getTrimmedValues(final String[] values)
  2. rtrim(long[] array)
  3. safeTrim(final char[] ca, final int len)
  4. trim(byte[] bytes)
  5. trim(byte[] bytes, int endMargin)
  6. trim(byte[] data)