Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Deflater.cs
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20 */
21 
22 using System;
23 
24 namespace Lucene.Net.Support
25 {
26  public class Deflater
27  {
28  delegate void SetLevelDelegate(int level);
29  delegate void SetInputDelegate(byte[] input, int offset, int count);
30  delegate void FinishDelegate();
31  delegate bool GetIsFinishedDelegate();
32  delegate int DeflateDelegate(byte[] output);
33 
34  SetLevelDelegate setLevelMethod;
35  SetInputDelegate setInputMethod;
36  FinishDelegate finishMethod;
37  GetIsFinishedDelegate getIsFinishedMethod;
38  DeflateDelegate deflateMethod;
39 
40  public const int BEST_COMPRESSION = 9;
41 
42  internal Deflater(object deflaterInstance)
43  {
44  Type type = deflaterInstance.GetType();
45 
46  setLevelMethod = (SetLevelDelegate)Delegate.CreateDelegate(
47  typeof(SetLevelDelegate),
48  deflaterInstance,
49  type.GetMethod("SetLevel", new Type[] { typeof(int) }));
50 
51  setInputMethod = (SetInputDelegate)Delegate.CreateDelegate(
52  typeof(SetInputDelegate),
53  deflaterInstance,
54  type.GetMethod("SetInput", new Type[] { typeof(byte[]), typeof(int), typeof(int) }));
55 
56  finishMethod = (FinishDelegate)Delegate.CreateDelegate(
57  typeof(FinishDelegate),
58  deflaterInstance,
59  type.GetMethod("Finish", Type.EmptyTypes));
60 
61  getIsFinishedMethod = (GetIsFinishedDelegate)Delegate.CreateDelegate(
62  typeof(GetIsFinishedDelegate),
63  deflaterInstance,
64  type.GetMethod("get_IsFinished", Type.EmptyTypes));
65 
66  deflateMethod = (DeflateDelegate)Delegate.CreateDelegate(
67  typeof(DeflateDelegate),
68  deflaterInstance,
69  type.GetMethod("Deflate", new Type[] { typeof(byte[]) }));
70  }
71 
72  public void SetLevel(int level)
73  {
74  setLevelMethod(level);
75  }
76 
77  public void SetInput(byte[] input, int offset, int count)
78  {
79  setInputMethod(input, offset, count);
80  }
81 
82  public void Finish()
83  {
84  finishMethod();
85  }
86 
87  public bool IsFinished
88  {
89  get { return getIsFinishedMethod(); }
90  }
91 
92  public int Deflate(byte[] output)
93  {
94  return deflateMethod(output);
95  }
96  }
97 }