2 **********************************************************************
\r
3 * Copyright (c) 2002-2006, 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
16 * A DataInputStream that implements random-access seeking. For this
\r
17 * to work, the size of the data stream must be known in advance, or
\r
18 * the data must be supplied as a raw byte[] array.
\r
20 * Seeking doesn't work directly on all streams. If a given stream
\r
21 * doesn't support seeking, extract the bytes into a byte[] array and
\r
22 * use the byte[] constructor.
\r
24 class ICUBinaryStream extends DataInputStream {
\r
27 * Construct a stream from the given stream and size.
\r
28 * @param stream the stream of data
\r
29 * @param size the number of bytes that should be made available
\r
30 * for seeking. Bytes beyond this may be read, but seeking will
\r
31 * not work for offset >= size.
\r
33 public ICUBinaryStream(InputStream stream, int size) {
\r
39 * Construct a stream from the given raw bytes.
\r
41 public ICUBinaryStream(byte[] raw) {
\r
42 this(new ByteArrayInputStream(raw), raw.length);
\r
46 * Seek to the given offset. Offset is from the position of the
\r
47 * stream passed to the constructor, or from the start of the
\r
50 public void seek(int offset) throws IOException {
\r
52 int actual = skipBytes(offset);
\r
53 if (actual != offset) {
\r
54 throw new IllegalStateException("Skip(" + offset + ") only skipped " +
\r
57 if (false) System.out.println("(seek " + offset + ")");
\r