KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > store > _TestHelper


1 package org.apache.lucene.store;
2 import java.io.RandomAccessFile JavaDoc;
3 import java.io.IOException JavaDoc;
4
5 /** This class provides access to package-level features defined in the
6  * store package. It is used for testing only.
7  */

8 public class _TestHelper {
9
10     /** Returns true if the instance of the provided input stream is actually
11      * an FSInputStream.
12      */

13     public static boolean isFSInputStream(InputStream is) {
14         return is instanceof FSInputStream;
15     }
16
17     /** Returns true if the provided input stream is an FSInputStream and
18      * is a clone, that is it does not own its underlying file descriptor.
19      */

20     public static boolean isFSInputStreamClone(InputStream is) {
21         if (isFSInputStream(is)) {
22             return ((FSInputStream) is).isClone;
23         } else {
24             return false;
25         }
26     }
27
28     /** Given an instance of FSDirectory.FSInputStream, this method returns
29      * true if the underlying file descriptor is valid, and false otherwise.
30      * This can be used to determine if the OS file has been closed.
31      * The descriptor becomes invalid when the non-clone instance of the
32      * FSInputStream that owns this descriptor is closed. However, the
33      * descriptor may possibly become invalid in other ways as well.
34      */

35     public static boolean isFSInputStreamOpen(InputStream is)
36     throws IOException JavaDoc
37     {
38         if (isFSInputStream(is)) {
39             FSInputStream fis = (FSInputStream) is;
40             return fis.isFDValid();
41         } else {
42             return false;
43         }
44     }
45
46 }
47
Popular Tags