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.epg.section.body.networkinformationtable; import loggingsupport.loggerfactory.LoggerFactory; import java.lang.invoke.MethodHandles; import java.text.MessageFormat; import libepg.epg.section.descriptor.DescriptorsLoop; import libepg.epg.section.range.SectionValueRangeChecker; import libepg.util.bytearray.ByteConverter; import libepg.util.bytearray.ByteDataBlock; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.logging.Log; /** * ? * * @author normal */ public class TransportStreamLoop { /** * false????????????? */ public static final boolean CLASS_LOG_OUTPUT_MODE = true; private static final Log LOG; static { final Class<?> myClass = MethodHandles.lookup().lookupClass(); LOG = new LoggerFactory(myClass, TransportStreamLoop.CLASS_LOG_OUTPUT_MODE).getLOG(); } private final ByteDataBlock data; public TransportStreamLoop(byte[] data) { this.data = new ByteDataBlock(data); } public byte[] getData() { return data.getData(); } /** * ?<br> * 16bit<br> * SDT??????????????<br> * * @return ? * @throws IllegalStateException 0x0000????0xffff???? */ public final synchronized int getTransport_stream_id() throws IllegalStateException { byte[] t = new byte[2]; System.arraycopy(this.getData(), 0, t, 0, t.length); int x = ByteConverter.bytesToInt(t); if (!SectionValueRangeChecker.TRANSPORT_STREAM_ID_RANGE.contains(x)) { throw new IllegalStateException("???? = " + Integer.toHexString(x)); } return x; } /** * original_network_id(?):??16??? * ???????? * * @return ? */ public final synchronized int getOriginal_network_id() { byte[] t = new byte[2]; System.arraycopy(this.getData(), 2, t, 0, t.length); int temp = ByteConverter.bytesToInt(t); return temp; } /** * ??????? ??????ARIB * STD-B10?????????????? 4bit * * @return ? */ public final synchronized int getReserved_future_use() { int temp; temp = ByteConverter.byteToInt(this.getData()[4]); temp = temp >>> 4; return temp; } /** * descriptors_loop_length(?):network_descriptors_length????12 * ??? ???????? * * @return ? */ public synchronized int getDescriptors_loop_length() { byte[] t = new byte[2]; System.arraycopy(this.getData(), 4, t, 0, t.length); int it = ByteConverter.bytesToInt(t); it = it & 0x0FFF; return it; } /** * ??? * * @return ? */ public synchronized DescriptorsLoop getDescriptors_loop() { byte[] t = new byte[this.getDescriptors_loop_length()]; if (t.length > 0) { System.arraycopy(this.getData(), 6, t, 0, t.length); } return new DescriptorsLoop(t); } /** * @return ???????? */ @Override public int hashCode() { return HashCodeBuilder.reflectionHashCode(7, 17, this); } /** * @return ???true */ @Override public boolean equals(Object obj) { return EqualsBuilder.reflectionEquals(this, obj, true); } private static final String TITLE = "?"; private static final MessageFormat TS_DESC = new MessageFormat( "\n" + TITLE + " ? = {0}\n" + TITLE + " ? = {1}\n" + TITLE + " ? = {2}\n" + TITLE + " = {3}\n" + TITLE + " ? = {4}\n" + TITLE + " ? = {5}\n"); @Override /** * ????????? */ public String toString() { Object[] parameters = { this.data, Integer.toHexString(this.getTransport_stream_id()), Integer.toHexString(this.getOriginal_network_id()), this.getReserved_future_use(), this.getDescriptors_loop_length(), this.getDescriptors_loop() }; return TS_DESC.format(parameters); } }