2
* Created on 19-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.io.base;
10
import java.io.FileOutputStream;
11
import java.util.Iterator;
13
import org.herac.tuxguitar.song.factory.TGFactory;
14
import org.herac.tuxguitar.song.models.TGSong;
19
* TODO To change the template for this generated type comment go to
20
* Window - Preferences - Java - Code Style - Code Templates
22
public class TGSongWriter {
24
public TGSongWriter(){
28
public void write(TGFactory factory,TGSong song,String path) throws TGFileFormatException{
30
Iterator it = TGFileFormatManager.instance().getOutputStreams();
32
TGOutputStreamBase writer = (TGOutputStreamBase)it.next();
33
if(isSupportedExtension(writer,path)){
34
writer.init(factory,new FileOutputStream(new File(path)));
35
writer.writeSong(song);
39
} catch (Throwable t) {
40
throw new TGFileFormatException(t);
42
throw new TGFileFormatException("Unsupported file format");
45
private boolean isSupportedExtension(TGOutputStreamBase writer,String path){
46
int index = path.lastIndexOf(".");
48
return writer.isSupportedExtension(path.substring(index));