Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add some additional encoding-aware constructors and bump version to 1…

….0.2.
  • Loading branch information...
commit bd21b807b11ef1a7172114795871b59118289330 1 parent 50b7398
Charles Oliver Nutter headius authored

Showing 2 changed files with 32 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 build.xml
  2. +30 0 src/org/jruby/util/ByteList.java
4 build.xml
@@ -41,7 +41,7 @@
41 41 </target>
42 42
43 43 <target name="jar" depends="test" description="Create the bytelist.jar file">
44   - <jar destfile="lib/bytelist-1.0.1.jar">
  44 + <jar destfile="lib/bytelist-1.0.2.jar">
45 45 <fileset dir="build/classes">
46 46 <include name="**/*.class"/>
47 47 <include name="**/*.properties"/>
@@ -54,6 +54,6 @@
54 54
55 55 <target name="clean" depends="init" description="clean everything">
56 56 <delete dir="build"/>
57   - <delete file="lib/bytelist-1.0.1.jar" quiet="true"/>
  57 + <delete file="lib/bytelist-1.0.2.jar" quiet="true"/>
58 58 </target>
59 59 </project>
30 src/org/jruby/util/ByteList.java
@@ -129,6 +129,19 @@ public ByteList(byte[] wrap) {
129 129 * @param copy whether to arraycopy wrap for the backing store or not
130 130 */
131 131 public ByteList(byte[] wrap, boolean copy) {
  132 + this(wrap, ASCIIEncoding.INSTANCE, copy);
  133 + }
  134 +
  135 + /**
  136 + * Create a new instance of ByteList with the contents of wrap. If copy is true then it will
  137 + * array copy the contents. Otherwise it will use the byte array passed in as its initial
  138 + * backing store.
  139 + *
  140 + * @param wrap the initial bytes for this ByteList
  141 + * @param encoding the encoding for the bytes
  142 + * @param copy whether to arraycopy wrap for the backing store or not
  143 + */
  144 + public ByteList(byte[] wrap, Encoding encoding, boolean copy) {
132 145 assert wrap != null;
133 146 if (copy) {
134 147 bytes = (byte[])wrap.clone();
@@ -188,10 +201,26 @@ public ByteList(byte[] wrap, int index, int len) {
188 201 * @param wrap the bytes to use
189 202 * @param index where in the bytes the data starts
190 203 * @param len how long the data is in the wrap array
  204 + * @param encoding the encoding of the bytes
191 205 * @param copy if true array copy wrap. otherwise use as backing store
192 206 */
193 207 // FIXME: Fix the index != 0 not honoring copy and separate out into a different caller. JRuby.next would be the right time for this.
194 208 public ByteList(byte[] wrap, int index, int len, boolean copy) {
  209 + this(wrap, index, len, ASCIIEncoding.INSTANCE, copy);
  210 + }
  211 +
  212 + /**
  213 + * Create a new instance of ByteList using wrap as a backing store where index is the first
  214 + * index in the byte array where the data starts and len indicates how long the data portion
  215 + * of the bytelist is. wrap will be array copied if copy is true OR if index != 0.
  216 + *
  217 + * @param wrap the bytes to use
  218 + * @param index where in the bytes the data starts
  219 + * @param len how long the data is in the wrap array
  220 + * @param copy if true array copy wrap. otherwise use as backing store
  221 + */
  222 + // FIXME: Fix the index != 0 not honoring copy and separate out into a different caller. JRuby.next would be the right time for this.
  223 + public ByteList(byte[] wrap, int index, int len, Encoding encoding, boolean copy) {
195 224 assert wrap != null : "'wrap' must not be null";
196 225 assert index >= 0 && index <= wrap.length : "'index' is not without bounds of 'wrap' array";
197 226 assert wrap.length >= index + len : "'index' + 'len' is longer than the 'wrap' array";
@@ -203,6 +232,7 @@ public ByteList(byte[] wrap, int index, int len, boolean copy) {
203 232 bytes = wrap;
204 233 }
205 234 realSize = len;
  235 + this.encoding = encoding;
206 236 }
207 237
208 238 /**

0 comments on commit bd21b80

Please sign in to comment.
Something went wrong with that request. Please try again.