Initial revision
[beagle.git] / Lucene.Net / Index / SegmentInfos.cs
blobd6a0333573a2bba850b5fe237c872ec9cbda7d26
1 using System.Collections;
2 using Lucene.Net.Store;
4 namespace Lucene.Net.Index
6 /* ====================================================================
7 * The Apache Software License, Version 1.1
9 * Copyright (c) 2001 The Apache Software Foundation. All rights
10 * reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
24 * 3. The end-user documentation included with the redistribution,
25 * if any, must include the following acknowledgment:
26 * "This product includes software developed by the
27 * Apache Software Foundation (http://www.apache.org/)."
28 * Alternately, this acknowledgment may appear in the software itself,
29 * if and wherever such third-party acknowledgments normally appear.
31 * 4. The names "Apache" and "Apache Software Foundation" and
32 * "Apache Lucene" must not be used to endorse or promote products
33 * derived from this software without prior written permission. For
34 * written permission, please contact apache@apache.org.
36 * 5. Products derived from this software may not be called "Apache",
37 * "Apache Lucene", nor may "Apache" appear in their name, without
38 * prior written permission of the Apache Software Foundation.
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 * ====================================================================
54 * This software consists of voluntary contributions made by many
55 * individuals on behalf of the Apache Software Foundation. For more
56 * information on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
60 sealed class SegmentInfos : ArrayList
62 public int counter = 0; // used to name new segments
64 public SegmentInfo Info(int i)
66 return (SegmentInfo)this[i];
69 public void Read(Directory directory)
71 InputStream input = directory.OpenFile("segments");
72 try
74 counter = input.ReadInt(); // read counter
75 for (int i = input.ReadInt(); i > 0; i--)
76 { // read segmentInfos
77 SegmentInfo si =
78 new SegmentInfo(input.ReadString(), input.ReadInt(), directory);
79 Add(si);
82 finally
84 input.Close();
88 public void Write(Directory directory)
90 OutputStream output = directory.CreateFile("segments.new");
91 try
93 output.WriteInt(counter); // write counter
94 output.WriteInt(Count); // write infos
95 for (int i = 0; i < Count; i++)
97 SegmentInfo si = Info(i);
98 output.WriteString(si.name);
99 output.WriteInt(si.docCount);
102 finally
104 output.Close();
107 // install new segment info
108 directory.RenameFile("segments.new", "segments");