lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/store MMapDirectory.java
Date Tue, 28 Sep 2004 21:55:59 GMT
cutting     2004/09/28 14:55:59

  Modified:    src/java/org/apache/lucene/store MMapDirectory.java
  Log:
  Fixed so that file is no longer kept open.
  
  Revision  Changes    Path
  1.2       +13 -16    jakarta-lucene/src/java/org/apache/lucene/store/MMapDirectory.java
  
  Index: MMapDirectory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/MMapDirectory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MMapDirectory.java	28 Sep 2004 21:40:11 -0000	1.1
  +++ MMapDirectory.java	28 Sep 2004 21:55:59 -0000	1.2
  @@ -37,14 +37,16 @@
     private class MMapIndexInput extends IndexInput {
   
       private ByteBuffer buffer;
  -    private RandomAccessFile file;
  -    private long length;
  -    private boolean isClone;
  -
  -    public MMapIndexInput(String path) throws IOException {
  -      this.file = new RandomAccessFile(path, "r");
  -      this.length = file.length();
  -      this.buffer = file.getChannel().map(MapMode.READ_ONLY, 0, length);
  +    private final long length;
  +
  +    public MMapIndexInput(File file) throws IOException {
  +      RandomAccessFile raf = new RandomAccessFile(file, "r");
  +      try {
  +        this.length = raf.length();
  +        this.buffer = raf.getChannel().map(MapMode.READ_ONLY, 0, length);
  +      } finally {
  +        raf.close();
  +      }
       }
   
       public byte readByte() throws IOException {
  @@ -70,21 +72,16 @@
   
       public Object clone() {
         MMapIndexInput clone = (MMapIndexInput)super.clone();
  -      clone.isClone = true;
         clone.buffer = buffer.duplicate();
         return clone;
       }
   
  -    public void close() throws IOException {
  -      if (!isClone)
  -        file.close();
  -    }
  -  }
  +    public void close() throws IOException {}
   
  -  private MMapDirectory() {}                      // no public ctor
  +  }
   
     public IndexInput openInput(String name) throws IOException {
  -    return new MMapIndexInput(new File(getFile(), name).getPath());
  +    return new MMapIndexInput(new File(getFile(), name));
     }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message