KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > util > TestInputStream


1 /*
2  *
3  * Derby - Class TestInputStream
4  *
5  * Licensed to the Apache Software Foundation (ASF) under one or more
6  * contributor license agreements. See the NOTICE file distributed with
7  * this work for additional information regarding copyright ownership.
8  * The ASF licenses this file to You under the Apache License, Version 2.0
9  * (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 import java.io.InputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 /**
25  * TestInputStream class is a InputStream which returns
26  * a lot of data which can be inserted into a LOB.
27  */

28 public final class TestInputStream extends InputStream JavaDoc
29 {
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     {
37         this.value = value;
38         this.length = length;
39         this.pos = 0;
40     }
41     
42     /**
43      * Implementation of InputStream.read(). Returns
44      * the value specified in constructor, unless the
45      * end of the stream has been reached.
46      */

47     public int read()
48         throws IOException JavaDoc
49     {
50         if (++pos>length) return -1;
51         return value;
52     }
53     
54     /** Current position in stream */
55     private long pos;
56     
57     /** Value to return */
58     final int value;
59     
60     /** Length of stream */
61     final long length;
62 }
63
Popular Tags