~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/io/base/TGSongLoader.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 19-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.io.base;
 
8
 
 
9
import java.io.BufferedInputStream;
 
10
import java.io.InputStream;
 
11
import java.util.Iterator;
 
12
 
 
13
import org.herac.tuxguitar.song.factory.TGFactory;
 
14
import org.herac.tuxguitar.song.models.TGSong;
 
15
 
 
16
/**
 
17
 * @author julian
 
18
 *
 
19
 * TODO To change the template for this generated type comment go to
 
20
 * Window - Preferences - Java - Code Style - Code Templates
 
21
 */
 
22
public class TGSongLoader {
 
23
        
 
24
        public TGSongLoader(){
 
25
                super();
 
26
        }
 
27
        
 
28
        /**
 
29
         * @return TGSong
 
30
         * @throws TGFileFormatException
 
31
         */
 
32
        public TGSong load(TGFactory factory,InputStream is) throws TGFileFormatException{
 
33
                try{
 
34
                        BufferedInputStream stream = new BufferedInputStream(is);
 
35
                        stream.mark(1);
 
36
                        Iterator it = TGFileFormatManager.instance().getInputStreams();
 
37
                        while(it.hasNext()){
 
38
                                TGInputStreamBase reader = (TGInputStreamBase)it.next();
 
39
                                reader.init(factory,stream);
 
40
                                if(reader.isSupportedVersion()){
 
41
                                        return reader.readSong();
 
42
                                }
 
43
                                stream.reset();
 
44
                        }
 
45
                        stream.close();
 
46
                }catch(Throwable t){
 
47
                        throw new TGFileFormatException(t);
 
48
                }
 
49
                throw new TGFileFormatException("Unsupported file format");
 
50
        }
 
51
}
 
 
b'\\ No newline at end of file'