Kinetica   C#   API  Version 7.2.3.0
DeflateCodec.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 using System.IO;
23 using System.IO.Compression;
24 
25 namespace Avro.File
26 {
27  public class DeflateCodec : Codec
28  {
29  public override byte[] Compress(byte[] uncompressedData)
30  {
31  MemoryStream outStream = new MemoryStream();
32 
33  using (DeflateStream Compress =
34  new DeflateStream(outStream,
35  CompressionMode.Compress))
36  {
37  Compress.Write(uncompressedData, 0, uncompressedData.Length);
38  }
39  return outStream.ToArray();
40  }
41 
42  public override byte[] Decompress(byte[] compressedData)
43  {
44  MemoryStream inStream = new MemoryStream(compressedData);
45  MemoryStream outStream = new MemoryStream();
46 
47  using (DeflateStream Decompress =
48  new DeflateStream(inStream,
49  CompressionMode.Decompress))
50  {
51  CopyTo(Decompress, outStream);
52  }
53  return outStream.ToArray();
54  }
55 
56  private static void CopyTo(Stream from, Stream to)
57  {
58  byte[] buffer = new byte[4096];
59  int read;
60  while((read = from.Read(buffer, 0, buffer.Length)) != 0)
61  {
62  to.Write(buffer, 0, read);
63  }
64  }
65 
66  public override string GetName()
67  {
69  }
70 
71  public override bool Equals(object other)
72  {
73  if (this == other)
74  return true;
75  return (this.GetType().Name == other.GetType().Name);
76  }
77 
78  public override int GetHashCode()
79  {
81  }
82  }
83 }
override int GetHashCode()
Codecs must implement a HashCode() method that is consistent with Equals
Definition: DeflateCodec.cs:78
override string GetName()
Name of this codec type
Definition: DeflateCodec.cs:66
override bool Equals(object other)
Codecs must implement an equals() method
Definition: DeflateCodec.cs:71
override byte [] Compress(byte[] uncompressedData)
Compress data using implemented codec
Definition: DeflateCodec.cs:29
override byte [] Decompress(byte[] compressedData)
Decompress data using implemented codec
Definition: DeflateCodec.cs:42