platform/shared/rubyJVM/src/j2me/io/File.java in rhodes-2.0.0.beta11 vs platform/shared/rubyJVM/src/j2me/io/File.java in rhodes-2.0.0.rc1

- old
+ new

@@ -11,12 +11,15 @@ import java.io.IOException; import com.rho.FilePath; import com.rho.RhoClassFactory; import com.rho.file.IFileAccess; +import com.rho.file.IRAFile; import j2me.lang.UnsupportedOperationException; +import java.util.Enumeration; +import java.util.Vector; /** * Class provided for the sole purpose of compiling the FileFilter and * FilenameFilter interfaces. */ @@ -31,15 +34,47 @@ public static final char pathSeparatorChar = pathSeparator.charAt(0); private String _path; private transient int prefixLength = 0; + private IRAFile m_raFile; + private String m_strFullPath; - public File(String path) { + public File(String path) + { _path = path; + + try + { + m_strFullPath = _path; + if (!m_strFullPath.startsWith("file:")) + m_strFullPath = FilePath.join(RhoClassFactory.createFile().getDirPath(""), m_strFullPath); + + m_raFile = RhoClassFactory.createFSRAFile(); + m_raFile.open(m_strFullPath); + }catch(Exception exc) + { + } } + public File(String path, String mode) + { + _path = path; + + try + { + m_strFullPath = _path; + if (!m_strFullPath.startsWith("file:")) + m_strFullPath = FilePath.join(RhoClassFactory.createFile().getDirPath(""), m_strFullPath); + + m_raFile = RhoClassFactory.createFSRAFile(); + m_raFile.open(m_strFullPath, mode); + }catch(Exception exc) + { + } + } + public String getPath() { return _path; } public String getParent() { @@ -70,64 +105,80 @@ return _path.substring(index+1, _path.length()); } public boolean exists() { - try - { - String strPath = _path; - if (!strPath.startsWith("file:")) - strPath = FilePath.join(RhoClassFactory.createFile().getDirPath(""), strPath); - - com.rho.file.IRAFile fs = RhoClassFactory.createFSRAFile(); - fs.open(strPath); - return fs.exists(); - }catch(Exception exc) - { - return false; - } + return m_raFile != null && m_raFile.exists(); } - public boolean isDirectory() { - throw new UnsupportedOperationException( - "File operations not supported for J2ME build"); + public boolean isDirectory() + { + return m_raFile != null && m_raFile.isDirectory(); } public File[] listFiles() { throw new UnsupportedOperationException( "File operations not supported for J2ME build"); } - public String[] list() { - //TODO: list - throw new RuntimeException("Not Implemented"); - //return new String[0]; + public Vector list() + { + if ( m_raFile == null ) + return new Vector(); + + Vector res = new Vector(); + + try{ + Enumeration eFiles = m_raFile.list(); + while( eFiles != null && eFiles.hasMoreElements() ) + { + res.addElement(eFiles.nextElement()); + } + }catch(IOException exc) + { + + } + return res; } public String getAbsolutePath() { - return _path; - //TODO: getAbsolutePath - //throw new RuntimeException("Not Implemented"); - //return _path; + return m_strFullPath; } - public boolean mkdir() { - //TODO: mkdir - throw new RuntimeException("Not Implemented"); - //return false; + public boolean mkdir() + { + if ( m_raFile != null ) + return m_raFile.mkdir(); + + return false; } - public boolean delete() { - //TODO: delete - throw new RuntimeException("Not Implemented"); - //return false; + + public boolean delete() + { + try + { + if ( m_raFile != null ) + { + m_raFile.close(); + m_raFile.open(m_strFullPath, "w"); + m_raFile.delete(); + m_raFile.close(); + m_raFile = null; + return true; + } + }catch(IOException exc) + { + + } + + return false; } public boolean isFile() { - //TODO: isFile - throw new RuntimeException("Not Implemented"); - //return false; + return m_raFile != null && m_raFile.isFile(); } + public boolean canWrite() { //TODO: canWrite throw new RuntimeException("Not Implemented"); //return false; } @@ -139,14 +190,20 @@ public long lastModified() { //TODO: lastModified throw new RuntimeException("Not Implemented"); //return 0; } - public long length() { - //TODO: length - throw new RuntimeException("Not Implemented"); - //return 0; + public long length() + { + try{ + if ( m_raFile != null ) + return m_raFile.size(); + }catch(IOException exc) + { + } + return 0; } + public boolean renameTo(File dest) { //TODO: renameTo throw new RuntimeException("Not Implemented"); //return false; }