1 package org.apache.lucene.store;
3 import java.io.IOException;
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * Used by MockDirectoryWrapper to create an input stream that
25 * keeps track of when it's been closed.
28 public class MockIndexInputWrapper extends IndexInput {
29 private MockDirectoryWrapper dir;
31 private IndexInput delegate;
32 private boolean isClone;
33 private boolean closed;
35 /** Construct an empty output buffer. */
36 public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
37 super("MockIndexInputWrapper(name=" + name + " delegate=" + delegate + ")");
40 this.delegate = delegate;
44 public void close() throws IOException {
46 // turn on the following to look for leaks closing inputs,
47 // after fixing TestTransactions
48 // dir.maybeThrowDeterministicException();
52 // Pending resolution on LUCENE-686 we may want to
53 // remove the conditional check so we also track that
54 // all clones get closed:
56 dir.removeIndexInput(this, name);
61 private void ensureOpen() {
63 throw new RuntimeException("Abusing closed IndexInput!");
68 public Object clone() {
70 dir.inputCloneCount.incrementAndGet();
71 IndexInput iiclone = (IndexInput) delegate.clone();
72 MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone);
74 // Pending resolution on LUCENE-686 we may want to
75 // uncomment this code so that we also track that all
78 synchronized(dir.openFiles) {
79 if (dir.openFiles.containsKey(name)) {
80 Integer v = (Integer) dir.openFiles.get(name);
81 v = Integer.valueOf(v.intValue()+1);
82 dir.openFiles.put(name, v);
84 throw new RuntimeException("BUG: cloned file was not open?");
92 public long getFilePointer() {
94 return delegate.getFilePointer();
98 public void seek(long pos) throws IOException {
104 public long length() {
106 return delegate.length();
110 public byte readByte() throws IOException {
112 return delegate.readByte();
116 public void readBytes(byte[] b, int offset, int len) throws IOException {
118 delegate.readBytes(b, offset, len);
122 public void copyBytes(IndexOutput out, long numBytes) throws IOException {
124 delegate.copyBytes(out, numBytes);
128 public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
131 delegate.readBytes(b, offset, len, useBuffer);
135 public int readInt() throws IOException {
137 return delegate.readInt();
141 public int readVInt() throws IOException {
143 return delegate.readVInt();
147 public long readLong() throws IOException {
149 return delegate.readLong();
153 public long readVLong() throws IOException {
155 return delegate.readVLong();
159 public String readString() throws IOException {
161 return delegate.readString();
165 public Map<String,String> readStringStringMap() throws IOException {
167 return delegate.readStringStringMap();
171 public void setModifiedUTF8StringsMode() {
173 delegate.setModifiedUTF8StringsMode();
177 public void readChars(char[] buffer, int start, int length)
180 delegate.readChars(buffer, start, length);
184 public void skipChars(int length) throws IOException {
186 delegate.skipChars(length);