Here you can find the source of safeTrim(byte[] ba, int len)
private static byte[] safeTrim(byte[] ba, int len)
//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); } }