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    
019    package org.apache.hadoop.io;
020    
021    import java.io.IOException;
022    
023    import org.apache.hadoop.classification.InterfaceAudience;
024    import org.apache.hadoop.classification.InterfaceStability;
025    
026    /**
027     * Stringifier interface offers two methods to convert an object 
028     * to a string representation and restore the object given its 
029     * string representation.
030     * @param <T> the class of the objects to stringify
031     */
032    @InterfaceAudience.Public
033    @InterfaceStability.Stable
034    public interface Stringifier<T> extends java.io.Closeable {
035    
036      /**
037       * Converts the object to a string representation
038       * @param obj the object to convert
039       * @return the string representation of the object
040       * @throws IOException if the object cannot be converted
041       */
042      public String toString(T obj)  throws IOException;
043      
044      /**
045       * Restores the object from its string representation.
046       * @param str the string representation of the object
047       * @return restored object
048       * @throws IOException if the object cannot be restored
049       */
050      public T fromString(String str) throws IOException;
051      
052      
053      /** 
054       * Closes this object. 
055       * @throws IOException if an I/O error occurs 
056       * */
057      @Override
058      public void close() throws IOException;
059      
060    }