亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? btimageserver.java

?? j2me下的藍牙技術 簡單易懂 直接放到wtk下即可運行
?? JAVA
字號:
/* * @(#)BTImageServer.java	1.3 04/06/24 * * Copyright (c) 2000-2004 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms */package example.bluetooth.demo;// jsr082 APIimport javax.bluetooth.DataElement;import javax.bluetooth.DiscoveryAgent;import javax.bluetooth.LocalDevice;import javax.bluetooth.ServiceRecord;import javax.bluetooth.ServiceRegistrationException;import javax.bluetooth.UUID;// midp/cldc APIimport javax.microedition.io.Connector;import javax.microedition.io.StreamConnection;import javax.microedition.io.StreamConnectionNotifier;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.Vector;import java.util.Hashtable;/** * Established the BT service, accepts connections * and send the requested image silently. * * @version 1.3, 06/24/04 */final class BTImageServer implements Runnable {    /** Describes this server */    private static final UUID PICTURES_SERVER_UUID =         new UUID("F0E0D0C0B0A000908070605040302010", false);    /** The attribute id of the record item with images names. */    private static final int IMAGES_NAMES_ATTRIBUTE_ID = 0x4321;    /** Keeps the local device reference. */    private LocalDevice localDevice;    /** Accepts new connections. */    private StreamConnectionNotifier notifier;    /** Keeps the information about this server. */    private ServiceRecord record;    /** Keeps the parent reference to process specific actions. */    private GUIImageServer parent;    /** Becomes 'true' when this component is finilized. */    private boolean isClosed;    /** Creates notifier and accepts clients to be processed. */    private Thread accepterThread;    /** Process the particular client from queue. */    private ClientProcessor processor;    /** Optimization: keeps the table of data elements to be published. */    private final Hashtable dataElements = new Hashtable();    /**     * Constructs the bluetooth server, but it is initialized     * in the different thread to "avoid dead lock".     */    BTImageServer(GUIImageServer parent) {        this.parent = parent;        // we have to initialize a system in different thread...        accepterThread = new Thread(this);        accepterThread.start();    }    /**     * Accepts a new client and send him/her a requested image.     */    public void run() {        boolean isBTReady = false;        try {            // create/get a local device            localDevice = LocalDevice.getLocalDevice();            // set we are discoverable            if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC)) {                // Some implementations always return false, even if                 // setDiscoverable successful                // throw new IOException("Can't set discoverable mode...");            }            // prepare a URL to create a notifier            StringBuffer url = new StringBuffer("btspp://");            // indicate this is a server            url.append("localhost").append(':');            // add the UUID to identify this service            url.append(PICTURES_SERVER_UUID.toString());            // add the name for our service            url.append(";name=Picture Server");            // request all of the client not to be authorized            // some devices fail on authorize=true            url.append(";authorize=false");            // create notifier now            notifier = (StreamConnectionNotifier) Connector.open(                    url.toString());            // and remember the service record for the later updates            record = localDevice.getRecord(notifier);            // create a special attribute with images names            DataElement base = new DataElement(DataElement.DATSEQ);            record.setAttributeValue(IMAGES_NAMES_ATTRIBUTE_ID, base);            // remember we've reached this point.            isBTReady = true;        } catch (Exception e) {            System.err.println("Can't initialize bluetooth: " + e);        }        parent.completeInitialization(isBTReady);        // nothing to do if no bluetooth available        if (!isBTReady) {            return;        }        // ok, start processor now        processor = new ClientProcessor();        // ok, start accepting connections then        while (!isClosed) {            StreamConnection conn = null;            try {                conn = notifier.acceptAndOpen();            } catch (IOException e) {                // wrong client or interrupted - continue anyway                continue;            }            processor.addConnection(conn);        }    }    /**     * Updates the service record with the information     * about the published images availability.     * <p>     * This method is invoked after the caller has cheched     * already that the real action should be done.     *     * @return true if record was updated successfully, false otherwise.     */    boolean changeImageInfo(String name, boolean isPublished) {        // ok, get the record from service        DataElement base = record.getAttributeValue(IMAGES_NAMES_ATTRIBUTE_ID);        // check the corresponding DataElement object is created already        DataElement de = (DataElement) dataElements.get(name);        // if no, then create a new DataElement that describes this image        if (de == null) {            de = new DataElement(DataElement.STRING, name);            dataElements.put(name, de);        }        // we know this data element has DATSEQ type        if (isPublished) {            base.addElement(de);        } else {            if (!base.removeElement(de)) {                System.err.println("Error: item was not removed for: " + name);                return false;            }        }        record.setAttributeValue(IMAGES_NAMES_ATTRIBUTE_ID, base);        try {            localDevice.updateRecord(record);        } catch (ServiceRegistrationException e) {            System.err.println("Can't update record now for: " + name);            return false;        }        return true;    }    /**     * Destroy a work with bluetooth - exits the accepting     * thread and close notifier.     */    void destroy() {        isClosed = true;        // finilize notifier work        if (notifier != null) {            try {                notifier.close();            } catch (IOException e) {} // ignore        }        // wait for acceptor thread is done        try {            accepterThread.join();        } catch (InterruptedException e) {} // ignore        // finilize processor        if (processor != null) {            processor.destroy(true);        }        processor = null;    }    /**     * Reads the image name from the specified connection     * and sends this image through this connection, then     * close it after all.     */    private void processConnection(StreamConnection conn) {        // read the image name first        String imgName = readImageName(conn);        // check this image is published and get the image file name        imgName = parent.getImageFileName(imgName);        // load image data into buffer to be send        byte[] imgData = getImageData(imgName);        // send image data now        sendImageData(imgData, conn);        // close connection and good-bye        try {            conn.close();        } catch (IOException e) {} // ignore    }    /** Send image data. */    private void sendImageData(byte[] imgData, StreamConnection conn) {        if (imgData == null) {            return;        }        OutputStream out = null;        try {            out = conn.openOutputStream();            out.write(imgData.length >> 8);            out.write(imgData.length & 0xff);            out.write(imgData);            out.flush();        } catch (IOException e) {            System.err.println("Can't send image data: " + e);        }        // close output stream anyway        if (out != null) {            try {                out.close();            } catch (IOException e) {} // ignore        }    }    /** Reads image name from specified connection. */    private String readImageName(StreamConnection conn) {        String imgName = null;        InputStream in = null;        try {            in = conn.openInputStream();            int length = in.read(); // 'name' length is 1 byte            if (length <= 0) {                throw new IOException("Can't read name length");            }            byte[] nameData = new byte[length];            length = 0;            while (length != nameData.length) {                int n = in.read(nameData, length, nameData.length - length);                if (n == -1) {                    throw new IOException("Can't read name data");                }                length += n;            }            imgName = new String(nameData);        } catch (IOException e) {            System.err.println(e);        }        // close input stream anyway        if (in != null) {            try {                in.close();            } catch (IOException e) {} // ignore        }        return imgName;    }    /** Reads images data from MIDlet archive to array. */    private byte[] getImageData(String imgName) {        if (imgName == null) {            return null;        }        InputStream in = getClass().getResourceAsStream(imgName);        // read image data and create a byte array        byte[] buff = new byte[1024];        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);        try {            while (true) {                int length = in.read(buff);                if (length == -1) {                    break;                }                baos.write(buff, 0, length);            }        } catch (IOException e) {            System.err.println("Can't get image data: imgName=" + imgName + " :"                    + e);            return null;        }        return baos.toByteArray();    }    /**     * Orginizes the queue of clients to be processed,     * processes the clients one by one until destroyed.     */    private class ClientProcessor implements Runnable {        private Thread processorThread;        private Vector queue = new Vector();        private boolean isOk = true;        ClientProcessor() {            processorThread = new Thread(this);            processorThread.start();        }        public void run() {            while (!isClosed) {                // wait for new task to be processed                synchronized (this) {                    if (queue.size() == 0) {                        try {                            wait();                        } catch (InterruptedException e) {                            System.err.println("Unexpected exception: " + e);                            destroy(false);                            return;                        }                    }                }                // send the image to specified connection                StreamConnection conn;                synchronized (this) {                    // may be awaked by "destroy" method.                    if (isClosed) {                        return;                    }                    conn = (StreamConnection) queue.firstElement();                    queue.removeElementAt(0);                    processConnection(conn);                }            }        }        /** Adds the connection to queue and notifys the thread. */        void addConnection(StreamConnection conn) {            synchronized (this) {                queue.addElement(conn);                notify();            }        }        /** Closes the connections and . */        void destroy(boolean needJoin) {            StreamConnection conn;            synchronized (this) {                notify();                while (queue.size() != 0) {                    conn = (StreamConnection) queue.firstElement();                    queue.removeElementAt(0);                    try {                        conn.close();                    } catch (IOException e) {} // ignore                }            }            // wait until dispatching thread is done            try {                processorThread.join();            } catch (InterruptedException e) {} // ignore        }    }} // end of class 'BTImageServer' definition

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日韩欧美电影| 91精品视频网| 日本一不卡视频| 欧美国产1区2区| 日韩欧美一二三四区| 91免费版在线看| 久久国产婷婷国产香蕉| 亚洲黄色小视频| 99精品视频一区二区三区| 久久久久久97三级| 91在线视频观看| 视频一区欧美日韩| 欧美久久久一区| 国产资源在线一区| 综合自拍亚洲综合图不卡区| 成人永久免费视频| 亚洲欧美日韩国产成人精品影院| 国内成人免费视频| 色素色在线综合| 国产在线看一区| 午夜av一区二区三区| 亚洲欧美另类久久久精品2019| 国产亚洲制服色| 欧美伦理电影网| 国产精品一区二区久久不卡| 精品欧美一区二区在线观看| 欧美亚男人的天堂| 91蜜桃视频在线| 99在线精品免费| 成人高清免费在线播放| 国产精品99久久久久久宅男| 日韩免费电影网站| 视频一区欧美精品| 亚洲美女偷拍久久| 国产精品久99| ㊣最新国产の精品bt伙计久久| 久久九九国产精品| 国产欧美一区二区精品婷婷| 久久久久久久久久美女| 久久亚洲综合av| 国产女主播一区| 中文字幕日韩av资源站| 国产精品色一区二区三区| 国产天堂亚洲国产碰碰| 中文字幕欧美区| 中文字幕中文乱码欧美一区二区 | 成人免费在线观看入口| 久久久天堂av| 国产校园另类小说区| 国产欧美久久久精品影院| 欧美国产日韩亚洲一区| 国产精品人妖ts系列视频| 亚洲色图欧美偷拍| 亚洲精品欧美综合四区| 亚洲va欧美va国产va天堂影院| 依依成人精品视频| 亚洲精品成人在线| 亚洲电影一区二区三区| 午夜精品一区二区三区电影天堂 | 麻豆成人久久精品二区三区红| 午夜伦理一区二区| 久久99热99| 国产成人av一区二区三区在线| 成人伦理片在线| 在线一区二区三区做爰视频网站| 欧美群妇大交群中文字幕| 欧美一区二区精品久久911| 精品国产亚洲在线| 国产精品成人一区二区艾草 | 国产精品一二三四| 91丝袜美腿高跟国产极品老师 | 老司机精品视频在线| 国产成人亚洲精品狼色在线| 91蜜桃免费观看视频| 欧美日韩精品一二三区| 2017欧美狠狠色| 一区二区高清在线| 久久国产生活片100| 99re在线视频这里只有精品| 这里只有精品电影| 久久精品一区二区三区不卡 | 免费观看日韩av| 成人精品在线视频观看| 7777精品伊人久久久大香线蕉最新版| 久久久久久毛片| 亚洲国产视频网站| 国产寡妇亲子伦一区二区| 91视频www| 精品国产三级电影在线观看| 亚洲欧美色综合| 亚洲福利一区二区| 国产精品影视天天线| 欧洲一区二区三区在线| 亚洲精品一区二区三区精华液| 中文字幕制服丝袜成人av | 国产精品99久久久久久似苏梦涵 | 国产精品不卡一区| 免费看黄色91| 91激情在线视频| 久久久久国产一区二区三区四区 | www.亚洲色图.com| 欧美午夜电影一区| 国产精品无圣光一区二区| 日韩中文字幕亚洲一区二区va在线| 狠狠网亚洲精品| 色美美综合视频| 久久久久久一级片| 久久精品99国产精品| 91成人网在线| 亚洲视频一区二区在线| 国产精品一级黄| ww久久中文字幕| 日本欧洲一区二区| 欧美区视频在线观看| 亚洲精品高清在线观看| 99久久精品国产麻豆演员表| 久久久久9999亚洲精品| 精品在线观看视频| 777奇米成人网| 午夜电影网一区| 欧美日韩在线观看一区二区| 亚洲日本va午夜在线影院| 国产suv精品一区二区883| 久久男人中文字幕资源站| 美女视频黄免费的久久 | 国产精品自拍一区| 欧美一区二区三区精品| 天天操天天干天天综合网| 在线观看一区日韩| 玉足女爽爽91| 在线观看欧美精品| 一区二区三区精品| 91国产免费观看| 亚洲中国最大av网站| 日本韩国欧美一区二区三区| 亚洲免费在线播放| 91成人免费在线| 亚洲h动漫在线| 欧美年轻男男videosbes| 亚洲va国产天堂va久久en| 欧美久久高跟鞋激| 青青草97国产精品免费观看| 日韩一区国产二区欧美三区| 男人的j进女人的j一区| 日韩一级片网址| 另类中文字幕网| 久久精品在线免费观看| www.成人网.com| 亚洲精品一二三四区| 欧美视频中文字幕| 日韩国产欧美一区二区三区| 欧美一级免费观看| 精品一区二区三区免费视频| 国产亚洲精品7777| 99久久国产综合精品麻豆| 亚洲另类在线一区| 欧美人牲a欧美精品| 激情五月激情综合网| 国产区在线观看成人精品| 99re热视频这里只精品| 午夜精品久久久久影视| 亚洲精品一线二线三线| 99久久99久久精品免费看蜜桃| 亚洲美女在线国产| 日韩一区二区免费在线电影| 国产一区二区三区在线看麻豆| 国产精品久久久久影院老司| 欧美日韩中文国产| 久久成人久久爱| 国产精品久久久久久亚洲毛片 | 午夜久久久久久电影| 精品国产亚洲在线| 99re8在线精品视频免费播放| 亚洲国产婷婷综合在线精品| 亚洲精品在线免费观看视频| 色呦呦国产精品| 麻豆久久一区二区| 中文字幕在线不卡国产视频| 欧美一区二区久久久| 99久久精品国产网站| 日本最新不卡在线| 中文字幕制服丝袜成人av| 91精品国产黑色紧身裤美女| 成人免费的视频| 日本sm残虐另类| 综合分类小说区另类春色亚洲小说欧美| 欧美精品一二三| 成人不卡免费av| 蜜臀精品一区二区三区在线观看| 中文字幕一区二区三区精华液| 欧美一区二区三区免费在线看 | 国产激情一区二区三区桃花岛亚洲| 一区二区国产视频| 欧美激情综合五月色丁香小说| 欧美日本在线观看| 91麻豆蜜桃一区二区三区| 紧缚捆绑精品一区二区| 五月天中文字幕一区二区| 国产精品电影一区二区| 久久婷婷国产综合国色天香|