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="https://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 public abstract int compareTo (final Object peer) throws ClassCastException; 058 059 /** 060 * Serialize a record without a tag 061 * @param rout Record output destination 062 */ 063 public void serialize(RecordOutput rout) throws IOException { 064 this.serialize(rout, ""); 065 } 066 067 /** 068 * Deserialize a record without a tag 069 * @param rin Record input source 070 */ 071 public void deserialize(RecordInput rin) throws IOException { 072 this.deserialize(rin, ""); 073 } 074 075 // inherit javadoc 076 public void write(final DataOutput out) throws java.io.IOException { 077 BinaryRecordOutput bout = BinaryRecordOutput.get(out); 078 this.serialize(bout); 079 } 080 081 // inherit javadoc 082 public void readFields(final DataInput din) throws java.io.IOException { 083 BinaryRecordInput rin = BinaryRecordInput.get(din); 084 this.deserialize(rin); 085 } 086 087 // inherit javadoc 088 public String toString() { 089 try { 090 ByteArrayOutputStream s = new ByteArrayOutputStream(); 091 CsvRecordOutput a = new CsvRecordOutput(s); 092 this.serialize(a); 093 return new String(s.toByteArray(), "UTF-8"); 094 } catch (Throwable ex) { 095 throw new RuntimeException(ex); 096 } 097 } 098}