⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moto.java

📁 J2ME上的一个播放器,可以更换皮肤.开源软件.
💻 JAVA
字号:
package inline.fs;

import com.motorola.io.FileConnection;
import com.motorola.io.FileSystemRegistry;
import java.io.*;
import javax.microedition.io.Connector;

class Moto implements FileAccessible
{
    private FileConnection connection;
    private String location;

    Moto()
    {
    }
    
    public boolean close()
    {
        boolean result = true;
        
        try
        {
            connection.close();
            connection = null;
        }
        catch(Exception exception)
        {
            System.err.println("Close connection failed: " + exception.getMessage());
            result = false;
        }
        
        return result;
    }

    public boolean open(String filename, int mode)
    {
        boolean result = true;
        
        try
        {
            connection = (FileConnection)Connector.open("file://" + filename, mode);
            location = filename;
        }
        catch(Exception exception)
        {
            connection = null;
            System.err.println("Open connection '" + filename + "' failed: " + exception.getMessage());

            result = false;
        }
       
        return result;
    }

    public String[] list()
    {
        String as[] = {};
        if(connection != null)
        {
            try
            {
                as = connection.list();
            }
            catch(Exception e)
            {
                System.err.println("Can't list the directory: "+e.getMessage());
            }
        }
        else
        {
            System.err.println("List failed: connection is null ");
        }
        return as;
    }

    public static String[] listRoots()
    {
        return FileSystemRegistry.listRoots();
    }

    public boolean isDirectory()
    {
        boolean flag = false;
        if(connection != null)
        {
            flag = connection.isDirectory();
        }
        return flag;
    }

    public InputStream openInputStream()
    {
        InputStream inputstream = null;
	if (connection != null)
	{
	    try
	    {
		inputstream = connection.openInputStream();
	    }
	    catch(Exception exception)
	    {
		inputstream = null;
		System.out.println("openInputStream from '" + location + "' failed: " + exception.getMessage());
	    }
	}
        return inputstream;
    }

    public OutputStream openOutputStream()
    {
        OutputStream outputstream = null;
	if (connection != null)
	{
	    try
	    {
		outputstream = connection.openOutputStream();
	    }
	    catch(Exception exception)
	    {
		outputstream = null;
		System.out.println("openOutputStream from '" + location + "' failed: " + exception.getMessage());
	    }
	}
	
	return outputstream;
    }

    public boolean create() throws Exception
    {
        boolean flag = false;
        if(connection != null)
        {
            if(!connection.exists())
	    {
		connection.create();
                flag = true;
	    }
        }
        return flag;
    }

    public boolean delete() throws Exception
    {
        boolean flag = false;
        if(connection != null)
        {
            if(connection.exists())
	    {
		connection.delete();
                flag = true;
	    }
        }
        return flag;
    }

    public boolean exists() throws Exception
    {
        boolean flag = false;
        if(connection != null)
        {
            flag = connection.exists();
        }
        return flag;
    }
    
    public long fileSize() throws Exception
    {
        long l = -1L;
        if(connection != null)
        {
            l = connection.fileSize();
        }
        return l;
    }
////////////////////////// UNCHECKED    
/*    
    private void open()
    {
        System.err.println("N/A today, use open(filename, mode)");
    }
    
    private void open(int i)
    {
        open();
    }
    
    public long availableSize()
    {
        long l = -1L;
        open();
        if(connection != null)
        {
            l = connection.availableSize();
            close();
        }
        return l;
    }

    public boolean canRead()
    {
        boolean flag = false;
        open();
        if(connection != null)
        {
            flag = connection.canRead();
            close();
        }
        return flag;
    }

    public boolean canWrite()
    {
        boolean flag = false;
        open();
        if(connection != null)
        {
            flag = connection.canWrite();
            close();
        }
        return flag;
    }

    public boolean isHidden()
    {
        boolean flag = false;
        open();
        if(connection != null)
        {
            flag = connection.isHidden();
            close();
        }
        return flag;
    }

    public long lastModified()
    {
        long l = -1L;
        open();
        if(connection != null)
        {
            l = connection.lastModified();
            close();
        }
        return l;
    }

    public boolean mkdir()
    {
        boolean flag = false;
        open(2);
        if(connection != null)
        {
            if(connection.exists() || connection.mkdir())
                flag = true;
            close();
        }
        return flag;
    }

    public byte[] read()
    {
        byte abyte0[] = null;
        try
        {
            open();
            long l = connection.fileSize();
            abyte0 = new byte[(int)l];
            InputStream inputstream = connection.openInputStream();
            if(l != (long)inputstream.read(abyte0))
                abyte0 = null;
            inputstream.close();
            inputstream = null;
            close();
        }
        catch(Exception exception)
        {
            abyte0 = null;
            System.out.println("Read from '" + location + "' failed: " + exception.getMessage());
        }
        return abyte0;
    }

    public boolean rename(String s)
    {
        boolean flag = false;
        open(2);
        if(connection != null)
        {
            if(connection.rename("file://" + s))
                flag = true;
            close();
        }
        return flag;
    }

    public boolean write(byte abyte0[])
    {
        boolean flag = false;
        try
        {
            open(2);
            if(connection.exists())
                connection.delete();
            connection.create();
            OutputStream outputstream = connection.openOutputStream();
            outputstream.write(abyte0, 0, abyte0.length);
            outputstream.flush();
            outputstream.close();
            close();
            flag = true;
        }
        catch(Exception exception)
        {
            System.out.println("Write to '" + location + "' failed: " + exception.getMessage());
        }
        return flag;
    }

    public void setHidden(boolean flag)
    {
        open();
        if(connection != null)
        {
            connection.setHidden(flag);
            close();
        }
    }

    public void setReadable(boolean flag)
    {
        open();
        if(connection != null)
        {
            connection.setReadable(flag);
            close();
        }
    }

    public void setWriteable(boolean flag)
    {
        open();
        if(connection != null)
        {
            connection.setWriteable(flag);
            close();
        }
    }

    public long usedSize()
    {
        long l = -1L;
        open();
        if(connection != null)
        {
            l = connection.usedSize();
            close();
        }
        return l;
    }
*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -