Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * event_id 16 uimsbf * start_time 40 bslbf * duration 24 uimsbf * running_status 3 uimsbf * free_CA_mode 1 bslbf * descriptors_loop_length 12 uimsbf * for(i=0;i<N;i++){ * descriptor() * } */ package libepg.epg.section.body.eventinformationtable; import libepg.util.bytearray.ByteConverter; import java.lang.invoke.MethodHandles; import java.sql.Timestamp; import java.text.MessageFormat; import java.text.ParseException; import java.util.Objects; import org.apache.commons.codec.binary.Hex; import org.apache.commons.logging.Log; import java.util.logging.Level; import java.util.logging.Logger; import libepg.epg.section.descriptor.DescriptorsLoop; import libepg.epg.util.datetime.DateTimeFieldConverter; import epgtools.loggerfactory.LoggerFactory; import libepg.util.bytearray.ByteDataBlock; /** * ?? * * @author normal */ public final class EventInformationTableRepeatingPart { /** * 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, EventInformationTableRepeatingPart.CLASS_LOG_OUTPUT_MODE).getLOG(); } private final ByteDataBlock data; EventInformationTableRepeatingPart(byte[] data) { this.data = new ByteDataBlock(data); } public synchronized byte[] getData() { return data.getData(); } /** * event_id??16 ???????? 1 * ????? */ public synchronized int getEvent_id() { byte[] t = new byte[2]; System.arraycopy(this.getData(), 0, t, 0, t.length); return ByteConverter.bytesToInt(t); } /** * start_time??40 ???? JST?MJDC * ???????MJD ??16 16 ??????24 6 ?4 2 10 * BCD??????????NVOD ?? ?????????1??? * 93/10/13 12:45:00 ?0xC079124500???? * * @return */ public synchronized byte[] getStart_time() { byte[] t = new byte[5]; System.arraycopy(this.getData(), 2, t, 0, t.length); return t; } /** * start_time * @return ???? * @throws java.text.ParseException ???????????? */ public synchronized Timestamp getStart_time_Object() throws ParseException { try { byte[] t = this.getStart_time(); return (DateTimeFieldConverter.BytesToSqlDateTime(t)); } catch (ParseException ex) { LOG.warn("????????"); throw ex; } } /** * duration24 ??????? * ???????????????? ??????1??? ?6?4 * BCD ? = 24 201:45:30 ?0x014530???? * * @return */ public synchronized byte[] getDuration() { byte[] t = new byte[3]; System.arraycopy(this.getData(), 7, t, 0, t.length); return t; } /** * * * @return ???? * @throws java.text.ParseException ???????????? */ public synchronized Timestamp getStopTime_Object() throws ParseException { try { byte[] t = this.getDuration(); long x = DateTimeFieldConverter.BcdTimeToSecond(t) * 1000; x = x + this.getStart_time_Object().getTime(); return new Timestamp(x); } catch (ParseException ex) { LOG.warn("????????"); throw ex; } } /** * running_status():??3????<br> * 0__=_<br> * 1__=_?<br> * 2__=_??<br> * 3__=_?<br> * 4__=_<br> * 5-7=_??????<br> * * @return */ public synchronized int getRunning_status() { int t = ByteConverter.byteToInt(this.getData()[10]); t = t >>> 5; return t; } /** * free_CA_mode():??1??? * ???0????????????????????? * 1??????????CA??????? * * @return */ public synchronized int getFree_CA_mode() { int temp; temp = ByteConverter.byteToInt(this.data.getData()[10]); temp = temp >>> 4; temp = temp & 0x01; return temp; } /** * descriptors_loop_length(?):???12??? ?????? * * @return */ public synchronized int getDescriptors_loop_length() { byte[] t = new byte[2]; System.arraycopy(this.data.getData(), 10, 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.data.getData(), 12, t, 0, t.length); } return new DescriptorsLoop(t); } private static final MessageFormat EIT_RP_DESC = new MessageFormat("? = {0}\n" + " = {1}\n" + " = {2}\n" + "() = {3}\n" + " = {4}\n" + "() = {5}\n" + " = {6}\n" + " = {7}\n" + "? = {8}\n" + "? = {9}\n"); @Override public String toString() { String start = "", stop = ""; try { start = this.getStart_time_Object().toString(); stop = this.getStopTime_Object().toString(); } catch (ParseException ex) { Logger.getLogger(EventInformationTableRepeatingPart.class.getName()).log(Level.SEVERE, null, ex); } Object[] parameters = { this.data, Integer.toHexString(this.getEvent_id()), Hex.encodeHexString(this.getStart_time()), start, Hex.encodeHexString(this.getDuration()), stop, Integer.toHexString(this.getRunning_status()), Integer.toHexString(this.getFree_CA_mode()), this.getDescriptors_loop_length(), this.getDescriptors_loop() }; return EIT_RP_DESC.format(parameters); } @Override public int hashCode() { int hash = 5; hash = 23 * hash + Objects.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 EventInformationTableRepeatingPart other = (EventInformationTableRepeatingPart) obj; if (!Objects.equals(this.data, other.data)) { return false; } return true; } }