updated to jalview 2.1 and begun ArchiveClient/VamsasClient/VamsasStore updates.
[jalview.git] / src / jalview / io / FileParse.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.io;
20
21 import java.io.*;
22 import java.net.*;
23
24 public class FileParse
25 {
26   public File inFile;
27   protected String type;
28   protected BufferedReader dataIn;
29
30   public FileParse()
31   {
32   }
33
34   public FileParse(String fileStr, String type)
35       throws MalformedURLException, IOException
36   {
37     this.type = type;
38
39     if (type.equals(AppletFormatAdapter.FILE))
40     {
41       this.inFile = new File(fileStr);
42       dataIn = new BufferedReader(new FileReader(fileStr));
43     }
44     else if (type.equals(AppletFormatAdapter.URL))
45     {
46       URL url = new URL(fileStr);
47       dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
48     }
49    else if (type.equals(AppletFormatAdapter.PASTE))
50     {
51       dataIn = new BufferedReader(new StringReader(fileStr));
52     }
53     else if (type.equals(AppletFormatAdapter.CLASSLOADER))
54     {
55       java.io.InputStream is = getClass().getResourceAsStream("/" + fileStr);
56       if (is != null)
57       {
58         dataIn = new BufferedReader(new java.io.InputStreamReader(is));
59       }
60     }
61   }
62
63   public String nextLine()
64       throws IOException
65   {
66     return dataIn.readLine();
67   }
68 }