001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.mapreduce; 019 020import java.io.DataInputStream; 021import java.io.DataOutputStream; 022import java.io.IOException; 023import java.io.InputStream; 024import java.io.OutputStream; 025 026import org.apache.hadoop.hbase.KeyValue; 027import org.apache.hadoop.hbase.KeyValueUtil; 028import org.apache.yetus.audience.InterfaceAudience; 029import org.apache.hadoop.io.serializer.Deserializer; 030import org.apache.hadoop.io.serializer.Serialization; 031import org.apache.hadoop.io.serializer.Serializer; 032/** 033 * Use to specify the type of serialization for the mappers 034 * and reducers 035 * @deprecated Use {@link CellSerialization}. Will be 036 * removed from 3.0 onwards 037 */ 038@Deprecated 039@InterfaceAudience.Public 040public class KeyValueSerialization implements Serialization<KeyValue> { 041 @Override 042 public boolean accept(Class<?> c) { 043 return KeyValue.class.isAssignableFrom(c); 044 } 045 046 @Override 047 public KeyValueDeserializer getDeserializer(Class<KeyValue> t) { 048 return new KeyValueDeserializer(); 049 } 050 051 @Override 052 public KeyValueSerializer getSerializer(Class<KeyValue> c) { 053 return new KeyValueSerializer(); 054 } 055 056 public static class KeyValueDeserializer implements Deserializer<KeyValue> { 057 private DataInputStream dis; 058 059 @Override 060 public void close() throws IOException { 061 this.dis.close(); 062 } 063 064 @Override 065 public KeyValue deserialize(KeyValue ignore) throws IOException { 066 // I can't overwrite the passed in KV, not from a proto kv, not just yet. TODO 067 return KeyValueUtil.create(this.dis); 068 } 069 070 @Override 071 public void open(InputStream is) throws IOException { 072 this.dis = new DataInputStream(is); 073 } 074 } 075 076 public static class KeyValueSerializer implements Serializer<KeyValue> { 077 private DataOutputStream dos; 078 079 @Override 080 public void close() throws IOException { 081 this.dos.close(); 082 } 083 084 @Override 085 public void open(OutputStream os) throws IOException { 086 this.dos = new DataOutputStream(os); 087 } 088 089 @Override 090 public void serialize(KeyValue kv) throws IOException { 091 KeyValueUtil.write(kv, this.dos); 092 } 093 } 094}