View Javadoc
1   /*
2    * Copyright (C) 2010-2014 Hamburg Sud and the contributors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.aludratest.content.separated;
17  
18  import java.io.Reader;
19  import java.io.Writer;
20  
21  import org.aludratest.content.ContentHandler;
22  import org.aludratest.content.separated.data.SeparatedFileBeanData;
23  
24  /**
25   * Content Handler for separated file formats (like CSV or tab-separated).
26   * @author Volker Bergmann
27   */
28  public interface SeparatedContent extends ContentHandler {
29  
30      /** Creates a writer object for persisting SeparateFileBeans. 
31       *  @param out the writer to use for persisting the file content 
32       *  @param beanClass 
33       *  @param separator 
34       *  @param header 
35       *  @return the id of the new writer */
36      Object createWriter(Writer out, Class<? extends SeparatedFileBeanData> beanClass, 
37              char separator, String header);
38  
39      /** Appends a row to the flat file writer denoted by the writerId. 
40       *  @param rowBean the FlatFileBean holding the data 
41       *  @param writerId the id of the writer with which to store the formatted text */
42      void writeRow(SeparatedFileBeanData rowBean, Object writerId);
43  
44      /** Closes the writer and returns its content as string. 
45       *  @param writerId the id of the writer to close */
46      void closeWriter(Object writerId);
47  
48      /** Creates a reader object for reading JavaBeans. 
49       *  @param source the source reader that provides the flat file's character data
50       *  @param rowType 
51       *  @param separator 
52       *  @return the id of the writer */
53      <T extends SeparatedFileBeanData> Object createReader(Reader source, Class<T> rowType, char separator);
54  
55      /**
56       * Reads a file header row.
57       * @param readerId
58       * @return the content of the file header
59       */
60      String readHeader(Object readerId);
61  
62      /** Reads a flat file cell and provides it as Java object. 
63       *  @param readerId the id of the reader 
64       *  @return the id of the new reader */
65      SeparatedFileBeanData readRow(Object readerId);
66  
67      /** Closes a reader. 
68       *  @param readerId the id of the reader to close */
69      void closeReader(Object readerId);
70  
71  }