pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / backwards / src / test-framework / org / apache / lucene / store / MockIndexInputWrapper.java
1 package org.apache.lucene.store;
2
3 import java.io.IOException;
4 import java.util.Map;
5
6 /**
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements.  See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License.  You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22
23 /**
24  * Used by MockDirectoryWrapper to create an input stream that
25  * keeps track of when it's been closed.
26  */
27
28 public class MockIndexInputWrapper extends IndexInput {
29   private MockDirectoryWrapper dir;
30   final String name;
31   private IndexInput delegate;
32   private boolean isClone;
33
34   /** Construct an empty output buffer. */
35   public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
36     this.name = name;
37     this.dir = dir;
38     this.delegate = delegate;
39   }
40
41   @Override
42   public void close() throws IOException {
43     try {
44       // turn on the following to look for leaks closing inputs,
45       // after fixing TestTransactions
46       // dir.maybeThrowDeterministicException();
47     } finally {
48       delegate.close();
49       // Pending resolution on LUCENE-686 we may want to
50       // remove the conditional check so we also track that
51       // all clones get closed:
52       if (!isClone) {
53         dir.removeIndexInput(this, name);
54       }
55     }
56   }
57
58   @Override
59   public Object clone() {
60     IndexInput iiclone = (IndexInput) delegate.clone();
61     MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone);
62     clone.isClone = true;
63     // Pending resolution on LUCENE-686 we may want to
64     // uncomment this code so that we also track that all
65     // clones get closed:
66     /*
67     synchronized(dir.openFiles) {
68       if (dir.openFiles.containsKey(name)) {
69         Integer v = (Integer) dir.openFiles.get(name);
70         v = Integer.valueOf(v.intValue()+1);
71         dir.openFiles.put(name, v);
72       } else {
73         throw new RuntimeException("BUG: cloned file was not open?");
74       }
75     }
76     */
77     return clone;
78   }
79
80   @Override
81   public long getFilePointer() {
82     return delegate.getFilePointer();
83   }
84
85   @Override
86   public void seek(long pos) throws IOException {
87     delegate.seek(pos);
88   }
89
90   @Override
91   public long length() {
92     return delegate.length();
93   }
94
95   @Override
96   public byte readByte() throws IOException {
97     return delegate.readByte();
98   }
99
100   @Override
101   public void readBytes(byte[] b, int offset, int len) throws IOException {
102     delegate.readBytes(b, offset, len);
103   }
104
105   @Override
106   public void copyBytes(IndexOutput out, long numBytes) throws IOException {
107     delegate.copyBytes(out, numBytes);
108   }
109
110   @Override
111   public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
112       throws IOException {
113     delegate.readBytes(b, offset, len, useBuffer);
114   }
115
116   @Override
117   public int readInt() throws IOException {
118     return delegate.readInt();
119   }
120
121   @Override
122   public int readVInt() throws IOException {
123     return delegate.readVInt();
124   }
125
126   @Override
127   public long readLong() throws IOException {
128     return delegate.readLong();
129   }
130
131   @Override
132   public long readVLong() throws IOException {
133     return delegate.readVLong();
134   }
135
136   @Override
137   public String readString() throws IOException {
138     return delegate.readString();
139   }
140
141   @Override
142   public Map<String,String> readStringStringMap() throws IOException {
143     return delegate.readStringStringMap();
144   }
145
146   @Override
147   public void setModifiedUTF8StringsMode() {
148     delegate.setModifiedUTF8StringsMode();
149   }
150
151   @Override
152   public void readChars(char[] buffer, int start, int length)
153       throws IOException {
154     delegate.readChars(buffer, start, length);
155   }
156
157   @Override
158   public void skipChars(int length) throws IOException {
159     delegate.skipChars(length);
160   }
161 }