⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractbuffer.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public byte peek()    {        return peek(_get);    }    public Buffer peek(int index, int length)    {        if (_view == null)        {            _view = new View(this, -1, index, index + length, isReadOnly() ? READONLY : READWRITE);        }        else        {            _view.update(this.buffer());            _view.setMarkIndex(-1);            _view.setGetIndex(0);            _view.setPutIndex(index + length);            _view.setGetIndex(index);                    }        return _view;    }    public int poke(int index, Buffer src)    {        _hash=0;        /*         if (isReadOnly())             throw new IllegalStateException(__READONLY);        if (index < 0)             throw new IllegalArgumentException("index<0: " + index + "<0");        */                int length=src.length();        if (index + length > capacity())        {            length=capacity()-index;            /*            if (length<0)                throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());            */        }                byte[] src_array = src.array();        byte[] dst_array = array();        if (src_array != null && dst_array != null)            Portable.arraycopy(src_array, src.getIndex(), dst_array, index, length);        else if (src_array != null)        {            int s=src.getIndex();            for (int i=0;i<length;i++)                poke(index++,src_array[s++]);        }        else if (dst_array != null)        {            int s=src.getIndex();            for (int i=0;i<length;i++)                dst_array[index++]=src.peek(s++);        }        else        {            int s=src.getIndex();            for (int i=0;i<length;i++)                poke(index++,src.peek(s++));        }                return length;    }        public int poke(int index, byte[] b, int offset, int length)    {        _hash=0;        /*        if (isReadOnly())             throw new IllegalStateException(__READONLY);        if (index < 0)             throw new IllegalArgumentException("index<0: " + index + "<0");        */        if (index + length > capacity())        {            length=capacity()-index;            /* if (length<0)                throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());            */        }                byte[] dst_array = array();        if (dst_array != null)            Portable.arraycopy(b, offset, dst_array, index, length);        else        {            int s=offset;            for (int i=0;i<length;i++)                poke(index++,b[s++]);        }        return length;    }    public int put(Buffer src)    {        int pi = putIndex();        int l=poke(pi, src);        setPutIndex(pi + l);        return l;    }    public void put(byte b)    {        int pi = putIndex();        poke(pi, b);        setPutIndex(pi + 1);    }    public int put(byte[] b, int offset, int length)    {        int pi = putIndex();        int l = poke(pi, b, offset, length);        setPutIndex(pi + l);        return l;    }        public int put(byte[] b)    {        int pi = putIndex();        int l = poke(pi, b, 0, b.length);        setPutIndex(pi + l);        return l;    }    public final int putIndex()    {        return _put;    }    public void reset()    {        if (markIndex() >= 0) setGetIndex(markIndex());    }    public void rewind()    {        setGetIndex(0);        setMarkIndex(-1);    }    public void setGetIndex(int getIndex)    {        /* bounds checking        if (isImmutable())             throw new IllegalStateException(__IMMUTABLE);        if (getIndex < 0)            throw new IllegalArgumentException("getIndex<0: " + getIndex + "<0");        if (getIndex > putIndex())            throw new IllegalArgumentException("getIndex>putIndex: " + getIndex + ">" + putIndex());         */        _get = getIndex;        _hash=0;    }    public void setMarkIndex(int index)    {        /*        if (index>=0 && isImmutable())             throw new IllegalStateException(__IMMUTABLE);        */        _mark = index;    }    public void setPutIndex(int putIndex)    {        /* bounds checking        if (isImmutable())             throw new IllegalStateException(__IMMUTABLE);        if (putIndex > capacity())                throw new IllegalArgumentException("putIndex>capacity: " + putIndex + ">" + capacity());        if (getIndex() > putIndex)                throw new IllegalArgumentException("getIndex>putIndex: " + getIndex() + ">" + putIndex);         */        _put = putIndex;        _hash=0;    }    public int skip(int n)    {        if (length() < n) n = length();        setGetIndex(getIndex() + n);        return n;    }    public Buffer slice()    {        return peek(getIndex(), length());    }    public Buffer sliceFromMark()    {        return sliceFromMark(getIndex() - markIndex() - 1);    }    public Buffer sliceFromMark(int length)    {        if (markIndex() < 0) return null;        Buffer view = peek(markIndex(), length);        setMarkIndex(-1);        return view;    }    public int space()    {        return capacity() - _put;    }    public String toDetailString()    {        StringBuffer buf = new StringBuffer();        buf.append("[");        buf.append(super.hashCode());        buf.append(",");        buf.append(this.array().hashCode());        buf.append(",m=");        buf.append(markIndex());        buf.append(",g=");        buf.append(getIndex());        buf.append(",p=");        buf.append(putIndex());        buf.append(",c=");        buf.append(capacity());        buf.append("]={");        if (markIndex() >= 0)        {            for (int i = markIndex(); i < getIndex(); i++)            {                char c = (char) peek(i);                if (Character.isISOControl(c))                {                    buf.append(c < 16 ? "\\0" : "\\");                    buf.append(Integer.toString(c, 16));                }                else                    buf.append(c);            }            buf.append("}{");        }        int count = 0;        for (int i = getIndex(); i < putIndex(); i++)        {            char c = (char) peek(i);            if (Character.isISOControl(c))            {                buf.append(c < 16 ? "\\0" : "\\");                buf.append(Integer.toString(c, 16));            }            else                buf.append(c);            if (count++ == 50)            {                if (putIndex() - i > 20)                {                    buf.append(" ... ");                    i = putIndex() - 20;                }            }        }        buf.append('}');        return buf.toString();    }    /* ------------------------------------------------------------ */    public String toString()    {        if (isImmutable())        {            if (_string == null)                 _string = new String(asArray(), 0, length());            return _string;        }        return new String(asArray(), 0, length());    }    /* ------------------------------------------------------------ */    public String toDebugString()    {        return getClass()+"@"+super.hashCode();    }    /* ------------------------------------------------------------ */    public void writeTo(OutputStream out)    	throws IOException    {        byte[] array = array();                if (array!=null)        {            out.write(array,getIndex(),length());        }        else        {            int len = this.length();            byte[] buf=new byte[len>1024?1024:len];            int offset=_get;            while (len>0)            {                int l=peek(offset,buf,0,len>buf.length?buf.length:len);                out.write(buf,0,l);                offset+=l;                len-=l;            }        }         clear();    }        /* ------------------------------------------------------------ */    public int readFrom(InputStream in,int max) throws IOException    {        byte[] array = array();        int s=space();        if (s>max)            s=max;        if (array!=null)        {            int l=in.read(array,_put,s);            if (l>0)                _put+=l;            return l;        }        else        {            byte[] buf=new byte[s>1024?1024:s];            int total=0;            while (s>0)            {                int l=in.read(buf,0,buf.length);                if (l<0)                    return total>0?total:-1;                int p=put(buf,0,l);                assert l==p;                s-=l;            }            return total;         }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -