~hudson-ubuntu/+junk/windows-remote-command

« back to all changes in this revision

Viewing changes to src/main/java/org/jvnet/hudson/remcom/Payload.java

  • Committer: James Page
  • Date: 2010-12-06 10:47:32 UTC
  • Revision ID: james.page@canonical.com-20101206104732-nctfskg5ky3vinf4
Initial release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jvnet.hudson.remcom;
 
2
 
 
3
import java.io.DataInputStream;
 
4
import java.io.IOException;
 
5
import java.io.OutputStream;
 
6
 
 
7
/**
 
8
 * @author Kohsuke Kawaguchi
 
9
 */
 
10
class Payload extends Packet {
 
11
    public static Object/*byte[] or RemComResponse*/ read(DataInputStream in) throws IOException {
 
12
        byte[] len = new byte[4];
 
13
        in.readFully(len);
 
14
        int size = readInt(len,0);
 
15
 
 
16
        if (size==0) {
 
17
            // EOF from the service
 
18
            return new RemComResponse(in);
 
19
        }
 
20
 
 
21
        if (size<0)
 
22
            throw new IllegalArgumentException("Negative: "+size);
 
23
        byte[] buf = new byte[size];
 
24
        in.readFully(buf);
 
25
 
 
26
        return buf;
 
27
    }
 
28
    
 
29
    public static void write(byte[] data, int offset, int len, OutputStream dst) throws IOException {
 
30
        byte[] pack = new byte[len+4];
 
31
        setIntAt(len, pack, 0); // len
 
32
        System.arraycopy(data,offset, pack, 4, len);
 
33
        dst.write(pack);
 
34
    }
 
35
}