My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2008-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 net.sf.bluecove.obex;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;

/**
*
*
*/
public class Deploy implements UserInteraction {

private String fileName;

private int progressMaximum;

public static void main(String[] args) {
if ((args.length < 2) || args[0].equalsIgnoreCase("--help")) {
StringBuffer usage = new StringBuffer();
usage.append("Usage:\n java ").append(Deploy.class.getName());
usage.append(" bluetoothURL yourApp.jar\n");
System.out.println(usage);
System.exit(1);
return;
}
String obexUrl = args[0];

String filePath = args[1];

Logger.debugOn = false;
Deploy d = new Deploy();
byte[] data = d.readFile(filePath);
if (data == null) {
System.exit(1);
return;
}
ObexBluetoothClient o = new ObexBluetoothClient(d, d.fileName, data);
if (o.obexPut(obexUrl)) {
System.exit(0);
} else {
System.exit(2);
}
}

private Deploy() {
}

private static String simpleFileName(String filePath) {
int idx = filePath.lastIndexOf('/');
if (idx == -1) {
idx = filePath.lastIndexOf('\\');
}
if (idx == -1) {
return filePath;
}
return filePath.substring(idx + 1);
}

private byte[] readFile(final String filePath) {
InputStream is = null;
byte[] data = null;
try {
String path = filePath;
String inputFileName;
File file = new File(filePath);
if (file.exists()) {
is = new FileInputStream(file);
inputFileName = file.getName();
} else {
URL url = new URL(path);
is = url.openConnection().getInputStream();
inputFileName = url.getFile();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[0xFF];
int i = is.read(buffer);
int done = 0;
while (i != -1) {
bos.write(buffer, 0, i);
done += i;
// setProgressValue(done);
i = is.read(buffer);
}
data = bos.toByteArray();
fileName = simpleFileName(inputFileName);
showStatus((data.length / 1024) + "k " + fileName);
} catch (Throwable e) {
Logger.error(e);
showStatus("Download error " + e.getMessage());
} finally {
IOUtils.closeQuietly(is);
}
return data;
}

/*
* (non-Javadoc)
*
* @see net.sf.bluecove.obex.UserInteraction#setProgressMaximum(int)
*/
public void setProgressMaximum(int n) {
progressMaximum = n;
}

/*
* (non-Javadoc)
*
* @see net.sf.bluecove.obex.UserInteraction#setProgressValue(int)
*/
public void setProgressValue(int n) {
// TODO Auto-generated method stub

}

/*
* (non-Javadoc)
*
* @see net.sf.bluecove.obex.UserInteraction#setProgressDone()
*/
public void setProgressDone() {
// TODO Auto-generated method stub
}

/*
* (non-Javadoc)
*
* @see net.sf.bluecove.obex.UserInteraction#showStatus(java.lang.String)
*/
public void showStatus(String message) {
System.out.println(message);
}

}

Change log

r2916 by skarzhevskyy on Mar 13, 2009   Diff
Updated javadocs and Copyright
Go to: 
Project members, sign in to write a code review

Older revisions

r2476 by skarzhevskyy on Dec 1, 2008   Diff
Correction to headers
r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
r2408 by skarzhevskyy on Oct 9, 2008   Diff
organize product to modules
All revisions of this file

File info

Size: 3882 bytes, 159 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Author Id Revision
Powered by Google Project Hosting