亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
久久国产麻豆精品| 精品一二线国产| 国产日韩欧美综合一区| 91麻豆精品国产综合久久久久久| 色综合天天综合| 色婷婷久久久久swag精品 | 欧美日本精品一区二区三区| 99re亚洲国产精品| 99精品视频在线播放观看| av在线综合网| 欧美亚州韩日在线看免费版国语版| 色88888久久久久久影院按摩| 色诱亚洲精品久久久久久| 欧美日韩国产综合草草| 91精品一区二区三区在线观看| 这里只有精品电影| 久久婷婷成人综合色| 国产精品丝袜91| 亚洲男同性视频| 日本最新不卡在线| 激情综合色播激情啊| 成人福利视频网站| 欧美三片在线视频观看| 天堂午夜影视日韩欧美一区二区| 亚洲国产精品ⅴa在线观看| 日韩欧美亚洲国产另类| 久久久综合视频| 亚洲欧美综合色| 亚洲永久免费av| 精品不卡在线视频| 亚洲一二三四区| 久久久91精品国产一区二区精品| 水蜜桃久久夜色精品一区的特点| 91精品91久久久中77777| 一区二区三区资源| 欧美综合一区二区三区| 亚洲国产欧美在线| 欧美精品 国产精品| 婷婷久久综合九色综合绿巨人| 欧美日韩国产另类一区| 无吗不卡中文字幕| 日韩欧美一区二区久久婷婷| 精品在线观看免费| 久久青草欧美一区二区三区| 成人午夜视频免费看| 亚洲欧洲日产国码二区| 色吊一区二区三区| 丝瓜av网站精品一区二区| 日韩欧美你懂的| 粉嫩久久99精品久久久久久夜| 亚洲欧美一区二区视频| 91精彩视频在线观看| 日韩在线卡一卡二| 国产女同性恋一区二区| av动漫一区二区| 亚洲aaa精品| 精品对白一区国产伦| 国产99久久久国产精品免费看| 国产精品护士白丝一区av| 欧美色爱综合网| 国产一区二区三区综合| 国产精品高清亚洲| 91精品国产黑色紧身裤美女| 国产一区二区视频在线| 日韩一区在线播放| 日韩午夜av电影| 成人av动漫网站| 免费看精品久久片| 国产精品久久毛片a| 91精品啪在线观看国产60岁| 丁香婷婷综合网| 午夜天堂影视香蕉久久| 国产午夜精品在线观看| 欧美在线观看18| 国产不卡一区视频| 婷婷开心久久网| 国产精品妹子av| 欧美一区二区三区性视频| 97成人超碰视| 精品一区二区三区免费播放| 夜夜亚洲天天久久| www国产亚洲精品久久麻豆| 日本精品裸体写真集在线观看 | 欧美日韩日日骚| 国产精品一二三区| 日韩不卡一二三区| 亚洲狠狠丁香婷婷综合久久久| 久久五月婷婷丁香社区| 欧美日韩精品高清| 99久久综合狠狠综合久久| 久久99最新地址| 午夜在线成人av| 亚洲精品欧美专区| 国产精品三级在线观看| 久久色.com| 日韩欧美二区三区| 欧美丰满高潮xxxx喷水动漫| 色妞www精品视频| av毛片久久久久**hd| 国产精品一区在线观看你懂的| 日韩av不卡在线观看| 亚洲综合精品自拍| 亚洲你懂的在线视频| 亚洲欧美在线aaa| 亚洲视频免费在线观看| 国产精品久线在线观看| 中文字幕不卡在线观看| 久久久蜜臀国产一区二区| 久久网这里都是精品| 久久综合99re88久久爱| 精品国产a毛片| 欧美va天堂va视频va在线| 欧美一区在线视频| 91麻豆精品国产91久久久久久 | 91精品国产综合久久精品性色| 色婷婷狠狠综合| 色欲综合视频天天天| 日本高清无吗v一区| 色8久久精品久久久久久蜜| 91在线播放网址| 色婷婷一区二区| 精品视频一区三区九区| 欧美日韩卡一卡二| 欧美一二三在线| 精品国产91乱码一区二区三区 | 美女视频黄 久久| 久久国产剧场电影| 激情六月婷婷综合| 不卡的电视剧免费网站有什么| 成人国产精品免费观看动漫| 99久久精品99国产精品| 91福利在线观看| 欧美一区二区三区视频免费| 欧美va天堂va视频va在线| 久久婷婷综合激情| 一色屋精品亚洲香蕉网站| 亚洲一区在线观看免费观看电影高清 | 亚洲视频综合在线| 亚洲亚洲精品在线观看| 奇米精品一区二区三区四区| 久久激情综合网| 成人av电影免费在线播放| 一本大道久久a久久精二百 | 精品国产1区二区| 国产精品二三区| 亚洲成av人片在线观看无码| 毛片av中文字幕一区二区| 国产大片一区二区| 欧美亚洲一区二区在线| 日韩免费电影网站| 一色屋精品亚洲香蕉网站| 五月婷婷综合网| 国产成人a级片| 欧美少妇一区二区| 亚洲精品在线一区二区| 亚洲激情在线激情| 国产一区二区主播在线| 色综合一区二区三区| 日韩欧美久久一区| 色婷婷综合久色| 精品国产乱码久久久久久1区2区| 亚洲日本丝袜连裤袜办公室| 毛片av一区二区| 欧洲人成人精品| 中文字幕精品三区| 麻豆91在线观看| 欧美视频中文一区二区三区在线观看| 2023国产精品视频| 性做久久久久久免费观看| 成人免费看视频| 精品国免费一区二区三区| 一区二区三区成人| 99这里都是精品| 久久九九国产精品| 美女诱惑一区二区| 欧美亚洲日本一区| 亚洲男同1069视频| 白白色亚洲国产精品| 久久久精品免费观看| 美女任你摸久久 | 欧美一二三区精品| 亚洲综合久久久久| 99久久精品免费| 成人欧美一区二区三区| 国产丶欧美丶日本不卡视频| 精品久久久三级丝袜| 免费在线成人网| 欧美一区二区三区啪啪| 午夜影院在线观看欧美| 欧美少妇xxx| 亚洲综合在线第一页| 91看片淫黄大片一级| 亚洲女人的天堂| 色嗨嗨av一区二区三区| 国产精品毛片高清在线完整版| 国产一区999| 国产视频亚洲色图| 国产999精品久久久久久绿帽| 精品国精品国产尤物美女| 极品销魂美女一区二区三区|