Java Array Trim trim(byte[] bytes, int endMargin)

Here you can find the source of trim(byte[] bytes, int endMargin)

Description

trim

License

Open Source License

Declaration

public static byte[] trim(byte[] bytes, int endMargin) 

Method Source Code

//package com.java2s;
/*******************************************************************************
Copyright 2014 Pawel Pastuszak//w  w w  . ja v  a2s.  c o m
     
This file is part of Arget.
    
Arget is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Arget 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 General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Arget.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.util.Arrays;

public class Main {
    public static byte[] trim(byte[] bytes, int endMargin) {
        int i = bytes.length - 1;
        while (i >= 0 && bytes[i] == 0) {
            --i;
        }

        return Arrays.copyOf(bytes, i + 1 + endMargin);
    }
}

Related

  1. getTrimmedValues(final String[] values)
  2. rtrim(long[] array)
  3. safeTrim(byte[] ba, int len)
  4. safeTrim(final char[] ca, final int len)
  5. trim(byte[] bytes)
  6. trim(byte[] data)
  7. trim(byte[] src, byte padding, boolean right, int minLength)
  8. trim(String s, char delimit[])
  9. trim(String[] args)