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 * @return the byte array containing the serialized class hierarchy 054 * @throws IOException if there is an error in the process 055 */ 056 byte[] toByteArray(final ClassHierarchy classHierarchy) throws IOException; 057 058 /** 059 * Serializes a ClassHierarchy as a String. 060 * 061 * @param classHierarchy the ClassHierarchy to store 062 * @return the string containing the serialized class hierarchy 063 * @throws IOException if there is an error in the process 064 */ 065 String toString(final ClassHierarchy classHierarchy) throws IOException; 066 067 /** 068 * Loads a ClassHierarchy from a file created with toFile(). 069 * 070 * @param file the File to read from 071 * @return the class hierarchy 072 * @throws IOException if the File can't be read or parsed 073 */ 074 ClassHierarchy fromFile(final File file) throws IOException; 075 076 /** 077 * Loads a ClassHierarchy from a text file created with toTextFile(). 078 * 079 * @param file the File to read from 080 * @return the class hierarchy 081 * @throws IOException if the File can't be read or parsed 082 */ 083 ClassHierarchy fromTextFile(final File file) throws IOException; 084 085 /** 086 * Deserializes a ClassHierarchy from a byte[] created with toByteArray(). 087 * 088 * @param theBytes the byte[] to deserialize 089 * @return the class hierarchy 090 * @throws IOException if the byte[] can't be read or parsed 091 */ 092 ClassHierarchy fromByteArray(final byte[] theBytes) throws IOException; 093 094 /** 095 * Deserializes a ClassHierarchy from a String created with toString(). 096 * 097 * @param theString the String to deserialize 098 * @return the class hierarchy 099 * @throws IOException if the String can't be read or parsed 100 */ 101 ClassHierarchy fromString(final String theString) throws IOException; 102}