/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.IO;
namespace Avro.File
{
///
/// Base class for Avro-supported compression codecs for data files. Note that Codec objects may
/// maintain internal state (e.g. buffers) and are not thread safe.
///
public abstract class Codec
{
///
/// Compress data using implemented codec
///
///
///
abstract public byte[] Compress(byte[] uncompressedData);
///
/// Compress data using implemented codec
///
/// The stream which contains the data to be compressed
/// A reusable stream which will hold the compressed data. That stream should be empty.
abstract public void Compress(MemoryStream inputStream, MemoryStream outputStream);
///
/// Decompress data using implemented codec
///
///
///
abstract public byte[] Decompress(byte[] compressedData);
///
/// Name of this codec type
///
///
abstract public string GetName();
///
/// Codecs must implement an equals() method
///
///
///
abstract public override bool Equals(object other);
///
/// Codecs must implement a HashCode() method that is
/// consistent with Equals
///
///
abstract public override int GetHashCode();
///
/// Codec types
///
public enum Type
{
///
/// Codec type that implments the "deflate" compression algorithm.
///
Deflate,
//Snappy
///
/// Codec that does not perform any compression.
///
Null
};
///
/// Factory method to return child
/// codec instance based on Codec.Type
///
///
///
public static Codec CreateCodec(Type codecType)
{
switch (codecType)
{
case Type.Deflate:
return new DeflateCodec();
default:
return new NullCodec();
}
}
///
/// Factory method to return child
/// codec instance based on string type
///
///
///
public static Codec CreateCodecFromString(string codecType)
{
switch (codecType)
{
case DataFileConstants.DeflateCodec:
return new DeflateCodec();
default:
return new NullCodec();
}
}
///
/// Returns name of codec
///
///
public override string ToString()
{
return GetName();
}
}
}