1 18 19 package com.martiansoftware.nailgun; 20 21 import java.io.IOException ; 22 23 33 class NGOutputStream extends java.io.FilterOutputStream { 34 35 private byte[] header; 36 37 44 public NGOutputStream(java.io.OutputStream out, char code) { 45 super(out); 46 header = new byte[5]; 47 header[4] = (byte) code; 48 } 49 50 53 public void write(byte[] b) throws IOException { 54 write(b, 0, b.length); 55 } 56 57 60 public void write(int b) throws IOException { 61 byte[] b2 = {(byte) b}; 62 write(b2, 0, 1); 63 } 64 65 68 public void write(byte[] b, int offset, int len) throws IOException { 69 LongUtils.toArray(len, header, 0); 70 synchronized(out) { 71 out.write(header, 0, 5); 72 out.write(b, offset, len); 73 } 74 out.flush(); 75 } 76 } 77 | Popular Tags |