Package org.apache.lucene.store

Examples of org.apache.lucene.store.IndexInput


  /**
   * Copy the contents of the file with specified extension into the provided
   * output stream.
   */
  private void copyFile(FileEntry source, IndexOutput os) throws IOException {
    IndexInput is = source.dir.openInput(source.file);
    try {
      long startPtr = os.getFilePointer();
      long length = is.length();
      os.copyBytes(is, length);

      if (checkAbort != null) {
        checkAbort.work(length);
      }

      // Verify that the output length diff is equal to original file
      long endPtr = os.getFilePointer();
      long diff = endPtr - startPtr;
      if (diff != length)
        throw new IOException("Difference in the output file offsets " + diff
            + " does not match the original file length " + length);

    } finally {
      is.close();
    }
  }
View Full Code Here


            j++;
            break;
          }
        } while(numDocs < MAX_RAW_MERGE_DOCS);
       
        IndexInput stream = matchingFieldsReader.rawDocs(rawDocStarts,rawDocEnds, start, numDocs);
        fieldsWriter.addRawDocuments(stream, rawDocStarts,rawDocEnds, numDocs);
        docCount += numDocs;
        checkAbort.work(300 * numDocs);
      }
    } else {
View Full Code Here

    int docCount = 0;
    if (matchingFieldsReader != null) {
      // We can bulk-copy because the fieldInfos are "congruent"
      while (docCount < maxDoc) {
        int len = Math.min(MAX_RAW_MERGE_DOCS, maxDoc - docCount);
        IndexInput stream = matchingFieldsReader.rawDocs(rawDocStarts,rawDocEnds, docCount, len);
        fieldsWriter.addRawDocuments(stream, rawDocStarts,rawDocEnds, len);
        docCount += len;
        checkAbort.work(300 * len);
      }
    } else {
View Full Code Here

   * "2.x" for all pre-3.0 segments, or "3.0" for 3.0 segments. This method
   * should not be called for 3.1+ segments since they already record their code
   * version.
   */
  static String detectCodeVersion(Directory dir, String segment) throws IOException {
    IndexInput idxStream = dir.openInput(IndexFileNames.segmentFileName(segment, IndexFileNames.FIELDS_INDEX_EXTENSION), 1024);
    try {
      int format = idxStream.readInt();
      if(format==FieldsWriterCompress.FORMAT_CURRENT) {
        return "3.0";
      }else if (format < FieldsWriter.FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS) {
        return "2.x";
      } else {
        return "3.0";
      }
    } finally {
      idxStream.close();
    }
  }
View Full Code Here

      lazy = true;
      this.isCompressed = isCompressed;
    }

    private IndexInput getFieldStream() {
      IndexInput localFieldsStream = fieldsStreamTL.get();
      if (localFieldsStream == null) {
        localFieldsStream = (IndexInput) cloneableFieldsStream.clone();
        fieldsStreamTL.set(localFieldsStream);
      }
      return localFieldsStream;
View Full Code Here

      ensureOpen();
      if (isBinary)
        return null;
      else {
        if (fieldsData == null) {
          IndexInput localFieldsStream = getFieldStream();
      String value;
          try {
            localFieldsStream.seek(pointer);
            if (isCompressed) {
              final byte[] b = new byte[toRead];
              localFieldsStream.readBytes(b, 0, b.length);
              value = new String(uncompress(b), "UTF-8");
            } else {
              if (format >= FieldsWriter.FORMAT_VERSION_UTF8_LENGTH_IN_BYTES) {
                byte[] bytes = new byte[toRead];
                localFieldsStream.readBytes(bytes, 0, toRead);
                value = new String(bytes, "UTF-8");
              } else {
                //read in chars b/c we already know the length we need to read
                char[] chars = new char[toRead];
                localFieldsStream.readChars(chars, 0, toRead);
                value = new String(chars);
              }
            }
          } catch (IOException e) {
            throw new FieldReaderException(e);
View Full Code Here

          if (result == null || result.length < toRead)
            b = new byte[toRead];
          else
            b = result;
  
          IndexInput localFieldsStream = getFieldStream();

          // Throw this IOException since IndexReader.document does so anyway, so probably not that big of a change for people
          // since they are already handling this exception when getting the document
          try {
            localFieldsStream.seek(pointer);
            localFieldsStream.readBytes(b, 0, toRead);
            if (isCompressed == true) {
              value = uncompress(b);
            } else {
              value = b;
            }
View Full Code Here

   * @param d The directory to open the IndexInput from
   * @param name The name of the file to open the IndexInput from in the Directory
   * @throws IOException
   */
  FieldInfos(Directory d, String name) throws IOException {
    IndexInput input = d.openInput(name);
    try {
      try {
        read(input, name);
      } catch (IOException ioe) {
        if (format == FORMAT_PRE) {
          // LUCENE-1623: FORMAT_PRE (before there was a
          // format) may be 2.3.2 (pre-utf8) or 2.4.x (utf8)
          // encoding; retry with input set to pre-utf8
          input.seek(0);
          input.setModifiedUTF8StringsMode();
          byNumber.clear();
          byName.clear();
          try {
            read(input, name);
          } catch (Throwable t) {
            // Ignore any new exception & throw original IOE
            throw ioe;
          }
        } else {
          // The IOException cannot be caused by
          // LUCENE-1623, so re-throw it
          throw ioe;
        }
      }
    } finally {
      input.close();
    }
  }
View Full Code Here

      String quickTis=IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_EXTENSION_QUICK);
      String quickTisTxt=IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_EXTENSION_QUICK_TXT);
      String quickTisVal=IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_EXTENSION_QUICK_VAL);
      if(directory.fileExists(tisFileSize))
      {
      IndexInput sizebuff=directory.openInput(tisFileSize, readBufferSize);
      tisfilesize=sizebuff.readLong();
         
      if(directory.fileExists(quickTis))
      {
       docValues=new DocValuesReader()
      
         docValues.quicktisInput=new SmallBufferedInput(directory.openInput(quickTis, 8),8);
       docValues.quicktisInputTxt=new SmallBufferedInput(directory.openInput(quickTisTxt,1024),1024);
       docValues.quicktisInputVal=new SmallBufferedInput(directory.openInput(quickTisVal,8),8);
     
//       if(directory instanceof FSDirectory){
//            docValues.quicktisInput=BlockBufferInput.MaybeInstance(directory.openInput(quickTis,readBufferSize),directory,quickTis,directory.getP());
//          docValues.quicktisInputTxt=BlockBufferInput.MaybeInstance(directory.openInput(quickTisTxt,readBufferSize),directory,quickTisTxt,directory.getP());
//          docValues.quicktisInputVal=BlockBufferInput.MaybeInstance(directory.openInput(quickTisVal,readBufferSize),directory,quickTisVal,directory.getP());
//        }else if(directory instanceof FileSystemDirectory){
//            docValues.quicktisInput=BlockBufferInput.MaybeInstance(directory.openInput(quickTis,readBufferSize),directory,quickTis,directory.getP());
//          docValues.quicktisInputTxt=BlockBufferInput.MaybeInstance(directory.openInput(quickTisTxt,readBufferSize),directory,quickTisTxt,directory.getP());
//          docValues.quicktisInputVal=BlockBufferInput.MaybeInstance(directory.openInput(quickTisVal,readBufferSize),directory,quickTisVal,directory.getP());
//        }else{}
       docValues.readPosForm(sizebuff);
       supportquick.set(true);
     }
      sizebuff.close();
      }
     
      String filename=IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_EXTENSION);
      final String indexFileName = IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_INDEX_EXTENSION);
      final String indexFileNamequick = IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_INDEX_EXTENSION_QUICK);

    
      if (directory instanceof FSDirectory) {
        tisInput = BlockBufferInput.MaybeInstance(
            directory.openInput(filename, readBufferSize),
            directory, filename, directory.getP());
        tiiInput = directory.openInput(indexFileName, readBufferSize);
      } else if (directory instanceof FileSystemDirectory) {
        tisInput = BlockBufferInput.MaybeInstance(
            directory.openInput(filename, readBufferSize),
            directory, filename, directory.getP());
        tiiInput = directory.openInput(indexFileName, readBufferSize);
      } else {
        tisInput = directory.openInput(filename, readBufferSize);
        tiiInput = directory.openInput(indexFileName, readBufferSize);
      }
     
      if(directory.fileExists(indexFileNamequick))
      {
        tiiInputquick=directory.openInput(indexFileNamequick, readBufferSize);
        this.isQuickMode.set(true);
      }

     
      origEnum = new SegmentTermEnum(tisInput, fieldInfos, false,tisfilesize);
      size = origEnum.size;


      if (indexDivisor != -1) {
   
    long tiifilesize=-1;
          String tiiFileSize=IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_INDEX_EXTENSION_SIZE);
          if(directory.fileExists(tiiFileSize))
          {
          IndexInput sizebuff=directory.openInput(tiiFileSize, readBufferSize);
          tiifilesize=sizebuff.readLong();
          sizebuff.close();
          }
        // Load terms index
        totalIndexInterval = origEnum.indexInterval * indexDivisor;
         SegmentTermEnum indexEnum=null ;
        try {
View Full Code Here

   
    try {
      stream = dir.openInput(name, readBufferSize);
     
      pos = new HashMap<Long, Long>();
      IndexInput streampos = dir.openInput(fileNamepos, readBufferSize);
      int size = streampos.readInt();
      for (int i = 0; i < size; i++) {
  Long key = streampos.readLong();
  Long value = streampos.readLong();
  pos.put(key, value);
      }

      streampos.close();
     
      // read the first VInt. If it is negative, it's the version number
      // otherwise it's the count (pre-3.1 indexes)
      int firstInt = stream.readVInt();
     
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.IndexInput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.