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

📄 bufferimage.java

📁 j2me写的google地图
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        } else
        {
            return defaultIma;
        }
    }

    public static void fetcher(Vector fileList)throws Exception
    {
        HttpConnection hc;
        DataInputStream dis;
        DataOutputStream dos;
        StringBuffer messagebuffer;
        StringBuffer request;
        hc = null;
        dis = null;
        dos = null;
        messagebuffer = new StringBuffer();
        if(fileList.size() == 0)
            return;
        request = new StringBuffer("nbReq=" + fileList.size());
        Vector tiles = new Vector();
        for(int i = 0; i < fileList.size(); i++)
        {
            BufferImage ima = (BufferImage)fileList.elementAt(i);
            ima.state = 2;
            String name = UtilMidp.urlEncode(ima.name);
            if(tiles.indexOf(name) == -1)
                tiles.addElement(name);
            request.append("&req" + i + "=" + (ima.numSat % 2 != 1 ? "png" : "jpg") + "|png|" + ima.offx + "|" + ima.offy + "|" + ima.size + "|" + ima.size + "|" + tiles.indexOf(name));
        }

        for(int i = 0; i < tiles.size(); i++)
            request.append("&tile" + i + "=" + (String)tiles.elementAt(i));

        if(extraInfo != null)
            request.append(extraInfo);
        System.out.println(request);
        UtilMidp.addInfo("before open");
        System.out.println("Sending:" + fetcherUrl.toString());
        hc = URLFetcher.open(fetcherUrl);
        hc.setRequestMethod("POST");
        UtilMidp.addInfo("before post");
        byte request_body[] = request.toString().getBytes();
        hc.setRequestProperty("Content-Length", Integer.toString(request_body.length));
        hc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
        dos = hc.openDataOutputStream();
        for(int i = 0; i < request_body.length; i++)
            dos.writeByte(request_body[i]);

        messagebuffer.append(hc.getResponseMessage() + "\r\n");
        dis = new DataInputStream(hc.openInputStream());
        long len = hc.getLength();
        for(int i = 0; i < fileList.size();)
        {
            int code = dis.readShort();
            int size = dis.readInt();
            try
            {
                BufferImage ima = (BufferImage)fileList.elementAt(i);
                if(code == 200)
                {
                    ima.ImagecreateImage(dis, size);
                } else
                {
                    ima.ima = null;
                    System.out.println("Null ima...");
                }
//                ima;
                if(m_listener != null)
                {
//                    ima;
                    m_listener.imageLoaded(ima);
                }
                continue;
            }
            catch(Exception e)
            {
                e.printStackTrace();
                UtilMidp.showException(e);
                UtilMidp.addInfo(e.toString());
                i++;
            }
        }

        dis.close();
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        break MISSING_BLOCK_LABEL_787;
        messagebuffer = new StringBuffer("ERROR!");
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        break MISSING_BLOCK_LABEL_787;
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
    }

    public void delete()
    {
        delete(false);
    }

    public void delete(boolean doDelete)
    {
        try
        {
            if(rmsId != -1)
            {
                if(rs == null)
                    rs = RecordStore.openRecordStore("CacheRMS", true);
                if(doDelete)
                {
                    if(UtilMidp.DEBUG)
                        System.out.println("Deleting record:" + rmsId);
                    rs.deleteRecord(rmsId);
                } else
                {
                    oneElemRms r = new oneElemRms();
                    r.id = rmsId;
                    r.size = rs.getRecordSize(rmsId);
                    elemRms.addElement(r);
                    System.out.println("Adding element:" + rmsId + " size:" + r.size);
                }
                rmsId = -1;
            }
            ima = null;
            buff = null;
        }
        catch(Exception e)
        {
            System.out.println("ERROR in bufferImage.delete()");
            e.printStackTrace();
        }
    }

    void fetchImage()
        throws Exception
    {
        HttpConnection cnx;
        InputStream is;
        cnx = null;
        is = null;
//        if(!getFromRMS())
//            break MISSING_BLOCK_LABEL_45;
        if(m_listener != null)
            m_listener.imageLoaded(this);
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        return;
//        if(m_doNotUseNetwork)
//            break MISSING_BLOCK_LABEL_366;
        if(UtilMidp.DEBUG)
            System.out.println("Try to load:" + name);
//        if(name != null)
//            break MISSING_BLOCK_LABEL_118;
        state = 6;
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        return;
        cnx = URLFetcher.open(name);
        cnx.setRequestMethod("GET");
        cnx.setRequestProperty("Referer", "http://tiles.ask.com");
        cnx.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) Gecko/20061010 Firefox/2.0");
        int rc = cnx.getResponseCode();
//        if(rc == 200)
//            break MISSING_BLOCK_LABEL_251;
        if(UtilMidp.DEBUG)
            System.out.println("Response code:" + rc);
        state = 4;
        ima = nullIma;
        if(m_listener != null)
            m_listener.imageLoaded(this);
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        return;
        state = 2;
        if(m_listener != null)
            m_listener.imageLoaded(this);
        is = cnx.openInputStream();
        String type = cnx.getType();
        if(UtilMidp.DEBUG)
            System.out.println("Type:" + type);
        ImagecreateImage(is, 0);
        state = 3;
        while(count > m_nbIma) 
            deleteLast();
        if(m_listener != null)
            m_listener.imageLoaded(this);
        name = null;
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        break MISSING_BLOCK_LABEL_592;
        IllegalArgumentException e;
//        e;
        System.out.println("Illegal argument exception: url:" + name);
//        e.printStackTrace();
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        break MISSING_BLOCK_LABEL_592;
//        e;
        System.out.println("ERROR while fetching image:" );
        state = 6;
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        break MISSING_BLOCK_LABEL_592;
//        e;
        m_doNotUseNetwork = true;
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        break MISSING_BLOCK_LABEL_592;
//        e;
        System.out.println("URL was:" + name);
//        throw new IllegalArgumentException("Not an HTTP URL");
//        Exception exception;
//        exception;
        if(is != null)
            is.close();
        if(cnx != null)
            cnx.close();
//        throw exception;
    }

    boolean equals(int px, int py, int zoom, int inNumSat, int size)
    {
        return this.px == px && this.py == py && this.zoom == zoom && numSat == inNumSat && this.size == size;
    }

    public static void dumpState()
    {
        System.out.println("----------------------------------------------");
        System.out.println(getDump());
        System.out.println("----------------------------------------------");
    }

    public static String getDump()
    {
        StringBuffer res = new StringBuffer();
        BufferImage l = first;
        int i = 1;
        res.append("Total: " + count + " m_nbIma:" + m_nbIma + " m_nbImaVis:" + m_nbImaVis + "\n");
        try
        {
            if(rs == null)
                rs = RecordStore.openRecordStore("CacheRMS", true);
            res.append("RecordStore, size:" + rs.getSize() + " avail:" + rs.getSizeAvailable() + " Number:" + rs.getNumRecords() + "\n");
            res.append("*********************\n");
        }
        catch(Exception e) { }
        oneElemRms r;
        for(Enumeration e = elemRms.elements(); e.hasMoreElements(); res.append("elemRms:" + r.id + " size:" + r.size + "\n"))
            r = (oneElemRms)e.nextElement();

        for(; l != null; l = l.next)
        {
            res.append("Slot[" + i++ + "]:");
            res.append(" rmsID:" + l.rmsId + " state:" + l.state + " ima:" + (l.ima != null ? "ok" : "null") + " c:" + l.count + " x:" + l.px + " y:" + l.py + " " + l.zoom + " sat:" + l.numSat + " " + l + " next:" + l.next + " \n");
        }

        return res.toString();
    }

    public static BufferImage getImage(int px, int py, int zoom, int inNumSat, int size)
    {
//    	Image temp=Image.createImage(250, 250);
//    	Graphics g=temp.getGraphics();
//    	g.setColor(0xff0000);
//    	g.fillRect(0, 0, 250, 250);
        return getImage(px, py, zoom, inNumSat, size, true);
    }

    public static BufferImage getImage(int px, int py, int zoom, int inNumSat, int size, boolean loadIt)
    {
    	System.out.println("www.xx.com");
        int emptySlot;
        BufferImage prev;
        BufferImage ima;
        emptySlot = 0;
        prev = null;
        ima = first;
        int d = 0;
        Object obj = lock;
        synchronized(lock)
        {
            if(ima != first)
            {
                if(prev != null)
                    prev.next = ima.next;
                ima.next = first;
                first = ima;
            }
        }
        if(ima.state == 5)
            ima.state = 1;
        else
        return ima;
        prev = ima;
        ima = ima.next;
        if(++d > 1000)
        {
            System.out.println("Error in get Image");
            dumpState();
        }
        if(UtilMidp.DEBUG)
            System.out.println(" Image not in cache, loading....at pos:" + emptySlot);
        ima = new BufferImage(px, py, zoom, inNumSat, size);
        push(ima);
        return ima;
    }

    public String toString()
    {
        return "bufferImage, x:" + px + " y:" + py + " zoom:" + zoom + " size:" + size + " sat:" + numSat;
    }

    private String name;
    private int numSat;
    private int px;
    private int py;
    private int size;
    private int zoom;
    private int offx;
    private int offy;
    private byte buff[];
    public Image ima;
    static bufferImageLoaded listener = null;
    public static final int ST_NONE = 0;
    public static final int ST_TOLOAD = 1;
    public static final int ST_LOADING = 2;
    public static final int ST_LOADED = 3;
    public static final int ST_NOTFOUND = 4;
    public static final int ST_IN_RMS = 5;
    public static final int ST_TO_DELETE = 6;
    public int state;
    protected int rmsId;
    protected static Image nullIma = Image.createImage(1, 1);
    static int count = 0;
    public Object my_data;
    public static boolean m_modePacked = true;
    static int m_nbIma = 20;
    static int m_nbImaVis = 16;
    static int sizeSq = 256;
    static BufferImage first = null;
    private BufferImage next;
    private static RecordStore rs = null;
    private static BufferImageListener m_listener = null;
    private static Display m_display;
    private static Displayable m_displayable;
    public static String extraInfo = null;
    static Vector elemRms = new Vector();
    public static MapCustomOverlay m_customOverlay = null;
    public static boolean m_useProxy = false;
    public static boolean m_useRMS = true;
    public static boolean m_doNotUseNetwork = false;
    public static boolean m_useFileAPI = false;
    static boolean m_cont = false;
    public String debugString;
    static Object lock = new Object();
    public static String GOOGLE_SAT_VERSION = "27";
    public static String GOOGLE_MAP_VERSION = "w2.74";
    public static int m_dataDownloadCounter = 0;
    public static String ROOT_DIR = "file:////cache/";
    private static final String SEP_STR = "/";
    private static Vector rootTiles = new Vector();
    public static String tabSats[] = {
        "GoogleMap", "GoogleSat", "MicrosoftMap", "MicrosoftSat", "YahooMap", "YahooSat", "AskDotComMap", "AskDotComSat"
    };
    public static String fetcherUrl = "http://mob.8motions.com/mob/fetcher.php";
    static boolean isInit = false;
    private char tabIdxGoogle[] = {
        'q', 'r', 't', 's'
    };
    private char tabIdxVearth[] = {
        '0', '1', '2', '3'
    };
    static Image defaultIma = null;

}

⌨️ 快捷键说明

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