MtasPayloadDecoder.java.html
10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasPayloadDecoder.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.codec.payload</a> > <span class="el_source">MtasPayloadDecoder.java</span></div><h1>MtasPayloadDecoder.java</h1><pre class="source lang-java linenums">package mtas.codec.payload;
import java.io.IOException;
import java.util.SortedSet;
import java.util.TreeSet;
import mtas.analysis.token.MtasOffset;
import mtas.analysis.token.MtasPosition;
/**
* The Class MtasPayloadDecoder.
*/
<span class="fc" id="L13">public class MtasPayloadDecoder {</span>
/** The byte stream. */
private MtasBitInputStream byteStream;
/** The mtas position. */
private MtasPosition mtasPosition;
/** The mtas start position. */
private int mtasStartPosition;
/** The mtas positions. */
private SortedSet<Integer> mtasPositions;
/** The mtas id. */
<span class="fc" id="L28"> private Integer mtasId = null;</span>
/** The mtas payload value. */
<span class="fc" id="L31"> private byte[] mtasPayloadValue = null;</span>
/** The mtas parent id. */
<span class="fc" id="L34"> private Integer mtasParentId = null;</span>
/** The mtas payload. */
<span class="fc" id="L37"> private Boolean mtasPayload = null;</span>
/** The mtas parent. */
<span class="fc" id="L40"> private Boolean mtasParent = null;</span>
/** The mtas position type. */
<span class="fc" id="L43"> private String mtasPositionType = null;</span>
/** The mtas offset. */
private MtasOffset mtasOffset;
/** The mtas real offset. */
private MtasOffset mtasRealOffset;
/**
* Inits the.
*
* @param startPosition the start position
* @param payload the payload
* @throws IOException Signals that an I/O exception has occurred.
*/
public void init(int startPosition, byte[] payload) throws IOException {
<span class="fc" id="L59"> byteStream = new MtasBitInputStream(payload);</span>
<span class="fc" id="L60"> mtasStartPosition = startPosition;</span>
// analyse initial bits - position
Boolean getOffset;
Boolean getRealOffset;
<span class="fc bfc" id="L64" title="All 2 branches covered."> if (byteStream.readBit() == 1) {</span>
<span class="pc bpc" id="L65" title="1 of 2 branches missed."> if (byteStream.readBit() == 1) {</span>
<span class="nc" id="L66"> mtasPositionType = null;</span>
} else {
<span class="fc" id="L68"> mtasPositionType = MtasPosition.POSITION_RANGE;</span>
}
} else {
<span class="fc bfc" id="L71" title="All 2 branches covered."> if (byteStream.readBit() == 1) {</span>
<span class="fc" id="L72"> mtasPositionType = MtasPosition.POSITION_SET;</span>
} else {
<span class="fc" id="L74"> mtasPositionType = MtasPosition.POSITION_SINGLE;</span>
}
}
// analyze initial bits - offset
<span class="pc bpc" id="L78" title="1 of 2 branches missed."> if (byteStream.readBit() == 1) {</span>
<span class="nc" id="L79"> getOffset = true;</span>
} else {
<span class="fc" id="L81"> getOffset = false;</span>
}
// analyze initial bits - realOffset
<span class="pc bpc" id="L84" title="1 of 2 branches missed."> if (byteStream.readBit() == 1) {</span>
<span class="nc" id="L85"> getRealOffset = true;</span>
} else {
<span class="fc" id="L87"> getRealOffset = false;</span>
}
// analyze initial bits - parent
<span class="fc bfc" id="L90" title="All 2 branches covered."> if (byteStream.readBit() == 1) {</span>
<span class="fc" id="L91"> mtasParent = true;</span>
} else {
<span class="fc" id="L93"> mtasParent = false;</span>
}
// analyse initial bits - payload
<span class="pc bpc" id="L96" title="1 of 2 branches missed."> if (byteStream.readBit() == 1) {</span>
<span class="nc" id="L97"> mtasPayload = true;</span>
} else {
<span class="fc" id="L99"> mtasPayload = false;</span>
}
<span class="pc bpc" id="L101" title="1 of 2 branches missed."> if (byteStream.readBit() == 0) {</span>
// string
} else {
// other
}
// get id
<span class="fc" id="L107"> mtasId = byteStream.readEliasGammaCodingNonNegativeInteger();</span>
// get position info
<span class="pc bpc" id="L109" title="1 of 2 branches missed."> if (mtasPositionType != null</span>
<span class="fc bfc" id="L110" title="All 2 branches covered."> && mtasPositionType.equals(MtasPosition.POSITION_SINGLE)) {</span>
<span class="fc" id="L111"> mtasPosition = new MtasPosition(mtasStartPosition);</span>
<span class="pc bpc" id="L112" title="1 of 2 branches missed."> } else if (mtasPositionType != null</span>
<span class="fc bfc" id="L113" title="All 2 branches covered."> && mtasPositionType.equals(MtasPosition.POSITION_RANGE)) {</span>
<span class="fc" id="L114"> mtasPosition = new MtasPosition(mtasStartPosition, (mtasStartPosition</span>
<span class="fc" id="L115"> + byteStream.readEliasGammaCodingPositiveInteger() - 1));</span>
<span class="pc bpc" id="L116" title="1 of 2 branches missed."> } else if (mtasPositionType != null</span>
<span class="pc bpc" id="L117" title="1 of 2 branches missed."> && mtasPositionType.equals(MtasPosition.POSITION_SET)) {</span>
<span class="fc" id="L118"> mtasPositions = new TreeSet<>();</span>
<span class="fc" id="L119"> mtasPositions.add(mtasStartPosition);</span>
<span class="fc" id="L120"> int numberOfPoints = byteStream.readEliasGammaCodingPositiveInteger();</span>
<span class="fc" id="L121"> int[] positionList = new int[numberOfPoints];</span>
<span class="fc" id="L122"> positionList[0] = mtasStartPosition;</span>
<span class="fc" id="L123"> int previousPosition = 0;</span>
<span class="fc" id="L124"> int currentPosition = mtasStartPosition;</span>
<span class="fc bfc" id="L125" title="All 2 branches covered."> for (int i = 1; i < numberOfPoints; i++) {</span>
<span class="fc" id="L126"> previousPosition = currentPosition;</span>
<span class="fc" id="L127"> currentPosition = previousPosition</span>
<span class="fc" id="L128"> + byteStream.readEliasGammaCodingPositiveInteger();</span>
<span class="fc" id="L129"> positionList[i] = currentPosition;</span>
}
<span class="fc" id="L131"> mtasPosition = new MtasPosition(positionList);</span>
<span class="fc" id="L132"> } else {</span>
<span class="nc" id="L133"> mtasPosition = null;</span>
}
// get offset and realOffset info
<span class="pc bpc" id="L136" title="1 of 2 branches missed."> if (getOffset) {</span>
<span class="nc" id="L137"> int offsetStart = byteStream.readEliasGammaCodingNonNegativeInteger();</span>
<span class="nc" id="L138"> int offsetEnd = offsetStart</span>
<span class="nc" id="L139"> + byteStream.readEliasGammaCodingPositiveInteger() - 1;</span>
<span class="nc" id="L140"> mtasOffset = new MtasOffset(offsetStart, offsetEnd);</span>
<span class="nc bnc" id="L141" title="All 2 branches missed."> if (getRealOffset) {</span>
<span class="nc" id="L142"> int realOffsetStart = byteStream.readEliasGammaCodingInteger()</span>
+ offsetStart;
<span class="nc" id="L144"> int realOffsetEnd = realOffsetStart</span>
<span class="nc" id="L145"> + byteStream.readEliasGammaCodingPositiveInteger() - 1;</span>
<span class="nc" id="L146"> mtasRealOffset = new MtasOffset(realOffsetStart, realOffsetEnd);</span>
}
<span class="pc bpc" id="L148" title="1 of 2 branches missed."> } else if (getRealOffset) {</span>
<span class="nc" id="L149"> int realOffsetStart = byteStream.readEliasGammaCodingNonNegativeInteger();</span>
<span class="nc" id="L150"> int realOffsetEnd = realOffsetStart</span>
<span class="nc" id="L151"> + byteStream.readEliasGammaCodingPositiveInteger() - 1;</span>
<span class="nc" id="L152"> mtasRealOffset = new MtasOffset(realOffsetStart, realOffsetEnd);</span>
}
<span class="fc bfc" id="L154" title="All 2 branches covered."> if (mtasParent) {</span>
<span class="fc" id="L155"> mtasParentId = byteStream.readEliasGammaCodingInteger() + mtasId;</span>
}
<span class="pc bpc" id="L157" title="1 of 2 branches missed."> if (mtasPayload) {</span>
<span class="nc" id="L158"> mtasPayloadValue = byteStream.readRemainingBytes();</span>
}
<span class="fc" id="L160"> }</span>
/**
* Gets the mtas id.
*
* @return the mtas id
*/
public Integer getMtasId() {
<span class="fc" id="L168"> return mtasId;</span>
}
/**
* Gets the mtas parent id.
*
* @return the mtas parent id
*/
public Integer getMtasParentId() {
<span class="fc" id="L177"> return mtasParentId;</span>
}
/**
* Gets the mtas payload.
*
* @return the mtas payload
*/
public byte[] getMtasPayload() {
<span class="pc bpc" id="L186" title="1 of 2 branches missed."> return mtasPayload ? mtasPayloadValue : null;</span>
}
/**
* Gets the mtas position.
*
* @return the mtas position
*/
public MtasPosition getMtasPosition() {
<span class="fc" id="L195"> return mtasPosition;</span>
}
/**
* Gets the mtas offset.
*
* @return the mtas offset
*/
public MtasOffset getMtasOffset() {
<span class="fc" id="L204"> return mtasOffset;</span>
}
/**
* Gets the mtas real offset.
*
* @return the mtas real offset
*/
public MtasOffset getMtasRealOffset() {
<span class="fc" id="L213"> return mtasRealOffset;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>