Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/AbstractBuffer.java @ 1010:2712133d5bce
simplify Buffer code
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 23 Oct 2016 22:23:50 -0600 |
parents | 0e96ce3db20a |
children | f126d30e04a4 |
comparison
equal
deleted
inserted
replaced
1009:c3a04bded909 | 1010:2712133d5bce |
---|---|
90 return new ByteArrayBuffer.CaseInsensitive(asArray(), 0, length(),access); | 90 return new ByteArrayBuffer.CaseInsensitive(asArray(), 0, length(),access); |
91 else | 91 else |
92 return new ByteArrayBuffer(asArray(), 0, length(), access); | 92 return new ByteArrayBuffer(asArray(), 0, length(), access); |
93 } | 93 } |
94 | 94 |
95 /* | |
96 * @see org.eclipse.io.Buffer#asNonVolatile() | |
97 */ | |
98 public Buffer asNonVolatileBuffer() | |
99 { | |
100 if (!isVolatile()) return this; | |
101 return duplicate(_access); | |
102 } | |
103 | |
104 public Buffer asImmutableBuffer() | 95 public Buffer asImmutableBuffer() |
105 { | 96 { |
106 if (isImmutable()) return this; | 97 if (isImmutable()) return this; |
107 return duplicate(IMMUTABLE); | 98 return duplicate(IMMUTABLE); |
108 } | 99 } |
112 */ | 103 */ |
113 public Buffer asReadOnlyBuffer() | 104 public Buffer asReadOnlyBuffer() |
114 { | 105 { |
115 if (isReadOnly()) return this; | 106 if (isReadOnly()) return this; |
116 return new View(this, markIndex(), getIndex(), putIndex(), READONLY); | 107 return new View(this, markIndex(), getIndex(), putIndex(), READONLY); |
117 } | |
118 | |
119 public Buffer asMutableBuffer() | |
120 { | |
121 if (!isImmutable()) return this; | |
122 | |
123 Buffer b=this.buffer(); | |
124 if (b.isReadOnly()) | |
125 { | |
126 return duplicate(READWRITE); | |
127 } | |
128 return new View(b, markIndex(), getIndex(), putIndex(), _access); | |
129 } | 108 } |
130 | 109 |
131 public Buffer buffer() | 110 public Buffer buffer() |
132 { | 111 { |
133 return this; | 112 return this; |
667 { | 646 { |
668 return getClass()+"@"+super.hashCode(); | 647 return getClass()+"@"+super.hashCode(); |
669 } | 648 } |
670 | 649 |
671 /* ------------------------------------------------------------ */ | 650 /* ------------------------------------------------------------ */ |
672 public void writeTo(OutputStream out) | |
673 throws IOException | |
674 { | |
675 byte[] array = array(); | |
676 | |
677 if (array!=null) | |
678 { | |
679 out.write(array,getIndex(),length()); | |
680 } | |
681 else | |
682 { | |
683 int len = this.length(); | |
684 byte[] buf=new byte[len>1024?1024:len]; | |
685 int offset=_get; | |
686 while (len>0) | |
687 { | |
688 int l=peek(offset,buf,0,len>buf.length?buf.length:len); | |
689 out.write(buf,0,l); | |
690 offset+=l; | |
691 len-=l; | |
692 } | |
693 } | |
694 clear(); | |
695 } | |
696 | |
697 /* ------------------------------------------------------------ */ | |
698 public int readFrom(InputStream in,int max) throws IOException | 651 public int readFrom(InputStream in,int max) throws IOException |
699 { | 652 { |
700 byte[] array = array(); | 653 byte[] array = array(); |
701 int s=space(); | 654 int s=space(); |
702 if (s>max) | 655 if (s>max) |