001/* 002 * Archives Unleashed Toolkit (AUT): 003 * An open-source platform for analyzing web archives. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 /** 019 * @deprecated as of 0.11.0 and will be removed 020 * in a future release. Use GenericArchiveRecordWritable instead. 021 */ 022 023package io.archivesunleashed.io; 024 025import io.archivesunleashed.data.ArcRecordUtils; 026import java.io.DataInput; 027import java.io.DataOutput; 028import java.io.IOException; 029import org.apache.hadoop.io.Writable; 030import org.archive.io.arc.ARCRecord; 031 032/** 033 * Implements Hadoop Writable for ARC Records. 034 */ 035@Deprecated 036public class ArcRecordWritable implements Writable { 037 038 /** 039 * Initialize ARC Record to null. 040 */ 041 private ARCRecord record = null; 042 043 /** 044 * Utility function. 045 */ 046 public ArcRecordWritable() { 047 } 048 049 /** 050 * Initialize ARC Record. 051 * 052 * @param r ARC Record 053 */ 054 public ArcRecordWritable(final ARCRecord r) { 055 this.record = r; 056 } 057 058 /** 059 * Set ARC Record. 060 * 061 * @param r ARC Record 062 */ 063 public final void setRecord(final ARCRecord r) { 064 this.record = r; 065 } 066 067 /** 068 * Get ARC Record. 069 * 070 * @return record ARC Record 071 */ 072 public final ARCRecord getRecord() { 073 return record; 074 } 075 076 @Override 077 public final void readFields(final DataInput in) throws IOException { 078 int len = in.readInt(); 079 if (len == 0) { 080 this.record = null; 081 return; 082 } 083 084 byte[] bytes = new byte[len]; 085 in.readFully(bytes); 086 087 this.record = ArcRecordUtils.fromBytes(bytes); 088 } 089 090 @Override 091 public final void write(final DataOutput out) throws IOException { 092 if (record == null) { 093 out.writeInt(0); 094 } 095 byte[] bytes = ArcRecordUtils.toBytes(record); 096 097 out.writeInt(bytes.length); 098 out.write(bytes); 099 } 100}