RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
ResourceProcessor.java
1/*
2 * Copyright (c) 2013 Creative Sphere Limited.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing,
9 * software distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 *
14 * Contributors:
15 *
16 * Creative Sphere - initial API and implementation
17 *
18 */
19package org.ah.java.remotevmlauncher.protocol;
20
21import java.io.DataInputStream;
22import java.io.DataOutputStream;
23import java.io.IOException;
24import java.io.InputStream;
25
26
32public class ResourceProcessor extends AbstractProcessor {
33
34 public static final String ID = "R!";
35
36 public ResourceProcessor() {
37 super(ID);
38 }
39
40 public void receive(DataInputStream dis) throws IOException {
41 int size = dis.readInt();
42 loadResource(dis, size);
43 }
44
45 public void loadResource(DataInputStream dis, int size) throws IOException {
46 }
47
48 public void send(DataOutputStream dos, InputStream is, int size) throws IOException {
49 dos.writeUTF(getId());
50 dos.writeInt(size);
51 if (size > 0) {
52 byte[] buffer = new byte[10240];
53 while (size > 0) {
54 int s = size;
55 if (s > buffer.length) { s = buffer.length; }
56 int r = is.read(buffer, 0, s);
57 if (r <= 0) {
58 size = 0;
59 } else {
60 size = size - r;
61 }
62 dos.write(buffer, 0, r);
63 }
64 }
65 dos.flush();
66 }
67}