I am writing the bytes onto the socket in the beloew fasion to avaoid

problem with byte stuffing with 0x7e and 0x7d

if u look at the code below. I have a byte array and a buffer buf.

the buffer has a length of 3.

i need to add 0x7e before and after the length of the buffer...

lets say if the buffer has 01 01 01 ..it should be sent as 0x7e 01 01 01


so in the code below I am first writing 0x7e

then I am iterating over each element in the buffer and doing some

processing and wring the individual elements...

at the end os iteration I am writing the last 0x7e

hence on the socket I want the out put to be 0x7e 01 01 01 0x7e

but the problem is

first it is writing 0x7e just as 1 byte

and after that it is writing the rest of the 4 bytes 01 01 01 0x7e

thats a problem.....

as it is only when the server gets the info as 0x7e 01 01 01 0x7e it can

understand as a bind request but as it is getting data in two sections

i.e first 0x7e and after that the rest of the 4 bytes...

it is not able to interpret it to be as a bind request and rejecting the


so what I am doing is I am loading the buffer value into a locally created
array list and then moving the values of the arraylist into another byte
array and then writing the byte array atonce onto the stream...

when I am printing the values from the arraylist it is printing correctly

similarly when I am printing values from the byte array b1 after moving the
values from the arraylist a1 then also it is printing the correct values..but
when I am writing the same byte array b1 on to the socket the server is getting
4 null values for 1st 4 byte and the last one correctly.....I think its bit
a confusing...but if U are able to follow something then just help me..otherwise
I will try by myself....

protected void writePDU(OutputStream os, PDUBuffer buf) throws IOException,
ProtocolException {
byte[] b = buf.getBytes();
byte[] b1 = new byte[5];
ArrayList a = new ArrayList();
Integer frameChar = new Integer(0x7e);
Integer escapeChar = new Integer(0x7d);
Integer xor7e = new Integer(0x5e);
Integer xor7d = new Integer(0x5d);
for (int i = 0; i < buf.getLength(); i++) {
int txChar = b[i];
if (txChar == 0x7d) {
} else if (txChar == 0x7e) {
} else {
a.add(new Integer(txChar));
for (int i=0; i < a.size(); i++) {
int k = ((Integer) a.get(i)).intValue();
b1 = new byte[a.size()];
b1[i] = (byte)k;
if I am printing the values here i prints the write values for b1[i]
leys say like 126,1,1,1,126
but when writing onto the stearm it writes 00,00,00,00,126 ...
I have no idea why this is happening......