@@ -68,20 +68,16 @@ public int read() throws IOException {
68
68
block = getFirstBlock ();
69
69
readFirst = true ;
70
70
}
71
-
72
71
if (block != null && blockIndex >= block .bytes .length ) {
73
72
block = block .getNext ();
74
73
blockIndex = 0 ;
75
74
}
76
-
77
75
if (null == block ) {
78
76
return -1 ;
79
77
}
80
-
81
78
if (blockIndex >= block .bytes .length ) {
82
79
return -1 ;
83
80
}
84
-
85
81
return 0xff & block .bytes [blockIndex ++];
86
82
}
87
83
@@ -95,30 +91,24 @@ public int read(final byte[] array, final int off, final int len) throws IOExcep
95
91
if (len == 0 ) {
96
92
return 0 ;
97
93
}
98
-
99
94
// optimized block read
100
-
101
95
if (null == block ) {
102
96
if (readFirst ) {
103
97
return -1 ;
104
98
}
105
99
block = getFirstBlock ();
106
100
readFirst = true ;
107
101
}
108
-
109
102
if (block != null && blockIndex >= block .bytes .length ) {
110
103
block = block .getNext ();
111
104
blockIndex = 0 ;
112
105
}
113
-
114
106
if (null == block ) {
115
107
return -1 ;
116
108
}
117
-
118
109
if (blockIndex >= block .bytes .length ) {
119
110
return -1 ;
120
111
}
121
-
122
112
final int readSize = Math .min (len , block .bytes .length - blockIndex );
123
113
System .arraycopy (block .bytes , blockIndex , array , off , readSize );
124
114
blockIndex += readSize ;
@@ -127,13 +117,10 @@ public int read(final byte[] array, final int off, final int len) throws IOExcep
127
117
128
118
@ Override
129
119
public long skip (final long n ) throws IOException {
130
-
131
120
long remaining = n ;
132
-
133
121
if (n <= 0 ) {
134
122
return 0 ;
135
123
}
136
-
137
124
while (remaining > 0 ) {
138
125
// read the first block
139
126
if (null == block ) {
@@ -143,27 +130,21 @@ public long skip(final long n) throws IOException {
143
130
block = getFirstBlock ();
144
131
readFirst = true ;
145
132
}
146
-
147
133
// get next block
148
134
if (block != null && blockIndex >= block .bytes .length ) {
149
135
block = block .getNext ();
150
136
blockIndex = 0 ;
151
137
}
152
-
153
138
if (null == block ) {
154
139
break ;
155
140
}
156
-
157
141
if (blockIndex >= block .bytes .length ) {
158
142
break ;
159
143
}
160
-
161
144
final int readSize = Math .min ((int ) Math .min (BLOCK_SIZE , remaining ), block .bytes .length - blockIndex );
162
-
163
145
blockIndex += readSize ;
164
146
remaining -= readSize ;
165
147
}
166
-
167
148
return n - remaining ;
168
149
}
169
150
@@ -188,10 +169,8 @@ public byte[] getByteArray(final long position, final int length) throws IOExcep
188
169
throw new ImagingException (
189
170
"Could not read block (block start: " + position + ", block length: " + length + ", data length: " + streamLength + ")." );
190
171
}
191
-
192
172
final InputStream cis = getInputStream ();
193
173
BinaryFunctions .skipBytes (cis , position );
194
-
195
174
final byte [] bytes = Allocator .byteArray (length );
196
175
int total = 0 ;
197
176
while (true ) {
0 commit comments