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, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.tang; 020 021import org.apache.reef.tang.annotations.DefaultImplementation; 022import org.apache.reef.tang.implementation.avro.AvroClassHierarchySerializer; 023 024import java.io.*; 025 026/** 027 * A base interface for ClassHierarchy serializers. 028 */ 029@DefaultImplementation(AvroClassHierarchySerializer.class) 030public interface ClassHierarchySerializer { 031 /** 032 * Writes a ClassHierarchy into a file. 033 * 034 * @param classHierarchy the ClassHierarchy to store 035 * @param file the file to store the ClassHierarchy 036 * @throws IOException if there is an error in the process 037 */ 038 void toFile(final ClassHierarchy classHierarchy, final File file) throws IOException; 039 040 /** 041 * Writes a ClassHierarchy into a text file. 042 * 043 * @param classHierarchy the ClassHierarchy to store 044 * @param file the text file to store the ClassHierarchy 045 * @throws IOException if there is an error in the process 046 */ 047 void toTextFile(final ClassHierarchy classHierarchy, final File file) throws IOException; 048 049 /** 050 * Serializes a ClassHierarchy as a byte[]. 051 * 052 * @param classHierarchy the ClassHierarchy to store 053 * @throws IOException if there is an error in the process 054 */ 055 byte[] toByteArray(final ClassHierarchy classHierarchy) throws IOException; 056 057 /** 058 * Serializes a ClassHierarchy as a String. 059 * 060 * @param classHierarchy the ClassHierarchy to store 061 * @throws IOException if there is an error in the process 062 */ 063 String toString(final ClassHierarchy classHierarchy) throws IOException; 064 065 /** 066 * Loads a ClassHierarchy from a file created with toFile(). 067 * 068 * @param file the File to read from 069 * @throws IOException if the File can't be read or parsed 070 */ 071 ClassHierarchy fromFile(final File file) throws IOException; 072 073 /** 074 * Loads a ClassHierarchy from a text file created with toTextFile(). 075 * 076 * @param file the File to read from 077 * @throws IOException if the File can't be read or parsed 078 */ 079 ClassHierarchy fromTextFile(final File file) throws IOException; 080 081 /** 082 * Deserializes a ClassHierarchy from a byte[] created with toByteArray(). 083 * 084 * @param theBytes the byte[] to deserialize 085 * @throws IOException if the byte[] can't be read or parsed 086 */ 087 ClassHierarchy fromByteArray(final byte[] theBytes) throws IOException; 088 089 /** 090 * Deserializes a ClassHierarchy from a String created with toString(). 091 * 092 * @param theString the String to deserialize 093 * @throws IOException if the String can't be read or parsed 094 */ 095 ClassHierarchy fromString(final String theString) throws IOException; 096}