1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ package org .apache .arrow .adapter .avro ;
19+
20+ import org .apache .avro .file .*;
21+
22+ import java .nio .ByteBuffer ;
23+
24+
25+ public class AvroCompression {
26+
27+ public static Codec getAvroCodec (String codecName ) {
28+
29+ if (codecName == null || DataFileConstants .NULL_CODEC .equals (codecName )) {
30+ return new NullCodec ();
31+ }
32+
33+ switch (codecName ) {
34+ case DataFileConstants .DEFLATE_CODEC :
35+ return new DeflateCodec (CodecFactory .DEFAULT_DEFLATE_LEVEL );
36+ case DataFileConstants .BZIP2_CODEC :
37+ return new BZip2Codec ();
38+ case DataFileConstants .XZ_CODEC :
39+ return new XZCodec (CodecFactory .DEFAULT_XZ_LEVEL );
40+ case DataFileConstants .ZSTANDARD_CODEC :
41+ return new ZstandardCodec (CodecFactory .DEFAULT_ZSTANDARD_LEVEL , false , false );
42+ }
43+
44+ throw new IllegalArgumentException ("Unsupported codec: " + codecName );
45+ }
46+
47+ private static class NullCodec extends Codec {
48+
49+ @ Override
50+ public String getName () {
51+ return DataFileConstants .NULL_CODEC ;
52+ }
53+
54+ @ Override
55+ public ByteBuffer compress (ByteBuffer buffer ) {
56+ return buffer ;
57+ }
58+
59+ @ Override
60+ public ByteBuffer decompress (ByteBuffer buffer ) {
61+ return buffer ;
62+ }
63+
64+ @ Override
65+ public boolean equals (Object other ) {
66+ if (this == other )
67+ return true ;
68+ return (other != null && other .getClass () == getClass ());
69+ }
70+
71+ @ Override
72+ public int hashCode () {
73+ return 2 ;
74+ }
75+ }
76+
77+ }
0 commit comments