01: /*
02: *
03: * Derby - Class TestInputStream
04: *
05: * Licensed to the Apache Software Foundation (ASF) under one or more
06: * contributor license agreements. See the NOTICE file distributed with
07: * this work for additional information regarding copyright ownership.
08: * The ASF licenses this file to You under the Apache License, Version 2.0
09: * (the "License"); you may not use this file except in compliance with
10: * the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17: * either express or implied. See the License for the specific
18: * language governing permissions and limitations under the License.
19: */
20: package org.apache.derbyTesting.functionTests.util;
21:
22: import java.io.InputStream;
23: import java.io.IOException;
24:
25: /**
26: * TestInputStream class is a InputStream which returns
27: * a lot of data which can be inserted into a LOB.
28: */
29: public final class TestInputStream extends InputStream {
30: /**
31: * Constructor for TestInputStream
32: * @param length length of stream
33: * @param value value to return
34: */
35: public TestInputStream(long length, int value) {
36: this .value = value;
37: this .length = length;
38: this .pos = 0;
39: }
40:
41: /**
42: * Implementation of InputStream.read(). Returns
43: * the value specified in constructor, unless the
44: * end of the stream has been reached.
45: */
46: public int read() throws IOException {
47: if (++pos > length)
48: return -1;
49: return value;
50: }
51:
52: /** Current position in stream */
53: private long pos;
54:
55: /** Value to return */
56: final int value;
57:
58: /** Length of stream */
59: final long length;
60: }
|