~ubuntu-branches/ubuntu/oneiric/weka/oneiric

« back to all changes in this revision

Viewing changes to weka/core/converters/AbstractFileLoader.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner, Soeren Sonnenburg, Torsten Werner
  • Date: 2008-08-10 21:27:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080810212705-tr8etpnkdx2ziktp
Tags: 3.5.8-1
[ Soeren Sonnenburg ]
* Bump Standards Version to 3.8.0.
* Remove references to non-free Java in debian/copyright.

[ Torsten Werner ]
* new upstream release
* Switch to openjdk-6.
* Move package to main.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import java.io.FileInputStream;
30
30
import java.io.FileNotFoundException;
31
31
import java.io.IOException;
 
32
import java.util.zip.GZIPInputStream;
32
33
 
33
34
 
34
35
/**
35
36
 * Abstract superclass for all file loaders.
36
37
 * 
37
38
 * @author  fracpete (fracpete at waikato dot ac dot nz)
38
 
 * @version $Revision: 1.2 $
 
39
 * @version $Revision: 1.5 $
39
40
 */
40
41
public abstract class AbstractFileLoader
41
42
  extends AbstractLoader
50
51
  /** Holds the source of the data set. */
51
52
  protected File m_sourceFile = null;
52
53
 
 
54
  /** the extension for compressed files */
 
55
  public static String FILE_EXTENSION_COMPRESSED = ".gz";
 
56
 
 
57
  /** use relative file paths */
 
58
  protected boolean m_useRelativePath = false;
 
59
 
53
60
  /**
54
61
   * get the File specified as the source
55
62
   *
69
76
    m_structure = null;
70
77
    setRetrieval(NONE);
71
78
 
72
 
    m_File = file.getAbsolutePath();
 
79
    //m_File = file.getAbsolutePath();
73
80
    setSource(file);
74
81
  }
75
82
  
87
94
   * Resets the Loader object and sets the source of the data set to be 
88
95
   * the supplied File object.
89
96
   *
 
97
   * @param file                the source file.
 
98
   * @throws IOException        if an error occurs
 
99
   */
 
100
  public void setSource(File file) throws IOException {
 
101
    m_structure = null;
 
102
    
 
103
    setRetrieval(NONE);
 
104
 
 
105
    if (file == null)
 
106
      throw new IOException("Source file object is null!");
 
107
 
 
108
    try {
 
109
      String fName = file.getPath();
 
110
      try {
 
111
        fName = weka.core.Environment.substitute(fName);
 
112
      } catch (Exception e) {
 
113
        throw new IOException(e.getMessage());
 
114
      }
 
115
      file = new File(fName);
 
116
      if (file.getName().endsWith(getFileExtension() + FILE_EXTENSION_COMPRESSED)) {
 
117
        setSource(new GZIPInputStream(new FileInputStream(file)));
 
118
      } else {
 
119
        setSource(new FileInputStream(file));
 
120
      }
 
121
    }
 
122
    catch (FileNotFoundException ex) {
 
123
      throw new IOException("File not found");
 
124
    }
 
125
 
 
126
    if (m_useRelativePath) {
 
127
      try {
 
128
        m_sourceFile = Utils.convertToRelativePath(file);
 
129
        m_File = m_sourceFile.getPath();
 
130
      } catch (Exception ex) {
 
131
        //        System.err.println("[AbstractFileLoader] can't convert path to relative path.");
 
132
        m_sourceFile = file;
 
133
        m_File       = file.getPath();
 
134
      }
 
135
    } else {
 
136
      m_sourceFile = file;
 
137
      m_File       = file.getAbsolutePath();
 
138
    }
 
139
  }
 
140
 
 
141
  /**
 
142
   * Resets the Loader object and sets the source of the data set to be 
 
143
   * the supplied File object.
 
144
   *
90
145
   * @param file the source file.
91
146
   * @exception IOException if an error occurs
92
 
   */
 
147
   *
93
148
  public void setSource(File file) throws IOException {
94
149
    m_structure = null;
95
150
    setRetrieval(NONE);
107
162
 
108
163
    m_sourceFile = file;
109
164
    m_File       = file.getAbsolutePath();
 
165
    } */
 
166
 
 
167
  /**
 
168
   * Tip text suitable for displaying int the GUI
 
169
   *
 
170
   * @return a description of this property as a String
 
171
   */
 
172
  public String useRelativePathTipText() {
 
173
    return "Use relative rather than absolute paths";
 
174
  }
 
175
 
 
176
  /**
 
177
   * Set whether to use relative rather than absolute paths
 
178
   *
 
179
   * @param rp true if relative paths are to be used
 
180
   */
 
181
  public void setUseRelativePath(boolean rp) {
 
182
    m_useRelativePath = rp;
 
183
  }
 
184
 
 
185
  /**
 
186
   * Gets whether relative paths are to be used
 
187
   *
 
188
   * @return true if relative paths are to be used
 
189
   */
 
190
  public boolean getUseRelativePath() {
 
191
    return m_useRelativePath;
110
192
  }
111
193
 
112
194
  /**