1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 }