01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.record;
19:
20: import java.io.ByteArrayInputStream;
21: import org.apache.poi.util.LittleEndian;
22:
23: /**
24: * A Record Input Stream derivative that makes access to byte arrays used in the
25: * test cases work a bit easier.
26: * <p> Creates the sream and moves to the first record.
27: *
28: * @author Jason Height (jheight at apache.org)
29: */
30: public class TestcaseRecordInputStream extends RecordInputStream {
31: public TestcaseRecordInputStream(short sid, short length,
32: byte[] data) {
33: super (new ByteArrayInputStream(mergeDataAndSid(sid, length,
34: data)));
35: nextRecord();
36: }
37:
38: public static byte[] mergeDataAndSid(short sid, short length,
39: byte[] data) {
40: byte[] result = new byte[data.length + 4];
41: LittleEndian.putShort(result, 0, sid);
42: LittleEndian.putShort(result, 2, length);
43: System.arraycopy(data, 0, result, 4, data.length);
44: return result;
45: }
46: }
|