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.IOException; 022import java.util.TreeMap; 023import java.util.ArrayList; 024import java.io.DataOutput; 025import java.io.DataOutputStream; 026import java.io.OutputStream; 027 028import org.apache.hadoop.classification.InterfaceAudience; 029import org.apache.hadoop.classification.InterfaceStability; 030 031/** 032 * @deprecated Replaced by <a href="https://hadoop.apache.org/avro/">Avro</a>. 033 */ 034@Deprecated 035@InterfaceAudience.Public 036@InterfaceStability.Stable 037public class BinaryRecordOutput implements RecordOutput { 038 039 private DataOutput out; 040 041 private BinaryRecordOutput() {} 042 043 private void setDataOutput(DataOutput out) { 044 this.out = out; 045 } 046 047 private static ThreadLocal bOut = new ThreadLocal() { 048 protected synchronized Object initialValue() { 049 return new BinaryRecordOutput(); 050 } 051 }; 052 053 /** 054 * Get a thread-local record output for the supplied DataOutput. 055 * @param out data output stream 056 * @return binary record output corresponding to the supplied DataOutput. 057 */ 058 public static BinaryRecordOutput get(DataOutput out) { 059 BinaryRecordOutput bout = (BinaryRecordOutput) bOut.get(); 060 bout.setDataOutput(out); 061 return bout; 062 } 063 064 /** Creates a new instance of BinaryRecordOutput */ 065 public BinaryRecordOutput(OutputStream out) { 066 this.out = new DataOutputStream(out); 067 } 068 069 /** Creates a new instance of BinaryRecordOutput */ 070 public BinaryRecordOutput(DataOutput out) { 071 this.out = out; 072 } 073 074 075 public void writeByte(byte b, String tag) throws IOException { 076 out.writeByte(b); 077 } 078 079 public void writeBool(boolean b, String tag) throws IOException { 080 out.writeBoolean(b); 081 } 082 083 public void writeInt(int i, String tag) throws IOException { 084 Utils.writeVInt(out, i); 085 } 086 087 public void writeLong(long l, String tag) throws IOException { 088 Utils.writeVLong(out, l); 089 } 090 091 public void writeFloat(float f, String tag) throws IOException { 092 out.writeFloat(f); 093 } 094 095 public void writeDouble(double d, String tag) throws IOException { 096 out.writeDouble(d); 097 } 098 099 public void writeString(String s, String tag) throws IOException { 100 Utils.toBinaryString(out, s); 101 } 102 103 public void writeBuffer(Buffer buf, String tag) 104 throws IOException { 105 byte[] barr = buf.get(); 106 int len = buf.getCount(); 107 Utils.writeVInt(out, len); 108 out.write(barr, 0, len); 109 } 110 111 public void startRecord(Record r, String tag) throws IOException {} 112 113 public void endRecord(Record r, String tag) throws IOException {} 114 115 public void startVector(ArrayList v, String tag) throws IOException { 116 writeInt(v.size(), tag); 117 } 118 119 public void endVector(ArrayList v, String tag) throws IOException {} 120 121 public void startMap(TreeMap v, String tag) throws IOException { 122 writeInt(v.size(), tag); 123 } 124 125 public void endMap(TreeMap v, String tag) throws IOException {} 126 127}