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;
34 /** Construct an empty output buffer. */
35 public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
38 this.delegate = delegate;
42 public void close() throws IOException {
44 // turn on the following to look for leaks closing inputs,
45 // after fixing TestTransactions
46 // dir.maybeThrowDeterministicException();
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:
53 dir.removeIndexInput(this, name);
59 public Object clone() {
60 IndexInput iiclone = (IndexInput) delegate.clone();
61 MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone);
63 // Pending resolution on LUCENE-686 we may want to
64 // uncomment this code so that we also track that all
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);
73 throw new RuntimeException("BUG: cloned file was not open?");
81 public long getFilePointer() {
82 return delegate.getFilePointer();
86 public void seek(long pos) throws IOException {
91 public long length() {
92 return delegate.length();
96 public byte readByte() throws IOException {
97 return delegate.readByte();
101 public void readBytes(byte[] b, int offset, int len) throws IOException {
102 delegate.readBytes(b, offset, len);
106 public void copyBytes(IndexOutput out, long numBytes) throws IOException {
107 delegate.copyBytes(out, numBytes);
111 public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
113 delegate.readBytes(b, offset, len, useBuffer);
117 public int readInt() throws IOException {
118 return delegate.readInt();
122 public int readVInt() throws IOException {
123 return delegate.readVInt();
127 public long readLong() throws IOException {
128 return delegate.readLong();
132 public long readVLong() throws IOException {
133 return delegate.readVLong();
137 public String readString() throws IOException {
138 return delegate.readString();
142 public Map<String,String> readStringStringMap() throws IOException {
143 return delegate.readStringStringMap();
147 public void setModifiedUTF8StringsMode() {
148 delegate.setModifiedUTF8StringsMode();
152 public void readChars(char[] buffer, int start, int length)
154 delegate.readChars(buffer, start, length);
158 public void skipChars(int length) throws IOException {
159 delegate.skipChars(length);