2 **********************************************************************
\r
3 * Copyright (c) 2002-2010, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 **********************************************************************
\r
7 * Created: November 5 2002
\r
9 **********************************************************************
\r
11 package com.ibm.icu.impl;
\r
13 import java.io.ByteArrayInputStream;
\r
14 import java.io.DataInputStream;
\r
15 import java.io.IOException;
\r
16 import java.io.InputStream;
\r
19 * A DataInputStream that implements random-access seeking. For this
\r
20 * to work, the size of the data stream must be known in advance, or
\r
21 * the data must be supplied as a raw byte[] array.
\r
23 * Seeking doesn't work directly on all streams. If a given stream
\r
24 * doesn't support seeking, extract the bytes into a byte[] array and
\r
25 * use the byte[] constructor.
\r
27 class ICUBinaryStream extends DataInputStream {
\r
30 * Construct a stream from the given stream and size.
\r
31 * @param stream the stream of data
\r
32 * @param size the number of bytes that should be made available
\r
33 * for seeking. Bytes beyond this may be read, but seeking will
\r
34 * not work for offset >= size.
\r
36 public ICUBinaryStream(InputStream stream, int size) {
\r
42 * Construct a stream from the given raw bytes.
\r
44 public ICUBinaryStream(byte[] raw) {
\r
45 this(new ByteArrayInputStream(raw), raw.length);
\r
49 * Seek to the given offset. Offset is from the position of the
\r
50 * stream passed to the constructor, or from the start of the
\r
53 public void seek(int offset) throws IOException {
\r
55 int actual = skipBytes(offset);
\r
56 if (actual != offset) {
\r
57 throw new IllegalStateException("Skip(" + offset + ") only skipped " +
\r