View Javadoc

1   // Copyright (C) 2005  Michael Wever ( mick@wever.org )
2   // 
3   // This program is free software; you can redistribute it and/or
4   // modify it under the terms of the GNU General Public License
5   // as published by the Free Software Foundation; either version 2
6   // of the License, or (at your option) any later version.
7   // 
8   // This program is distributed in the hope that it will be useful,
9   // but WITHOUT ANY WARRANTY; without even the implied warranty of
10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  // GNU General Public License for more details.
12  // 
13  // You should have received a copy of the GNU General Public License
14  // along with this program; if not, write to the Free Software
15  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16  /*
17   * IceCastPlaylistImpl.java
18   *
19   * Created on 16. juli 2005, 20:28
20   *
21   * To change this template, choose Tools | Options and locate the template under
22   * the Source Creation and Management node. Right-click the template and choose
23   * Open. You can then make changes to the template in the Source Editor.
24   */
25  
26  package org.wever.jradiodj.services.playlist;
27  
28  import java.io.BufferedWriter;
29  import java.io.File;
30  import java.io.FileWriter;
31  import java.io.IOException;
32  import java.util.logging.Logger;
33  import org.wever.jradiodj.beans.SongCollection;
34  
35  /***
36   The following is for a IceCast specific playlist. 
37   That is, a plain text file with absolute pathnames to each song to play.
38   IceCast 2.x only supports ogg songs currently.
39   * @author mick
40   * @version $Id$
41   */
42  public class IceCastPlaylistGeneratorImpl implements PlaylistGenerator{
43      private static final String PLAYLIST_FILE = "org.wever.jradiodj.playlist.file";
44      private final static Logger LOG = Logger.getLogger(PlaylistGenerator.class.getName());
45      
46      /***
47       * Creates a new instance of IceCastPlaylistGeneratorImpl
48       */
49      public IceCastPlaylistGeneratorImpl() {
50      }
51  
52      public void createPlaylist(final SongCollection collection) throws IOException {
53  
54  
55          final File file = new File(System.getProperty( PLAYLIST_FILE) );
56  
57          BufferedWriter writer = null;
58          try {
59              writer = new BufferedWriter(
60                  new FileWriter(file)
61              );
62  
63              for(File song : collection.getFiles() ) {
64                  writer.write( song.getAbsolutePath() );
65                  writer.newLine();
66                  LOG.finest(" adding song "+song.getName() );
67              }
68              writer.flush();
69  
70          } finally {
71              if( writer != null ){ 
72                  writer.close(); 
73              }
74  
75          }
76      }
77      
78      
79      
80  }