|
From: <fd...@us...> - 2008-02-05 22:55:00
|
Revision: 3761
http://jnode.svn.sourceforge.net/jnode/?rev=3761&view=rev
Author: fduminy
Date: 2008-02-05 14:54:57 -0800 (Tue, 05 Feb 2008)
Log Message:
-----------
in all FileSystemType implementations : replaced ID attribute by a getInstance() method
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java
trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java
trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystemType.java
trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/jifs/def/JIFSPlugin.java
trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java
trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/ramfs/RAMFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/ramfs/def/RAMFSPlugin.java
trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java
trunk/fs/src/fs/org/jnode/fs/util/FSUtils.java
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -26,10 +26,9 @@
import org.jnode.driver.Device;
import org.jnode.driver.block.FSBlockDeviceAPI;
-import org.jnode.fs.FileSystem;
+import org.jnode.fs.BlockDeviceFileSystemType;
import org.jnode.fs.FileSystemException;
-import org.jnode.fs.FileSystemType;
-import org.jnode.fs.BlockDeviceFileSystemType;
+import org.jnode.fs.util.FSUtils;
import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTypes;
@@ -39,7 +38,10 @@
*/
public class Ext2FileSystemType implements BlockDeviceFileSystemType<Ext2FileSystem> {
- public static final Class<Ext2FileSystemType> ID = Ext2FileSystemType.class;
+ public static Ext2FileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(Ext2FileSystemType.class);
+ }
/**
* @see org.jnode.fs.FileSystemType#create(Device, boolean)
Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -23,9 +23,9 @@
import org.jnode.driver.Device;
import org.jnode.driver.block.FSBlockDeviceAPI;
+import org.jnode.fs.BlockDeviceFileSystemType;
import org.jnode.fs.FileSystemException;
-import org.jnode.fs.FileSystemType;
-import org.jnode.fs.BlockDeviceFileSystemType;
+import org.jnode.fs.util.FSUtils;
import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTypes;
@@ -35,9 +35,12 @@
*/
public class FatFileSystemType implements BlockDeviceFileSystemType<FatFileSystem> {
- /** Name of this filesystem type */
- public static final Class<FatFileSystemType> ID = FatFileSystemType.class;
+ public static FatFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(FatFileSystemType.class);
+ }
+
/**
* Gets the unique name of this file system type.
*/
Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -21,18 +21,20 @@
package org.jnode.fs.ftpfs;
+import org.jnode.driver.Device;
+import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
-import org.jnode.fs.FileSystem;
-import org.jnode.fs.FileSystemException;
-import org.jnode.driver.Device;
-import org.jnode.driver.block.FSBlockDeviceAPI;
-import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.fs.util.FSUtils;
/**
* @author Levente S\u00e1ntha
*/
public class FTPFileSystemType implements FileSystemType<FTPFileSystem> {
- public static final Class<FTPFileSystemType> ID = FTPFileSystemType.class;
+ public static FTPFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(FTPFileSystemType.class);
+ }
+
/**
* Create a filesystem from a given device.
*
Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -73,7 +73,7 @@
final DeviceManager dm = DeviceUtils.getDeviceManager();
dm.register(dev);
final FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME);
- FTPFileSystemType type = fss.getFileSystemType(FTPFileSystemType.ID);
+ FTPFileSystemType type = FTPFileSystemType.getInstance();
final FTPFileSystem fs = type.create(dev, true);
fss.registerFileSystem(fs);
fss.mount(mount_point, fs, null);
Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -7,13 +7,19 @@
import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.fs.BlockDeviceFileSystemType;
import org.jnode.fs.FileSystemException;
+import org.jnode.fs.util.FSUtils;
import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTypes;
import org.jnode.util.BigEndian;
public class HfsPlusFileSystemType implements BlockDeviceFileSystemType<HfsPlusFileSystem> {
- public static final Class<HfsPlusFileSystemType> ID = HfsPlusFileSystemType.class;
+
+ public static HfsPlusFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(HfsPlusFileSystemType.class);
+ }
+
public HfsPlusFileSystem create(Device device, boolean readOnly)
throws FileSystemException {
HfsPlusFileSystem fs = new HfsPlusFileSystem(device, readOnly);
Modified: trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -26,10 +26,9 @@
import org.jnode.driver.Device;
import org.jnode.driver.block.FSBlockDeviceAPI;
-import org.jnode.fs.FileSystem;
+import org.jnode.fs.BlockDeviceFileSystemType;
import org.jnode.fs.FileSystemException;
-import org.jnode.fs.FileSystemType;
-import org.jnode.fs.BlockDeviceFileSystemType;
+import org.jnode.fs.util.FSUtils;
import org.jnode.partitions.PartitionTableEntry;
/**
@@ -37,7 +36,10 @@
*/
public class ISO9660FileSystemType implements BlockDeviceFileSystemType<ISO9660FileSystem> {
- public static final Class<ISO9660FileSystemType> ID = ISO9660FileSystemType.class;
+ public static ISO9660FileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(ISO9660FileSystemType.class);
+ }
public final String getName() {
return "ISO9660";
Modified: trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -22,12 +22,10 @@
package org.jnode.fs.jarfs;
import org.jnode.driver.Device;
-import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.driver.block.JarFileDevice;
-import org.jnode.fs.FileSystem;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
-import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.fs.util.FSUtils;
/**
*
@@ -35,6 +33,10 @@
*
*/
public class JarFileSystemType implements FileSystemType<JarFileSystem> {
+ public static JarFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(JarFileSystemType.class);
+ }
public static final Class<JarFileSystemType> ID = JarFileSystemType.class;
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -21,12 +21,11 @@
*/
package org.jnode.fs.jfat;
-import org.apache.log4j.Logger;
import org.jnode.driver.Device;
import org.jnode.driver.block.FSBlockDeviceAPI;
+import org.jnode.fs.BlockDeviceFileSystemType;
import org.jnode.fs.FileSystemException;
-import org.jnode.fs.FileSystemType;
-import org.jnode.fs.BlockDeviceFileSystemType;
+import org.jnode.fs.util.FSUtils;
import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTypes;
@@ -37,9 +36,13 @@
* @author Tango
*/
public class FatFileSystemType implements BlockDeviceFileSystemType<FatFileSystem> {
- public static final Class<FatFileSystemType> ID=FatFileSystemType.class;
+ public static FatFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(FatFileSystemType.class);
+ }
+
public String getName() {
return "JFAT";
}
Modified: trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -23,19 +23,19 @@
import org.apache.log4j.Logger;
import org.jnode.driver.Device;
-import org.jnode.driver.block.FSBlockDeviceAPI;
-import org.jnode.fs.FileSystem;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
-import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.fs.util.FSUtils;
/**
* @author Andreas H\u00e4nel
*/
public class JIFileSystemType implements FileSystemType<JIFileSystem> {
+ public static JIFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(JIFileSystemType.class);
+ }
- /** Name of this filesystem type */
- public static final Class<JIFileSystemType> ID = JIFileSystemType.class;
public static final String VIRTUAL_DEVICE_NAME = "jifs";
/** Logger*/
Modified: trunk/fs/src/fs/org/jnode/fs/jifs/def/JIFSPlugin.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jifs/def/JIFSPlugin.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/jifs/def/JIFSPlugin.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -70,12 +70,12 @@
protected void startPlugin() throws PluginException {
log.info("start jifs");
try {
- FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
- JIFileSystemType type = fSS.getFileSystemType(JIFileSystemType.ID);
+ JIFileSystemType type = JIFileSystemType.getInstance();
try {
VirtualDevice dev = VirtualDeviceFactory.createDevice(JIFileSystemType.VIRTUAL_DEVICE_NAME);
log.info(dev.getId() + " registered");
final JIFileSystem fs = type.create(dev, true);
+ final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
fSS.registerFileSystem(fs);
final String mountPath = "jifs";
@@ -100,8 +100,6 @@
} catch (NameNotFoundException e) {
log.error("filsystemservice / filesystemtype not found");
- } catch (FileSystemException e) {
- log.error(e);
}
}
Modified: trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -141,8 +141,7 @@
dm.register(dev);
final FileSystemService fss = InitialNaming
.lookup(FileSystemService.NAME);
- NFS2FileSystemType type = fss
- .getFileSystemType(NFS2FileSystemType.ID);
+ NFS2FileSystemType type = NFS2FileSystemType.getInstance();
final NFS2FileSystem fs = type.create(dev, readOnly);
fss.registerFileSystem(fs);
fss.mount(mount_point, fs, null);
Modified: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -22,20 +22,22 @@
package org.jnode.fs.nfs.nfs2;
import org.jnode.driver.Device;
-import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
-import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.fs.util.FSUtils;
/**
* @author Andrei Dore
*/
public class NFS2FileSystemType implements FileSystemType<NFS2FileSystem> {
- public static final Class<NFS2FileSystemType> ID = NFS2FileSystemType.class;
+ public static NFS2FileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(NFS2FileSystemType.class);
+ }
/**
* Create a filesystem from a given device.
- *
+ *
* @param device
* @param readOnly
*/
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -23,10 +23,9 @@
import org.jnode.driver.Device;
import org.jnode.driver.block.FSBlockDeviceAPI;
-import org.jnode.fs.FileSystem;
+import org.jnode.fs.BlockDeviceFileSystemType;
import org.jnode.fs.FileSystemException;
-import org.jnode.fs.FileSystemType;
-import org.jnode.fs.BlockDeviceFileSystemType;
+import org.jnode.fs.util.FSUtils;
import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTypes;
@@ -37,7 +36,10 @@
*/
public class NTFSFileSystemType implements BlockDeviceFileSystemType<NTFSFileSystem> {
- public static final Class<NTFSFileSystemType> ID = NTFSFileSystemType.class;
+ public static NTFSFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(NTFSFileSystemType.class);
+ }
public static final String TAG = "NTFS";
Modified: trunk/fs/src/fs/org/jnode/fs/ramfs/RAMFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ramfs/RAMFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/ramfs/RAMFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -1,10 +1,9 @@
package org.jnode.fs.ramfs;
import org.jnode.driver.Device;
-import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
-import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.fs.util.FSUtils;
/**
* FileSystemType for RAMFS, a filesystem implementation in system RAM
@@ -15,8 +14,10 @@
private static final int DEFAULT_SIZE = 104857600;
- /** the name of this filesystem */
- public static final Class<RAMFileSystemType> ID = RAMFileSystemType.class;
+ public static RAMFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(RAMFileSystemType.class);
+ }
/** Virtual Device name for this filesystem */
public static final String VIRTUAL_DEVICE_NAME = "ramfsdevice";
Modified: trunk/fs/src/fs/org/jnode/fs/ramfs/def/RAMFSPlugin.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ramfs/def/RAMFSPlugin.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/ramfs/def/RAMFSPlugin.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -51,7 +51,7 @@
try {
FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
- RAMFileSystemType type = fSS.getFileSystemType(RAMFileSystemType.ID);
+ RAMFileSystemType type = RAMFileSystemType.getInstance();
try {
@@ -83,8 +83,6 @@
}
} catch (NameNotFoundException e){
log.error("filsystemservice / filesystemtype not found");
- } catch (FileSystemException e){
- log.error(e);
}
}
Modified: trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -22,16 +22,18 @@
package org.jnode.fs.smbfs;
import org.jnode.driver.Device;
-import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
-import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.fs.util.FSUtils;
/**
* @author Levente S\u00e1ntha
*/
public class SMBFileSystemType implements FileSystemType<SMBFileSystem> {
- public static final Class<SMBFileSystemType> ID = SMBFileSystemType.class;
+ public static SMBFileSystemType getInstance()
+ {
+ return FSUtils.getFileSystemType(SMBFileSystemType.class);
+ }
/**
* Create a filesystem from a given device.
Modified: trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -76,7 +76,7 @@
final DeviceManager dm = DeviceUtils.getDeviceManager();
dm.register(dev);
final FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME);
- SMBFileSystemType type = fss.getFileSystemType(SMBFileSystemType.ID);
+ SMBFileSystemType type = SMBFileSystemType.getInstance();
final SMBFileSystem fs = type.create(dev, true);
fss.registerFileSystem(fs);
fss.mount(mount_point, fs, null);
Modified: trunk/fs/src/fs/org/jnode/fs/util/FSUtils.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/util/FSUtils.java 2008-02-05 22:28:59 UTC (rev 3760)
+++ trunk/fs/src/fs/org/jnode/fs/util/FSUtils.java 2008-02-05 22:54:57 UTC (rev 3761)
@@ -9,16 +9,16 @@
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful, but
+ * This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.fs.util;
import java.io.IOException;
@@ -26,26 +26,34 @@
import java.text.SimpleDateFormat;
import java.util.Date;
+import javax.naming.NameNotFoundException;
+
import org.apache.log4j.Logger;
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
import org.jnode.fs.FSFile;
+import org.jnode.fs.FileSystem;
+import org.jnode.fs.FileSystemException;
+import org.jnode.fs.FileSystemType;
+import org.jnode.fs.ftpfs.FTPFileSystemType;
+import org.jnode.fs.service.FileSystemService;
+import org.jnode.naming.InitialNaming;
/**
- *
+ *
* @author Fabien DUMINY
*/
-public class FSUtils {
+public class FSUtils {
- private static final Logger log = Logger.getLogger(FSUtils.class);
+ private static final Logger log = Logger.getLogger(FSUtils.class);
private static final int MAX_DUMP_SIZE = 256;
private static final int LINE_SIZE = 16;
-
+
protected static DateFormat dateFormat = new SimpleDateFormat();
-
+
/**
* @param path
* @param separator
@@ -55,25 +63,25 @@
int idx = path.lastIndexOf(separator);
if(idx >= 0) {
path = path.substring(idx+1);
- }
+ }
return path;
}
/**
* @param path
* @param separator
- * @return
+ * @return
*/
public static String getParentName(String path, char separator) {
int idx = path.lastIndexOf(separator);
if(idx < 0) {
path = "";
} else {
- path = path.substring(0, idx);
+ path = path.substring(0, idx);
}
return path;
}
-
+
/**
* @param entry
* @param deep
@@ -82,8 +90,8 @@
public static String toString(FSEntry entry, boolean deep) {
if(entry == null)
return "<FSEntry>NULL</FSEntry>";
-
- StringBuilder sb = new StringBuilder(2048);
+
+ StringBuilder sb = new StringBuilder(2048);
sb.append("<FSEntry>");
sb.append(" name="+entry.getName());
try {
@@ -99,7 +107,7 @@
log.error("error in isDirty", e1);
}
sb.append(" isValid="+entry.isValid());
-
+
sb.append(" isFile="+entry.isFile());
if(deep && entry.isFile()) {
try {
@@ -107,10 +115,10 @@
} catch (IOException e2) {
sb.append(" getFile=###"+e2.getMessage()+"###");
log.error("error in getFile", e2);
- }
+ }
}
- sb.append(" isDir="+entry.isDirectory());
+ sb.append(" isDir="+entry.isDirectory());
if(deep && entry.isDirectory())
try {
sb.append(toString(entry.getDirectory()));
@@ -119,7 +127,7 @@
log.error("error in getDirectory", e3);
}
sb.append("</FSEntry>");
-
+
return sb.toString();
}
@@ -141,32 +149,32 @@
public static String toString(FSDirectory dir, boolean deep) throws IOException {
if(dir == null)
return "<FSDirectory>NULL</FSDirectory>";
-
+
String str = "<FSDirectory>isValid="+dir.isValid()+"</FSDirectory>";
if(deep)
str += "\n" + dir.toString(); // also print entry table
-
+
return str;
}
-
+
/**
* @param file
* @return
*/
- public static String toString(FSFile file) {
+ public static String toString(FSFile file) {
if(file == null)
return "<FSEntry>NULL</FSEntry>";
-
+
StringBuilder sb = new StringBuilder(32);
sb.append("<FSFile>");
sb.append(" isValid"+file.isValid());
sb.append(" length"+file.getLength());
sb.append("</FSFile>");
-
+
return sb.toString();
}
-
+
/**
* @param str
* @param date
@@ -175,7 +183,7 @@
public static String toStringDate(String str, long date) {
return toString(str, new Date(date));
}
-
+
/**
* @param str
* @param date
@@ -184,7 +192,7 @@
public static String toString(String str, Date date) {
return str + dateFormat.format(date);
}
-
+
/**
* @param data
* @return
@@ -192,7 +200,7 @@
public static String toString(byte[] data) {
return toString(data, 0, data.length);
}
-
+
/**
* @param data
* @param offset
@@ -202,32 +210,32 @@
public static String toString(byte[] data, int offset, int length) {
StringBuilder sb = new StringBuilder(1024);
StringBuilder chars = new StringBuilder(LINE_SIZE);
-
+
int l = Math.min(Math.min(length - offset, data.length - offset),
MAX_DUMP_SIZE);
int mod = l % LINE_SIZE;
if(mod != 0) l += LINE_SIZE - mod;
-
+
for(int i = 0 ; i < l ; i++) {
if((i % 16) == 0) {
sb.append(lpad(Integer.toHexString(i), 4)).append(" - ");
chars.setLength(0); // empty
}
-
+
int idx = offset + i;
- boolean end = (idx >= data.length);
+ boolean end = (idx >= data.length);
if(!end) {
sb.append(lpad(Integer.toHexString(data[idx]),2)).append(' ');
chars.append((char) data[idx]);
}
-
+
if(((i % 16) == 15) || end) {
sb.append(" ").append(chars.toString()).append('\n');
}
}
return sb.toString();
}
-
+
/**
* @param str
* @param size
@@ -241,10 +249,10 @@
int nbBlanks = size - str.length();
for(int i = 0 ; i < nbBlanks ; i++ )
pad += " ";
-
+
return pad + str;
}
-
+
/**
* @param data
* @param offset
@@ -257,7 +265,20 @@
for(int i = offset ; i < l ; i++) {
sb.append((char) data[i]);
}
-
+
return sb.toString();
- }
+ }
+
+ public static <T extends FileSystemType<? extends FileSystem<?>>> T getFileSystemType(Class<T> typeClass)
+ {
+ try {
+ final FileSystemService fss = InitialNaming
+ .lookup(FileSystemService.NAME);
+ return fss.getFileSystemType(typeClass);
+ } catch (NameNotFoundException e) {
+ throw new RuntimeException(typeClass.getName() + " not properly registered", e);
+ } catch (FileSystemException e) {
+ throw new RuntimeException("internal error", e);
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|