View Javadoc

1   /*
2    * Copyright 2004 Diogo Quintela (dquintela@users.sourceforge.net)
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 net.sf.whatsnew.filter.impl;
17  
18  import java.io.File;
19  import java.io.FileWriter;
20  import java.io.IOException;
21  import java.io.Writer;
22  
23  import net.sf.whatsnew.exceptions.AppException;
24  import net.sf.whatsnew.filter.OutputWriter;
25  
26  
27  /***
28   * <p>
29   * An OutputWriter implementation that plain the buffer using UNIX line feeds
30   * </p>
31   *
32   * @author <a href="mailto:dquintela@users.sourceforge.net">Diogo Quintela</a>
33   * @version $Id: UnixOutputWriter.java,v 1.1 2004/05/13 01:22:35 dquintela Exp $
34   */
35  public class UnixOutputWriter
36  implements OutputWriter {
37      /***
38       * Plains the array
39       *
40       * @param outputFile The file write to
41       * @param input The array to process
42       *
43       * @throws AppException in case of error
44       */
45      public void output(
46          File outputFile,
47          String[] input)
48      throws AppException {
49          try {
50  //        	Writer out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile),"ISO-8859-1"));
51          	Writer out = new FileWriter(outputFile);
52              try {
53                  for (int i = 0; i < input.length; i++) {
54                      out.write(input[i]);
55                      out.write("\n");
56                  }
57                  out.flush();
58              } finally {
59                  out.close();
60              }
61          } catch (IOException ex) {
62              throw new AppException(ex.getMessage());
63          }
64      }
65  }
66  // EOF