/** * BlueCove - Java library for Bluetooth * Copyright (C) 2006-2009 Vlad Skarzhevskyy * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * @author vlads * @version $Id$ */ package com.intel.bluetooth.javadoc; import java.io.IOException; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.obex.*; /** * * Minimal OBEX Put Client example for javadoc. */ public class ObexPutClient { public static void main(String[] args) throws IOException, InterruptedException { String serverURL; if ((args != null) && (args.length > 0)) { serverURL = args[0]; } else { String[] searchArgs = null; // Connect to OBEXPutServer from examples // searchArgs = new String[] { "11111111111111111111111111111123" }; ServicesSearch.main(searchArgs); if (ServicesSearch.serviceFound.size() == 0) { System.out.println("OBEX service not found"); return; } // Select the first service found serverURL = (String)ServicesSearch.serviceFound.elementAt(0); } System.out.println("Connecting to " + serverURL); ClientSession clientSession = (ClientSession) Connector.open(serverURL); HeaderSet hsConnectReply = clientSession.connect(null); if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) { System.out.println("Failed to connect"); return; } HeaderSet hsOperation = clientSession.createHeaderSet(); hsOperation.setHeader(HeaderSet.NAME, "Hello.txt"); hsOperation.setHeader(HeaderSet.TYPE, "text"); //Create PUT Operation Operation putOperation = clientSession.put(hsOperation); // Send some text to server byte data[] = "Hello world!".getBytes("iso-8859-1"); OutputStream os = putOperation.openOutputStream(); os.write(data); os.close(); putOperation.close(); clientSession.disconnect(null); clientSession.close(); } }