FileDocCategorySizeDatePackage
NdrBuffer.javaAPI DocJCIFS 1.3.17 API6461Tue Oct 18 15:26:24 BST 2011jcifs.dcerpc.ndr

NdrBuffer

public class NdrBuffer extends Object

Fields Summary
int
referent
HashMap
referents
public byte[]
buf
public int
start
public int
index
public int
length
public NdrBuffer
deferred
Constructors Summary
public NdrBuffer(byte[] buf, int start)

        this.buf = buf;
        this.start = index = start;
        length = 0;
        deferred = this;
    
Methods Summary
public voidadvance(int n)

        index += n;
        if ((index - start) > deferred.length) {
            deferred.length = index - start;
        }
    
public intalign(int boundary)

        int m = boundary - 1;
        int i = index - start;
        int n = ((i + m) & ~m) - i;
        advance(n);
        return n;
    
public intalign(int boundary, byte value)

        int n = align(boundary);
        int i = n;
        while (i > 0) {
            buf[index - i] = value;
            i--;
        }
        return n;
    
public longdec_ndr_hyper()

        align(8);
        long val = Encdec.dec_uint64le(buf, index);
        advance(8);
        return val;
    
public intdec_ndr_long()

        align(4);
        int val = Encdec.dec_uint32le(buf, index);
        advance(4);
        return val;
    
public intdec_ndr_short()

        align(2);
        int val = Encdec.dec_uint16le(buf, index);
        advance(2);
        return val;
    
public intdec_ndr_small()

        int val = buf[index] & 0xFF;
        advance(1);
        return val;
    
public java.lang.Stringdec_ndr_string()

        align(4);
        int i = index;
        String val = null;
        int len = Encdec.dec_uint32le(buf, i);
        i += 12;
        if (len != 0) {
            len--;
            int size = len * 2;
            try {
                if (size < 0 || size > 0xFFFF) throw new NdrException( NdrException.INVALID_CONFORMANCE );
                val = new String(buf, i, size, "UTF-16LE");
                i += size + 2;
            } catch( UnsupportedEncodingException uee ) {
            }
        }
        advance(i - index);
        return val;
    
public jcifs.dcerpc.ndr.NdrBufferderive(int idx)

        NdrBuffer nb = new NdrBuffer(buf, start);
        nb.index = idx;
        nb.deferred = deferred;
        return nb;
    
public voidenc_ndr_hyper(long h)

        align(8);
        Encdec.enc_uint64le(h, buf, index);
        advance(8);
    
public voidenc_ndr_long(int l)

        align(4);
        Encdec.enc_uint32le(l, buf, index);
        advance(4);
    
public voidenc_ndr_referent(java.lang.Object obj, int type)

        if (obj == null) {
            enc_ndr_long(0);
            return;
        }
        switch (type) {
            case 1: /* unique */
            case 3: /* ref */
                enc_ndr_long(System.identityHashCode(obj));
                return;
            case 2: /* ptr */
                enc_ndr_long(getDceReferent(obj));
                return;
        }
    
public voidenc_ndr_short(int s)

        align(2);
        Encdec.enc_uint16le((short)s, buf, index);
        advance(2);
    
public voidenc_ndr_small(int s)

        buf[index] = (byte)(s & 0xFF);
        advance(1);
    
public voidenc_ndr_string(java.lang.String s)

        align(4);
        int i = index;
        int len = s.length();
        Encdec.enc_uint32le(len + 1, buf, i); i += 4;
        Encdec.enc_uint32le(0, buf, i); i += 4;
        Encdec.enc_uint32le(len + 1, buf, i); i += 4;
        try {
            System.arraycopy(s.getBytes("UTF-16LE"), 0, buf, i, len * 2);
        } catch( UnsupportedEncodingException uee ) {
        }
        i += len * 2;
        buf[i++] = (byte)'\0";
        buf[i++] = (byte)'\0";
        advance(i - index);
    
public byte[]getBuffer()

        return buf;
    
public intgetCapacity()

        return buf.length - start;
    
private intgetDceReferent(java.lang.Object obj)

        Entry e;

        if (referents == null) {
            referents = new HashMap();
            referent = 1;
        }

        if ((e = (Entry)referents.get(obj)) == null) {
            e = new Entry();
            e.referent = referent++;
            e.obj = obj;
            referents.put(obj, e);
        }

        return e.referent;
    
public intgetIndex()

        return index;
    
public intgetLength()

        return deferred.length;
    
public intgetTailSpace()

        return buf.length - index;
    
public voidreadOctetArray(byte[] b, int i, int l)

        System.arraycopy(buf, index, b, i, l);
        advance(l);
    
public voidreset()

        this.index = start;
        length = 0;
        deferred = this;
    
public voidsetIndex(int index)

        this.index = index;
    
public voidsetLength(int length)

        deferred.length = length;
    
public java.lang.StringtoString()

        return "start=" + start + ",index=" + index + ",length=" + getLength();
    
public voidwriteOctetArray(byte[] b, int i, int l)

        System.arraycopy(b, i, buf, index, l);
        advance(l);