Java tutorial
/* * Copyright (C) 2016 normal * * This program 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. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package libepg.util.bytearray; import java.util.Arrays; import org.apache.commons.codec.binary.Hex; /** * ?????? * * @author normal */ public final class ByteDataBlock { private final byte[] data; public ByteDataBlock(byte[] data) throws NullPointerException { if (data == null) { throw new NullPointerException("???????????"); } //? this.data = Arrays.copyOf(data, data.length); } /** * ???????????? * * @return ?????????? */ public synchronized final byte[] getData() { return Arrays.copyOf(this.data, this.data.length); } /** * ?????????????? * * @return ??????????? */ public synchronized int length() { return this.data.length; } /** * @return ??????????16 */ @Override public String toString() { return Hex.encodeHexString(this.data); } @Override public int hashCode() { int hash = 5; hash = 89 * hash + Arrays.hashCode(this.data); return hash; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final ByteDataBlock other = (ByteDataBlock) obj; if (!Arrays.equals(this.data, other.data)) { return false; } return true; } }