Skip to content

Commit 03a41f7

Browse files
author
Jin Kwon
committed
[#14] Add skip methods; Still need to be tested
1 parent bb5f4ee commit 03a41f7

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

docker.maven.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
if [ $# -lt 3 ]; then
3+
echo "Usage: $0 <tag> <phases...>, e.g. $0 3-jdk-11-openj9 clean install"
4+
echo "See https://hub.docker.com/_/maven for available tags"
5+
exit 1
6+
fi
7+
groupId=$(mvn help:evaluate -Dexpression=project.groupId | grep -v '\[')
8+
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId | grep -v '\[')
9+
version=$(mvn help:evaluate -Dexpression=project.version | grep -v '\[')
10+
echo $groupId:$artifactId:$version
11+
tag="$1"
12+
shift
13+
echo run -it --rm \
14+
--name $artifactId \
15+
-v "$HOME/.m2":/root/.m2 \
16+
-v "$(pwd)":/usr/src/"$groupId"/"$artifactId"/"$version" \
17+
-w /usr/src/"$groupId"/"$artifactId"/"$version" \
18+
maven:"$tag" mvn "$@"
19+
docker run -it --rm \
20+
--name $artifactId \
21+
-v "$HOME/.m2":/root/.m2 \
22+
-v "$(pwd)":/usr/src/"$groupId"/"$artifactId"/"$version" \
23+
-w /usr/src/"$groupId"/"$artifactId"/"$version" \
24+
maven:"$tag" mvn "$@"

src/main/java/com/github/jinahya/bit/io/AbstractBitInput.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,34 @@ public char readChar16() throws IOException {
249249
}
250250

251251
// -----------------------------------------------------------------------------------------------------------------
252+
@Override
253+
public void skip(final int bits) throws IOException {
254+
if (bits <= 0) {
255+
throw new IllegalArgumentException("bits(" + bits + ") <= 0");
256+
}
257+
final int q = bits / Byte.SIZE;
258+
for (int i = 0; i < q; i++) {
259+
readInt(true, Byte.SIZE);
260+
}
261+
final int r = bits % Byte.SIZE;
262+
for (int i = 0; i < r; i++) {
263+
readBoolean();
264+
}
265+
}
266+
252267
@Override
253268
public long align(final int bytes) throws IOException {
254269
if (bytes <= 0) {
255270
throw new IllegalArgumentException("bytes(" + bytes + ") <= 0");
256271
}
257-
long bits = 0; // number of bits discarded
272+
// TODO: 2020/02/14 Use skip()!!!
273+
long bits = 0; // number of bits to discard
258274
if (available > 0) {
259275
bits += available;
260276
readInt(true, available);
261277
}
262278
assert available == 0;
263-
for (; count % bytes > 0L; bits += Byte.SIZE) {
279+
for (; (count % bytes) > 0L; bits += Byte.SIZE) {
264280
readInt(true, Byte.SIZE);
265281
}
266282
assert count % bytes == 0L;

src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,28 @@ public void writeChar16(final char value) throws IOException {
239239
}
240240

241241
// -----------------------------------------------------------------------------------------------------------------
242+
@Override
243+
public void skip(final int bits) throws IOException {
244+
if (bits <= 0) {
245+
throw new IllegalArgumentException("bits(" + bits + ") <= 0");
246+
}
247+
final int q = bits / Byte.SIZE;
248+
for (int i = 0; i < q; i++) {
249+
writeInt(true, Byte.SIZE, 0);
250+
}
251+
final int r = bits % Byte.SIZE;
252+
for (int i = 0; i < r; i++) {
253+
writeBoolean(false);
254+
}
255+
}
256+
242257
@Override
243258
public long align(final int bytes) throws IOException {
244259
if (bytes <= 0) {
245260
throw new IllegalArgumentException("bytes(" + bytes + ") <= 0");
246261
}
247-
long bits = 0; // the number of bits padded
262+
// TODO: 2020/02/14 Use skip()!!!
263+
long bits = 0; // the number of bits to pad
248264
if (available < Byte.SIZE) {
249265
bits += available;
250266
writeInt(true, available, 0x00);

src/main/java/com/github/jinahya/bit/io/BitInput.java

+8
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ public interface BitInput {
184184

185185
// -----------------------------------------------------------------------------------------------------------------
186186

187+
/**
188+
* Skips specified number of bits by discarding bits.
189+
*
190+
* @param bits the number of bit to skip; must be positive.
191+
* @throws IOException if an I/O error occurs.
192+
*/
193+
void skip(int bits) throws IOException;
194+
187195
/**
188196
* Aligns to specified number of bytes by discarding bits.
189197
*

src/main/java/com/github/jinahya/bit/io/BitOutput.java

+8
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ public interface BitOutput {
186186

187187
// -----------------------------------------------------------------------------------------------------------------
188188

189+
/**
190+
* Skips specified number of bits by padding zero bits.
191+
*
192+
* @param bits the number of bit to skip; must be positive.
193+
* @throws IOException if an I/O error occurs.
194+
*/
195+
void skip(int bits) throws IOException;
196+
189197
/**
190198
* Aligns to specified number of bytes by padding zero bits.
191199
*

0 commit comments

Comments
 (0)