Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * jPOS Project [http://jpos.org]
 * Copyright (C) 2000-2012 Alejandro P. Revilla
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * 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/>.
 */

public class Main {
    public static byte[] unpadLeft(byte[] tgt, byte padding) {
        int offset = 0;
        for (; offset < tgt.length; offset++) {
            if (tgt[offset] != padding) {
                break;
            }
        }
        if (offset < tgt.length) {
            byte[] rslt = new byte[tgt.length - offset];
            System.arraycopy(tgt, offset, rslt, 0, rslt.length);
            return rslt;
        }
        return new byte[0];
    }

    /**
     * Unpad from left. 
     * @param s - original string
     * @param c - padding char
     * @return unPadded string.
     */
    public static String unPadLeft(String s, char c) {
        int fill = 0, end = s.length();
        if (end == 0)
            return s;
        while ((fill < end) && (s.charAt(fill) == c))
            fill++;
        return (fill < end) ? s.substring(fill, end) : s.substring(fill - 1, end);
    }
}