MCPcopy Create free account
hub / github.com/jetlang/remoting / ByteArrayBuffer

Class ByteArrayBuffer

src/main/java/org/jetlang/remote/core/ByteArrayBuffer.java:11–63  ·  view source on GitHub ↗

User: mrettig Date: 4/27/11 Time: 10:36 AM

Source from the content-addressed store, hash-verified

9 * Time: 10:36 AM
10 */
11public class ByteArrayBuffer {
12
13 protected byte[] buffer = new byte[1024];
14 protected int position;
15
16 public void reset() {
17 position = 0;
18 }
19
20 public void appendIntAsByte(int msgType) {
21 resize(1);
22 buffer[position++] = (byte) msgType;
23 }
24
25 private void resize(int i) {
26 if (position + i >= buffer.length) {
27 byte[] newBuffer = new byte[buffer.length + i];
28 System.arraycopy(buffer, 0, newBuffer, 0, position);
29 buffer = newBuffer;
30 afterResize();
31 }
32 }
33
34 protected void afterResize() {
35
36 }
37
38 public void appendInt(int v) {
39 appendIntAsByte((v >>> 24) & 0xFF);
40 appendIntAsByte((v >>> 16) & 0xFF);
41 appendIntAsByte((v >>> 8) & 0xFF);
42 appendIntAsByte((v >>> 0) & 0xFF);
43 }
44
45 public void append(byte[] bytes, int offset, int length) {
46 resize(length);
47 System.arraycopy(bytes, offset, buffer, position, length);
48 position += length;
49 }
50
51 public void append(byte[] bytes) {
52 append(bytes, 0, bytes.length);
53 }
54
55 public void flushTo(OutputStream socketOutputStream) throws IOException {
56 try {
57 socketOutputStream.write(buffer, 0, position);
58 } finally {
59 position = 0;
60 }
61 }
62
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…