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/test/org/apache/lucene/store _TestHelper.java
Date Tue, 28 Sep 2004 20:45:26 GMT
cutting     2004/09/28 13:45:26

  Modified:    src/java/org/apache/lucene/store BufferedIndexOutput.java
                        FSDirectory.java IndexOutput.java RAMDirectory.java
                        RAMInputStream.java RAMOutputStream.java
               src/test/org/apache/lucene/index TestCompoundFile.java
               src/test/org/apache/lucene/store _TestHelper.java
  Log:
  Updated FSDirectory and RAMDirectory to no longer use deprecated methods.
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-lucene/src/java/org/apache/lucene/store/BufferedIndexOutput.java
  
  Index: BufferedIndexOutput.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/BufferedIndexOutput.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BufferedIndexOutput.java	28 Sep 2004 18:15:52 -0000	1.1
  +++ BufferedIndexOutput.java	28 Sep 2004 20:45:26 -0000	1.2
  @@ -27,7 +27,7 @@
     private int bufferPosition = 0;		  // position in buffer
   
     /** Writes a single byte.
  -   * @see InputStream#readByte()
  +   * @see IndexInput#readByte()
      */
     public void writeByte(byte b) throws IOException {
       if (bufferPosition >= BUFFER_SIZE)
  @@ -38,7 +38,7 @@
     /** Writes an array of bytes.
      * @param b the bytes to write
      * @param length the number of bytes to write
  -   * @see InputStream#readBytes(byte[],int,int)
  +   * @see IndexInput#readBytes(byte[],int,int)
      */
     public void writeBytes(byte[] b, int length) throws IOException {
       for (int i = 0; i < length; i++)
  
  
  
  1.36      +18 -37    jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java
  
  Index: FSDirectory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- FSDirectory.java	16 Sep 2004 21:13:37 -0000	1.35
  +++ FSDirectory.java	28 Sep 2004 20:45:26 -0000	1.36
  @@ -278,13 +278,13 @@
   
     /** Creates a new, empty file in the directory with the given name.
         Returns a stream writing this file. */
  -  public OutputStream createFile(String name) throws IOException {
  -    return new FSOutputStream(new File(directory, name));
  +  public IndexOutput createOutput(String name) throws IOException {
  +    return new FSIndexOutput(new File(directory, name));
     }
   
     /** Returns a stream reading an existing file. */
  -  public InputStream openFile(String name) throws IOException {
  -    return new FSInputStream(new File(directory, name));
  +  public IndexInput openInput(String name) throws IOException {
  +    return new FSIndexInput(new File(directory, name));
     }
   
     /**
  @@ -385,47 +385,25 @@
   }
   
   
  -class FSInputStream extends InputStream {
  +class FSIndexInput extends BufferedIndexInput {
  +
     private class Descriptor extends RandomAccessFile {
  -    /* DEBUG */
  -    //private String name;
  -    /* DEBUG */
       public long position;
       public Descriptor(File file, String mode) throws IOException {
         super(file, mode);
  -      /* DEBUG */
  -      //name = file.toString();
  -      //debug_printInfo("OPEN");
  -      /* DEBUG */
  -    }
  -
  -    /* DEBUG */
  -    //public void close() throws IOException {
  -    //  debug_printInfo("CLOSE");
  -    //    super.close();
  -    //}
  -    //
  -    //private void debug_printInfo(String op) {
  -    //  try { throw new Exception(op + " <" + name + ">");
  -    //  } catch (Exception e) {
  -    //    java.io.StringWriter sw = new java.io.StringWriter();
  -    //    java.io.PrintWriter pw = new java.io.PrintWriter(sw);
  -    //    e.printStackTrace(pw);
  -    //    System.out.println(sw.getBuffer().toString());
  -    //  }
  -    //}
  -    /* DEBUG */
  +    }
     }
   
  -  Descriptor file = null;
  +  private Descriptor file = null;
     boolean isClone;
  +  private long length;
   
  -  public FSInputStream(File path) throws IOException {
  +  public FSIndexInput(File path) throws IOException {
       file = new Descriptor(path, "r");
       length = file.length();
     }
   
  -  /** InputStream methods */
  +  /** IndexInput methods */
     protected void readInternal(byte[] b, int offset, int len)
          throws IOException {
       synchronized (file) {
  @@ -450,16 +428,19 @@
         file.close();
     }
   
  -  /** Random-access methods */
     protected void seekInternal(long position) {
     }
   
  +  public long length() {
  +    return length;
  +  }
  +
     protected void finalize() throws IOException {
       close();            // close the file
     }
   
     public Object clone() {
  -    FSInputStream clone = (FSInputStream)super.clone();
  +    FSIndexInput clone = (FSIndexInput)super.clone();
       clone.isClone = true;
       return clone;
     }
  @@ -473,10 +454,10 @@
   }
   
   
  -class FSOutputStream extends OutputStream {
  +class FSIndexOutput extends BufferedIndexOutput {
     RandomAccessFile file = null;
   
  -  public FSOutputStream(File path) throws IOException {
  +  public FSIndexOutput(File path) throws IOException {
       file = new RandomAccessFile(path, "rw");
     }
   
  
  
  
  1.2       +9 -9      jakarta-lucene/src/java/org/apache/lucene/store/IndexOutput.java
  
  Index: IndexOutput.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/IndexOutput.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IndexOutput.java	28 Sep 2004 18:15:52 -0000	1.1
  +++ IndexOutput.java	28 Sep 2004 20:45:26 -0000	1.2
  @@ -21,24 +21,24 @@
   /** Abstract base class for output to a file in a Directory.  A random-access
    * output stream.  Used for all Lucene index output operations.
    * @see Directory
  - * @see InputStream
  + * @see IndexInput
    */
   public abstract class IndexOutput {
   
     /** Writes a single byte.
  -   * @see InputStream#readByte()
  +   * @see IndexInput#readByte()
      */
     public abstract void writeByte(byte b) throws IOException;
   
     /** Writes an array of bytes.
      * @param b the bytes to write
      * @param length the number of bytes to write
  -   * @see InputStream#readBytes(byte[],int,int)
  +   * @see IndexInput#readBytes(byte[],int,int)
      */
     public abstract void writeBytes(byte[] b, int length) throws IOException;
   
     /** Writes an int as four bytes.
  -   * @see InputStream#readInt()
  +   * @see IndexInput#readInt()
      */
     public void writeInt(int i) throws IOException {
       writeByte((byte)(i >> 24));
  @@ -50,7 +50,7 @@
     /** Writes an int in a variable-length format.  Writes between one and
      * five bytes.  Smaller values take fewer bytes.  Negative numbers are not
      * supported.
  -   * @see InputStream#readVInt()
  +   * @see IndexInput#readVInt()
      */
     public void writeVInt(int i) throws IOException {
       while ((i & ~0x7F) != 0) {
  @@ -61,7 +61,7 @@
     }
   
     /** Writes a long as eight bytes.
  -   * @see InputStream#readLong()
  +   * @see IndexInput#readLong()
      */
     public void writeLong(long i) throws IOException {
       writeInt((int) (i >> 32));
  @@ -71,7 +71,7 @@
     /** Writes an long in a variable-length format.  Writes between one and five
      * bytes.  Smaller values take fewer bytes.  Negative numbers are not
      * supported.
  -   * @see InputStream#readVLong()
  +   * @see IndexInput#readVLong()
      */
     public void writeVLong(long i) throws IOException {
       while ((i & ~0x7F) != 0) {
  @@ -82,7 +82,7 @@
     }
   
     /** Writes a string.
  -   * @see InputStream#readString()
  +   * @see IndexInput#readString()
      */
     public void writeString(String s) throws IOException {
       int length = s.length();
  @@ -94,7 +94,7 @@
      * @param s the source of the characters
      * @param start the first character in the sequence
      * @param length the number of characters in the sequence
  -   * @see InputStream#readChars(char[],int,int)
  +   * @see IndexInput#readChars(char[],int,int)
      */
     public void writeChars(String s, int start, int length)
          throws IOException {
  
  
  
  1.17      +8 -8      jakarta-lucene/src/java/org/apache/lucene/store/RAMDirectory.java
  
  Index: RAMDirectory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/RAMDirectory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- RAMDirectory.java	7 Aug 2004 11:19:28 -0000	1.16
  +++ RAMDirectory.java	28 Sep 2004 20:45:26 -0000	1.17
  @@ -22,8 +22,8 @@
   import java.util.Enumeration;
   
   import org.apache.lucene.store.Directory;
  -import org.apache.lucene.store.InputStream;
  -import org.apache.lucene.store.OutputStream;
  +import org.apache.lucene.store.IndexInput;
  +import org.apache.lucene.store.IndexOutput;
   
   /**
    * A memory-resident {@link Directory} implementation.
  @@ -55,9 +55,9 @@
       final String[] files = dir.list();
       for (int i = 0; i < files.length; i++) {
         // make place on ram disk
  -      OutputStream os = createFile(files[i]);
  +      IndexOutput os = createOutput(files[i]);
         // read current file
  -      InputStream is = dir.openFile(files[i]);
  +      IndexInput is = dir.openInput(files[i]);
         // and copy to ram disk
         int len = (int) is.length();
         byte[] buf = new byte[len];
  @@ -153,14 +153,14 @@
   
     /** Creates a new, empty file in the directory with the given name.
         Returns a stream writing this file. */
  -  public final OutputStream createFile(String name) {
  +  public final IndexOutput createOutput(String name) {
       RAMFile file = new RAMFile();
       files.put(name, file);
       return new RAMOutputStream(file);
     }
   
     /** Returns a stream reading an existing file. */
  -  public final InputStream openFile(String name) {
  +  public final IndexInput openInput(String name) {
       RAMFile file = (RAMFile)files.get(name);
       return new RAMInputStream(file);
     }
  @@ -173,7 +173,7 @@
         public boolean obtain() throws IOException {
           synchronized (files) {
             if (!fileExists(name)) {
  -            createFile(name).close();
  +            createOutput(name).close();
               return true;
             }
             return false;
  
  
  
  1.3       +9 -3      jakarta-lucene/src/java/org/apache/lucene/store/RAMInputStream.java
  
  Index: RAMInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/RAMInputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RAMInputStream.java	29 Mar 2004 22:48:05 -0000	1.2
  +++ RAMInputStream.java	28 Sep 2004 20:45:26 -0000	1.3
  @@ -17,14 +17,15 @@
    */
   
   /**
  - * A memory-resident {@link InputStream} implementation.
  + * A memory-resident {@link IndexInput} implementation.
    *
    * @version $Id$
    */
   
  -class RAMInputStream extends InputStream implements Cloneable {
  +class RAMInputStream extends BufferedIndexInput implements Cloneable {
     private RAMFile file;
     private int pointer = 0;
  +  private long length;
   
     public RAMInputStream(RAMFile f) {
       file = f;
  @@ -54,4 +55,9 @@
     public void seekInternal(long pos) {
       pointer = (int)pos;
     }
  +
  +  public long length() {
  +    return length;
  +  }
  +
   }
  
  
  
  1.4       +2 -2      jakarta-lucene/src/java/org/apache/lucene/store/RAMOutputStream.java
  
  Index: RAMOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/RAMOutputStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RAMOutputStream.java	28 Sep 2004 18:15:52 -0000	1.3
  +++ RAMOutputStream.java	28 Sep 2004 20:45:26 -0000	1.4
  @@ -24,7 +24,7 @@
    * @version $Id$
    */
   
  -public class RAMOutputStream extends OutputStream {
  +public class RAMOutputStream extends BufferedIndexOutput {
     private RAMFile file;
     private int pointer = 0;
   
  
  
  
  1.9       +5 -5      jakarta-lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
  
  Index: TestCompoundFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestCompoundFile.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestCompoundFile.java	28 Sep 2004 18:15:52 -0000	1.8
  +++ TestCompoundFile.java	28 Sep 2004 20:45:26 -0000	1.9
  @@ -306,10 +306,10 @@
   
   
       public void testReadAfterClose() throws IOException {
  -        demo_FSInputStreamBug((FSDirectory) dir, "test");
  +        demo_FSIndexInputBug((FSDirectory) dir, "test");
       }
   
  -    private void demo_FSInputStreamBug(FSDirectory fsdir, String file)
  +    private void demo_FSIndexInputBug(FSDirectory fsdir, String file)
       throws IOException
       {
           // Setup the test file - we need more than 1024 bytes
  @@ -352,7 +352,7 @@
               CompoundFileReader.CSIndexInput cis =
               (CompoundFileReader.CSIndexInput) is;
   
  -            return _TestHelper.isFSInputStreamOpen(cis.base);
  +            return _TestHelper.isFSIndexInputOpen(cis.base);
           } else {
               return false;
           }
  @@ -365,7 +365,7 @@
   
           // basic clone
           IndexInput expected = dir.openInput("f11");
  -        assertTrue(_TestHelper.isFSInputStreamOpen(expected));
  +        assertTrue(_TestHelper.isFSIndexInputOpen(expected));
   
           IndexInput one = cr.openInput("f11");
           assertTrue(isCSIndexInputOpen(one));
  
  
  
  1.4       +12 -12    jakarta-lucene/src/test/org/apache/lucene/store/_TestHelper.java
  
  Index: _TestHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/store/_TestHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- _TestHelper.java	16 Sep 2004 21:13:37 -0000	1.3
  +++ _TestHelper.java	28 Sep 2004 20:45:26 -0000	1.4
  @@ -8,35 +8,35 @@
   public class _TestHelper {
   
       /** Returns true if the instance of the provided input stream is actually
  -     *  an FSInputStream.
  +     *  an FSIndexInput.
        */
  -    public static boolean isFSInputStream(IndexInput is) {
  -        return is instanceof FSInputStream;
  +    public static boolean isFSIndexInput(IndexInput is) {
  +        return is instanceof FSIndexInput;
       }
   
  -    /** Returns true if the provided input stream is an FSInputStream and
  +    /** Returns true if the provided input stream is an FSIndexInput and
        *  is a clone, that is it does not own its underlying file descriptor.
        */
  -    public static boolean isFSInputStreamClone(IndexInput is) {
  -        if (isFSInputStream(is)) {
  -            return ((FSInputStream) is).isClone;
  +    public static boolean isFSIndexInputClone(IndexInput is) {
  +        if (isFSIndexInput(is)) {
  +            return ((FSIndexInput) is).isClone;
           } else {
               return false;
           }
       }
   
  -    /** Given an instance of FSDirectory.FSInputStream, this method returns
  +    /** Given an instance of FSDirectory.FSIndexInput, this method returns
        *  true if the underlying file descriptor is valid, and false otherwise.
        *  This can be used to determine if the OS file has been closed.
        *  The descriptor becomes invalid when the non-clone instance of the
  -     *  FSInputStream that owns this descriptor is closed. However, the
  +     *  FSIndexInput that owns this descriptor is closed. However, the
        *  descriptor may possibly become invalid in other ways as well.
        */
  -    public static boolean isFSInputStreamOpen(IndexInput is)
  +    public static boolean isFSIndexInputOpen(IndexInput is)
       throws IOException
       {
  -        if (isFSInputStream(is)) {
  -            FSInputStream fis = (FSInputStream) is;
  +        if (isFSIndexInput(is)) {
  +            FSIndexInput fis = (FSIndexInput) is;
               return fis.isFDValid();
           } else {
               return false;
  
  
  

---------------------------------------------------------------------
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