obexmanager.java

来自「GPS Track connects to a GPS and records 」· Java 代码 · 共 45 行

JAVA
45
字号
// J2ME GPS Track
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/gpstrack

package org.qcontinuum.gpstrack;

import java.io.*;
import javax.microedition.io.*;
import javax.obex.*;

// optional package wrapper class
// technique described in Chapter 8 of JSR 248

public class ObexManager implements ObexUsage {
    
    ClientSession mClientSession = null;
    Operation mOperation = null;

    public ObexManager() {
    }
    
    public DataOutputStream open(String url, String filename) throws IOException {
        try {
            mClientSession = (ClientSession)Connector.open(url);
        } catch (ConnectionNotFoundException ex) {
            mClientSession = (ClientSession)de.avetana.obexsolo.OBEXConnector.open(url);
        }
        HeaderSet headerSet = mClientSession.connect(mClientSession.createHeaderSet());
        headerSet.setHeader(HeaderSet.NAME, filename);
        headerSet.setHeader(HeaderSet.TYPE, "text");
        mOperation = mClientSession.put(headerSet);
        return mOperation.openDataOutputStream();
    }
    
    public void close() throws IOException {
        if (mOperation != null)
            mOperation.close();
        if (mClientSession != null) {
            mClientSession.disconnect(null);
            mClientSession.close();
        }
    }

}

⌨️ 快捷键说明

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