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

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

?? btimageserver.java

?? 這是一個藍牙代碼,大家快來下載玩玩..謝謝大家的支持,
?? 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一区二区三区免费野_久草精品视频
久国产精品韩国三级视频| 7777精品伊人久久久大香线蕉完整版 | 手机精品视频在线观看| 精品亚洲成a人| 色天使久久综合网天天| 欧美电视剧在线观看完整版| 中文字幕一区二区三区色视频| 亚洲大型综合色站| 国产做a爰片久久毛片| 欧美日韩精品一区二区三区| ...av二区三区久久精品| 免费观看成人av| 欧美少妇xxx| 国产精品福利一区二区三区| 激情六月婷婷久久| 欧美区在线观看| 樱桃国产成人精品视频| 大美女一区二区三区| 欧美一区二区三区视频| 亚洲福利电影网| 色噜噜狠狠色综合中国| 综合欧美一区二区三区| 高清视频一区二区| 中文字幕乱码亚洲精品一区| 麻豆免费看一区二区三区| 欧美日韩不卡一区| 亚洲无线码一区二区三区| 色婷婷综合久久久久中文| 国产精品理论在线观看| 极品少妇xxxx偷拍精品少妇| 日韩一级黄色片| 日韩电影在线观看一区| 91精品国产综合久久精品图片| 国产激情视频一区二区三区欧美| 国产精品一区久久久久| 七七婷婷婷婷精品国产| 亚洲免费伊人电影| 国产亚洲福利社区一区| 欧美精品一区二区三区在线播放| 日韩欧美高清dvd碟片| 欧美色倩网站大全免费| 精品三级在线看| 97se亚洲国产综合在线| 欧美精品丝袜中出| 日韩精品一区第一页| 91精品国产综合久久精品| 日韩成人免费看| 日韩美女视频在线| 国产一区不卡视频| 国产精品沙发午睡系列990531| k8久久久一区二区三区| 亚洲精品第一国产综合野| 欧美日韩成人综合| 精品一区二区三区欧美| 最新久久zyz资源站| 欧美高清视频在线高清观看mv色露露十八| 亚洲国产精品麻豆| 懂色av中文字幕一区二区三区| 色综合久久九月婷婷色综合| 亚洲一区自拍偷拍| 色综合夜色一区| 日韩女优av电影| 99久久99久久久精品齐齐| 久久99国产精品麻豆| 亚洲成人www| 亚洲精品日产精品乱码不卡| 中文字幕亚洲在| 欧美激情艳妇裸体舞| 精品国产乱码久久| 欧美群妇大交群的观看方式| 欧美亚洲国产bt| 在线看日韩精品电影| 色综合婷婷久久| 色婷婷av一区二区三区之一色屋| 成人av资源下载| av不卡免费在线观看| 97久久精品人人澡人人爽| 成人av在线资源网站| 成人午夜看片网址| av电影天堂一区二区在线观看| 成人avav影音| 91蝌蚪国产九色| 91久久免费观看| 欧美精品一二三四| 欧美一区日本一区韩国一区| 欧美一区二区三区电影| 欧美电视剧在线看免费| 久久一区二区三区国产精品| 久久精品欧美一区二区三区不卡| 欧美极品少妇xxxxⅹ高跟鞋| 麻豆91精品视频| 一区二区三区在线免费| 日韩国产欧美在线播放| 亚洲午夜国产一区99re久久| 亚洲丝袜制服诱惑| 亚洲欧美一区二区三区极速播放 | 国产在线乱码一区二区三区| 亚洲精品在线网站| 欧美一区二区三区在| 日韩丝袜情趣美女图片| 欧美大胆一级视频| 国产欧美一区二区精品久导航| 国产精品三级在线观看| 亚洲美女屁股眼交| 午夜激情综合网| 黄色小说综合网站| 成人蜜臀av电影| 欧美少妇性性性| 久久久精品中文字幕麻豆发布| 国产精品系列在线| 亚洲国产成人tv| 国产乱子伦视频一区二区三区 | 久久综合久久鬼色中文字| 国产欧美精品一区二区色综合 | 亚洲综合免费观看高清完整版在线 | 国产精品国产三级国产三级人妇 | 视频一区国产视频| 狠狠色狠狠色综合| 91丝袜美腿高跟国产极品老师| 欧美日韩一区在线| 久久久亚洲综合| 亚洲影院久久精品| 国产精品123区| 欧美日韩在线免费视频| 久久精品人人爽人人爽| 亚洲第一成年网| heyzo一本久久综合| 日韩一级大片在线| 中文字幕制服丝袜一区二区三区 | 国产精品全国免费观看高清 | 欧美挠脚心视频网站| 日韩精品中文字幕一区| 亚洲欧美视频在线观看视频| 国内成人自拍视频| 欧美区在线观看| 亚洲自拍都市欧美小说| 成人一级片网址| 国产精品网站在线播放| 成人天堂资源www在线| 色婷婷久久久久swag精品| 精品日韩一区二区三区免费视频| 一区二区三区日韩欧美| 国产呦萝稀缺另类资源| 欧美日韩性生活| 亚洲色图另类专区| 国产精品一区二区三区四区| 91精品国产综合久久精品麻豆| 一区二区三区波多野结衣在线观看| 国产剧情av麻豆香蕉精品| 欧美一区永久视频免费观看| 亚洲高清免费在线| 欧美亚日韩国产aⅴ精品中极品| 欧美极品美女视频| 国产精品一线二线三线| 日韩欧美一区二区免费| 五月激情丁香一区二区三区| 91视频免费观看| 国产精品日韩成人| 成人一区二区三区中文字幕| 日韩一区二区视频| 日本伊人色综合网| 欧美日韩国产色站一区二区三区| 亚洲欧美日韩一区二区三区在线观看| 国模娜娜一区二区三区| 精品国产免费视频| 蜜桃视频一区二区| 精品久久久久99| 国内成人自拍视频| 欧美精品一区二区三区四区| 精品在线播放免费| www日韩大片| 久久福利资源站| 精品欧美黑人一区二区三区| 国内久久精品视频| 久久蜜桃一区二区| 国产成人超碰人人澡人人澡| 国产精品网曝门| av激情综合网| 亚洲国产婷婷综合在线精品| 欧美日韩一区二区三区不卡| 午夜精品国产更新| 日韩一区二区三区在线视频| 韩国欧美国产1区| 国产三级精品视频| 成人久久久精品乱码一区二区三区| 国产精品人人做人人爽人人添| 色综合久久天天| 丝袜美腿一区二区三区| 日韩欧美中文字幕制服| 国产精品一区免费视频| 中文字幕日本乱码精品影院| 欧美午夜精品久久久久久孕妇| 日本美女视频一区二区| 久久久久久黄色| 色哟哟一区二区在线观看| 五月婷婷综合激情| 成人三级伦理片| 波多野结衣精品在线| 国产精品一区在线观看你懂的| 久久精品一区二区三区av|