RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
CacheResponseProcessor.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.util.ArrayList;
25import java.util.List;
26
27
33public class CacheResponseProcessor extends AbstractProcessor {
34
35 public static final String ID = "CR";
36
37 private List<ResourceResponse> resources = new ArrayList<ResourceResponse>();
38
39 public CacheResponseProcessor() {
40 super(ID);
41 }
42
43 public List<ResourceResponse> getResources() {
44 return resources;
45 }
46
47 public void receive(DataInputStream dis) throws IOException {
48 resources.clear();
49 int size = dis.readInt();
50 for (int i = 0; i < size; i++) {
51 long hash = dis.readLong();
52 long length = dis.readLong();
53 String pathId = dis.readUTF();
54 String name = dis.readUTF();
55 ResourceResponse rr = new ResourceResponse();
56 rr.hash = hash;
57 rr.length = length;
58 rr.pathId = pathId;
59 rr.name = name;
60 resources.add(rr);
61 }
62
63 synchronized (this) {
64 notifyAll();
65 }
66 }
67
68 public void send(DataOutputStream dos) throws IOException {
69 dos.writeUTF(ID);
70 dos.writeInt(resources.size());
71 for (ResourceResponse rr : resources) {
72 dos.writeLong(rr.hash);
73 dos.writeLong(rr.length);
74 dos.writeUTF(rr.pathId);
75 dos.writeUTF(rr.name);
76 }
77 dos.flush();
78 }
79
80 public static class ResourceResponse {
81 public String pathId;
82 public String name;
83 public long hash;
84 public long length;
85
86 public String toString() {
87 return "Resource[" + pathId + "," + name + "," + Long.toHexString(hash) + "," + Long.toString(length) + "]";
88 }
89 }
90}