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 */ 018 019package org.apache.hadoop.record; 020 021import java.io.DataInput; 022import java.io.DataOutput; 023import java.io.ByteArrayOutputStream; 024import java.io.IOException; 025 026import org.apache.hadoop.classification.InterfaceAudience; 027import org.apache.hadoop.classification.InterfaceStability; 028import org.apache.hadoop.io.WritableComparable; 029 030/** 031 * Abstract class that is extended by generated classes. 032 * 033 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>. 034 */ 035@Deprecated 036@InterfaceAudience.Public 037@InterfaceStability.Stable 038public abstract class Record implements WritableComparable, Cloneable { 039 040 /** 041 * Serialize a record with tag (ususally field name) 042 * @param rout Record output destination 043 * @param tag record tag (Used only in tagged serialization e.g. XML) 044 */ 045 public abstract void serialize(RecordOutput rout, String tag) 046 throws IOException; 047 048 /** 049 * Deserialize a record with a tag (usually field name) 050 * @param rin Record input source 051 * @param tag Record tag (Used only in tagged serialization e.g. XML) 052 */ 053 public abstract void deserialize(RecordInput rin, String tag) 054 throws IOException; 055 056 // inheric javadoc 057 @Override 058 public abstract int compareTo (final Object peer) throws ClassCastException; 059 060 /** 061 * Serialize a record without a tag 062 * @param rout Record output destination 063 */ 064 public void serialize(RecordOutput rout) throws IOException { 065 this.serialize(rout, ""); 066 } 067 068 /** 069 * Deserialize a record without a tag 070 * @param rin Record input source 071 */ 072 public void deserialize(RecordInput rin) throws IOException { 073 this.deserialize(rin, ""); 074 } 075 076 // inherit javadoc 077 @Override 078 public void write(final DataOutput out) throws java.io.IOException { 079 BinaryRecordOutput bout = BinaryRecordOutput.get(out); 080 this.serialize(bout); 081 } 082 083 // inherit javadoc 084 @Override 085 public void readFields(final DataInput din) throws java.io.IOException { 086 BinaryRecordInput rin = BinaryRecordInput.get(din); 087 this.deserialize(rin); 088 } 089 090 // inherit javadoc 091 @Override 092 public String toString() { 093 try { 094 ByteArrayOutputStream s = new ByteArrayOutputStream(); 095 CsvRecordOutput a = new CsvRecordOutput(s); 096 this.serialize(a); 097 return new String(s.toByteArray(), "UTF-8"); 098 } catch (Throwable ex) { 099 throw new RuntimeException(ex); 100 } 101 } 102}